diff --git a/CHANGELOG.md b/CHANGELOG.md index ae638b4..bc69a30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/prefill-gravity-forms.php b/prefill-gravity-forms.php index 15f4af9..d1fed9c 100644 --- a/prefill-gravity-forms.php +++ b/prefill-gravity-forms.php @@ -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 @@ -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'); diff --git a/src/PrefillGravityForms/Abstracts/PostController.php b/src/PrefillGravityForms/Abstracts/PostController.php index 6175645..f28a6a8 100644 --- a/src/PrefillGravityForms/Abstracts/PostController.php +++ b/src/PrefillGravityForms/Abstracts/PostController.php @@ -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. * diff --git a/src/PrefillGravityForms/Controllers/EnableUV2Controller.php b/src/PrefillGravityForms/Controllers/EnableUV2Controller.php index 7f4ec40..a3844f5 100644 --- a/src/PrefillGravityForms/Controllers/EnableUV2Controller.php +++ b/src/PrefillGravityForms/Controllers/EnableUV2Controller.php @@ -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); diff --git a/src/PrefillGravityForms/Controllers/PinkRoccadeV2Controller.php b/src/PrefillGravityForms/Controllers/PinkRoccadeV2Controller.php index 5c3c8b1..0667702 100644 --- a/src/PrefillGravityForms/Controllers/PinkRoccadeV2Controller.php +++ b/src/PrefillGravityForms/Controllers/PinkRoccadeV2Controller.php @@ -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); diff --git a/src/PrefillGravityForms/Controllers/WeAreFrankController.php b/src/PrefillGravityForms/Controllers/WeAreFrankController.php index cd0e0f7..32ec2bf 100644 --- a/src/PrefillGravityForms/Controllers/WeAreFrankController.php +++ b/src/PrefillGravityForms/Controllers/WeAreFrankController.php @@ -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); diff --git a/tests/Unit/Controllers/GoalBindingTest.php b/tests/Unit/Controllers/GoalBindingTest.php new file mode 100644 index 0000000..65bf637 --- /dev/null +++ b/tests/Unit/Controllers/GoalBindingTest.php @@ -0,0 +1,96 @@ + 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; + } +}