Skip to content

Commit

Permalink
Fixes for nested multipliers (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocicak authored Jan 4, 2024
1 parent a2ccdcf commit 39725d3
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 38 deletions.
9 changes: 2 additions & 7 deletions src/ComponentResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,17 @@ final class ComponentResolver
/** @var mixed[] */
private ?array $purgedHttpData = null;

/** @var mixed[] */
private array $defaults = [];

private int $minCopies;

private bool $reached = false;

/**
* @param mixed[] $httpData
* @param mixed[] $defaults
*/
public function __construct(array $httpData, array $defaults, ?int $maxCopies, int $minCopies)
public function __construct(array $httpData, ?int $maxCopies, int $minCopies)
{
$this->httpData = $httpData;
$this->maxCopies = $maxCopies;
$this->defaults = $defaults;
$this->minCopies = $minCopies;

foreach ($httpData as $index => $_) {
Expand Down Expand Up @@ -71,7 +66,7 @@ public function getCreateNum(): int
*/
public function getDefaults(): array
{
return array_slice($this->defaults, 0, $this->maxCopies, true);
return array_slice([], 0, $this->maxCopies, true);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Latte/Extension/MultiplierExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ 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'],
];
}

Expand Down
58 changes: 34 additions & 24 deletions src/Multiplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class Multiplier extends Container

protected ?RemoveButton $removeButton = null;

/** @var mixed[] */
protected array $httpData = [];

protected ?int $maxCopies = null;

protected int $totalCopies = 0;
Expand All @@ -69,6 +66,9 @@ class Multiplier extends Container

private bool $attachedCalled = false;

/** @var ComponentResolver */

Check failure on line 69 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Property \Contributte\FormMultiplier\Multiplier::$resolver has useless @var annotation.

Check failure on line 69 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Property \Contributte\FormMultiplier\Multiplier::$resolver has useless @var annotation.

Check failure on line 69 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Property \Contributte\FormMultiplier\Multiplier::$resolver has useless @var annotation.

Check failure on line 69 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Property \Contributte\FormMultiplier\Multiplier::$resolver has useless @var annotation.

Check failure on line 69 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Property \Contributte\FormMultiplier\Multiplier::$resolver has useless @var annotation.

Check failure on line 69 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Property \Contributte\FormMultiplier\Multiplier::$resolver has useless @var annotation.

Check failure on line 69 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Property \Contributte\FormMultiplier\Multiplier::$resolver has useless @var annotation.
protected ComponentResolver $resolver;

Check failure on line 70 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

The placement of "protected properties" group is invalid. Last group was "private properties" and one of these is expected after it: private properties, constructor, destructor, static constructors, public static abstract methods, public static final methods, public static methods, public abstract methods, public final methods, public methods, protected static abstract methods, protected static final methods, protected static methods, protected abstract methods, protected final methods, protected methods, private static methods, private methods, magic methods

Check failure on line 70 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

The placement of "protected properties" group is invalid. Last group was "private properties" and one of these is expected after it: private properties, constructor, destructor, static constructors, public static abstract methods, public static final methods, public static methods, public abstract methods, public final methods, public methods, protected static abstract methods, protected static final methods, protected static methods, protected abstract methods, protected final methods, protected methods, private static methods, private methods, magic methods

Check failure on line 70 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

The placement of "protected properties" group is invalid. Last group was "private properties" and one of these is expected after it: private properties, constructor, destructor, static constructors, public static abstract methods, public static final methods, public static methods, public abstract methods, public final methods, public methods, protected static abstract methods, protected static final methods, protected static methods, protected abstract methods, protected final methods, protected methods, private static methods, private methods, magic methods

Check failure on line 70 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

The placement of "protected properties" group is invalid. Last group was "private properties" and one of these is expected after it: private properties, constructor, destructor, static constructors, public static abstract methods, public static final methods, public static methods, public abstract methods, public final methods, public methods, protected static abstract methods, protected static final methods, protected static methods, protected abstract methods, protected final methods, protected methods, private static methods, private methods, magic methods

Check failure on line 70 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

The placement of "protected properties" group is invalid. Last group was "private properties" and one of these is expected after it: private properties, constructor, destructor, static constructors, public static abstract methods, public static final methods, public static methods, public abstract methods, public final methods, public methods, protected static abstract methods, protected static final methods, protected static methods, protected abstract methods, protected final methods, protected methods, private static methods, private methods, magic methods

Check failure on line 70 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

The placement of "protected properties" group is invalid. Last group was "private properties" and one of these is expected after it: private properties, constructor, destructor, static constructors, public static abstract methods, public static final methods, public static methods, public abstract methods, public final methods, public methods, protected static abstract methods, protected static final methods, protected static methods, protected abstract methods, protected final methods, protected methods, private static methods, private methods, magic methods

Check failure on line 70 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

The placement of "protected properties" group is invalid. Last group was "private properties" and one of these is expected after it: private properties, constructor, destructor, static constructors, public static abstract methods, public static final methods, public static methods, public abstract methods, public final methods, public methods, protected static abstract methods, protected static final methods, protected static methods, protected abstract methods, protected final methods, protected methods, private static methods, private methods, magic methods

public function __construct(callable $factory, int $copyNumber = 1, ?int $maxCopies = null)
{
$this->factory = $factory;
Expand Down Expand Up @@ -211,28 +211,32 @@ public function addCopy(?int $number = null, array|object $defaults = []): Conta
return $container;
}

public function createCopies(): void
public function createCopies(bool $forceValues = false): void
{
if ($this->created === true) {

Check failure on line 216 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Expected 1 line after "if", found 0.

Check failure on line 216 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Expected 1 line after "if", found 0.

Check failure on line 216 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Expected 1 line after "if", found 0.

Check failure on line 216 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Expected 1 line after "if", found 0.

Check failure on line 216 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Expected 1 line after "if", found 0.

Check failure on line 216 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Expected 1 line after "if", found 0.

Check failure on line 216 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Expected 1 line after "if", found 0.
return;
}

$this->created = true;

$resolver = new ComponentResolver($this->httpData, $this->values, $this->maxCopies, $this->minCopies);
if (!isset($this->resolver)) {
$this->resolver = new ComponentResolver($this->values, $this->maxCopies, $this->minCopies);
}

$this->attachCreateButtons();
$this->createComponents($resolver);
$this->createComponents($forceValues);
$this->detachCreateButtons();

if ($this->maxCopies === null || $this->totalCopies < $this->maxCopies) {
$this->attachCreateButtons();
}

if ($this->form !== null && $resolver->isRemoveAction() && $this->totalCopies >= $this->minCopies && !$resolver->reachedMinLimit()) {
/** @var RemoveButton $removeButton */
$removeButton = $this->removeButton;
$this->form->setSubmittedBy($removeButton->create($this));
if (
$this->form !== null &&
$this->resolver->isRemoveAction() &&
$this->totalCopies >= $this->minCopies &&
!$this->resolver->reachedMinLimit()
) {
$this->form->setSubmittedBy($this->removeButton->create($this));

Check failure on line 239 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method create() on Contributte\FormMultiplier\Buttons\RemoveButton|null.

Check failure on line 239 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method create() on Contributte\FormMultiplier\Buttons\RemoveButton|null.

Check failure on line 239 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method create() on Contributte\FormMultiplier\Buttons\RemoveButton|null.

Check failure on line 239 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method create() on Contributte\FormMultiplier\Buttons\RemoveButton|null.

Check failure on line 239 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method create() on Contributte\FormMultiplier\Buttons\RemoveButton|null.

Check failure on line 239 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method create() on Contributte\FormMultiplier\Buttons\RemoveButton|null.

Check failure on line 239 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method create() on Contributte\FormMultiplier\Buttons\RemoveButton|null.

$this->resetFormEvents();

Expand Down Expand Up @@ -329,10 +333,12 @@ public function setValues($values, bool $erase = false): self
if ($this->created) {
foreach ($this->getContainers() as $container) {
$this->removeComponent($container);
$this->totalCopies--;
}

$this->created = false;
$this->detachCreateButtons();
$this->resolver = new ComponentResolver($this->values, $this->maxCopies, $this->minCopies);

Check failure on line 341 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 341 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 341 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 341 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 341 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 341 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 341 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed
$this->createCopies();
}

Expand Down Expand Up @@ -379,8 +385,9 @@ protected function isFormSubmitted(): bool

protected function loadHttpData(): void
{
if ($this->form !== null && $this->isFormSubmitted()) {
$this->httpData = (array) Arrays::get($this->form->getHttpData(), $this->getHtmlName(), []);
if ($this->isFormSubmitted()) {
$httpData = Arrays::get($this->form->getHttpData(), $this->getHtmlName(), []);

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method getHttpData() on Nette\Forms\Form|null.

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method getHttpData() on Nette\Forms\Form|null.

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method getHttpData() on Nette\Forms\Form|null.

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method getHttpData() on Nette\Forms\Form|null.

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method getHttpData() on Nette\Forms\Form|null.

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method getHttpData() on Nette\Forms\Form|null.

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 389 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Cannot call method getHttpData() on Nette\Forms\Form|null.
$this->resolver = new ComponentResolver($httpData ?? [], $this->maxCopies, $this->minCopies);

Check failure on line 390 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 390 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 390 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 390 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 390 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 390 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 390 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Tabs must be used to indent lines; spaces are not allowed
}
}

Expand Down Expand Up @@ -443,31 +450,34 @@ protected function removeComponentProperly(IComponent $component): void
$this->removeComponent($component);
}

private function createComponents(ComponentResolver $resolver): void
private function createComponents(bool $forceValues = false): void
{
$containers = [];
$containerDefaults = $this->createContainer()->getValues('array');

// Components from httpData
if ($this->isFormSubmitted()) {
foreach ($resolver->getValues() as $number => $_) {
if ($this->isFormSubmitted() && !$forceValues) {
foreach ($this->resolver->getValues() as $number => $_) {
$containers[] = $container = $this->addCopy($number);

/** @var BaseControl $control */
foreach ($container->getControls() as $control) {
foreach ($container->getComponents(false, Control::class) as $control) {

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Parameter #2 $filterType of method Nette\ComponentModel\Container::getComponents() expects class-string<Nette\ComponentModel\IComponent>|null, string given.

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Unable to resolve the template type T in call to method Nette\ComponentModel\Container::getComponents()

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Parameter #2 $filterType of method Nette\ComponentModel\Container::getComponents() expects class-string<Nette\ComponentModel\IComponent>|null, string given.

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Unable to resolve the template type T in call to method Nette\ComponentModel\Container::getComponents()

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Parameter #2 $filterType of method Nette\ComponentModel\Container::getComponents() expects class-string<Nette\ComponentModel\IComponent>|null, string given.

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Unable to resolve the template type T in call to method Nette\ComponentModel\Container::getComponents()

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Parameter #2 $filterType of method Nette\ComponentModel\Container::getComponents() expects class-string<Nette\ComponentModel\IComponent>|null, string given.

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Unable to resolve the template type T in call to method Nette\ComponentModel\Container::getComponents()

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Parameter #2 $filterType of method Nette\ComponentModel\Container::getComponents() expects class-string<Nette\ComponentModel\IComponent>|null, string given.

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Unable to resolve the template type T in call to method Nette\ComponentModel\Container::getComponents()

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Parameter #2 $filterType of method Nette\ComponentModel\Container::getComponents() expects class-string<Nette\ComponentModel\IComponent>|null, string given.

Check failure on line 464 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.1)

Unable to resolve the template type T in call to method Nette\ComponentModel\Container::getComponents()
$control->loadHttpData();
}
}
} else { // Components from default values
foreach ($resolver->getDefaults() as $number => $values) {
$containers[] = $this->addCopy($number, $values);
foreach ($this->resolver->getValues() as $number => $values) {
$containers[] = $container = $this->addCopy($number, $values);
$container->setValues($values);
}
}

// Default number of copies
if (!$this->isFormSubmitted() && !$this->values) {
if (!$this->values) {
$copyNumber = $this->copyNumber;
while ($copyNumber > 0 && $this->isValidMaxCopies()) {
while ($copyNumber > 0 && $this->isValidMaxCopies() && $this->totalCopies < $this->minCopies) {
$containers[] = $container = $this->addCopy();
$container->setValues($containerDefaults);
$copyNumber--;
}
}
Expand All @@ -478,11 +488,11 @@ private function createComponents(ComponentResolver $resolver): void
}

// New containers, if create button hitted
if ($this->form !== null && $resolver->isCreateAction() && $this->form->isValid()) {
$count = $resolver->getCreateNum();
if ($this->form !== null && $this->resolver->isCreateAction() && $this->form->isValid()) {
$count = $this->resolver->getCreateNum();
while ($count > 0 && $this->isValidMaxCopies()) {
$this->noValidate[] = $containers[] = $container = $this->addCopy();
$container->setValues($this->createContainer()->getValues('array'));
$container->setValues($containerDefaults);
$count--;
}
}
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/CreateButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ public function testCallback()
$submitter->setHtmlAttribute('class', 'add-btn');
});

$response = $this->services->form->createRequest($factory->createForm())->setPost([
$response = $this->services->form->createRequest($factory
->formModifier(function (\Nette\Application\UI\Form $form) {
$form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () {
};
})->createForm())->setPost([
'm' => [
['bar' => ''],
['bar' => ''],
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/LatteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function testBtnCreate()
$presenter['m'] = $form;

$string = $this->latte->renderToString(__DIR__ . '/templates/macros.latte', ['form' => $form]);
$this->assertRegExp('#name="m\[multiplier_creator]"#', $string);
$this->assertRegExp('#name="m\[multiplier_creator2]"#', $string);
$this->assertMatchesRegularExpression('#name="m\[multiplier_creator]"#', $string);
$this->assertMatchesRegularExpression('#name="m\[multiplier_creator2]"#', $string);
}

}
Expand Down
33 changes: 29 additions & 4 deletions tests/unit/MultiplierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public function testSendBase()
$this->parameters['onCreate'][] = $container;
};
})
->formModifier(function (Form $form) {
$form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () {
};
})
->createForm()
)
->setPost($params = [
Expand Down Expand Up @@ -93,6 +97,10 @@ public function testSendCopy2()
$this->parameters['onCreate'][] = $container;
};
})
->formModifier(function (Form $form) {
$form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () {
};
})
->createForm()
)
->setPost($params = [
Expand Down Expand Up @@ -143,6 +151,10 @@ public function testSendMaxCopy()
$this->parameters['onCreate'][] = $container;
};
})
->formModifier(function (Form $form) {
$form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () {
};
})
->createForm()
)
->setPost([
Expand Down Expand Up @@ -209,6 +221,10 @@ public function testSendNested()
}));
$container['m2']->addCreateButton('create');
})
->formModifier(function (Form $form) {
$form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () {
};
})
->createForm()
);
$request->setPost([
Expand Down Expand Up @@ -239,11 +255,15 @@ public function testSendNested()
],
[
'bar' => 'bar',
'm2' => [],
'm2' => [
['bar2' => ''],
],
],
[
'bar' => '',
'm2' => [],
'm2' => [
['bar2' => ''],
],
],
],
], $send->getValues());
Expand Down Expand Up @@ -299,14 +319,15 @@ 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]"]');
}
Expand Down Expand Up @@ -375,6 +396,10 @@ public function testPromptSelect()
->setPrompt('Select');
})
->addCreateButton()
->formModifier(function (Form $form) {
$form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () {
};
})
->createForm()
)
->setPost($params = [
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/RemoveButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public function testAddClass()
$submitter->setHtmlAttribute('class', 'btn btn-remove');
})
->addCreateButton()
->formModifier(function (Form $form) {
$form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () {
};
})
->createForm()
)->setPost([
'm' => [
Expand All @@ -210,6 +214,10 @@ 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([
Expand Down Expand Up @@ -239,6 +247,10 @@ public function testOnRemoveEvent()
$called = true;
};
})
->formModifier(function (Form $form) {
$form->onSuccess[] = $form->onError[] = $form->onSubmit[] = function () {
};
})
->createForm()
)->setPost([
'm' => [
Expand Down

0 comments on commit 39725d3

Please sign in to comment.