From bb37be2b66cd8057d798e878cb268ddca1652db1 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sun, 18 Feb 2024 02:05:38 +0100 Subject: [PATCH] Revert unneeded changes from "Fixes for nested multipliers (#59)" This partially reverts commit 39725d333355b2a1ef21dac3948909cf1e5d4744, only keeping the part relevant for nested support and a PHPUnit deprecation fix. The commit introduced a regression in `testGroupManualRenderWithButtons` so this will minimize the changes that could affect it. - Latte 2 macros are trivial to migrate and unclearly named, no need to keep them for BC. - The onSuccess handlers were already fixed in ed96ba0276a2db878841836c403f60568c7a3a98. - `testGroupManualRenderWithButtons` look like remnants of debugging effort, they do not fix the test. For reference, the reverted change is the following commit that was squashed into 39725d333355b2a1ef21dac3948909cf1e5d4744, except for the change to `testSendNested`: https://github.com/contributte/forms-multiplier/pull/59/commits/2c33de22b8343ba08210764711e4776a5bf58227 --- src/Latte/Extension/MultiplierExtension.php | 2 -- tests/unit/CreateButtonTest.php | 6 +---- tests/unit/MultiplierTest.php | 25 ++------------------- tests/unit/RemoveButtonTest.php | 12 ---------- 4 files changed, 3 insertions(+), 42 deletions(-) diff --git a/src/Latte/Extension/MultiplierExtension.php b/src/Latte/Extension/MultiplierExtension.php index 8890c2d..426a70c 100644 --- a/src/Latte/Extension/MultiplierExtension.php +++ b/src/Latte/Extension/MultiplierExtension.php @@ -20,8 +20,6 @@ public function getTags(): array 'n:multiplier' => [MultiplierNode::class, 'create'], 'multiplier:remove' => [MultiplierRemoveNode::class, 'create'], 'multiplier:add' => [MultiplierAddNode::class, 'create'], - 'btnRemove' => [MultiplierRemoveNode::class, 'create'], - 'btnCreate' => [MultiplierAddNode::class, 'create'], ]; } diff --git a/tests/unit/CreateButtonTest.php b/tests/unit/CreateButtonTest.php index 049ddb5..ff88596 100644 --- a/tests/unit/CreateButtonTest.php +++ b/tests/unit/CreateButtonTest.php @@ -89,11 +89,7 @@ public function testCallback() $submitter->setHtmlAttribute('class', 'add-btn'); }); - $response = $this->services->form->createRequest($factory - ->formModifier(function (\Nette\Application\UI\Form $form) { - $form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () { - }; - })->createForm())->setPost([ + $response = $this->services->form->createRequest($factory->createForm())->setPost([ 'm' => [ ['bar' => ''], ['bar' => ''], diff --git a/tests/unit/MultiplierTest.php b/tests/unit/MultiplierTest.php index 001713f..1e8eed0 100644 --- a/tests/unit/MultiplierTest.php +++ b/tests/unit/MultiplierTest.php @@ -44,10 +44,6 @@ public function testSendBase() $this->parameters['onCreate'][] = $container; }; }) - ->formModifier(function (Form $form) { - $form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () { - }; - }) ->createForm() ) ->setPost($params = [ @@ -97,10 +93,6 @@ public function testSendCopy2() $this->parameters['onCreate'][] = $container; }; }) - ->formModifier(function (Form $form) { - $form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () { - }; - }) ->createForm() ) ->setPost($params = [ @@ -151,10 +143,6 @@ public function testSendMaxCopy() $this->parameters['onCreate'][] = $container; }; }) - ->formModifier(function (Form $form) { - $form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () { - }; - }) ->createForm() ) ->setPost([ @@ -221,10 +209,6 @@ public function testSendNested() })); $container['m2']->addCreateButton('create'); }) - ->formModifier(function (Form $form) { - $form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () { - }; - }) ->createForm() ); $request->setPost([ @@ -319,15 +303,14 @@ public function testGroupManualRenderWithButtons() ->multiplierModifier(function (Multiplier $multiplier) { $multiplier->onCreate[] = function (Container $container) { $this->parameters['onCreate'][] = $container; - $container->setParent(null, 'X'); - //var_dump($container); }; $multiplier->addCreateButton(); $multiplier->addRemoveButton(); - //$multiplier->setMinCopies(1); + $multiplier->setMinCopies(1); }) ->createForm()); $dom = $request->render(__DIR__ . '/templates/group.latte')->toDomQuery(); + $this->assertDomHas($dom, 'input[name="m[0][multiplier_remover]"]'); $this->assertDomHas($dom, 'input[name="m[1][multiplier_remover]"]'); } @@ -396,10 +379,6 @@ public function testPromptSelect() ->setPrompt('Select'); }) ->addCreateButton() - ->formModifier(function (Form $form) { - $form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () { - }; - }) ->createForm() ) ->setPost($params = [ diff --git a/tests/unit/RemoveButtonTest.php b/tests/unit/RemoveButtonTest.php index 25ccc59..17526f9 100644 --- a/tests/unit/RemoveButtonTest.php +++ b/tests/unit/RemoveButtonTest.php @@ -188,10 +188,6 @@ public function testAddClass() $submitter->setHtmlAttribute('class', 'btn btn-remove'); }) ->addCreateButton() - ->formModifier(function (Form $form) { - $form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () { - }; - }) ->createForm() )->setPost([ 'm' => [ @@ -214,10 +210,6 @@ public function testDeleteLastElementToZero() ->setMinCopies(0) ->addRemoveButton() ->addCreateButton() - ->formModifier(function (Form $form) { - $form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () { - }; - }) ->createForm() )->modifyForm(function (Form $form) { $form['m']->setValues([ @@ -247,10 +239,6 @@ public function testOnRemoveEvent() $called = true; }; }) - ->formModifier(function (Form $form) { - $form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () { - }; - }) ->createForm() )->setPost([ 'm' => [