Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [v2.1.2] - 2026-11-17

- Fix: use general goal binding when a form has no goal binding (V2 suppliers)

## [v2.1.1] - 2026-10-27

- Added: make log directory configurable to keep log files outside the webroot
Expand Down
4 changes: 2 additions & 2 deletions prefill-gravity-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Yard | BRP Prefill GravityForms
* Plugin URI: https://www.openwebconcept.nl/
* Description: Prefill GravityForms fields, based on a (Dutch) BSN number. Retrieve personal information and place these values in the corresponding fields.
* Version: 2.1.1
* Version: 2.1.2
* Author: Yard | Digital Agency
* Author URI: https://www.yard.nl/
* License: EUPL-1.2
Expand All @@ -21,7 +21,7 @@
die;
}

define('PG_VERSION', '2.1.1');
define('PG_VERSION', '2.1.2');
define('PG_DIR', basename(__DIR__));
define('PG_ROOT_PATH', __DIR__);
define('PG_PLUGIN_SLUG', 'prefill-gravity-forms');
Expand Down
8 changes: 8 additions & 0 deletions src/PrefillGravityForms/Abstracts/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ abstract class PostController extends BaseController
{
protected const BRP_API_VERSION = '2';

/**
* Returns the goal binding of the form, falls back to the general goal binding of the plugin settings.
*/
protected function getGoalBinding(array $form): string
{
return rgar($form, 'owc-iconnect-doelbinding', '') ?: $this->settings->getGoalBinding();
}

/**
* Filters deceased persons from the given embedded relation collection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle(array $form): array
return $form;
}

$goalBinding = rgar($form, 'owc-iconnect-doelbinding', '');
$goalBinding = $this->getGoalBinding($form);
$processing = rgar($form, 'owc-iconnect-processing', '') ?: $this->settings->getProcessing();
$expand = rgar($form, 'owc-iconnect-expand', '');
$excludeDeceased = (bool) rgar($form, 'owc-iconnect-exclude-deceased', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle(array $form): array
return $form;
}

$goalBinding = rgar($form, 'owc-iconnect-doelbinding', '');
$goalBinding = $this->getGoalBinding($form);
$processing = rgar($form, 'owc-iconnect-processing', '') ?: $this->settings->getProcessing();
$expand = rgar($form, 'owc-iconnect-expand', '');
$excludeDeceased = (bool) rgar($form, 'owc-iconnect-exclude-deceased', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle(array $form): array
return $form;
}

$goalBinding = rgar($form, 'owc-iconnect-doelbinding', '');
$goalBinding = $this->getGoalBinding($form);
$processing = rgar($form, 'owc-iconnect-processing', '') ?: $this->settings->getProcessing();
$expand = rgar($form, 'owc-iconnect-expand', '');
$excludeDeceased = (bool) rgar($form, 'owc-iconnect-exclude-deceased', false);
Expand Down
96 changes: 96 additions & 0 deletions tests/Unit/Controllers/GoalBindingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace OWC\PrefillGravityForms\Tests\Controllers;

use Mockery;
use OWC\PrefillGravityForms\Controllers\EnableUV2Controller;
use OWC\PrefillGravityForms\Controllers\PinkRoccadeV2Controller;
use OWC\PrefillGravityForms\Controllers\WeAreFrankController;
use OWC\PrefillGravityForms\Tests\TestCase;
use WP_Mock;

class GoalBindingTest extends TestCase
{
public function setUp(): void
{
parent::setUp();

WP_Mock::userFunction('rgar', [
'return' => function (array $array, string $key, $default = null) {
return $array[$key] ?? $default;
},
]);
}

/**
* @test
* @dataProvider controllers
*/
public function general_goal_binding_is_used_when_form_has_none(string $controller): void
{
$headers = $this->requestHeaders($controller, '', 'general');

$this->assertContains('x-doelbinding: general', $headers);
}

/**
* @test
* @dataProvider controllers
*/
public function goal_binding_of_form_overrides_general_goal_binding(string $controller): void
{
$headers = $this->requestHeaders($controller, 'form', 'general');

$this->assertContains('x-doelbinding: form', $headers);
$this->assertNotContains('x-doelbinding: general', $headers);
}

/**
* @test
* @dataProvider controllers
*/
public function no_goal_binding_is_sent_when_both_are_empty(string $controller): void
{
$headers = $this->requestHeaders($controller, '', '');

$this->assertNotEmpty($headers);
$this->assertSame([], preg_grep('/^x-doelbinding:/', $headers));
}

public function controllers(): array
{
return [
'PinkRoccade V2' => [PinkRoccadeV2Controller::class],
'EnableU V2' => [EnableUV2Controller::class],
'WeAreFrank' => [WeAreFrankController::class],
];
}

/**
* Headers of the request made when the controller handles a form.
*/
private function requestHeaders(string $controller, string $formGoalBinding, string $generalGoalBinding): array
{
WP_Mock::userFunction('get_option', [
'return' => ['owc-iconnect-goal-binding' => $generalGoalBinding],
]);

$bsn = '123456782';
$headers = [];

$mock = Mockery::mock($controller . '[getBSN,handleCurl,disableFormFields]', [])->shouldAllowMockingProtectedMethods();
$mock->shouldReceive('getBSN')->andReturn($bsn);
$mock->shouldReceive('disableFormFields')->andReturn('');
$mock->shouldReceive('handleCurl')->once()->andReturnUsing(function (array $args) use (&$headers, $bsn) {
$headers = $args[CURLOPT_HTTPHEADER];

return ['personen' => [['burgerservicenummer' => $bsn]]];
});

$mock->handle(['owc-iconnect-doelbinding' => $formGoalBinding, 'fields' => []]);

return $headers;
}
}