Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Improve coverage of nested multiplier #93

Merged
merged 1 commit into from
Feb 19, 2024
Merged
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
72 changes: 72 additions & 0 deletions tests/unit/MultiplierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,78 @@ public function testSendNested()
], $send->getValues());
}

/**
* Pressing “Create” inside a nested multiplier with fields with default values.
* This has been reported in the first bullet point in
* https://github.com/contributte/forms-multiplier/issues/56
*/
public function testSendNestedInnerWithDefault()
{
$request = $this->services->form->createRequest(
MultiplierBuilder::create()
->beforeFormModifier(function (Form $form) {
$form->addGroup('testGroup');
})
->multiplierModifier(function (Multiplier $multiplier) {
$multiplier->onCreate[] = function (Container $container) {
$this->parameters['onCreate'][] = $container;
};
})
->containerModifier(function (Container $container) {
$container['m2'] = (new Multiplier(function (Container $container) {
$container->addText('bar2')->setDefaultValue('qux');
}));
$container['m2']->addCreateButton('create');
})
->createForm()
);
$request->setPost([
'm' => [
[
'bar' => 'foo',
'm2' => [
[
'bar2' => 'xx',
],
Multiplier::SUBMIT_CREATE_NAME => '',
],
],
['bar' => 'bar'],
],
]);

$send = $request->send();
$dom = $send->toDomQuery();
$this->assertDomHas($dom, 'input[name="m[0][bar]"]');
$this->assertDomHas($dom, 'input[name="m[0][m2][0][bar2]"]');
$this->assertDomHas($dom, 'input[name="m[0][m2][1][bar2]"]');
$this->assertDomHas($dom, 'input[name="m[0][m2][' . Multiplier::SUBMIT_CREATE_NAME . ']"]');

$form = $send->getForm();
$this->assertSame(
[
'm' => [
[
'bar' => 'foo',
'm2' => [
['bar2' => 'xx'],
['bar2' => 'qux'],
],
],
[
'bar' => 'bar',
'm2' => [
['bar2' => 'qux'],
],
],
],
],
// Pass form, otherwise the values would be limited to m[0][m2] validation scope,
// since that is where the submitter button is pressed.
$form->getValues('array', [$form])
);
}

public function testGroup()
{
$request = $this->services->form->createRequest(
Expand Down
Loading