diff --git a/client-side/dependentSelectBox.js b/client-side/dependentSelectBox.js index ded41f0..da13339 100644 --- a/client-side/dependentSelectBox.js +++ b/client-side/dependentSelectBox.js @@ -33,23 +33,35 @@ var signalLink = element.data(dsb.settings.dataLinkName); var parents = element.data(dsb.settings.dataParentsName); - if (signalLink == undefined) { + if (signalLink === undefined) { return false; } $.each(parents, function (name, id) { var parentElement = $('#' + id); + if (parentElement.length > 0) { var val; + if (parentElement.prop('type') === 'checkbox') { val = parentElement.prop('checked') ? 1 : 0; + } else { val = $(parentElement).val(); if (!val) { return; } } - signalLink = signalLink + '&' + name + '=' + val; + + + if (val instanceof Array) { + $.each(val, function (key, value) { + signalLink += '&' + name + '[]=' + value; + }); + + } else { + signalLink += '&' + name + '=' + val; + } } }); diff --git a/src/Controls/DependentMultiSelectBox.php b/src/Controls/DependentMultiSelectBox.php index 50a965e..1441391 100644 --- a/src/Controls/DependentMultiSelectBox.php +++ b/src/Controls/DependentMultiSelectBox.php @@ -1,123 +1,124 @@ -parents = $parents; - parent::__construct($label); - } - - - /** - * @throws - * @param bool - * @return self - */ - public function setDisabled($value = true) - { - if (is_array($value)) { - throw new Nette\InvalidArgumentException('NasExt\\Forms\\Controls\\DependentMultiSelectBox not supported disabled items!'); - } - return parent::setDisabled($value); - } - - - /** - * @param string - * @return void - */ - public function signalReceived($signal) - { - $presenter = $this->lookup('Nette\\Application\\UI\\Presenter'); - - if ($presenter->isAjax() && $signal === self::SIGNAL_NAME && !$this->isDisabled()) { - $parentsNames = []; - foreach ($this->parents as $parent) { - $value = $presenter->getParameter($this->getNormalizeName($parent)); - $parent->setValue($value); - - $parentsNames[$parent->getName()] = $parent->getValue(); - } - - $data = $this->getDependentData([$parentsNames]); - $presenter->payload->dependentselectbox = [ - 'id' => $this->getHtmlId(), - 'items' => $data->getPreparedItems(!is_array($this->disabled) ?: $this->disabled), - 'value' => $data->getValue(), - 'prompt' => false, - 'disabledWhenEmpty' => $this->disabledWhenEmpty, - ]; - $presenter->sendPayload(); - } - } - - - /** - * @return void - */ - private function tryLoadItems() - { - if ($this->parents === array_filter($this->parents, function ($p) {return !$p->hasErrors();})) { - $parentsValues = []; - foreach ($this->parents as $parent) { - $parentsValues[$parent->getName()] = $parent->getValue(); - } - - $data = $this->getDependentData([$parentsValues]); - $items = $data->getItems(); - - - if ($this->getForm()->isSubmitted()) { - $this->setValue($this->value); - - } elseif ($this->tempValue !== null) { - $this->setValue($this->tempValue); - - } else { - $this->setValue($data->getValue()); - } - - - $this->loadHttpData(); - $this->setItems($items); - - if (count($items) === 0) { - if ($this->disabledWhenEmpty === true && !$this->isDisabled()) { - $this->setDisabled(); - } - } - } - } -} + $parents + */ + public function __construct($label, array $parents) + { + $this->parents = $parents; + parent::__construct($label); + } + + + /** + * @throws $value + * @param bool + * @return self + */ + public function setDisabled($value = true) + { + if (is_array($value)) { + throw new Nette\InvalidArgumentException('NasExt\\Forms\\Controls\\DependentMultiSelectBox not supported disabled items!'); + } + + return parent::setDisabled($value); + } + + + /** + * @param string $signal + * @return void + */ + public function signalReceived($signal) + { + $presenter = $this->lookup('Nette\\Application\\UI\\Presenter'); + + if ($presenter->isAjax() && $signal === self::SIGNAL_NAME && !$this->isDisabled()) { + $parentsNames = []; + foreach ($this->parents as $parent) {bdump($presenter->getParameters()); + $value = $presenter->getParameter($this->getNormalizeName($parent)); + $parent->setValue($value); + + $parentsNames[$parent->getName()] = $parent->getValue(); + } + + $data = $this->getDependentData([$parentsNames]); + $presenter->payload->dependentselectbox = [ + 'id' => $this->getHtmlId(), + 'items' => $data->getPreparedItems(!is_array($this->disabled) ?: $this->disabled), + 'value' => $data->getValue(), + 'prompt' => false, + 'disabledWhenEmpty' => $this->disabledWhenEmpty, + ]; + + $presenter->sendPayload(); + } + } + + + /** + * @return void + */ + private function tryLoadItems() + { + if ($this->parents === array_filter($this->parents, function ($p) {return !$p->hasErrors();})) { + $parentsValues = []; + foreach ($this->parents as $parent) { + $parentsValues[$parent->getName()] = $parent->getValue(); + } + + $data = $this->getDependentData([$parentsValues]); + $items = $data->getItems(); + + if ($this->getForm()->isSubmitted()) { + $this->setValue($this->value); + + } elseif ($this->tempValue !== null) { + $this->setValue($this->tempValue); + + } else { + $this->setValue($data->getValue()); + } + + + $this->loadHttpData(); + $this->setItems($items); + + if (count($items) === 0) { + if ($this->disabledWhenEmpty === true && !$this->isDisabled()) { + $this->setDisabled(); + } + } + } + } +} diff --git a/src/Controls/DependentSelectBox.php b/src/Controls/DependentSelectBox.php index 6f5e29e..7cc83a6 100644 --- a/src/Controls/DependentSelectBox.php +++ b/src/Controls/DependentSelectBox.php @@ -30,8 +30,8 @@ class DependentSelectBox extends Nette\Forms\Controls\SelectBox implements Nette /** - * @param string - * @param array[Nette\Forms\IControl] + * @param string $label + * @param array $parents */ public function __construct($label, array $parents) { @@ -41,7 +41,7 @@ public function __construct($label, array $parents) /** - * @param string + * @param string $signal * @return void */ public function signalReceived($signal) diff --git a/src/DependentData.php b/src/DependentData.php index 4076158..eaef923 100644 --- a/src/DependentData.php +++ b/src/DependentData.php @@ -1,140 +1,147 @@ -items = $items; - $this->value = $value; - $this->prompt = $prompt; - } - - - /** - * @param array - * @return self - */ - public function setItems(array $items) - { - $this->items = $items; - return $this; - } - - - /** - * @param string|int - * @return self - */ - public function setValue($value) - { - $this->value = $value; - return $this; - } - - - /** - * @param string|int - * @return self - */ - public function setPrompt($value) - { - $this->prompt = $value; - return $this; - } - - - /** - * @return array - */ - public function getItems() - { - return $this->items; - } - - - /** - * @param array - * @return array - */ - public function getPreparedItems($disabledItems = null) - { - $items = []; - foreach ($this->items as $key => $item) { - if (!($item instanceof Nette\Utils\Html)) { - $el = Nette\Utils\Html::el('option')->value($key)->setText($item); - } else { - $el = $item; - } - - // disable element - if (is_array($disabledItems) && array_key_exists($key, $disabledItems) && $disabledItems[$key] === true) { - $el->disabled(true); - } - - $items[$key] = [ - 'key' => $el->getValue(), - 'value' => $el->getText(), - ]; - - end($items); - $lKey = key($items); - foreach ($el->attrs as $attr => $val) { - $items[$lKey]['attributes'][$attr] = $val; - } - } - - return $items; - } - - - /** - * @return string|int - */ - public function getValue() - { - return $this->value; - } - - - /** - * @return string - */ - public function getPrompt() - { - return $this->prompt; - } -} +items = $items; + $this->value = $value; + $this->prompt = $prompt; + } + + + /** + * @return array + */ + public function getItems() + { + return $this->items; + } + + + /** + * @param array $items + * @return self + */ + public function setItems(array $items) + { + $this->items = $items; + return $this; + } + + + /** + * @return string|int + */ + public function getValue() + { + return $this->value; + } + + + /** + * @param string|int $value + * @return self + */ + public function setValue($value) + { + $this->value = $value; + return $this; + } + + + /** + * @return string + */ + public function getPrompt() + { + return $this->prompt; + } + + + /** + * @param string $value + * @return self + */ + public function setPrompt($value) + { + $this->prompt = $value; + return $this; + } + + + /** + * @param array $disabledItems + * @return array + */ + public function getPreparedItems($disabledItems = null) + { + $items = []; + foreach ($this->items as $key => $item) { + if (!($item instanceof Nette\Utils\Html)) { + $el = Nette\Utils\Html::el('option')->value($key)->setText($item); + + } else { + $el = $item; + } + + // disable element + if (is_array($disabledItems) && array_key_exists($key, $disabledItems) && $disabledItems[$key] === true) { + $el->disabled(true); + } + + $items[$key] = [ + 'key' => $el->getValue(), + 'value' => $el->getText(), + ]; + + end($items); + $lKey = key($items); + foreach ($el->attrs as $attr => $val) { + $items[$lKey]['attributes'][$attr] = $val; + } + } + + return $items; + } +} diff --git a/src/DependentExtension.php b/src/DependentExtension.php index 43fee54..6a20a58 100644 --- a/src/DependentExtension.php +++ b/src/DependentExtension.php @@ -1,48 +1,49 @@ - - * @author Ales Wita - * @license MIT - */ -class DependentExtension extends Nette\DI\CompilerExtension -{ - /** - * @param Nette\PhpGenerator\ClassType - * @return void - */ - public function afterCompile(Nette\PhpGenerator\ClassType $class) - { - $initialize = $class->getMethod('initialize'); - $initialize->addBody(__CLASS__ . '::registerControls();'); - } - - - /** - * @return void - */ - public static function registerControls() - { - Nette\Forms\Container::extensionMethod('addDependentSelectBox', function (Nette\Forms\Container $container, $name, $label, Nette\Forms\IControl ...$parents) { - return $container[$name] = new NasExt\Forms\Controls\DependentSelectBox($label, $parents); - }); - Nette\Forms\Container::extensionMethod('addDependentMultiSelectBox', function (Nette\Forms\Container $container, $name, $label, Nette\Forms\IControl ...$parents) { - return $container[$name] = new NasExt\Forms\Controls\DependentMultiSelectBox($label, $parents); - }); - } -} + + * @author Ales Wita + * @license MIT + */ +class DependentExtension extends Nette\DI\CompilerExtension +{ + /** + * @param Nette\PhpGenerator\ClassType $class + * @return void + */ + public function afterCompile(Nette\PhpGenerator\ClassType $class) + { + $initialize = $class->getMethod('initialize'); + $initialize->addBody(__CLASS__ . '::registerControls();'); + } + + + /** + * @return void + */ + public static function registerControls() + { + Nette\Forms\Container::extensionMethod('addDependentSelectBox', function (Nette\Forms\Container $container, $name, $label, Nette\Forms\IControl ...$parents) { + return $container[$name] = new NasExt\Forms\Controls\DependentSelectBox($label, $parents); + }); + + Nette\Forms\Container::extensionMethod('addDependentMultiSelectBox', function (Nette\Forms\Container $container, $name, $label, Nette\Forms\IControl ...$parents) { + return $container[$name] = new NasExt\Forms\Controls\DependentMultiSelectBox($label, $parents); + }); + } +} diff --git a/src/DependentTrait.php b/src/DependentTrait.php index b0b923e..81ac805 100644 --- a/src/DependentTrait.php +++ b/src/DependentTrait.php @@ -1,155 +1,153 @@ -tryLoadItems(); - - $attrs = []; - $control = parent::getControl(); - $form = $this->getForm(); - - $parents = []; - foreach ($this->parents as $parent) { - $parents[$this->getNormalizeName($parent)] = $parent->getHtmlId(); - } - - $attrs['data-dependentselectbox-parents'] = Nette\Utils\Json::encode($parents); - $attrs['data-dependentselectbox'] = $form->getPresenter()->link($this->lookupPath('Nette\\Application\\UI\\Presenter') . Nette\ComponentModel\IComponent::NAME_SEPARATOR . self::SIGNAL_NAME . '!'); - - $control->addAttributes($attrs); - return $control; - } - - - /** - * @return string|int - */ - public function getValue() - { - $this->tryLoadItems(); - - if (!in_array($this->tempValue, [null, '', []], true)) { - return $this->tempValue; - } - - return parent::getValue(); - } - - - /** - * @param string|int - * @return self - */ - public function setValue($value) - { - $this->tempValue = $value; - return $this; - } - - - /** - * @param array - * @param bool - * @return self - */ - public function setItems(array $items, $useKeys = true) - { - parent::setItems($items, $useKeys); - - if (!in_array($this->tempValue, [null, '', []], true)) { - parent::setValue($this->tempValue); - } - - return $this; - } - - - /** - * @throws NasExt\Forms\DependentCallbackException - * @param array - * @return NasExt\Forms\DependentData - */ - private function getDependentData(array $args = []) - { - if ($this->dependentCallback === null) { - throw new NasExt\Forms\DependentCallbackException('Dependent callback for "' . $this->getHtmlId() . '" must be set!'); - } - - $dependentData = Nette\Utils\Callback::invokeArgs($this->dependentCallback, $args); - - if (!($dependentData instanceof NasExt\Forms\DependentData) && !($dependentData instanceof NasExt\Forms\Controls\DependentSelectBoxData)) { - throw new NasExt\Forms\DependentCallbackException('Callback for "' . $this->getHtmlId() . '" must return NasExt\\Forms\\DependentData instance!'); - } - - return $dependentData; - } - - - /** - * @param callable - * @return self - */ - public function setDependentCallback(callable $callback) - { - $this->dependentCallback = $callback; - return $this; - } - - - /** - * @param bool - * @return self - */ - public function setDisabledWhenEmpty($value = true) - { - $this->disabledWhenEmpty = $value; - return $this; - } - - - /** - * @param Nette\Forms\Controls\BaseControl - * @return string - */ - protected function getNormalizeName(Nette\Forms\Controls\BaseControl $parent) - { - return str_replace('-', '_', $parent->getHtmlId()); - } -} +tryLoadItems(); + + $attrs = []; + $control = parent::getControl(); + $form = $this->getForm(); + + $parents = []; + foreach ($this->parents as $parent) { + $parents[$this->getNormalizeName($parent)] = $parent->getHtmlId(); + } + + $attrs['data-dependentselectbox-parents'] = Nette\Utils\Json::encode($parents); + $attrs['data-dependentselectbox'] = $form->getPresenter()->link($this->lookupPath('Nette\\Application\\UI\\Presenter') . Nette\ComponentModel\IComponent::NAME_SEPARATOR . self::SIGNAL_NAME . '!'); + + $control->addAttributes($attrs); + return $control; + } + + + /** + * @return string|int + */ + public function getValue() + { + $this->tryLoadItems(); + + if (!in_array($this->tempValue, [null, '', []], true)) { + return $this->tempValue; + } + + return parent::getValue(); + } + + + /** + * @param string|int $value + * @return self + */ + public function setValue($value) + { + $this->tempValue = $value; + return $this; + } + + + /** + * @param array $items + * @param bool $useKeys + * @return self + */ + public function setItems(array $items, $useKeys = true) + { + parent::setItems($items, $useKeys); + + if (!in_array($this->tempValue, [null, '', []], true)) { + parent::setValue($this->tempValue); + } + + return $this; + } + + + /** + * @param array $args + * @return NasExt\Forms\DependentData + * @throws NasExt\Forms\DependentCallbackException + */ + private function getDependentData(array $args = []) + { + if ($this->dependentCallback === null) { + throw new NasExt\Forms\DependentCallbackException('Dependent callback for "' . $this->getHtmlId() . '" must be set!'); + } + + $dependentData = Nette\Utils\Callback::invokeArgs($this->dependentCallback, $args); + + if (!($dependentData instanceof NasExt\Forms\DependentData) && !($dependentData instanceof NasExt\Forms\Controls\DependentSelectBoxData)) { + throw new NasExt\Forms\DependentCallbackException('Callback for "' . $this->getHtmlId() . '" must return NasExt\\Forms\\DependentData instance!'); + } + + return $dependentData; + } + + + /** + * @param callable $callback + * @return self + */ + public function setDependentCallback(callable $callback) + { + $this->dependentCallback = $callback; + return $this; + } + + + /** + * @param bool $value + * @return self + */ + public function setDisabledWhenEmpty($value = true) + { + $this->disabledWhenEmpty = $value; + return $this; + } + + /** + * @param Nette\Forms\Controls\BaseControl $parent + * @return string + */ + private function getNormalizeName(Nette\Forms\Controls\BaseControl $parent) { + return str_replace('-', '_', $parent->getHtmlId()); + } +} diff --git a/src/Exceptions.php b/src/Exceptions.php index 3ac9e2b..027efb8 100644 --- a/src/Exceptions.php +++ b/src/Exceptions.php @@ -1,30 +1,30 @@ -setView('dependentSelect2'); - } - - - /** - * @return void - */ - public function actionDependentSelect2Exception2() - { - $this['dependentSelectForm2']['dependentSelect']->setDependentCallback(function () {}); - $this->setView('dependentSelect2'); - } - - - /** - * @return void - */ - public function actionDependentSelect2Disabled1() - { - $this['dependentSelectForm2']['dependentSelect']->setDependentCallback([$this, 'dependentCallback']) - ->setDisabled(); - - $this->setView('dependentSelect2'); - } - - - /** - * @return void - */ - public function actionDependentSelect2Disabled2() - { - $this['dependentSelectForm2']['dependentSelect']->setDependentCallback([$this, 'dependentCallback']) - ->setDisabled([2]); - - $this->setView('dependentSelect2'); - } - - - /** - * @return void - */ - public function actionDependentSelect2Disabled3() - { - $this['dependentSelectForm2']['dependentSelect']->setDependentCallback([$this, 'dependentCallback']) - ->setDisabledWhenEmpty(); - - $this->setView('dependentSelect2'); - } - - - /** - * @return Nette\Application\UI\Form - */ - protected function createComponentDependentSelectForm1() - { - $form = new Nette\Application\UI\Form; - - $form->addSelect('select', 'Select', [1 => 'First', 2 => 'Second']) - ->setPrompt('---'); - - $form->addDependentSelectBox('dependentSelect', 'Dependent select', $form['select']) - ->setDependentCallback([$this, 'dependentCallback']) - ->setPrompt('Select select first'); - - return $form; - } - - - /** - * @return Nette\Application\UI\Form - */ - protected function createComponentDependentSelectForm2() - { - $form = new Nette\Application\UI\Form; - - $form->addSelect('select', 'Select', [1 => 'First', 2 => 'Second', 3 => 'Third']) - ->setPrompt('---'); - - $form->addDependentSelectBox('dependentSelect', 'Dependent select', $form['select']) - ->setPrompt('Select select first'); - - return $form; - } - - - /** - * @return void - */ - public function actionDependentMultiSelect1() - { - } - - - /** - * @return void - */ - public function actionDependentMultiSelect2() - { - } - - - /** - * @return void - */ - public function actionDependentMultiSelect2Exception1() - { - $this->setView('dependentMultiSelect2'); - } - - - /** - * @return void - */ - public function actionDependentMultiSelect2Exception2() - { - $this['dependentMultiSelectForm2']['dependentMultiSelect']->setDependentCallback(function () {}); - $this->setView('dependentMultiSelect2'); - } - - - /** - * @return void - */ - public function actionDependentMultiSelect2Disabled1() - { - $this['dependentMultiSelectForm2']['dependentMultiSelect']->setDependentCallback([$this, 'dependentCallback']) - ->setDisabled(); - - $this->setView('dependentMultiSelect2'); - } - - - /** - * @return void - */ - public function actionDependentMultiSelect2Disabled2() - { - $this['dependentMultiSelectForm2']['dependentMultiSelect']->setDependentCallback([$this, 'dependentCallback']) - ->setDisabled([2]); - - $this->setView('dependentMultiSelect2'); - } - - - /** - * @return void - */ - public function actionDependentMultiSelect2Disabled3() - { - $this['dependentMultiSelectForm2']['dependentMultiSelect']->setDependentCallback([$this, 'dependentCallback']) - ->setDisabledWhenEmpty(); - - $this->setView('dependentMultiSelect2'); - } - - - /** - * @return Nette\Application\UI\Form - */ - protected function createComponentDependentMultiSelectForm1() - { - $form = new Nette\Application\UI\Form; - - $form->addSelect('select', 'Select', [1 => 'First', 2 => 'Second']) - ->setPrompt('---'); - - $form->addDependentMultiSelectBox('dependentMultiSelect', 'Dependent multi select', $form['select']) - ->setDependentCallback([$this, 'dependentCallback']); - - return $form; - } - - - /** - * @return Nette\Application\UI\Form - */ - protected function createComponentDependentMultiSelectForm2() - { - $form = new Nette\Application\UI\Form; - - $form->addSelect('select', 'Select', [1 => 'First', 2 => 'Second', 3 => 'Third']) - ->setPrompt('---'); - - $form->addDependentMultiSelectBox('dependentMultiSelect', 'Dependent multi select', $form['select']); - - return $form; - } - - - /** - * @param array - * @return NasExt\Forms\DependentData - */ - public function dependentCallback(array $values) - { - $data = new NasExt\Forms\DependentData; - - switch ($values['select']) { - case 1: - $data->setItems([1 => 'First', 2 => 'Still first']) - ->setPrompt('---'); - break; - - case 2: - $data->setItems([3 => 'Second', 4 => 'Still second']) - ->setPrompt('---'); - break; - } - - return $data; - } -} +setView('dependentSelect2'); + } + + + /** + * @return void + */ + public function actionDependentSelect2Exception2() + { + $this['dependentSelectForm2']['dependentSelect']->setDependentCallback(function () {}); + $this->setView('dependentSelect2'); + } + + + /** + * @return void + */ + public function actionDependentSelect2Disabled1() + { + $this['dependentSelectForm2']['dependentSelect']->setDependentCallback([$this, 'dependentCallback']) + ->setDisabled(); + + $this->setView('dependentSelect2'); + } + + + /** + * @return void + */ + public function actionDependentSelect2Disabled2() + { + $this['dependentSelectForm2']['dependentSelect']->setDependentCallback([$this, 'dependentCallback']) + ->setDisabled([2]); + + $this->setView('dependentSelect2'); + } + + + /** + * @return void + */ + public function actionDependentSelect2Disabled3() + { + $this['dependentSelectForm2']['dependentSelect']->setDependentCallback([$this, 'dependentCallback']) + ->setDisabledWhenEmpty(); + + $this->setView('dependentSelect2'); + } + + + /** + * @return Nette\Application\UI\Form + */ + protected function createComponentDependentSelectForm1() + { + $form = new Nette\Application\UI\Form; + + $form->addSelect('select', 'Select', [1 => 'First', 2 => 'Second']) + ->setPrompt('---'); + + $form->addDependentSelectBox('dependentSelect', 'Dependent select', $form['select']) + ->setDependentCallback([$this, 'dependentCallback']) + ->setPrompt('Select select first'); + + return $form; + } + + + /** + * @return Nette\Application\UI\Form + */ + protected function createComponentDependentSelectForm2() + { + $form = new Nette\Application\UI\Form; + + $form->addSelect('select', 'Select', [1 => 'First', 2 => 'Second', 3 => 'Third']) + ->setPrompt('---'); + + $form->addDependentSelectBox('dependentSelect', 'Dependent select', $form['select']) + ->setPrompt('Select select first'); + + return $form; + } + + + /** + * @return void + */ + public function actionDependentMultiSelect1() + { + } + + + /** + * @return void + */ + public function actionDependentMultiSelect2() + { + } + + + /** + * @return void + */ + public function actionDependentMultiSelect2Exception1() + { + $this->setView('dependentMultiSelect2'); + } + + + /** + * @return void + */ + public function actionDependentMultiSelect2Exception2() + { + $this['dependentMultiSelectForm2']['dependentMultiSelect']->setDependentCallback(function () {}); + $this->setView('dependentMultiSelect2'); + } + + + /** + * @return void + */ + public function actionDependentMultiSelect2Disabled1() + { + $this['dependentMultiSelectForm2']['dependentMultiSelect']->setDependentCallback([$this, 'dependentCallback']) + ->setDisabled(); + + $this->setView('dependentMultiSelect2'); + } + + + /** + * @return void + */ + public function actionDependentMultiSelect2Disabled2() + { + $this['dependentMultiSelectForm2']['dependentMultiSelect']->setDependentCallback([$this, 'dependentCallback']) + ->setDisabled([2]); + + $this->setView('dependentMultiSelect2'); + } + + + /** + * @return void + */ + public function actionDependentMultiSelect2Disabled3() + { + $this['dependentMultiSelectForm2']['dependentMultiSelect']->setDependentCallback([$this, 'dependentCallback']) + ->setDisabledWhenEmpty(); + + $this->setView('dependentMultiSelect2'); + } + + + /** + * @return Nette\Application\UI\Form + */ + protected function createComponentDependentMultiSelectForm1() + { + $form = new Nette\Application\UI\Form; + + $form->addSelect('select', 'Select', [1 => 'First', 2 => 'Second']) + ->setPrompt('---'); + + $form->addDependentMultiSelectBox('dependentMultiSelect', 'Dependent multi select', $form['select']) + ->setDependentCallback([$this, 'dependentCallback']); + + return $form; + } + + + /** + * @return Nette\Application\UI\Form + */ + protected function createComponentDependentMultiSelectForm2() + { + $form = new Nette\Application\UI\Form; + + $form->addSelect('select', 'Select', [1 => 'First', 2 => 'Second', 3 => 'Third']) + ->setPrompt('---'); + + $form->addDependentMultiSelectBox('dependentMultiSelect', 'Dependent multi select', $form['select']); + + return $form; + } + + + /** + * @param array $values + * @return NasExt\Forms\DependentData + */ + public function dependentCallback(array $values) + { + $data = new NasExt\Forms\DependentData; + + switch ($values['select']) { + case 1: + $data->setItems([1 => 'First', 2 => 'Still first']) + ->setPrompt('---'); + break; + + case 2: + $data->setItems([3 => 'Second', 4 => 'Still second']) + ->setPrompt('---'); + break; + } + + return $data; + } +} diff --git a/tests/app/presenters/templates/Base/dependentMultiSelect1.latte b/tests/app/presenters/templates/Base.dependentMultiSelect1.latte similarity index 97% rename from tests/app/presenters/templates/Base/dependentMultiSelect1.latte rename to tests/app/presenters/templates/Base.dependentMultiSelect1.latte index e5283c9..eab2637 100644 --- a/tests/app/presenters/templates/Base/dependentMultiSelect1.latte +++ b/tests/app/presenters/templates/Base.dependentMultiSelect1.latte @@ -1 +1 @@ -{control dependentMultiSelectForm1} +{control dependentMultiSelectForm1} diff --git a/tests/app/presenters/templates/Base/dependentMultiSelect2.latte b/tests/app/presenters/templates/Base.dependentMultiSelect2.latte similarity index 97% rename from tests/app/presenters/templates/Base/dependentMultiSelect2.latte rename to tests/app/presenters/templates/Base.dependentMultiSelect2.latte index 01f5eea..06fddaf 100644 --- a/tests/app/presenters/templates/Base/dependentMultiSelect2.latte +++ b/tests/app/presenters/templates/Base.dependentMultiSelect2.latte @@ -1 +1 @@ -{control dependentMultiSelectForm2} +{control dependentMultiSelectForm2} diff --git a/tests/app/presenters/templates/Base/dependentSelect1.latte b/tests/app/presenters/templates/Base.dependentSelect1.latte similarity index 96% rename from tests/app/presenters/templates/Base/dependentSelect1.latte rename to tests/app/presenters/templates/Base.dependentSelect1.latte index 23030d8..d0096ac 100644 --- a/tests/app/presenters/templates/Base/dependentSelect1.latte +++ b/tests/app/presenters/templates/Base.dependentSelect1.latte @@ -1 +1 @@ -{control dependentSelectForm1} +{control dependentSelectForm1} diff --git a/tests/app/presenters/templates/Base/dependentSelect2.latte b/tests/app/presenters/templates/Base.dependentSelect2.latte similarity index 96% rename from tests/app/presenters/templates/Base/dependentSelect2.latte rename to tests/app/presenters/templates/Base.dependentSelect2.latte index 2650953..fb973d3 100644 --- a/tests/app/presenters/templates/Base/dependentSelect2.latte +++ b/tests/app/presenters/templates/Base.dependentSelect2.latte @@ -1 +1 @@ -{control dependentSelectForm2} +{control dependentSelectForm2} diff --git a/tests/app/router/Router.php b/tests/app/router/Router.php index e651df7..a7f707f 100644 --- a/tests/app/router/Router.php +++ b/tests/app/router/Router.php @@ -1,32 +1,32 @@ -/[/]', 'Base:default'); - return $route; - } -} +/[/]', 'Base:default'); + return $route; + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d967055..26deaa9 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,24 +1,24 @@ -setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentMultiSelect1']); - $response = $presenter->run($request); - - Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); - Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); - - - // check form - $form = $presenter['dependentMultiSelectForm1']; - - Tester\Assert::true($form instanceof Nette\Application\UI\Form); - - - // check dependent multi select - $dependentMultiSelect = $form['dependentMultiSelect']; - - Tester\Assert::true($dependentMultiSelect instanceof NasExt\Forms\Controls\DependentMultiSelectBox); - - - // check control - $control = $dependentMultiSelect->getControl(); - - Tester\Assert::true($control instanceof Nette\Utils\Html); - - - // check source - $source = (string) $response->getSource(); - $dom = Tester\DomQuery::fromHtml($source); - - - // dependent select tag - $data = $dom->find('select[name="dependentMultiSelect[]"]'); - - Tester\Assert::count(1, $data); - - $foo = (array) $data[0]; - Tester\Assert::count(5, $foo['@attributes']); - Tester\Assert::same($control->getAttribute('name'), $foo['@attributes']['name']); - Tester\Assert::same($control->getAttribute('id'), $foo['@attributes']['id']); - Tester\Assert::same('multiple', $foo['@attributes']['multiple']); - Tester\Assert::same($control->getAttribute('data-dependentselectbox'), $foo['@attributes']['data-dependentselectbox']); - Tester\Assert::same($control->getAttribute('data-dependentselectbox-parents'), $foo['@attributes']['data-dependentselectbox-parents']); - } - - - /** - * @return void - */ - public function testTwo() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect1'], ['_do' => 'dependentMultiSelectForm1-submit'], ['select' => 1, 'dependentMultiSelect' => [1]]); - $response = $presenter->run($request); - - Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); - Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); - - - // check multi dependent select - $dependentMultiSelect = $presenter['dependentMultiSelectForm1']['dependentMultiSelect']; - - Tester\Assert::true($dependentMultiSelect instanceof NasExt\Forms\Controls\DependentMultiSelectBox); - Tester\Assert::same([1], $dependentMultiSelect->getValue()); - } - - - /** - * @throws Nette\InvalidArgumentException Values '3', '4' are out of allowed set [1, 2] in field 'dependentMultiSelect'. - * @return void - */ - public function testThree() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect1'], ['_do' => 'dependentMultiSelectForm1-submit'], ['select' => 1, 'dependentMultiSelect' => [3, 4]]); - $response = $presenter->run($request); - - $presenter['dependentMultiSelectForm1']->getValues();// must load values for throws exception - } - - - /** - * @return void - */ - public function testFour() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect1'], ['_do' => 'dependentMultiSelectForm1-submit']); - $response = $presenter->run($request); - - - // check form - $form = $presenter['dependentMultiSelectForm1']; - - Tester\Assert::true($form->isSubmitted()); - Tester\Assert::true($form->isSuccess()); - Tester\Assert::same(['select' => null, 'dependentMultiSelect' => []], (array) $form->getValues()); - } - - - /** - * @return void - */ - public function testFive() - { - $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';// make ajax request - - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentMultiSelect1', 'do' => 'dependentMultiSelectForm1-dependentMultiSelect-load', 'frm_dependentMultiSelectForm1_select' => 1]); - $response = $presenter->run($request); - - Tester\Assert::true($response instanceof Nette\Application\Responses\JsonResponse); - Tester\Assert::same([ - 'id' => 'frm-dependentMultiSelectForm1-dependentMultiSelect', - 'items' => [ - 1 => ['key' => 1, 'value' => 'First', 'attributes' => ['value' => 1]], - 2 => ['key' => 2, 'value' => 'Still first', 'attributes' => ['value' => 2]], - ], - 'value' => null, - 'prompt' => false, - 'disabledWhenEmpty' => null, - ], $response->getPayload()->dependentselectbox); - } - - - /** - * @throws NasExt\Forms\DependentCallbackException Dependent callback for "frm-dependentMultiSelectForm2-dependentMultiSelect" must be set! - * @return void - */ - public function testSix() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentMultiSelect2Exception1']); - $response = $presenter->run($request); - - Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); - Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); - - $response->getSource()->render(); - } - - - /** - * @throws NasExt\Forms\DependentCallbackException Callback for "frm-dependentMultiSelectForm2-dependentMultiSelect" must return NasExt\Forms\DependentData instance! - * @return void - */ - public function testSeven() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentMultiSelect2Exception2']); - $response = $presenter->run($request); - - Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); - Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); - - $response->getSource()->render(); - } - - - /** - * @return void - */ - public function testEight() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect2Disabled1'], ['_do' => 'dependentMultiSelectForm2-submit'], ['select' => 1, 'dependentMultiSelect' => [2]]); - $response = $presenter->run($request); - - - // check form - $form = $presenter['dependentMultiSelectForm2']; - - Tester\Assert::true($form->isSubmitted()); - Tester\Assert::true($form->isSuccess()); - Tester\Assert::same(['select' => 1], (array) $form->getValues()); - } - - - /** - * @throws Nette\InvalidArgumentException NasExt\Forms\Controls\DependentMultiSelectBox not supported disabled items! - * @return void - */ - public function testNine() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect2Disabled2'], ['_do' => 'dependentMultiSelectForm2-submit'], ['select' => 1, 'dependentMultiSelect' => [2]]); - $response = $presenter->run($request); - - - // check form - //$form = $presenter['dependentMultiSelectForm2']; - - //Tester\Assert::true($form->isSubmitted()); - //Tester\Assert::true($form->isSuccess()); - //Tester\Assert::same(['select' => 1, 'dependentMultiSelect' => []], (array) $form->getValues()); - } - - - /** - * @return void - */ - public function testTen() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect2Disabled3'], ['_do' => 'dependentMultiSelectForm2-submit'], ['select' => 3]); - $response = $presenter->run($request); - - - // check form - $form = $presenter['dependentMultiSelectForm2']; - $form->getValues();// must load values for check if omitted - - Tester\Assert::true($form->isSubmitted()); - Tester\Assert::true($form->isSuccess()); - Tester\Assert::true($form['dependentMultiSelect']->isOmitted()); - Tester\Assert::same(['select' => 3], (array) $form->getValues()); - } -} - - -$test = new DependentMultiSelectBoxTest; -$test->run(); +setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentMultiSelect1']); + $response = $presenter->run($request); + + Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); + Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); + + + // check form + $form = $presenter['dependentMultiSelectForm1']; + + Tester\Assert::true($form instanceof Nette\Application\UI\Form); + + + // check dependent multi select + $dependentMultiSelect = $form['dependentMultiSelect']; + + Tester\Assert::true($dependentMultiSelect instanceof NasExt\Forms\Controls\DependentMultiSelectBox); + + + // check control + $control = $dependentMultiSelect->getControl(); + + Tester\Assert::true($control instanceof Nette\Utils\Html); + + + // check source + $source = (string) $response->getSource(); + $dom = Tester\DomQuery::fromHtml($source); + + + // dependent select tag + $data = $dom->find('select[name="dependentMultiSelect[]"]'); + + Tester\Assert::count(1, $data); + + $foo = (array) $data[0]; + Tester\Assert::count(5, $foo['@attributes']); + Tester\Assert::same($control->getAttribute('name'), $foo['@attributes']['name']); + Tester\Assert::same($control->getAttribute('id'), $foo['@attributes']['id']); + Tester\Assert::same('multiple', $foo['@attributes']['multiple']); + Tester\Assert::same($control->getAttribute('data-dependentselectbox'), $foo['@attributes']['data-dependentselectbox']); + Tester\Assert::same($control->getAttribute('data-dependentselectbox-parents'), $foo['@attributes']['data-dependentselectbox-parents']); + } + + + /** + * @return void + */ + public function testTwo() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect1'], ['_do' => 'dependentMultiSelectForm1-submit'], ['select' => 1, 'dependentMultiSelect' => [1]]); + $response = $presenter->run($request); + + Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); + Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); + + + // check multi dependent select + $dependentMultiSelect = $presenter['dependentMultiSelectForm1']['dependentMultiSelect']; + + Tester\Assert::true($dependentMultiSelect instanceof NasExt\Forms\Controls\DependentMultiSelectBox); + Tester\Assert::same([1], $dependentMultiSelect->getValue()); + } + + + /** + * @throws Nette\InvalidArgumentException Values '3', '4' are out of allowed set [1, 2] in field 'dependentMultiSelect'. + * @return void + */ + public function testThree() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect1'], ['_do' => 'dependentMultiSelectForm1-submit'], ['select' => 1, 'dependentMultiSelect' => [3, 4]]); + $response = $presenter->run($request); + + $presenter['dependentMultiSelectForm1']->getValues();// must load values for throws exception + } + + + /** + * @return void + */ + public function testFour() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect1'], ['_do' => 'dependentMultiSelectForm1-submit']); + $response = $presenter->run($request); + + + // check form + $form = $presenter['dependentMultiSelectForm1']; + + Tester\Assert::true($form->isSubmitted()); + Tester\Assert::true($form->isSuccess()); + Tester\Assert::same(['select' => null, 'dependentMultiSelect' => []], (array) $form->getValues()); + } + + + /** + * @return void + */ + public function testFive() + { + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';// make ajax request + + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentMultiSelect1', 'do' => 'dependentMultiSelectForm1-dependentMultiSelect-load', 'frm_dependentMultiSelectForm1_select' => 1]); + $response = $presenter->run($request); + + Tester\Assert::true($response instanceof Nette\Application\Responses\JsonResponse); + Tester\Assert::same([ + 'id' => 'frm-dependentMultiSelectForm1-dependentMultiSelect', + 'items' => [ + 1 => ['key' => 1, 'value' => 'First', 'attributes' => ['value' => 1]], + 2 => ['key' => 2, 'value' => 'Still first', 'attributes' => ['value' => 2]], + ], + 'value' => null, + 'prompt' => false, + 'disabledWhenEmpty' => null, + ], $response->getPayload()->dependentselectbox); + } + + + /** + * @throws NasExt\Forms\DependentCallbackException Dependent callback for "frm-dependentMultiSelectForm2-dependentMultiSelect" must be set! + * @return void + */ + public function testSix() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentMultiSelect2Exception1']); + $response = $presenter->run($request); + + Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); + Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); + + $response->getSource()->render(); + } + + + /** + * @throws NasExt\Forms\DependentCallbackException Callback for "frm-dependentMultiSelectForm2-dependentMultiSelect" must return NasExt\Forms\DependentData instance! + * @return void + */ + public function testSeven() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentMultiSelect2Exception2']); + $response = $presenter->run($request); + + Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); + Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); + + $response->getSource()->render(); + } + + + /** + * @return void + */ + public function testEight() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect2Disabled1'], ['_do' => 'dependentMultiSelectForm2-submit'], ['select' => 1, 'dependentMultiSelect' => [2]]); + $response = $presenter->run($request); + + + // check form + $form = $presenter['dependentMultiSelectForm2']; + + Tester\Assert::true($form->isSubmitted()); + Tester\Assert::true($form->isSuccess()); + Tester\Assert::same(['select' => 1], (array) $form->getValues()); + } + + + /** + * @throws Nette\InvalidArgumentException NasExt\Forms\Controls\DependentMultiSelectBox not supported disabled items! + * @return void + */ + public function testNine() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect2Disabled2'], ['_do' => 'dependentMultiSelectForm2-submit'], ['select' => 1, 'dependentMultiSelect' => [2]]); + $response = $presenter->run($request); + + + // check form + //$form = $presenter['dependentMultiSelectForm2']; + + //Tester\Assert::true($form->isSubmitted()); + //Tester\Assert::true($form->isSuccess()); + //Tester\Assert::same(['select' => 1, 'dependentMultiSelect' => []], (array) $form->getValues()); + } + + + /** + * @return void + */ + public function testTen() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentMultiSelect2Disabled3'], ['_do' => 'dependentMultiSelectForm2-submit'], ['select' => 3]); + $response = $presenter->run($request); + + + // check form + $form = $presenter['dependentMultiSelectForm2']; + $form->getValues();// must load values for check if omitted + + Tester\Assert::true($form->isSubmitted()); + Tester\Assert::true($form->isSuccess()); + Tester\Assert::true($form['dependentMultiSelect']->isOmitted()); + Tester\Assert::same(['select' => 3], (array) $form->getValues()); + } + + + /** + * @internal + */ + private function getConfig() + { + return Tester\FileMock::create(' +extensions: + dependentSelectBox: NasExt\Forms\DependentExtension + +application: + mapping: + *: NasExt\Forms\Tests\App\Presenters\*Presenter + +services: + base.presenter: + class: NasExt\Forms\Tests\App\Presenters\BasePresenter + + routing.router: NasExt\Forms\Tests\App\Router\Router::createRouter', 'neon'); + } +} + + +$test = new DependentMultiSelectBoxTest; +$test->run(); diff --git a/tests/tests/DependentSelectBoxTest.phpt b/tests/tests/DependentSelectBoxTest.phpt index e608602..01b0fe2 100644 --- a/tests/tests/DependentSelectBoxTest.phpt +++ b/tests/tests/DependentSelectBoxTest.phpt @@ -1,332 +1,353 @@ -setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentSelect1']); - $response = $presenter->run($request); - - Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); - Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); - - - // check form - $form = $presenter['dependentSelectForm1']; - - Tester\Assert::true($form instanceof Nette\Application\UI\Form); - - - // check dependent select - $dependentSelect = $form['dependentSelect']; - - Tester\Assert::true($dependentSelect instanceof NasExt\Forms\Controls\DependentSelectBox); - - - // check control - $control = $dependentSelect->getControl(); - - Tester\Assert::true($control instanceof Nette\Utils\Html); - - - // check source - $source = (string) $response->getSource(); - $dom = Tester\DomQuery::fromHtml($source); - - - // dependent select tag - $data = $dom->find('select[name="dependentSelect"]'); - - Tester\Assert::count(1, $data); - - $foo = (array) $data[0]; - Tester\Assert::count(4, $foo['@attributes']); - Tester\Assert::same($control->getAttribute('name'), $foo['@attributes']['name']); - Tester\Assert::same($control->getAttribute('id'), $foo['@attributes']['id']); - Tester\Assert::same($control->getAttribute('data-dependentselectbox'), $foo['@attributes']['data-dependentselectbox']); - Tester\Assert::same($control->getAttribute('data-dependentselectbox-parents'), $foo['@attributes']['data-dependentselectbox-parents']); - - Tester\Assert::same('Select select first', $foo['option']); - } - - - /** - * @return void - */ - public function testTwo() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect1'], ['_do' => 'dependentSelectForm1-submit'], ['select' => 1, 'dependentSelect' => 1]); - $response = $presenter->run($request); - - Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); - Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); - - - // check dependent select - $dependentSelect = $presenter['dependentSelectForm1']['dependentSelect']; - - Tester\Assert::true($dependentSelect instanceof NasExt\Forms\Controls\DependentSelectBox); - Tester\Assert::same(1, $dependentSelect->getValue()); - } - - - /** - * @throws Nette\InvalidArgumentException Value '3' is out of allowed set [1, 2] in field 'dependentSelect'. - * @return void - */ - public function testThree() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect1'], ['_do' => 'dependentSelectForm1-submit'], ['select' => 1, 'dependentSelect' => 3]); - $response = $presenter->run($request); - } - - - /** - * @return void - */ - public function testFour() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect1'], ['_do' => 'dependentSelectForm1-submit']); - $response = $presenter->run($request); - - - // check form - $form = $presenter['dependentSelectForm1']; - - Tester\Assert::true($form->isSubmitted()); - Tester\Assert::true($form->isSuccess()); - Tester\Assert::same(['select' => null, 'dependentSelect' => null], (array) $form->getValues()); - } - - - /** - * @return void - */ - public function testFive() - { - $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';// make ajax request - - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentSelect1', 'do' => 'dependentSelectForm1-dependentSelect-load', 'frm_dependentSelectForm1_select' => 1]); - $response = $presenter->run($request); - - Tester\Assert::true($response instanceof Nette\Application\Responses\JsonResponse); - Tester\Assert::same([ - 'id' => 'frm-dependentSelectForm1-dependentSelect', - 'items' => [ - 1 => ['key' => 1, 'value' => 'First', 'attributes' => ['value' => 1]], - 2 => ['key' => 2, 'value' => 'Still first', 'attributes' => ['value' => 2]], - ], - 'value' => null, - 'prompt' => '---', - 'disabledWhenEmpty' => null, - ], $response->getPayload()->dependentselectbox); - } - - - /** - * @throws NasExt\Forms\DependentCallbackException Dependent callback for "frm-dependentSelectForm2-dependentSelect" must be set! - * @return void - */ - public function testSix() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentSelect2Exception1']); - $response = $presenter->run($request); - - Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); - Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); - - $response->getSource()->render(); - } - - - /** - * @throws NasExt\Forms\DependentCallbackException Callback for "frm-dependentSelectForm2-dependentSelect" must return NasExt\Forms\DependentData instance! - * @return void - */ - public function testSeven() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentSelect2Exception2']); - $response = $presenter->run($request); - - Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); - Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); - - $response->getSource()->render(); - } - - - /** - * @return void - */ - public function testEight() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect2Disabled1'], ['_do' => 'dependentSelectForm2-submit'], ['select' => 1, 'dependentSelect' => 2]); - $response = $presenter->run($request); - - - // check form - $form = $presenter['dependentSelectForm2']; - - Tester\Assert::true($form->isSubmitted()); - Tester\Assert::true($form->isSuccess()); - Tester\Assert::same(['select' => 1], (array) $form->getValues()); - } - - - /** - * @return void - */ - public function testNine() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect2Disabled2'], ['_do' => 'dependentSelectForm2-submit'], ['select' => 1, 'dependentSelect' => 2]); - $response = $presenter->run($request); - - - // check form - $form = $presenter['dependentSelectForm2']; - - Tester\Assert::true($form->isSubmitted()); - Tester\Assert::true($form->isSuccess()); - Tester\Assert::same(['select' => 1, 'dependentSelect' => null], (array) $form->getValues()); - } - - - /** - * @return void - */ - public function testTen() - { - $configurator = new Nette\Configurator(); - $configurator->setTempDirectory(TEMP_DIR); - $configurator->addConfig(__DIR__ . '/../app/config/config.neon'); - - $container = $configurator->createContainer(); - $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); - - $presenter = $presenterFactory->createPresenter('Base'); - $presenter->autoCanonicalize = false; - $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect2Disabled3'], ['_do' => 'dependentSelectForm2-submit'], ['select' => 3]); - $response = $presenter->run($request); - - - // check form - $form = $presenter['dependentSelectForm2']; - - Tester\Assert::true($form->isSubmitted()); - Tester\Assert::true($form->isSuccess()); - Tester\Assert::true($form['dependentSelect']->isOmitted()); - Tester\Assert::same(['select' => 3], (array) $form->getValues()); - } -} - - -$test = new DependentSelectBoxTest; -$test->run(); +setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentSelect1']); + $response = $presenter->run($request); + + Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); + Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); + + + // check form + $form = $presenter['dependentSelectForm1']; + + Tester\Assert::true($form instanceof Nette\Application\UI\Form); + + + // check dependent select + $dependentSelect = $form['dependentSelect']; + + Tester\Assert::true($dependentSelect instanceof NasExt\Forms\Controls\DependentSelectBox); + + + // check control + $control = $dependentSelect->getControl(); + + Tester\Assert::true($control instanceof Nette\Utils\Html); + + + // check source + $source = (string) $response->getSource(); + $dom = Tester\DomQuery::fromHtml($source); + + + // dependent select tag + $data = $dom->find('select[name="dependentSelect"]'); + + Tester\Assert::count(1, $data); + + $foo = (array) $data[0]; + Tester\Assert::count(4, $foo['@attributes']); + Tester\Assert::same($control->getAttribute('name'), $foo['@attributes']['name']); + Tester\Assert::same($control->getAttribute('id'), $foo['@attributes']['id']); + Tester\Assert::same($control->getAttribute('data-dependentselectbox'), $foo['@attributes']['data-dependentselectbox']); + Tester\Assert::same($control->getAttribute('data-dependentselectbox-parents'), $foo['@attributes']['data-dependentselectbox-parents']); + + Tester\Assert::same('Select select first', $foo['option']); + } + + + /** + * @return void + */ + public function testTwo() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect1'], ['_do' => 'dependentSelectForm1-submit'], ['select' => 1, 'dependentSelect' => 1]); + $response = $presenter->run($request); + + Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); + Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); + + + // check dependent select + $dependentSelect = $presenter['dependentSelectForm1']['dependentSelect']; + + Tester\Assert::true($dependentSelect instanceof NasExt\Forms\Controls\DependentSelectBox); + Tester\Assert::same(1, $dependentSelect->getValue()); + } + + + /** + * @throws Nette\InvalidArgumentException Value '3' is out of allowed set [1, 2] in field 'dependentSelect'. + * @return void + */ + public function testThree() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect1'], ['_do' => 'dependentSelectForm1-submit'], ['select' => 1, 'dependentSelect' => 3]); + $response = $presenter->run($request); + } + + + /** + * @return void + */ + public function testFour() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect1'], ['_do' => 'dependentSelectForm1-submit']); + $response = $presenter->run($request); + + + // check form + $form = $presenter['dependentSelectForm1']; + + Tester\Assert::true($form->isSubmitted()); + Tester\Assert::true($form->isSuccess()); + Tester\Assert::same(['select' => null, 'dependentSelect' => null], (array) $form->getValues()); + } + + + /** + * @return void + */ + public function testFive() + { + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';// make ajax request + + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentSelect1', 'do' => 'dependentSelectForm1-dependentSelect-load', 'frm_dependentSelectForm1_select' => 1]); + $response = $presenter->run($request); + + Tester\Assert::true($response instanceof Nette\Application\Responses\JsonResponse); + Tester\Assert::same([ + 'id' => 'frm-dependentSelectForm1-dependentSelect', + 'items' => [ + 1 => ['key' => 1, 'value' => 'First', 'attributes' => ['value' => 1]], + 2 => ['key' => 2, 'value' => 'Still first', 'attributes' => ['value' => 2]], + ], + 'value' => null, + 'prompt' => '---', + 'disabledWhenEmpty' => null, + ], $response->getPayload()->dependentselectbox); + } + + + /** + * @throws NasExt\Forms\DependentCallbackException Dependent callback for "frm-dependentSelectForm2-dependentSelect" must be set! + * @return void + */ + public function testSix() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentSelect2Exception1']); + $response = $presenter->run($request); + + Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); + Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); + + $response->getSource()->render(); + } + + + /** + * @throws NasExt\Forms\DependentCallbackException Callback for "frm-dependentSelectForm2-dependentSelect" must return NasExt\Forms\DependentData instance! + * @return void + */ + public function testSeven() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'GET', ['action' => 'dependentSelect2Exception2']); + $response = $presenter->run($request); + + Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse); + Tester\Assert::true($response->getSource() instanceof Nette\Application\UI\ITemplate); + + $response->getSource()->render(); + } + + + /** + * @return void + */ + public function testEight() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect2Disabled1'], ['_do' => 'dependentSelectForm2-submit'], ['select' => 1, 'dependentSelect' => 2]); + $response = $presenter->run($request); + + + // check form + $form = $presenter['dependentSelectForm2']; + + Tester\Assert::true($form->isSubmitted()); + Tester\Assert::true($form->isSuccess()); + Tester\Assert::same(['select' => 1], (array) $form->getValues()); + } + + + /** + * @return void + */ + public function testNine() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect2Disabled2'], ['_do' => 'dependentSelectForm2-submit'], ['select' => 1, 'dependentSelect' => 2]); + $response = $presenter->run($request); + + + // check form + $form = $presenter['dependentSelectForm2']; + + Tester\Assert::true($form->isSubmitted()); + Tester\Assert::true($form->isSuccess()); + Tester\Assert::same(['select' => 1, 'dependentSelect' => null], (array) $form->getValues()); + } + + + /** + * @return void + */ + public function testTen() + { + $configurator = new Nette\Configurator(); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig($this->getConfig()); + + $container = $configurator->createContainer(); + $presenterFactory = $container->getByType('Nette\\Application\\IPresenterFactory'); + + $presenter = $presenterFactory->createPresenter('Base'); + $presenter->autoCanonicalize = false; + $request = new Nette\Application\Request('Base', 'POST', ['action' => 'dependentSelect2Disabled3'], ['_do' => 'dependentSelectForm2-submit'], ['select' => 3]); + $response = $presenter->run($request); + + + // check form + $form = $presenter['dependentSelectForm2']; + + Tester\Assert::true($form->isSubmitted()); + Tester\Assert::true($form->isSuccess()); + Tester\Assert::true($form['dependentSelect']->isOmitted()); + Tester\Assert::same(['select' => 3], (array) $form->getValues()); + } + + + /** + * @internal + */ + private function getConfig() + { + return Tester\FileMock::create(' +extensions: + dependentSelectBox: NasExt\Forms\DependentExtension + +application: + mapping: + *: NasExt\Forms\Tests\App\Presenters\*Presenter + +services: + base.presenter: + class: NasExt\Forms\Tests\App\Presenters\BasePresenter + + routing.router: NasExt\Forms\Tests\App\Router\Router::createRouter', 'neon'); + } +} + + +$test = new DependentSelectBoxTest; +$test->run();