From 131f7d2f6eea6ab070cbcf18fd94af6bd688e134 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 20 May 2015 16:56:22 +0200 Subject: [PATCH] used PHP 5.4 array syntax --- .travis.yml | 4 +- examples/basic-example.php | 22 +-- examples/bootstrap2-rendering.php | 12 +- examples/bootstrap3-rendering.php | 12 +- examples/custom-control.php | 4 +- examples/custom-rendering.php | 8 +- examples/html5.php | 4 +- examples/localization.php | 10 +- examples/manual-rendering.php | 4 +- src/Bridges/FormsDI/FormsExtension.php | 10 +- src/Bridges/FormsLatte/FormMacros.php | 18 +-- src/Bridges/FormsLatte/Runtime.php | 2 +- src/Forms/Container.php | 8 +- src/Forms/ControlGroup.php | 2 +- src/Forms/Controls/BaseControl.php | 16 +-- src/Forms/Controls/Button.php | 6 +- src/Forms/Controls/CheckboxList.php | 12 +- src/Forms/Controls/ChoiceControl.php | 6 +- src/Forms/Controls/HiddenField.php | 4 +- src/Forms/Controls/ImageButton.php | 2 +- src/Forms/Controls/MultiChoiceControl.php | 6 +- src/Forms/Controls/MultiSelectBox.php | 10 +- src/Forms/Controls/RadioList.php | 16 +-- src/Forms/Controls/SelectBox.php | 10 +- src/Forms/Controls/SubmitButton.php | 10 +- src/Forms/Controls/TextInput.php | 10 +- src/Forms/Form.php | 12 +- src/Forms/Helpers.php | 28 ++-- src/Forms/Rendering/DefaultFormRenderer.php | 40 +++--- src/Forms/Rules.php | 8 +- src/Forms/Validator.php | 24 ++-- tests/Forms.Latte/FormMacros.button.phpt | 2 +- .../Forms.Latte/FormMacros.formContainer.phpt | 4 +- tests/Forms.Latte/FormMacros.forms.phpt | 8 +- tests/Forms.Latte/FormMacros.get.phpt | 2 +- tests/Forms.Latte/Runtime.get.phpt | 2 +- tests/Forms/Container.validate().phpt | 6 +- tests/Forms/Container.values.phpt | 44 +++--- tests/Forms/Controls.BaseControl.phpt | 26 ++-- tests/Forms/Controls.Button.loadData.phpt | 16 +-- tests/Forms/Controls.Button.render.phpt | 2 +- tests/Forms/Controls.Checkbox.loadData.phpt | 10 +- .../Forms/Controls.CheckboxList.loadData.phpt | 74 +++++----- tests/Forms/Controls.CheckboxList.render.phpt | 40 +++--- .../Controls.ChoiceControl.loadData.phpt | 40 +++--- .../Controls.CsrfProtection.breachAttack.phpt | 6 +- tests/Forms/Controls.CsrfProtection.phpt | 8 +- .../Forms/Controls.HiddenField.loadData.phpt | 12 +- .../Forms/Controls.ImageButton.loadData.phpt | 28 ++-- .../Controls.MultiChoiceControl.loadData.phpt | 82 +++++------ .../Controls.MultiSelectBox.loadData.phpt | 122 ++++++++-------- .../Forms/Controls.MultiSelectBox.render.phpt | 36 ++--- tests/Forms/Controls.RadioList.loadData.phpt | 30 ++-- tests/Forms/Controls.RadioList.render.phpt | 48 +++---- tests/Forms/Controls.SelectBox.loadData.phpt | 74 +++++----- tests/Forms/Controls.SelectBox.render.phpt | 36 ++--- tests/Forms/Controls.TestBase.validators.phpt | 6 +- tests/Forms/Controls.TextArea.render.phpt | 2 +- tests/Forms/Controls.TextBase.loadData.phpt | 30 ++-- tests/Forms/Controls.TextInput.render.phpt | 12 +- .../Controls.UploadControl.loadData.phpt | 98 ++++++------- tests/Forms/Controls.translate().phpt | 8 +- tests/Forms/Forms.callbackParameters.phpt | 22 +-- tests/Forms/Forms.getHttpData.get.2.phpt | 8 +- tests/Forms/Forms.getHttpData.get.phpt | 16 +-- tests/Forms/Forms.getHttpData.post.phpt | 18 +-- tests/Forms/Forms.isValid.phpt | 18 +-- tests/Forms/Forms.omittedValue.phpt | 2 +- tests/Forms/Forms.onSuccess.phpt | 8 +- tests/Forms/Forms.renderer.1.phpt | 20 +-- tests/Forms/Forms.renderer.2.phpt | 20 +-- tests/Forms/Forms.submittedBy.phpt | 6 +- tests/Forms/Forms.toggle.phpt | 132 +++++++++--------- tests/Forms/Forms.userValidator.phpt | 10 +- tests/Forms/Forms.validationScope.phpt | 20 +-- tests/Forms/Helpers.createInputList.phpt | 36 ++--- tests/Forms/Helpers.createSelectBox.phpt | 36 ++--- tests/Forms/Helpers.extractHttpData.phpt | 92 ++++++------ tests/Forms/Rules.dynamic.phpt | 14 +- tests/Forms/Rules.formatMessage.phpt | 16 +-- tests/Forms/Rules.required.phpt | 6 +- 81 files changed, 877 insertions(+), 877 deletions(-) diff --git a/.travis.yml b/.travis.yml index 455c50834..2f523866e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ matrix: script: - vendor/bin/tester tests -s -p php -c tests/php-unix.ini - - php code-checker/src/code-checker.php -i netteForms + - php temp/code-checker/src/code-checker.php --short-arrays -i netteForms - if [ $TRAVIS_PHP_VERSION == "5.6" ]; then grunt --gruntfile tests/netteForms/Gruntfile.js test; fi after_failure: @@ -25,5 +25,5 @@ after_failure: before_script: # Install Nette Tester & Code Checker - composer install --no-interaction --prefer-source - - composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source + - composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction --prefer-source - if [ $TRAVIS_PHP_VERSION == "5.6" ]; then npm install -g grunt-cli; cd tests/netteForms; npm install; bower install; cd ../..; fi diff --git a/examples/basic-example.php b/examples/basic-example.php index 07f65e91d..54737ae13 100644 --- a/examples/basic-example.php +++ b/examples/basic-example.php @@ -29,18 +29,18 @@ $form->addText('age', 'Your age:') ->setRequired('Enter your age') ->addRule($form::INTEGER, 'Age must be numeric value') - ->addRule($form::RANGE, 'Age must be in range from %d to %d', array(10, 100)); + ->addRule($form::RANGE, 'Age must be in range from %d to %d', [10, 100]); -$form->addRadioList('gender', 'Your gender:', array( +$form->addRadioList('gender', 'Your gender:', [ 'm' => 'male', 'f' => 'female', -)); +]); -$form->addCheckboxList('colors', 'Favorite colors:', array( +$form->addCheckboxList('colors', 'Favorite colors:', [ 'r' => 'red', 'g' => 'green', 'b' => 'blue', -)); +]); $form->addText('email', 'Email:') ->setEmptyValue('@') @@ -67,14 +67,14 @@ ->addConditionOn($form['send'], $form::FILLED) ->setRequired('Enter your shipping address'); -$countries = array( - 'World' => array( +$countries = [ + 'World' => [ 'bu' => 'Buranda', 'qu' => 'Qumran', 'st' => 'Saint Georges Island', - ), + ], '?' => 'other', -); +]; $form->addSelect('country', 'Country:', $countries) ->setPrompt('Select your country') ->addConditionOn($form['send'], $form::FILLED) @@ -106,10 +106,10 @@ $form->addSubmit('submit', 'Send'); -$form->setDefaults(array( +$form->setDefaults([ 'name' => 'John Doe', 'userid' => 231, -)); +]); if ($form->isSuccess()) { diff --git a/examples/bootstrap2-rendering.php b/examples/bootstrap2-rendering.php index a8fc346ff..cfd60fbd7 100644 --- a/examples/bootstrap2-rendering.php +++ b/examples/bootstrap2-rendering.php @@ -23,17 +23,17 @@ $form->addText('name', 'Your name') ->setRequired('Enter your name'); -$form->addRadioList('gender', 'Your gender', array( +$form->addRadioList('gender', 'Your gender', [ 'male', 'female', -)); +]); -$form->addCheckboxList('colors', 'Favorite colors:', array( +$form->addCheckboxList('colors', 'Favorite colors:', [ 'red', 'green', 'blue', -)); +]); -$form->addSelect('country', 'Country', array( +$form->addSelect('country', 'Country', [ 'Buranda', 'Qumran', 'Saint Georges Island', -)); +]); $form->addCheckbox('send', 'Ship to address'); diff --git a/examples/bootstrap3-rendering.php b/examples/bootstrap3-rendering.php index fb0964083..0995c72ce 100644 --- a/examples/bootstrap3-rendering.php +++ b/examples/bootstrap3-rendering.php @@ -23,17 +23,17 @@ $form->addText('name', 'Your name') ->setRequired('Enter your name'); -$form->addRadioList('gender', 'Your gender', array( +$form->addRadioList('gender', 'Your gender', [ 'male', 'female', -)); +]); -$form->addCheckboxList('colors', 'Favorite colors:', array( +$form->addCheckboxList('colors', 'Favorite colors:', [ 'red', 'green', 'blue', -)); +]); -$form->addSelect('country', 'Country', array( +$form->addSelect('country', 'Country', [ 'Buranda', 'Qumran', 'Saint Georges Island', -)); +]); $form->addCheckbox('send', 'Ship to address'); diff --git a/examples/custom-control.php b/examples/custom-control.php index 2271bace2..3ccaf398e 100644 --- a/examples/custom-control.php +++ b/examples/custom-control.php @@ -66,8 +66,8 @@ public function getControl() return Html::el() ->add(Html::el('input')->name($name . '[day]')->id($this->getHtmlId())->value($this->day)) ->add(Nette\Forms\Helpers::createSelectBox( - array(1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), - array('selected?' => $this->month) + [1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], + ['selected?' => $this->month] )->name($name . '[month]')) ->add(Html::el('input')->name($name . '[year]')->value($this->year)); } diff --git a/examples/custom-rendering.php b/examples/custom-rendering.php index db483532e..f4bb54985 100644 --- a/examples/custom-rendering.php +++ b/examples/custom-rendering.php @@ -36,14 +36,14 @@ $form->addText('name', 'Your name') ->setRequired('Enter your name'); -$form->addRadioList('gender', 'Your gender', array( +$form->addRadioList('gender', 'Your gender', [ 'm' => Html::el('option', 'male')->style('color: #248bd3'), 'f' => Html::el('option', 'female')->style('color: #e948d4'), -)); +]); -$form->addSelect('country', 'Country', array( +$form->addSelect('country', 'Country', [ 'Buranda', 'Qumran', 'Saint Georges Island', -)); +]); $form->addCheckbox('send', 'Ship to address'); diff --git a/examples/html5.php b/examples/html5.php index 0fe07d21f..ab830bfbc 100644 --- a/examples/html5.php +++ b/examples/html5.php @@ -28,13 +28,13 @@ ->setType('number') ->setDefaultValue(10) ->addRule($form::INTEGER, 'Must be numeric value') - ->addRule($form::RANGE, 'Must be in range from %d to %d', array(1, 100)); + ->addRule($form::RANGE, 'Must be in range from %d to %d', [1, 100]); $form->addText('precision', 'Precision:') ->setType('range') ->setDefaultValue(50) ->addRule($form::INTEGER, 'Precision must be numeric value') - ->addRule($form::RANGE, 'Precision must be in range from %d to %d', array(0, 100)); + ->addRule($form::RANGE, 'Precision must be in range from %d to %d', [0, 100]); $form->addText('email', 'Send to email:') ->setType('email') diff --git a/examples/localization.php b/examples/localization.php index b3145cff4..5d539848c 100644 --- a/examples/localization.php +++ b/examples/localization.php @@ -49,16 +49,16 @@ public function translate($message, $count = NULL) $form->addText('age', 'Your age:') ->setRequired('Enter your age') ->addRule($form::INTEGER, 'Age must be numeric value') - ->addRule($form::RANGE, 'Age must be in range from %d to %d', array(10, 100)); + ->addRule($form::RANGE, 'Age must be in range from %d to %d', [10, 100]); -$countries = array( - 'World' => array( +$countries = [ + 'World' => [ 'bu' => 'Buranda', 'qu' => 'Qumran', 'st' => 'Saint Georges Island', - ), + ], '?' => 'other', -); +]; $form->addSelect('country', 'Country:', $countries) ->setPrompt('Select your country'); diff --git a/examples/manual-rendering.php b/examples/manual-rendering.php index 1059398f6..554bdb410 100644 --- a/examples/manual-rendering.php +++ b/examples/manual-rendering.php @@ -23,10 +23,10 @@ $form->addText('age') ->setRequired('Enter your age'); -$form->addRadioList('gender', NULL, array( +$form->addRadioList('gender', NULL, [ 'm' => 'male', 'f' => 'female', -)); +]); $form->addText('email') ->addCondition($form::FILLED) diff --git a/src/Bridges/FormsDI/FormsExtension.php b/src/Bridges/FormsDI/FormsExtension.php index 8b33e2619..0fbd595e3 100644 --- a/src/Bridges/FormsDI/FormsExtension.php +++ b/src/Bridges/FormsDI/FormsExtension.php @@ -18,9 +18,9 @@ */ class FormsExtension extends Nette\DI\CompilerExtension { - public $defaults = array( - 'messages' => array() - ); + public $defaults = [ + 'messages' => [] + ]; public function afterCompile(Nette\PhpGenerator\ClassType $class) @@ -30,9 +30,9 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) foreach ((array) $config['messages'] as $name => $text) { if (defined('Nette\Forms\Form::' . $name)) { - $initialize->addBody('Nette\Forms\Validator::$messages[Nette\Forms\Form::?] = ?;', array($name, $text)); + $initialize->addBody('Nette\Forms\Validator::$messages[Nette\Forms\Form::?] = ?;', [$name, $text]); } elseif (defined($name)) { - $initialize->addBody('Nette\Forms\Validator::$messages[' . $name . '] = ?;', array($text)); + $initialize->addBody('Nette\Forms\Validator::$messages[' . $name . '] = ?;', [$text]); } else { throw new Nette\InvalidArgumentException('Constant Nette\Forms\Form::' . $name . ' or constant ' . $name . ' does not exist.'); } diff --git a/src/Bridges/FormsLatte/FormMacros.php b/src/Bridges/FormsLatte/FormMacros.php index b0c56834d..a073bbdee 100644 --- a/src/Bridges/FormsLatte/FormMacros.php +++ b/src/Bridges/FormsLatte/FormMacros.php @@ -33,12 +33,12 @@ class FormMacros extends MacroSet public static function install(Latte\Compiler $compiler) { $me = new static($compiler); - $me->addMacro('form', array($me, 'macroForm'), 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form)'); - $me->addMacro('formContainer', array($me, 'macroFormContainer'), '$formContainer = $_form = array_pop($_formStack)'); - $me->addMacro('label', array($me, 'macroLabel'), array($me, 'macroLabelEnd')); - $me->addMacro('input', array($me, 'macroInput'), NULL, array($me, 'macroInputAttr')); - $me->addMacro('name', array($me, 'macroName'), array($me, 'macroNameEnd'), array($me, 'macroNameAttr')); - $me->addMacro('inputError', array($me, 'macroInputError')); + $me->addMacro('form', [$me, 'macroForm'], 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form)'); + $me->addMacro('formContainer', [$me, 'macroFormContainer'], '$formContainer = $_form = array_pop($_formStack)'); + $me->addMacro('label', [$me, 'macroLabel'], [$me, 'macroLabelEnd']); + $me->addMacro('input', [$me, 'macroInput'], NULL, [$me, 'macroInputAttr']); + $me->addMacro('name', [$me, 'macroName'], [$me, 'macroNameEnd'], [$me, 'macroNameAttr']); + $me->addMacro('inputError', [$me, 'macroInputError']); } @@ -97,7 +97,7 @@ public function macroLabel(MacroNode $node, PhpWriter $writer) . '->%1.raw) echo $_label' . ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : ''), $name, - $words ? ('getLabelPart(' . implode(', ', array_map(array($writer, 'formatWord'), $words)) . ')') : 'getLabel()' + $words ? ('getLabelPart(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')') : 'getLabel()' ); } @@ -129,7 +129,7 @@ public function macroInput(MacroNode $node, PhpWriter $writer) . '->%1.raw' . ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : ''), $name, - $words ? 'getControlPart(' . implode(', ', array_map(array($writer, 'formatWord'), $words)) . ')' : 'getControl()' + $words ? 'getControlPart(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')' : 'getControl()' ); } @@ -172,7 +172,7 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer) . ($node->htmlNode->attrs ? '->addAttributes(%2.var)' : '') . '->attributes()', $name, $words - ? $method . 'Part(' . implode(', ', array_map(array($writer, 'formatWord'), $words)) . ')' + ? $method . 'Part(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')' : "{method_exists(\$_input, '{$method}Part')?'{$method}Part':'{$method}'}()", array_fill_keys(array_keys($node->htmlNode->attrs), NULL) ); diff --git a/src/Bridges/FormsLatte/Runtime.php b/src/Bridges/FormsLatte/Runtime.php index ce4986502..6f9841b6c 100644 --- a/src/Bridges/FormsLatte/Runtime.php +++ b/src/Bridges/FormsLatte/Runtime.php @@ -53,7 +53,7 @@ public static function renderFormEnd(Form $form, $withTags = TRUE) $parts = explode('=', $param, 2); $name = urldecode($parts[0]); if (!isset($form[$name])) { - $s .= Html::el('input', array('type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1]))); + $s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])]); } } } diff --git a/src/Forms/Container.php b/src/Forms/Container.php index 528f7c453..368cb5c35 100644 --- a/src/Forms/Container.php +++ b/src/Forms/Container.php @@ -82,7 +82,7 @@ public function setValues($values, $erase = FALSE) $control->setValues($values[$name], $erase); } elseif ($erase) { - $control->setValues(array(), $erase); + $control->setValues([], $erase); } } } @@ -97,7 +97,7 @@ public function setValues($values, $erase = FALSE) */ public function getValues($asArray = FALSE) { - $values = $asArray ? array() : new Nette\Utils\ArrayHash; + $values = $asArray ? [] : new Nette\Utils\ArrayHash; foreach ($this->getComponents() as $name => $control) { if ($control instanceof IControl && !$control->isOmitted()) { $values[$name] = $control->getValue(); @@ -139,7 +139,7 @@ public function validate(array $controls = NULL) foreach ($controls === NULL ? $this->getComponents() : $controls as $control) { $control->validate(); } - foreach ($this->onValidate ?: array() as $handler) { + foreach ($this->onValidate ?: [] as $handler) { $params = Nette\Utils\Callback::toReflection($handler)->getParameters(); $values = isset($params[1]) ? $this->getValues($params[1]->isArray()) : NULL; Nette\Utils\Callback::invoke($handler, $this, $values); @@ -154,7 +154,7 @@ public function validate(array $controls = NULL) */ public function getErrors() { - $errors = array(); + $errors = []; foreach ($this->getControls() as $control) { $errors = array_merge($errors, $control->getErrors()); } diff --git a/src/Forms/ControlGroup.php b/src/Forms/ControlGroup.php index e3dd33030..b0cc023b7 100644 --- a/src/Forms/ControlGroup.php +++ b/src/Forms/ControlGroup.php @@ -24,7 +24,7 @@ class ControlGroup extends Nette\Object protected $controls; /** @var array user options */ - private $options = array(); + private $options = []; public function __construct() diff --git a/src/Forms/Controls/BaseControl.php b/src/Forms/Controls/BaseControl.php index 0db4c79e5..ed9430a3f 100644 --- a/src/Forms/Controls/BaseControl.php +++ b/src/Forms/Controls/BaseControl.php @@ -54,7 +54,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements ICo protected $label; /** @var array */ - private $errors = array(); + private $errors = []; /** @var bool */ protected $disabled = FALSE; @@ -69,7 +69,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements ICo private $translator = TRUE; // means autodetect /** @var array user options */ - private $options = array(); + private $options = []; /** @@ -79,7 +79,7 @@ public function __construct($caption = NULL) { $this->monitor('Nette\Forms\Form'); parent::__construct(); - $this->control = Html::el('input', array('type' => NULL, 'name' => NULL)); + $this->control = Html::el('input', ['type' => NULL, 'name' => NULL]); $this->label = Html::el('label'); $this->caption = $caption; $this->rules = new Nette\Forms\Rules($this); @@ -172,7 +172,7 @@ public function getValue() public function isFilled() { $value = $this->getValue(); - return $value !== NULL && $value !== array() && $value !== ''; + return $value !== NULL && $value !== [] && $value !== ''; } @@ -248,13 +248,13 @@ public function getControl() { $this->setOption('rendered', TRUE); $el = clone $this->control; - return $el->addAttributes(array( + return $el->addAttributes([ 'name' => $this->getHtmlName(), 'id' => $this->getHtmlId(), 'required' => $this->isRequired(), 'disabled' => $this->isDisabled(), 'data-nette-rules' => Nette\Forms\Helpers::exportRules($this->rules) ?: NULL, - )); + ]); } @@ -366,7 +366,7 @@ public function getTranslator() public function translate($value, $count = NULL) { if ($translator = $this->getTranslator()) { - $tmp = is_array($value) ? array(& $value) : array(array(& $value)); + $tmp = is_array($value) ? [& $value] : [[& $value]]; foreach ($tmp[0] as & $v) { if ($v != NULL && !$v instanceof Html) { // intentionally == $v = $translator->translate($v, $count); @@ -509,7 +509,7 @@ public function hasErrors() */ public function cleanErrors() { - $this->errors = array(); + $this->errors = []; } diff --git a/src/Forms/Controls/Button.php b/src/Forms/Controls/Button.php index 367c2da3b..69c38e937 100644 --- a/src/Forms/Controls/Button.php +++ b/src/Forms/Controls/Button.php @@ -35,7 +35,7 @@ public function __construct($caption = NULL) public function isFilled() { $value = $this->getValue(); - return $value !== NULL && $value !== array(); + return $value !== NULL && $value !== []; } @@ -58,11 +58,11 @@ public function getControl($caption = NULL) { $this->setOption('rendered', TRUE); $el = clone $this->control; - return $el->addAttributes(array( + return $el->addAttributes([ 'name' => $this->getHtmlName(), 'disabled' => $this->isDisabled(), 'value' => $this->translate($caption === NULL ? $this->caption : $caption), - )); + ]); } } diff --git a/src/Forms/Controls/CheckboxList.php b/src/Forms/Controls/CheckboxList.php index 6e1837f6f..ed527c739 100644 --- a/src/Forms/Controls/CheckboxList.php +++ b/src/Forms/Controls/CheckboxList.php @@ -43,13 +43,13 @@ public function getControl() $input = parent::getControl(); return Nette\Forms\Helpers::createInputList( $this->translate($items), - array_merge($input->attrs, array( + array_merge($input->attrs, [ 'id' => NULL, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'required' => NULL, - 'data-nette-rules:' => array(key($items) => $input->attrs['data-nette-rules']), - )), + 'data-nette-rules:' => [key($items) => $input->attrs['data-nette-rules']], + ]), $this->label->attrs, $this->separator ); @@ -82,14 +82,14 @@ public function getSeparatorPrototype() */ public function getControlPart($key) { - $key = key(array((string) $key => NULL)); - return parent::getControl()->addAttributes(array( + $key = key([(string) $key => NULL]); + return parent::getControl()->addAttributes([ 'id' => $this->getHtmlId() . '-' . $key, 'checked' => in_array($key, (array) $this->value, TRUE), 'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled, 'required' => NULL, 'value' => $key, - )); + ]); } diff --git a/src/Forms/Controls/ChoiceControl.php b/src/Forms/Controls/ChoiceControl.php index b536a1c5a..332ab5a8c 100644 --- a/src/Forms/Controls/ChoiceControl.php +++ b/src/Forms/Controls/ChoiceControl.php @@ -22,7 +22,7 @@ abstract class ChoiceControl extends BaseControl { /** @var array */ - private $items = array(); + private $items = []; public function __construct($label = NULL, array $items = NULL) @@ -45,7 +45,7 @@ public function loadHttpData() if (is_array($this->disabled) && isset($this->disabled[$this->value])) { $this->value = NULL; } else { - $this->value = key(array($this->value => NULL)); + $this->value = key([$this->value => NULL]); } } } @@ -62,7 +62,7 @@ public function setValue($value) $range = Nette\Utils\Strings::truncate(implode(', ', array_map(function($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...'); throw new Nette\InvalidArgumentException("Value '$value' is out of allowed range [$range] in field '{$this->name}'."); } - $this->value = $value === NULL ? NULL : key(array((string) $value => NULL)); + $this->value = $value === NULL ? NULL : key([(string) $value => NULL]); return $this; } diff --git a/src/Forms/Controls/HiddenField.php b/src/Forms/Controls/HiddenField.php index 47f9d9c70..df7c8f4cf 100644 --- a/src/Forms/Controls/HiddenField.php +++ b/src/Forms/Controls/HiddenField.php @@ -58,11 +58,11 @@ public function getControl() { $this->setOption('rendered', TRUE); $el = clone $this->control; - return $el->addAttributes(array( + return $el->addAttributes([ 'name' => $this->getHtmlName(), 'disabled' => $this->isDisabled(), 'value' => $this->value, - )); + ]); } diff --git a/src/Forms/Controls/ImageButton.php b/src/Forms/Controls/ImageButton.php index 30ca0bc88..4c0964c8d 100644 --- a/src/Forms/Controls/ImageButton.php +++ b/src/Forms/Controls/ImageButton.php @@ -39,7 +39,7 @@ public function loadHttpData() { parent::loadHttpData(); $this->value = $this->value - ? array((int) array_shift($this->value), (int) array_shift($this->value)) + ? [(int) array_shift($this->value), (int) array_shift($this->value)] : NULL; } diff --git a/src/Forms/Controls/MultiChoiceControl.php b/src/Forms/Controls/MultiChoiceControl.php index c5bac0fca..278bc571d 100644 --- a/src/Forms/Controls/MultiChoiceControl.php +++ b/src/Forms/Controls/MultiChoiceControl.php @@ -22,7 +22,7 @@ abstract class MultiChoiceControl extends BaseControl { /** @var array */ - private $items = array(); + private $items = []; public function __construct($label = NULL, array $items = NULL) @@ -59,7 +59,7 @@ public function setValue($values) } elseif (!is_array($values)) { throw new Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name)); } - $flip = array(); + $flip = []; foreach ($values as $value) { if (!is_scalar($value) && !method_exists($value, '__toString')) { throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name)); @@ -103,7 +103,7 @@ public function getRawValue() */ public function isFilled() { - return $this->getValue() !== array(); + return $this->getValue() !== []; } diff --git a/src/Forms/Controls/MultiSelectBox.php b/src/Forms/Controls/MultiSelectBox.php index de60df419..e9eb1de94 100644 --- a/src/Forms/Controls/MultiSelectBox.php +++ b/src/Forms/Controls/MultiSelectBox.php @@ -18,7 +18,7 @@ class MultiSelectBox extends MultiChoiceControl { /** @var array of option / optgroup */ - private $options = array(); + private $options = []; /** @@ -28,7 +28,7 @@ class MultiSelectBox extends MultiChoiceControl public function setItems(array $items, $useKeys = TRUE) { if (!$useKeys) { - $res = array(); + $res = []; foreach ($items as $key => $value) { unset($items[$key]); if (is_array($value)) { @@ -52,17 +52,17 @@ public function setItems(array $items, $useKeys = TRUE) */ public function getControl() { - $items = array(); + $items = []; foreach ($this->options as $key => $value) { $items[is_array($value) ? $this->translate($key) : $key] = $this->translate($value); } return Nette\Forms\Helpers::createSelectBox( $items, - array( + [ 'selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL - ) + ] )->addAttributes(parent::getControl()->attrs)->multiple(TRUE); } diff --git a/src/Forms/Controls/RadioList.php b/src/Forms/Controls/RadioList.php index 7134f3aa7..f8997f56e 100644 --- a/src/Forms/Controls/RadioList.php +++ b/src/Forms/Controls/RadioList.php @@ -97,7 +97,7 @@ public function getControl() { $input = parent::getControl(); $items = $this->getItems(); - $ids = array(); + $ids = []; if ($this->generateId) { foreach ($items as $value => $label) { $ids[$value] = $input->id . '-' . $value; @@ -107,13 +107,13 @@ public function getControl() return $this->container->setHtml( Nette\Forms\Helpers::createInputList( $this->translate($items), - array_merge($input->attrs, array( + array_merge($input->attrs, [ 'id:' => $ids, 'checked?' => $this->value, 'disabled:' => $this->disabled, - 'data-nette-rules:' => array(key($items) => $input->attrs['data-nette-rules']), - )), - array('for:' => $ids) + $this->itemLabel->attrs, + 'data-nette-rules:' => [key($items) => $input->attrs['data-nette-rules']], + ]), + ['for:' => $ids] + $this->itemLabel->attrs, $this->separator ) ); @@ -136,13 +136,13 @@ public function getLabel($caption = NULL) */ public function getControlPart($key) { - $key = key(array((string) $key => NULL)); - return parent::getControl()->addAttributes(array( + $key = key([(string) $key => NULL]); + return parent::getControl()->addAttributes([ 'id' => $this->getHtmlId() . '-' . $key, 'checked' => in_array($key, (array) $this->value, TRUE), 'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled, 'value' => $key, - )); + ]); } diff --git a/src/Forms/Controls/SelectBox.php b/src/Forms/Controls/SelectBox.php index dd9b75f8d..74caeac52 100644 --- a/src/Forms/Controls/SelectBox.php +++ b/src/Forms/Controls/SelectBox.php @@ -23,7 +23,7 @@ class SelectBox extends ChoiceControl const VALID = ':selectBoxValid'; /** @var array of option / optgroup */ - private $options = array(); + private $options = []; /** @var mixed */ private $prompt = FALSE; @@ -58,7 +58,7 @@ public function getPrompt() public function setItems(array $items, $useKeys = TRUE) { if (!$useKeys) { - $res = array(); + $res = []; foreach ($items as $key => $value) { unset($items[$key]); if (is_array($value)) { @@ -82,17 +82,17 @@ public function setItems(array $items, $useKeys = TRUE) */ public function getControl() { - $items = $this->prompt === FALSE ? array() : array('' => $this->translate($this->prompt)); + $items = $this->prompt === FALSE ? [] : ['' => $this->translate($this->prompt)]; foreach ($this->options as $key => $value) { $items[is_array($value) ? $this->translate($key) : $key] = $this->translate($value); } return Nette\Forms\Helpers::createSelectBox( $items, - array( + [ 'selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL - ) + ] )->addAttributes(parent::getControl()->attrs); } diff --git a/src/Forms/Controls/SubmitButton.php b/src/Forms/Controls/SubmitButton.php index 03d63fc64..a47493f42 100644 --- a/src/Forms/Controls/SubmitButton.php +++ b/src/Forms/Controls/SubmitButton.php @@ -73,8 +73,8 @@ public function setValidationScope(/*array*/$scope = NULL) if ($scope === NULL || $scope === TRUE) { $this->validationScope = NULL; } else { - $this->validationScope = array(); - foreach ($scope ?: array() as $control) { + $this->validationScope = []; + foreach ($scope ?: [] as $control) { if (!$control instanceof Nette\Forms\Container && !$control instanceof Nette\Forms\IControl) { throw new Nette\InvalidArgumentException('Validation scope accepts only Nette\Forms\Container or Nette\Forms\IControl instances.'); } @@ -112,14 +112,14 @@ public function click() */ public function getControl($caption = NULL) { - $scope = array(); + $scope = []; foreach ((array) $this->validationScope as $control) { $scope[] = $control->lookupPath('Nette\Forms\Form'); } - return parent::getControl($caption)->addAttributes(array( + return parent::getControl($caption)->addAttributes([ 'formnovalidate' => $this->validationScope !== NULL, 'data-nette-validation-scope' => $scope ?: NULL, - )); + ]); } } diff --git a/src/Forms/Controls/TextInput.php b/src/Forms/Controls/TextInput.php index cabe47292..7d7df1932 100644 --- a/src/Forms/Controls/TextInput.php +++ b/src/Forms/Controls/TextInput.php @@ -65,13 +65,13 @@ public function getControl() foreach ($this->getRules() as $rule) { if ($rule->isNegative || $rule->branch) { - } elseif (in_array($rule->validator, array(Form::MIN, Form::MAX, Form::RANGE), TRUE) - && in_array($input->type, array('number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'), TRUE) + } elseif (in_array($rule->validator, [Form::MIN, Form::MAX, Form::RANGE], TRUE) + && in_array($input->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], TRUE) ) { if ($rule->validator === Form::MIN) { - $range = array($rule->arg, NULL); + $range = [$rule->arg, NULL]; } elseif ($rule->validator === Form::MAX) { - $range = array(NULL, $rule->arg); + $range = [NULL, $rule->arg]; } else { $range = $rule->arg; } @@ -83,7 +83,7 @@ public function getControl() } } elseif ($rule->validator === Form::PATTERN && is_scalar($rule->arg) - && in_array($input->type, array('text', 'search', 'tel', 'url', 'email', 'password'), TRUE) + && in_array($input->type, ['text', 'search', 'tel', 'url', 'email', 'password'], TRUE) ) { $input->pattern = $rule->arg; } diff --git a/src/Forms/Form.php b/src/Forms/Form.php index b90acb4ac..4ddf7df45 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -108,10 +108,10 @@ class Form extends Container implements Nette\Utils\IHtmlString private $translator; /** @var ControlGroup[] */ - private $groups = array(); + private $groups = []; /** @var array */ - private $errors = array(); + private $errors = []; /** @var Nette\Http\IRequest used only by standalone form */ public $httpRequest; @@ -478,7 +478,7 @@ public function validateMaxPostSize() return; } $maxSize = ini_get('post_max_size'); - $units = array('k' => 10, 'm' => 20, 'g' => 30); + $units = ['k' => 10, 'm' => 20, 'g' => 30]; if (isset($units[$ch = strtolower(substr($maxSize, -1))])) { $maxSize <<= $units[$ch]; } @@ -523,7 +523,7 @@ public function hasErrors() */ public function cleanErrors() { - $this->errors = array(); + $this->errors = []; } @@ -587,7 +587,7 @@ public function render() { $args = func_get_args(); array_unshift($args, $this); - echo call_user_func_array(array($this->getRenderer(), 'render'), $args); + echo call_user_func_array([$this->getRenderer(), 'render'], $args); } @@ -631,7 +631,7 @@ private function getHttpRequest() */ public function getToggles() { - $toggles = array(); + $toggles = []; foreach ($this->getControls() as $control) { $toggles = $control->getRules()->getToggleStates($toggles); } diff --git a/src/Forms/Helpers.php b/src/Forms/Helpers.php index 63fc6767b..8ea47a33c 100644 --- a/src/Forms/Helpers.php +++ b/src/Forms/Helpers.php @@ -19,10 +19,10 @@ */ class Helpers extends Nette\Object { - private static $unsafeNames = array( + private static $unsafeNames = [ 'attributes', 'children', 'elements', 'focus', 'length', 'reset', 'style', 'submit', 'onsubmit', 'form', 'presenter', 'action', - ); + ]; /** @@ -35,13 +35,13 @@ class Helpers extends Nette\Object */ public static function extractHttpData(array $data, $htmlName, $type) { - $name = explode('[', str_replace(array('[]', ']', '.'), array('', '', '_'), $htmlName)); + $name = explode('[', str_replace(['[]', ']', '.'], ['', '', '_'], $htmlName)); $data = Nette\Utils\Arrays::get($data, $name, NULL); $itype = $type & ~Form::DATA_KEYS; if (substr($htmlName, -2) === '[]') { if (!is_array($data)) { - return array(); + return []; } foreach ($data as $k => $v) { $data[$k] = $v = static::sanitize($itype, $v); @@ -98,7 +98,7 @@ public static function generateHtmlName($id) */ public static function exportRules(Rules $rules) { - $payload = array(); + $payload = []; foreach ($rules as $rule) { if (!is_string($op = $rule->validator)) { if (!Nette\Utils\Callback::isStatic($op)) { @@ -107,24 +107,24 @@ public static function exportRules(Rules $rules) $op = Nette\Utils\Callback::toString($op); } if ($rule->branch) { - $item = array( + $item = [ 'op' => ($rule->isNegative ? '~' : '') . $op, 'rules' => static::exportRules($rule->branch), 'control' => $rule->control->getHtmlName() - ); + ]; if ($rule->branch->getToggles()) { $item['toggle'] = $rule->branch->getToggles(); } } else { - $item = array('op' => ($rule->isNegative ? '~' : '') . $op, 'msg' => Validator::formatMessage($rule, FALSE)); + $item = ['op' => ($rule->isNegative ? '~' : '') . $op, 'msg' => Validator::formatMessage($rule, FALSE)]; } if (is_array($rule->arg)) { foreach ($rule->arg as $key => $value) { - $item['arg'][$key] = $value instanceof IControl ? array('control' => $value->getHtmlName()) : $value; + $item['arg'][$key] = $value instanceof IControl ? ['control' => $value->getHtmlName()] : $value; } } elseif ($rule->arg !== NULL) { - $item['arg'] = $rule->arg instanceof IControl ? array('control' => $rule->arg->getHtmlName()) : $rule->arg; + $item['arg'] = $rule->arg instanceof IControl ? ['control' => $rule->arg->getHtmlName()] : $rule->arg; } $payload[] = $item; @@ -143,7 +143,7 @@ public static function createInputList(array $items, array $inputAttrs = NULL, a $res = ''; $input = Html::el(); $label = Html::el(); - list($wrapper, $wrapperEnd) = $wrapper instanceof Html ? array($wrapper->startTag(), $wrapper->endTag()) : array((string) $wrapper, ''); + list($wrapper, $wrapperEnd) = $wrapper instanceof Html ? [$wrapper->startTag(), $wrapper->endTag()] : [(string) $wrapper, '']; foreach ($items as $value => $caption) { foreach ($inputAttrs as $k => $v) { @@ -177,7 +177,7 @@ public static function createSelectBox(array $items, array $optionAttrs = NULL) $res .= Html::el('optgroup')->label($group)->startTag(); $tmp = ''; } else { - $subitems = array($group => $subitems); + $subitems = [$group => $subitems]; } foreach ($subitems as $value => $caption) { $option->value = $value; @@ -202,7 +202,7 @@ public static function createSelectBox(array $items, array $optionAttrs = NULL) private static function prepareAttrs($attrs, $name) { - $dynamic = array(); + $dynamic = []; foreach ((array) $attrs as $k => $v) { $p = str_split($k, strlen($k) - 1); if ($p[1] === '?' || $p[1] === ':') { @@ -216,7 +216,7 @@ private static function prepareAttrs($attrs, $name) } } } - return array($dynamic, '<' . $name . Html::el(NULL, $attrs)->attributes()); + return [$dynamic, '<' . $name . Html::el(NULL, $attrs)->attributes()]; } } diff --git a/src/Forms/Rendering/DefaultFormRenderer.php b/src/Forms/Rendering/DefaultFormRenderer.php index e72a0bb91..82657c4f3 100644 --- a/src/Forms/Rendering/DefaultFormRenderer.php +++ b/src/Forms/Rendering/DefaultFormRenderer.php @@ -55,35 +55,35 @@ class DefaultFormRenderer extends Nette\Object implements Nette\Forms\IFormRende * \-- * * @var array of HTML tags */ - public $wrappers = array( - 'form' => array( + public $wrappers = [ + 'form' => [ 'container' => NULL, - ), + ], - 'error' => array( + 'error' => [ 'container' => 'ul class=error', 'item' => 'li', - ), + ], - 'group' => array( + 'group' => [ 'container' => 'fieldset', 'label' => 'legend', 'description' => 'p', - ), + ], - 'controls' => array( + 'controls' => [ 'container' => 'table', - ), + ], - 'pair' => array( + 'pair' => [ 'container' => 'tr', '.required' => 'required', '.optional' => NULL, '.odd' => NULL, '.error' => NULL, - ), + ], - 'control' => array( + 'control' => [ 'container' => 'td', '.odd' => NULL, @@ -99,18 +99,18 @@ class DefaultFormRenderer extends Nette\Object implements Nette\Forms\IFormRende '.submit' => 'button', '.image' => 'imagebutton', '.button' => 'button', - ), + ], - 'label' => array( + 'label' => [ 'container' => 'th', 'suffix' => NULL, 'requiredsuffix' => '', - ), + ], - 'hidden' => array( + 'hidden' => [ 'container' => 'div', - ), - ); + ], + ]; /** @var Nette\Forms\Form */ protected $form; @@ -172,7 +172,7 @@ public function renderBegin() $parts = explode('=', $param, 2); $name = urldecode($parts[0]); if (!isset($this->form[$name])) { - $s .= Html::el('input', array('type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1]))); + $s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])]); } } return $el->startTag() . ($s ? "\n\t" . $this->getWrapper('hidden container')->setHtml($s) : ''); @@ -369,7 +369,7 @@ public function renderPair(Nette\Forms\IControl $control) */ public function renderPairMulti(array $controls) { - $s = array(); + $s = []; foreach ($controls as $control) { if (!$control instanceof Nette\Forms\IControl) { throw new Nette\InvalidArgumentException('Argument must be array of Nette\Forms\IControl instances.'); diff --git a/src/Forms/Rules.php b/src/Forms/Rules.php index 893f19561..724a0453f 100644 --- a/src/Forms/Rules.php +++ b/src/Forms/Rules.php @@ -24,13 +24,13 @@ class Rules extends Nette\Object implements \IteratorAggregate private $required; /** @var Rule[] */ - private $rules = array(); + private $rules = []; /** @var Rules */ private $parent; /** @var array */ - private $toggles = array(); + private $toggles = []; /** @var IControl */ private $control; @@ -196,7 +196,7 @@ public function getToggles($actual = FALSE) * @internal * @return array */ - public function getToggleStates($toggles = array(), $success = TRUE) + public function getToggleStates($toggles = [], $success = TRUE) { foreach ($this->toggles as $id => $hide) { $toggles[$id] = ($success xor !$hide) || !empty($toggles[$id]); @@ -238,7 +238,7 @@ public function validate() */ public static function validateRule(Rule $rule) { - $args = is_array($rule->arg) ? $rule->arg : array($rule->arg); + $args = is_array($rule->arg) ? $rule->arg : [$rule->arg]; foreach ($args as & $val) { $val = $val instanceof IControl ? $val->getValue() : $val; } diff --git a/src/Forms/Validator.php b/src/Forms/Validator.php index c25ed83ec..be9b3b41f 100644 --- a/src/Forms/Validator.php +++ b/src/Forms/Validator.php @@ -20,7 +20,7 @@ class Validator extends Nette\Object { /** @var array */ - public static $messages = array( + public static $messages = [ Form::PROTECTION => 'Your session has expired. Please return to the home page and try again.', Form::EQUAL => 'Please enter %s.', Form::NOT_EQUAL => 'This value should not be %s.', @@ -41,7 +41,7 @@ class Validator extends Nette\Object Form::MIME_TYPE => 'The uploaded file is not in the expected format.', Form::IMAGE => 'The uploaded file must be image in format JPEG, GIF or PNG.', Controls\SelectBox::VALID => 'Please select a valid option.', - ); + ]; /** @internal */ @@ -69,7 +69,7 @@ public static function formatMessage(Rule $rule, $withValue = TRUE) case 'label': return $rule->control->translate($rule->control->caption); case 'value': return $withValue ? $rule->control->getValue() : $m[0]; default: - $args = is_array($rule->arg) ? $rule->arg : array($rule->arg); + $args = is_array($rule->arg) ? $rule->arg : [$rule->arg]; $i = (int) $m[1] ? $m[1] - 1 : $i + 1; return isset($args[$i]) ? ($args[$i] instanceof IControl ? ($withValue ? $args[$i]->getValue() : "%$i") : $args[$i]) : ''; } @@ -88,8 +88,8 @@ public static function formatMessage(Rule $rule, $withValue = TRUE) public static function validateEqual(IControl $control, $arg) { $value = $control->getValue(); - foreach ((is_array($value) ? $value : array($value)) as $val) { - foreach ((is_array($arg) ? $arg : array($arg)) as $item) { + foreach ((is_array($value) ? $value : [$value]) as $val) { + foreach ((is_array($arg) ? $arg : [$arg]) as $item) { if ((string) $val === (string) $item) { continue 2; } @@ -156,7 +156,7 @@ public static function validateRange(IControl $control, $range) */ public static function validateMin(IControl $control, $minimum) { - return Validators::isInRange($control->getValue(), array($minimum, NULL)); + return Validators::isInRange($control->getValue(), [$minimum, NULL]); } @@ -166,7 +166,7 @@ public static function validateMin(IControl $control, $minimum) */ public static function validateMax(IControl $control, $maximum) { - return Validators::isInRange($control->getValue(), array(NULL, $maximum)); + return Validators::isInRange($control->getValue(), [NULL, $maximum]); } @@ -177,7 +177,7 @@ public static function validateMax(IControl $control, $maximum) public static function validateLength(IControl $control, $range) { if (!is_array($range)) { - $range = array($range, $range); + $range = [$range, $range]; } $value = $control->getValue(); return Validators::isInRange(is_array($value) ? count($value) : Strings::length($value), $range); @@ -190,7 +190,7 @@ public static function validateLength(IControl $control, $range) */ public static function validateMinLength(IControl $control, $length) { - return static::validateLength($control, array($length, NULL)); + return static::validateLength($control, [$length, NULL]); } @@ -200,7 +200,7 @@ public static function validateMinLength(IControl $control, $length) */ public static function validateMaxLength(IControl $control, $length) { - return static::validateLength($control, array(NULL, $length)); + return static::validateLength($control, [NULL, $length]); } @@ -273,7 +273,7 @@ public static function validateInteger(IControl $control) */ public static function validateFloat(IControl $control) { - $value = str_replace(array(' ', ','), array('', '.'), $control->getValue()); + $value = str_replace([' ', ','], ['', '.'], $control->getValue()); if (Validators::isNumeric($value)) { $control->setValue((float) $value); return TRUE; @@ -334,7 +334,7 @@ public static function validateImage(Controls\UploadControl $control) */ private static function toArray($value) { - return $value instanceof Nette\Http\FileUpload ? array($value) : (array) $value; + return $value instanceof Nette\Http\FileUpload ? [$value] : (array) $value; } } diff --git a/tests/Forms.Latte/FormMacros.button.phpt b/tests/Forms.Latte/FormMacros.button.phpt index 7046bb1ed..783f58a91 100644 --- a/tests/Forms.Latte/FormMacros.button.phpt +++ b/tests/Forms.Latte/FormMacros.button.phpt @@ -27,6 +27,6 @@ Assert::matchFile( __DIR__ . '/expected/FormMacros.button.html', $latte->renderToString( __DIR__ . '/templates/forms.button.latte', - array('_control' => array('myForm' => $form)) + ['_control' => ['myForm' => $form]] ) ); diff --git a/tests/Forms.Latte/FormMacros.formContainer.phpt b/tests/Forms.Latte/FormMacros.formContainer.phpt index 9dbb75df6..9d2c1094c 100644 --- a/tests/Forms.Latte/FormMacros.formContainer.phpt +++ b/tests/Forms.Latte/FormMacros.formContainer.phpt @@ -27,7 +27,7 @@ $cont2->addCheckbox('input6', 'Input 6'); $cont1->addText('input7', 'Input 7'); $contItems = $form->addContainer('items'); -$items = array(1, 3); +$items = [1, 3]; foreach ($items as $item) { $contItem = $contItems->addContainer($item); $contItem->addText('input', 'Input'); @@ -47,6 +47,6 @@ Assert::matchFile( __DIR__ . '/expected/FormMacros.formContainer.html', $latte->renderToString( __DIR__ . '/templates/forms.formContainer.latte', - array('_control' => array('myForm' => $form)) + ['_control' => ['myForm' => $form]] ) ); diff --git a/tests/Forms.Latte/FormMacros.forms.phpt b/tests/Forms.Latte/FormMacros.forms.phpt index 4590a1b8b..0875e0edc 100644 --- a/tests/Forms.Latte/FormMacros.forms.phpt +++ b/tests/Forms.Latte/FormMacros.forms.phpt @@ -29,11 +29,11 @@ class MyControl extends Nette\Forms\Controls\BaseControl $form = new Form; $form->addHidden('id'); $form->addText('username', 'Username:'); // must have just one textfield to generate IE fix -$form->addRadioList('sex', 'Sex:', array('m' => 'male', 'f' => 'female')); -$form->addSelect('select', NULL, array('m' => 'male', 'f' => 'female')); +$form->addRadioList('sex', 'Sex:', ['m' => 'male', 'f' => 'female']); +$form->addSelect('select', NULL, ['m' => 'male', 'f' => 'female']); $form->addTextArea('area', NULL)->setValue('oneaddCheckbox('checkbox', NULL); -$form->addCheckboxList('checklist', NULL, array('m' => 'male', 'f' => 'female')); +$form->addCheckboxList('checklist', NULL, ['m' => 'male', 'f' => 'female']); $form->addSubmit('send', 'Sign in'); $form['my'] = new MyControl; @@ -50,6 +50,6 @@ Assert::matchFile( __DIR__ . '/expected/FormMacros.forms.html', $latte->renderToString( __DIR__ . '/templates/forms.latte', - array('_control' => array('myForm' => $form)) + ['_control' => ['myForm' => $form]] ) ); diff --git a/tests/Forms.Latte/FormMacros.get.phpt b/tests/Forms.Latte/FormMacros.get.phpt index 65f78f279..7f9ffe10b 100644 --- a/tests/Forms.Latte/FormMacros.get.phpt +++ b/tests/Forms.Latte/FormMacros.get.phpt @@ -28,6 +28,6 @@ Assert::matchFile( __DIR__ . '/expected/FormMacros.get.html', $latte->renderToString( __DIR__ . '/templates/forms.get.latte', - array('_control' => array('myForm' => $form)) + ['_control' => ['myForm' => $form]] ) ); diff --git a/tests/Forms.Latte/Runtime.get.phpt b/tests/Forms.Latte/Runtime.get.phpt index bd9418258..b0f11a2b6 100644 --- a/tests/Forms.Latte/Runtime.get.phpt +++ b/tests/Forms.Latte/Runtime.get.phpt @@ -17,7 +17,7 @@ $form->action = 'http://example.com/?do=foo-submit#toc'; Assert::same( '
', - Runtime::renderFormBegin($form, array()) + Runtime::renderFormBegin($form, []) ); Assert::match( diff --git a/tests/Forms/Container.validate().phpt b/tests/Forms/Container.validate().phpt index 93fcc2464..54bf92a90 100644 --- a/tests/Forms/Container.validate().phpt +++ b/tests/Forms/Container.validate().phpt @@ -24,11 +24,11 @@ $container->onValidate[] = function (Container $container) { $container['name']->addError('fail 2'); }; -$form->setValues(array('name' => "invalid*input")); +$form->setValues(['name' => "invalid*input"]); $form->validate(); -Assert::same(array( +Assert::same([ 'Please enter a valid integer.', 'fail 1', 'fail 2' -), $form->getErrors()); +], $form->getErrors()); diff --git a/tests/Forms/Container.values.phpt b/tests/Forms/Container.values.phpt index 776e1cbca..f31d7911a 100644 --- a/tests/Forms/Container.values.phpt +++ b/tests/Forms/Container.values.phpt @@ -15,17 +15,17 @@ require __DIR__ . '/../bootstrap.php'; $_SERVER['REQUEST_METHOD'] = 'POST'; -$_POST = array( +$_POST = [ 'name' => 'jim', - 'first' => array( + 'first' => [ 'name' => 'jim', 'age' => '40', - 'second' => array( + 'second' => [ 'name' => 'david', - ), - ), + ], + ], 'invalid' => TRUE, -); +]; $first = new Nette\Forms\Container; @@ -35,22 +35,22 @@ $first->addText('age'); $second = $first->addContainer('second'); $second->addText('name'); -$first->setDefaults(array( +$first->setDefaults([ 'name' => 'xxx', 'age' => '50', - 'second' => array( + 'second' => [ 'name' => 'yyy', 'age' => '30', - ), -)); + ], +]); -Assert::equal( ArrayHash::from(array( +Assert::equal( ArrayHash::from([ 'name' => 'xxx', 'age' => '50', - 'second' => ArrayHash::from(array( + 'second' => ArrayHash::from([ 'name' => 'yyy', - )), -)), $first->getValues() ); + ]), +]), $first->getValues() ); $form = new Form; @@ -62,16 +62,16 @@ $form->addSubmit('send'); Assert::truthy( $form->isSubmitted() ); -Assert::equal( ArrayHash::from(array( +Assert::equal( ArrayHash::from([ 'name' => 'jim', - 'first' => ArrayHash::from(array( + 'first' => ArrayHash::from([ 'name' => 'jim', 'age' => '40', - 'second' => ArrayHash::from(array( + 'second' => ArrayHash::from([ 'name' => 'david', - )), - )), - 'invalid' => ArrayHash::from(array( + ]), + ]), + 'invalid' => ArrayHash::from([ 'name' => '', - )), -)), $form->getValues() ); + ]), +]), $form->getValues() ); diff --git a/tests/Forms/Controls.BaseControl.phpt b/tests/Forms/Controls.BaseControl.phpt index 8342bcaed..3613035fa 100644 --- a/tests/Forms/Controls.BaseControl.phpt +++ b/tests/Forms/Controls.BaseControl.phpt @@ -17,13 +17,13 @@ test(function() { // error handling $input = $form->addText('text') ->addRule($form::EMAIL, 'error'); - Assert::same( array(), $input->getErrors() ); + Assert::same( [], $input->getErrors() ); Assert::null( $input->getError() ); Assert::false( $input->hasErrors() ); $input->validate(); - Assert::same( array('error'), $input->getErrors() ); + Assert::same( ['error'], $input->getErrors() ); Assert::same( 'error', $input->getError() ); Assert::true( $input->hasErrors() ); @@ -39,8 +39,8 @@ test(function() { // validators Assert::true( Validator::validateEqual($input, 123) ); Assert::true( Validator::validateEqual($input, '123') ); - Assert::true( Validator::validateEqual($input, array(123, 3)) ); // "is in" - Assert::false( Validator::validateEqual($input, array('x')) ); + Assert::true( Validator::validateEqual($input, [123, 3]) ); // "is in" + Assert::false( Validator::validateEqual($input, ['x']) ); Assert::true( Validator::validateFilled($input) ); Assert::true( Validator::validateValid($input) ); @@ -55,9 +55,9 @@ test(function() { // validators Assert::true( Validator::validateMaxLength($input, 3) ); Assert::false( Validator::validateMaxLength($input, 2) ); - Assert::true( Validator::validateRange($input, array(NULL, NULL)) ); - Assert::true( Validator::validateRange($input, array(100, 1000)) ); - Assert::false( Validator::validateRange($input, array(1000, NULL)) ); + Assert::true( Validator::validateRange($input, [NULL, NULL]) ); + Assert::true( Validator::validateRange($input, [100, 1000]) ); + Assert::false( Validator::validateRange($input, [1000, NULL]) ); Assert::true( Validator::validateMin($input, 122) ); Assert::true( Validator::validateMin($input, 123) ); @@ -71,12 +71,12 @@ test(function() { // validators test(function() { // validators for array $form = new Form; - $input = $form->addMultiSelect('select', NULL, array('a', 'b', 'c', 'd')); - $input->setValue(array(1, 2, 3)); + $input = $form->addMultiSelect('select', NULL, ['a', 'b', 'c', 'd']); + $input->setValue([1, 2, 3]); - Assert::true( Validator::validateEqual($input, array(1, 2, 3, 4)) ); - Assert::true( Validator::validateEqual($input, array('1', '2', '3')) ); - Assert::false( Validator::validateEqual($input, array('x')) ); + Assert::true( Validator::validateEqual($input, [1, 2, 3, 4]) ); + Assert::true( Validator::validateEqual($input, ['1', '2', '3']) ); + Assert::false( Validator::validateEqual($input, ['x']) ); Assert::true( Validator::validateFilled($input) ); Assert::true( Validator::validateValid($input) ); @@ -123,7 +123,7 @@ test(function() { // disabled test(function() { // disabled & submitted $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = array('disabled' => 'submitted value'); + $_POST = ['disabled' => 'submitted value']; $form = new Form; $form->addText('disabled') diff --git a/tests/Forms/Controls.Button.loadData.phpt b/tests/Forms/Controls.Button.loadData.phpt index 7de977983..477c4a910 100644 --- a/tests/Forms/Controls.Button.loadData.phpt +++ b/tests/Forms/Controls.Button.loadData.phpt @@ -13,14 +13,14 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); test(function() { - $_POST = array( + $_POST = [ 'button' => 'x', - ); + ]; $form = new Form; $input = $form->addSubmit('button'); @@ -30,10 +30,10 @@ test(function() { test(function() { // empty value - $_POST = array( + $_POST = [ 'button1' => '', 'button2' => '0', - ); + ]; $form = new Form; $input = $form->addSubmit('button1'); @@ -56,9 +56,9 @@ test(function() { // missing data test(function() { // malformed data - $_POST = array( - 'malformed' => array(), - ); + $_POST = [ + 'malformed' => [], + ]; $form = new Form; $input = $form->addSubmit('malformed'); diff --git a/tests/Forms/Controls.Button.render.phpt b/tests/Forms/Controls.Button.render.phpt index 3adf6966a..9574be501 100644 --- a/tests/Forms/Controls.Button.render.phpt +++ b/tests/Forms/Controls.Button.render.phpt @@ -92,7 +92,7 @@ test(function() { // SubmitButton with scope $form = new Form; $text = $form->addText('text'); $select = $form->addSelect('select'); - $input = $form->addSubmit('button', 'Caption')->setValidationScope(array($text, $select)); + $input = $form->addSubmit('button', 'Caption')->setValidationScope([$text, $select]); Assert::same('', (string) $input->getControl()); }); diff --git a/tests/Forms/Controls.Checkbox.loadData.phpt b/tests/Forms/Controls.Checkbox.loadData.phpt index 736f248f4..de2e538c1 100644 --- a/tests/Forms/Controls.Checkbox.loadData.phpt +++ b/tests/Forms/Controls.Checkbox.loadData.phpt @@ -13,15 +13,15 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); test(function() { - $_POST = array( + $_POST = [ 'off' => '', 'on' => 1, - ); + ]; $form = new Form; $input = $form->addCheckbox('off'); @@ -37,7 +37,7 @@ test(function() { test(function() { // malformed data - $_POST = array('malformed' => array(NULL)); + $_POST = ['malformed' => [NULL]]; $form = new Form; $input = $form->addCheckbox('malformed'); @@ -53,6 +53,6 @@ test(function() { // setValue() and invalid argument $input->setValue(NULL); Assert::exception(function() use ($input) { - $input->setValue(array()); + $input->setValue([]); }, 'Nette\InvalidArgumentException', "Value must be scalar or NULL, array given in field 'checkbox'."); }); diff --git a/tests/Forms/Controls.CheckboxList.loadData.phpt b/tests/Forms/Controls.CheckboxList.loadData.phpt index 6cb4ccc46..c39248704 100644 --- a/tests/Forms/Controls.CheckboxList.loadData.phpt +++ b/tests/Forms/Controls.CheckboxList.loadData.phpt @@ -15,54 +15,54 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); -$series = array( +$series = [ 'red-dwarf' => 'Red Dwarf', 'the-simpsons' => 'The Simpsons', 0 => 'South Park', '' => 'Family Guy', -); +]; test(function() use ($series) { // invalid input - $_POST = array('list' => 'red-dwarf'); + $_POST = ['list' => 'red-dwarf']; $form = new Form; $input = $form->addCheckboxList('list', NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); - Assert::same( array(), $input->getSelectedItems() ); + Assert::same( [], $input->getValue() ); + Assert::same( [], $input->getSelectedItems() ); Assert::false( $input->isFilled() ); }); test(function() use ($series) { // multiple selected items, zero item - $_POST = array('multi' => array('red-dwarf', 'unknown', 0)); + $_POST = ['multi' => ['red-dwarf', 'unknown', 0]]; $form = new Form; $input = $form->addCheckboxList('multi', NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array('red-dwarf', 0), $input->getValue() ); - Assert::same( array('red-dwarf', 'unknown', 0), $input->getRawValue() ); - Assert::same( array('red-dwarf' => 'Red Dwarf', 0 => 'South Park'), $input->getSelectedItems() ); + Assert::same( ['red-dwarf', 0], $input->getValue() ); + Assert::same( ['red-dwarf', 'unknown', 0], $input->getRawValue() ); + Assert::same( ['red-dwarf' => 'Red Dwarf', 0 => 'South Park'], $input->getSelectedItems() ); Assert::true( $input->isFilled() ); }); test(function() use ($series) { // empty key - $_POST = array('empty' => array('')); + $_POST = ['empty' => ['']]; $form = new Form; $input = $form->addCheckboxList('empty', NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(''), $input->getValue() ); - Assert::same( array('' => 'Family Guy'), $input->getSelectedItems() ); + Assert::same( [''], $input->getValue() ); + Assert::same( ['' => 'Family Guy'], $input->getSelectedItems() ); Assert::true( $input->isFilled() ); }); @@ -72,60 +72,60 @@ test(function() use ($series) { // missing key $input = $form->addCheckboxList('missing', NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); - Assert::same( array(), $input->getSelectedItems() ); + Assert::same( [], $input->getValue() ); + Assert::same( [], $input->getSelectedItems() ); Assert::false( $input->isFilled() ); }); test(function() use ($series) { // disabled key - $_POST = array('disabled' => 'red-dwarf'); + $_POST = ['disabled' => 'red-dwarf']; $form = new Form; $input = $form->addCheckboxList('disabled', NULL, $series) ->setDisabled(); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); + Assert::same( [], $input->getValue() ); }); test(function() use ($series) { // malformed data - $_POST = array('malformed' => array(array(NULL))); + $_POST = ['malformed' => [[NULL]]]; $form = new Form; $input = $form->addCheckboxList('malformed', NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); - Assert::same( array(), $input->getSelectedItems() ); + Assert::same( [], $input->getValue() ); + Assert::same( [], $input->getSelectedItems() ); Assert::false( $input->isFilled() ); }); test(function() use ($series) { // validateLength - $_POST = array('multi' => array('red-dwarf', 'unknown', 0)); + $_POST = ['multi' => ['red-dwarf', 'unknown', 0]]; $form = new Form; $input = $form->addCheckboxList('multi', NULL, $series); Assert::true( Validator::validateLength($input, 2) ); Assert::false( Validator::validateLength($input, 3) ); - Assert::false( Validator::validateLength($input, array(3, )) ); - Assert::true( Validator::validateLength($input, array(0, 3)) ); + Assert::false( Validator::validateLength($input, [3, ]) ); + Assert::true( Validator::validateLength($input, [0, 3]) ); }); test(function() use ($series) { // validateEqual - $_POST = array('multi' => array('red-dwarf', 'unknown', 0)); + $_POST = ['multi' => ['red-dwarf', 'unknown', 0]]; $form = new Form; $input = $form->addCheckboxList('multi', NULL, $series); - Assert::true( Validator::validateEqual($input, array('red-dwarf', 0)) ); + Assert::true( Validator::validateEqual($input, ['red-dwarf', 0]) ); Assert::false( Validator::validateEqual($input, 'unknown') ); - Assert::false( Validator::validateEqual($input, array('unknown')) ); - Assert::false( Validator::validateEqual($input, array(0)) ); + Assert::false( Validator::validateEqual($input, ['unknown']) ); + Assert::false( Validator::validateEqual($input, [0]) ); }); @@ -142,36 +142,36 @@ test(function() use ($series) { // setValue() and invalid argument test(function() { // object as value $form = new Form; - $input = $form->addCheckboxList('list', NULL, array('2013-07-05 00:00:00' => 1)) - ->setValue(array(new DateTime('2013-07-05'))); + $input = $form->addCheckboxList('list', NULL, ['2013-07-05 00:00:00' => 1]) + ->setValue([new DateTime('2013-07-05')]); - Assert::same( array('2013-07-05 00:00:00'), $input->getValue() ); + Assert::same( ['2013-07-05 00:00:00'], $input->getValue() ); }); test(function() { // object as item $form = new Form; $input = $form->addCheckboxList('list') - ->setItems(array(new DateTime('2013-07-05')), FALSE) + ->setItems([new DateTime('2013-07-05')], FALSE) ->setValue('2013-07-05 00:00:00'); - Assert::equal( array('2013-07-05 00:00:00' => new DateTime('2013-07-05')), $input->getSelectedItems() ); + Assert::equal( ['2013-07-05 00:00:00' => new DateTime('2013-07-05')], $input->getSelectedItems() ); }); test(function() use ($series) { // disabled one - $_POST = array('list' => array('red-dwarf', 0)); + $_POST = ['list' => ['red-dwarf', 0]]; $form = new Form; $input = $form->addCheckboxList('list', NULL, $series) - ->setDisabled(array('red-dwarf')); + ->setDisabled(['red-dwarf']); - Assert::same( array(0), $input->getValue() ); + Assert::same( [0], $input->getValue() ); unset($form['list']); $input = new Nette\Forms\Controls\CheckboxList(NULL, $series); - $input->setDisabled(array('red-dwarf')); + $input->setDisabled(['red-dwarf']); $form['list'] = $input; - Assert::same( array(0), $input->getValue() ); + Assert::same( [0], $input->getValue() ); }); diff --git a/tests/Forms/Controls.CheckboxList.render.phpt b/tests/Forms/Controls.CheckboxList.render.phpt index 9668c744a..34e57cb23 100644 --- a/tests/Forms/Controls.CheckboxList.render.phpt +++ b/tests/Forms/Controls.CheckboxList.render.phpt @@ -23,10 +23,10 @@ class Translator implements Nette\Localization\ITranslator test(function() { $form = new Form; - $input = $form->addCheckboxList('list', 'Label', array( + $input = $form->addCheckboxList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); Assert::type('Nette\Utils\Html', $input->getLabel()); Assert::same('', (string) $input->getLabel()); @@ -45,10 +45,10 @@ test(function() { test(function() { // checked $form = new Form; - $input = $form->addCheckboxList('list', 'Label', array( + $input = $form->addCheckboxList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setValue(0); + ])->setValue(0); Assert::same('
', $input->getControl()); }); @@ -56,10 +56,10 @@ test(function() { // checked test(function() { // translator $form = new Form; - $input = $form->addCheckboxList('list', 'Label', array( + $input = $form->addCheckboxList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); $input->setTranslator(new Translator); Assert::same('', (string) $input->getLabel()); @@ -73,9 +73,9 @@ test(function() { // translator test(function() { // Html $form = new Form; - $input = $form->addCheckboxList('list', Html::el('b', 'Label'), array( + $input = $form->addCheckboxList('list', Html::el('b', 'Label'), [ 'a' => Html::el('b', 'First'), - )); + ]); $input->setTranslator(new Translator); Assert::same('', (string) $input->getLabel()); @@ -88,10 +88,10 @@ test(function() { // Html test(function() { // validation rules $form = new Form; - $input = $form->addCheckboxList('list', 'Label', array( + $input = $form->addCheckboxList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setRequired('required'); + ])->setRequired('required'); Assert::same('
', $input->getControl()); Assert::same('', (string) $input->getControlPart(0)); @@ -101,10 +101,10 @@ test(function() { // validation rules test(function() { // container $form = new Form; $container = $form->addContainer('container'); - $input = $container->addCheckboxList('list', 'Label', array( + $input = $container->addCheckboxList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); Assert::same('
', $input->getControl()); }); @@ -112,9 +112,9 @@ test(function() { // container test(function() { // separator prototype $form = new Form; - $input = $form->addCheckboxList('list', NULL, array( + $input = $form->addCheckboxList('list', NULL, [ 'a' => 'b', - )); + ]); $input->getSeparatorPrototype()->setName('div'); Assert::same('
', $input->getControl()); @@ -123,10 +123,10 @@ test(function() { // separator prototype test(function() { // disabled all $form = new Form; - $input = $form->addCheckboxList('list', 'Label', array( + $input = $form->addCheckboxList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setDisabled(TRUE); + ])->setDisabled(TRUE); Assert::same('
', $input->getControl()); }); @@ -134,10 +134,10 @@ test(function() { // disabled all test(function() { // disabled one $form = new Form; - $input = $form->addCheckboxList('list', 'Label', array( + $input = $form->addCheckboxList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setDisabled(array('a')); + ])->setDisabled(['a']); Assert::same('
', $input->getControl()); Assert::same('', (string) $input->getControlPart('a')); @@ -146,10 +146,10 @@ test(function() { // disabled one test(function() { // numeric key as string & getControlPart $form = new Form; - $input = $form->addCheckboxList('list', 'Label', array( + $input = $form->addCheckboxList('list', 'Label', [ 1 => 'First', 2 => 'Second', - ))->setDefaultValue(1); + ])->setDefaultValue(1); Assert::same('', (string) $input->getControlPart('1')); }); diff --git a/tests/Forms/Controls.ChoiceControl.loadData.phpt b/tests/Forms/Controls.ChoiceControl.loadData.phpt index 666f2b0c3..a297973d6 100644 --- a/tests/Forms/Controls.ChoiceControl.loadData.phpt +++ b/tests/Forms/Controls.ChoiceControl.loadData.phpt @@ -18,20 +18,20 @@ class ChoiceControl extends Nette\Forms\Controls\ChoiceControl before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); -$series = array( +$series = [ 'red-dwarf' => 'Red Dwarf', 'the-simpsons' => 'The Simpsons', 0 => 'South Park', '' => 'Family Guy', -); +]; test(function() use ($series) { // Select - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form['select'] = new ChoiceControl(NULL, $series); @@ -44,7 +44,7 @@ test(function() use ($series) { // Select test(function() use ($series) { // Select with invalid input - $_POST = array('select' => 'days-of-our-lives'); + $_POST = ['select' => 'days-of-our-lives']; $form = new Form; $input = $form['select'] = new ChoiceControl(NULL, $series); @@ -57,7 +57,7 @@ test(function() use ($series) { // Select with invalid input test(function() use ($series) { // Indexed arrays - $_POST = array('zero' => 0); + $_POST = ['zero' => 0]; $form = new Form; $input = $form['zero'] = new ChoiceControl(NULL, $series); @@ -71,7 +71,7 @@ test(function() use ($series) { // Indexed arrays test(function() use ($series) { // empty key - $_POST = array('empty' => ''); + $_POST = ['empty' => '']; $form = new Form; $input = $form['empty'] = new ChoiceControl(NULL, $series); @@ -95,7 +95,7 @@ test(function() use ($series) { // missing key test(function() use ($series) { // disabled key - $_POST = array('disabled' => 'red-dwarf'); + $_POST = ['disabled' => 'red-dwarf']; $form = new Form; $input = $form['disabled'] = new ChoiceControl(NULL, $series); @@ -108,7 +108,7 @@ test(function() use ($series) { // disabled key test(function() use ($series) { // malformed data - $_POST = array('malformed' => array(NULL)); + $_POST = ['malformed' => [NULL]]; $form = new Form; $input = $form['malformed'] = new ChoiceControl(NULL, $series); @@ -121,17 +121,17 @@ test(function() use ($series) { // malformed data test(function() use ($series) { // setItems without keys - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form['select'] = new ChoiceControl; $input->setItems(array_keys($series), FALSE); - Assert::same( array( + Assert::same( [ 'red-dwarf' => 'red-dwarf', 'the-simpsons' => 'the-simpsons', 0 => 0, '' => '', - ), $input->getItems() ); + ], $input->getItems() ); Assert::true( $form->isValid() ); Assert::same( 'red-dwarf', $input->getValue() ); @@ -153,7 +153,7 @@ test(function() use ($series) { // setValue() and invalid argument test(function() { // object as value $form = new Form; - $input = $form['select'] = new ChoiceControl(NULL, array('2013-07-05 00:00:00' => 1)); + $input = $form['select'] = new ChoiceControl(NULL, ['2013-07-05 00:00:00' => 1]); $input->setValue(new DateTime('2013-07-05')); Assert::same( '2013-07-05 00:00:00', $input->getValue() ); @@ -163,7 +163,7 @@ test(function() { // object as value test(function() { // object as item $form = new Form; $input = $form['select'] = new ChoiceControl; - $input->setItems(array(new DateTime('2013-07-05')), FALSE) + $input->setItems([new DateTime('2013-07-05')], FALSE) ->setValue(new DateTime('2013-07-05')); Assert::same( '2013-07-05 00:00:00', $input->getValue() ); @@ -171,31 +171,31 @@ test(function() { // object as item test(function() use ($series) { // disabled one - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form['select'] = new ChoiceControl(NULL, $series); - $input->setDisabled(array('red-dwarf')); + $input->setDisabled(['red-dwarf']); Assert::null( $input->getValue() ); unset($form['select']); $input = new ChoiceControl(NULL, $series); - $input->setDisabled(array('red-dwarf')); + $input->setDisabled(['red-dwarf']); $form['select'] = $input; Assert::null( $input->getValue() ); }); test(function() { - $_POST = array('select' => 1); + $_POST = ['select' => 1]; $form = new Form; $input = $form['select'] = new ChoiceControl(NULL); - $input->setItems(array( + $input->setItems([ 1 => NULL, 2 => 'Red dwarf' - )); + ]); Assert::same( 1, $input->getValue() ); }); diff --git a/tests/Forms/Controls.CsrfProtection.breachAttack.phpt b/tests/Forms/Controls.CsrfProtection.breachAttack.phpt index 8a65ab23b..5e02659c5 100644 --- a/tests/Forms/Controls.CsrfProtection.breachAttack.phpt +++ b/tests/Forms/Controls.CsrfProtection.breachAttack.phpt @@ -23,7 +23,7 @@ Assert::notSame($token, $input->getControl()->value); $charlist = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; $charCount = strlen($charlist); -$strings = array(); +$strings = []; for ($a = 0; $a < $charCount; $a++) { for ($b = 0; $b < $charCount; $b++) { $strings[] = $charlist[$a] . $charlist[$b]; @@ -33,14 +33,14 @@ for ($a = 0; $a < $charCount; $a++) { for ($i = 3; $i <= strlen($token); $i++) { $code = (string) $input->getControl(); $shortest = NULL; - $adepts = array(); + $adepts = []; foreach ($strings as $string) { for ($j = 0; $j < $charCount; $j++) { $try = $string . $charlist[$j]; $length = strlen(gzdeflate($code . $try)); if ($shortest === NULL || $length < $shortest) { $shortest = $length; - $adepts = array(); + $adepts = []; } if ($shortest === $length) { $adepts[] = $try; diff --git a/tests/Forms/Controls.CsrfProtection.phpt b/tests/Forms/Controls.CsrfProtection.phpt index 9656d7d9a..246b3c8d7 100644 --- a/tests/Forms/Controls.CsrfProtection.phpt +++ b/tests/Forms/Controls.CsrfProtection.phpt @@ -21,19 +21,19 @@ $input = $form->addProtection('Security token did not match. Possible CSRF attac $form->fireEvents(); -Assert::same( array('Security token did not match. Possible CSRF attack.'), $form->getErrors() ); +Assert::same( ['Security token did not match. Possible CSRF attack.'], $form->getErrors() ); Assert::match('', (string) $input->getControl()); $input->setValue(NULL); Assert::false(CsrfProtection::validateCsrf($input)); -call_user_func(array($input, 'Nette\Forms\Controls\BaseControl::setValue'), '12345678901234567890123456789012345678'); +call_user_func([$input, 'Nette\Forms\Controls\BaseControl::setValue'], '12345678901234567890123456789012345678'); Assert::false(CsrfProtection::validateCsrf($input)); $value = $input->getControl()->value; -call_user_func(array($input, 'Nette\Forms\Controls\BaseControl::setValue'), $value); +call_user_func([$input, 'Nette\Forms\Controls\BaseControl::setValue'], $value); Assert::true(CsrfProtection::validateCsrf($input)); session_regenerate_id(); -call_user_func(array($input, 'Nette\Forms\Controls\BaseControl::setValue'), $value); +call_user_func([$input, 'Nette\Forms\Controls\BaseControl::setValue'], $value); Assert::false(CsrfProtection::validateCsrf($input)); diff --git a/tests/Forms/Controls.HiddenField.loadData.phpt b/tests/Forms/Controls.HiddenField.loadData.phpt index 336efe1e2..3e62579fa 100644 --- a/tests/Forms/Controls.HiddenField.loadData.phpt +++ b/tests/Forms/Controls.HiddenField.loadData.phpt @@ -13,12 +13,12 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); test(function() { - $_POST = array('text' => " a\r b \n c "); + $_POST = ['text' => " a\r b \n c "]; $form = new Form; $input = $form->addHidden('text'); Assert::same( " a\n b \n c ", $input->getValue() ); @@ -35,7 +35,7 @@ test(function() { test(function() { // invalid data - $_POST = array('malformed' => array(NULL)); + $_POST = ['malformed' => [NULL]]; $form = new Form; $input = $form->addHidden('malformed'); Assert::same( '', $input->getValue() ); @@ -47,8 +47,8 @@ test(function() { // errors are moved to form $form = new Form; $input = $form->addHidden('hidden'); $input->addError('error'); - Assert::same( array(), $input->getErrors() ); - Assert::same( array('error'), $form->getErrors() ); + Assert::same( [], $input->getErrors() ); + Assert::same( ['error'], $form->getErrors() ); }); @@ -58,7 +58,7 @@ test(function() { // setValue() and invalid argument $input->setValue(NULL); Assert::exception(function() use ($input) { - $input->setValue(array()); + $input->setValue([]); }, 'Nette\InvalidArgumentException', "Value must be scalar or NULL, array given in field 'hidden'."); }); diff --git a/tests/Forms/Controls.ImageButton.loadData.phpt b/tests/Forms/Controls.ImageButton.loadData.phpt index 3ddc61c58..79de70d6f 100644 --- a/tests/Forms/Controls.ImageButton.loadData.phpt +++ b/tests/Forms/Controls.ImageButton.loadData.phpt @@ -13,25 +13,25 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); test(function() { - $_POST = array( - 'image' => array(1, 2), - 'container' => array( - 'image' => array(3, 4), - ), - ); + $_POST = [ + 'image' => [1, 2], + 'container' => [ + 'image' => [3, 4], + ], + ]; $form = new Form; $input = $form->addImage('image'); Assert::true( $input->isFilled() ); - Assert::same( array(1, 2), $input->getValue() ); + Assert::same( [1, 2], $input->getValue() ); $input = $form->addContainer('container')->addImage('image'); - Assert::same( array(3, 4), $form['container']['image']->getValue() ); + Assert::same( [3, 4], $form['container']['image']->getValue() ); }); @@ -44,15 +44,15 @@ test(function() { // missing data test(function() { // malformed data - $_POST = array( - 'malformed1' => array(1), - 'malformed2' => array(array(NULL)), - ); + $_POST = [ + 'malformed1' => [1], + 'malformed2' => [[NULL]], + ]; $form = new Form; $input = $form->addImage('malformed1'); Assert::true( $input->isFilled() ); - Assert::same( array(1, 0), $input->getValue() ); + Assert::same( [1, 0], $input->getValue() ); $input = $form->addImage('malformed2'); Assert::false( $input->isFilled() ); diff --git a/tests/Forms/Controls.MultiChoiceControl.loadData.phpt b/tests/Forms/Controls.MultiChoiceControl.loadData.phpt index 4a2313ceb..c83a235dc 100644 --- a/tests/Forms/Controls.MultiChoiceControl.loadData.phpt +++ b/tests/Forms/Controls.MultiChoiceControl.loadData.phpt @@ -19,54 +19,54 @@ class MultiChoiceControl extends Nette\Forms\Controls\MultiChoiceControl before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); -$series = array( +$series = [ 'red-dwarf' => 'Red Dwarf', 'the-simpsons' => 'The Simpsons', 0 => 'South Park', '' => 'Family Guy', -); +]; test(function() use ($series) { // invalid input - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form['select'] = new MultiChoiceControl(NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); - Assert::same( array(), $input->getSelectedItems() ); + Assert::same( [], $input->getValue() ); + Assert::same( [], $input->getSelectedItems() ); Assert::false( $input->isFilled() ); }); test(function() use ($series) { // multiple selected items, zero item - $_POST = array('multi' => array('red-dwarf', 'unknown', 0)); + $_POST = ['multi' => ['red-dwarf', 'unknown', 0]]; $form = new Form; $input = $form['multi'] = new MultiChoiceControl(NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array('red-dwarf', 0), $input->getValue() ); - Assert::same( array('red-dwarf', 'unknown', 0), $input->getRawValue() ); - Assert::same( array('red-dwarf' => 'Red Dwarf', 0 => 'South Park'), $input->getSelectedItems() ); + Assert::same( ['red-dwarf', 0], $input->getValue() ); + Assert::same( ['red-dwarf', 'unknown', 0], $input->getRawValue() ); + Assert::same( ['red-dwarf' => 'Red Dwarf', 0 => 'South Park'], $input->getSelectedItems() ); Assert::true( $input->isFilled() ); }); test(function() use ($series) { // empty key - $_POST = array('empty' => array('')); + $_POST = ['empty' => ['']]; $form = new Form; $input = $form['empty'] = new MultiChoiceControl(NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(''), $input->getValue() ); - Assert::same( array('' => 'Family Guy'), $input->getSelectedItems() ); + Assert::same( [''], $input->getValue() ); + Assert::same( ['' => 'Family Guy'], $input->getSelectedItems() ); Assert::true( $input->isFilled() ); }); @@ -76,80 +76,80 @@ test(function() use ($series) { // missing key $input = $form['missing'] = new MultiChoiceControl(NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); - Assert::same( array(), $input->getSelectedItems() ); + Assert::same( [], $input->getValue() ); + Assert::same( [], $input->getSelectedItems() ); Assert::false( $input->isFilled() ); }); test(function() use ($series) { // disabled key - $_POST = array('disabled' => 'red-dwarf'); + $_POST = ['disabled' => 'red-dwarf']; $form = new Form; $input = $form['disabled'] = new MultiChoiceControl(NULL, $series); $input->setDisabled(); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); + Assert::same( [], $input->getValue() ); }); test(function() use ($series) { // malformed data - $_POST = array('malformed' => array(array(NULL))); + $_POST = ['malformed' => [[NULL]]]; $form = new Form; $input = $form['malformed'] = new MultiChoiceControl(NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); - Assert::same( array(), $input->getSelectedItems() ); + Assert::same( [], $input->getValue() ); + Assert::same( [], $input->getSelectedItems() ); Assert::false( $input->isFilled() ); }); test(function() use ($series) { // setItems without keys - $_POST = array('multi' => array('red-dwarf')); + $_POST = ['multi' => ['red-dwarf']]; $form = new Form; $input = $form['multi'] = new MultiChoiceControl; $input->setItems(array_keys($series), FALSE); - Assert::same( array( + Assert::same( [ 'red-dwarf' => 'red-dwarf', 'the-simpsons' => 'the-simpsons', 0 => 0, '' => '', - ), $input->getItems() ); + ], $input->getItems() ); Assert::true( $form->isValid() ); - Assert::same( array('red-dwarf'), $input->getValue() ); - Assert::same( array('red-dwarf' => 'red-dwarf'), $input->getSelectedItems() ); + Assert::same( ['red-dwarf'], $input->getValue() ); + Assert::same( ['red-dwarf' => 'red-dwarf'], $input->getSelectedItems() ); Assert::true( $input->isFilled() ); }); test(function() use ($series) { // validateLength - $_POST = array('multi' => array('red-dwarf', 'unknown', 0)); + $_POST = ['multi' => ['red-dwarf', 'unknown', 0]]; $form = new Form; $input = $form['multi'] = new MultiChoiceControl(NULL, $series); Assert::true( Validator::validateLength($input, 2) ); Assert::false( Validator::validateLength($input, 3) ); - Assert::false( Validator::validateLength($input, array(3, )) ); - Assert::true( Validator::validateLength($input, array(0, 3)) ); + Assert::false( Validator::validateLength($input, [3, ]) ); + Assert::true( Validator::validateLength($input, [0, 3]) ); }); test(function() use ($series) { // validateEqual - $_POST = array('multi' => array('red-dwarf', 'unknown', 0)); + $_POST = ['multi' => ['red-dwarf', 'unknown', 0]]; $form = new Form; $input = $form['multi'] = new MultiChoiceControl(NULL, $series); - Assert::true( Validator::validateEqual($input, array('red-dwarf', 0)) ); + Assert::true( Validator::validateEqual($input, ['red-dwarf', 0]) ); Assert::false( Validator::validateEqual($input, 'unknown') ); - Assert::false( Validator::validateEqual($input, array('unknown')) ); - Assert::false( Validator::validateEqual($input, array(0)) ); + Assert::false( Validator::validateEqual($input, ['unknown']) ); + Assert::false( Validator::validateEqual($input, [0]) ); }); @@ -167,33 +167,33 @@ test(function() use ($series) { // setValue() and invalid argument }, 'Nette\InvalidArgumentException', "Value must be array or NULL, object given in field 'select'."); Assert::exception(function() use ($input) { - $input->setValue(array(new stdClass)); + $input->setValue([new stdClass]); }, 'Nette\InvalidArgumentException', "Values must be scalar, object given in field 'select'."); }); test(function() { // object as value $form = new Form; - $input = $form['select'] = new MultiChoiceControl(NULL, array('2013-07-05 00:00:00' => 1)); - $input->setValue(array(new DateTime('2013-07-05'))); + $input = $form['select'] = new MultiChoiceControl(NULL, ['2013-07-05 00:00:00' => 1]); + $input->setValue([new DateTime('2013-07-05')]); - Assert::same( array('2013-07-05 00:00:00'), $input->getValue() ); + Assert::same( ['2013-07-05 00:00:00'], $input->getValue() ); }); test(function() use ($series) { // disabled one - $_POST = array('select' => array('red-dwarf', 0)); + $_POST = ['select' => ['red-dwarf', 0]]; $form = new Form; $input = $form['select'] = new MultiChoiceControl(NULL, $series); - $input->setDisabled(array('red-dwarf')); + $input->setDisabled(['red-dwarf']); - Assert::same( array(0), $input->getValue() ); + Assert::same( [0], $input->getValue() ); unset($form['select']); $input = new Nette\Forms\Controls\MultiSelectBox(NULL, $series); - $input->setDisabled(array('red-dwarf')); + $input->setDisabled(['red-dwarf']); $form['select'] = $input; - Assert::same( array(0), $input->getValue() ); + Assert::same( [0], $input->getValue() ); }); diff --git a/tests/Forms/Controls.MultiSelectBox.loadData.phpt b/tests/Forms/Controls.MultiSelectBox.loadData.phpt index 55516c8a2..3b4bf8267 100644 --- a/tests/Forms/Controls.MultiSelectBox.loadData.phpt +++ b/tests/Forms/Controls.MultiSelectBox.loadData.phpt @@ -15,75 +15,75 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); -$series = array( +$series = [ 'red-dwarf' => 'Red Dwarf', 'the-simpsons' => 'The Simpsons', 0 => 'South Park', '' => 'Family Guy', -); +]; test(function() use ($series) { // Select with optgroups - $_POST = array('multi' => array('red-dwarf')); + $_POST = ['multi' => ['red-dwarf']]; $form = new Form; - $input = $form->addMultiSelect('multi', NULL, array( - 'usa' => array( + $input = $form->addMultiSelect('multi', NULL, [ + 'usa' => [ 'the-simpsons' => 'The Simpsons', 0 => 'South Park', - ), - 'uk' => array( + ], + 'uk' => [ 'red-dwarf' => 'Red Dwarf', - ), - )); + ], + ]); Assert::true( $form->isValid() ); - Assert::same( array('red-dwarf'), $input->getValue() ); - Assert::same( array('red-dwarf' => 'Red Dwarf'), $input->getSelectedItems() ); + Assert::same( ['red-dwarf'], $input->getValue() ); + Assert::same( ['red-dwarf' => 'Red Dwarf'], $input->getSelectedItems() ); Assert::true( $input->isFilled() ); }); test(function() use ($series) { // invalid input - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form->addMultiSelect('select', NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); - Assert::same( array(), $input->getSelectedItems() ); + Assert::same( [], $input->getValue() ); + Assert::same( [], $input->getSelectedItems() ); Assert::false( $input->isFilled() ); }); test(function() use ($series) { // multiple selected items, zero item - $_POST = array('multi' => array('red-dwarf', 'unknown', 0)); + $_POST = ['multi' => ['red-dwarf', 'unknown', 0]]; $form = new Form; $input = $form->addMultiSelect('multi', NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array('red-dwarf', 0), $input->getValue() ); - Assert::same( array('red-dwarf', 'unknown', 0), $input->getRawValue() ); - Assert::same( array('red-dwarf' => 'Red Dwarf', 0 => 'South Park'), $input->getSelectedItems() ); + Assert::same( ['red-dwarf', 0], $input->getValue() ); + Assert::same( ['red-dwarf', 'unknown', 0], $input->getRawValue() ); + Assert::same( ['red-dwarf' => 'Red Dwarf', 0 => 'South Park'], $input->getSelectedItems() ); Assert::true( $input->isFilled() ); }); test(function() use ($series) { // empty key - $_POST = array('empty' => array('')); + $_POST = ['empty' => ['']]; $form = new Form; $input = $form->addMultiSelect('empty', NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(''), $input->getValue() ); - Assert::same( array('' => 'Family Guy'), $input->getSelectedItems() ); + Assert::same( [''], $input->getValue() ); + Assert::same( ['' => 'Family Guy'], $input->getSelectedItems() ); Assert::true( $input->isFilled() ); }); @@ -93,78 +93,78 @@ test(function() use ($series) { // missing key $input = $form->addMultiSelect('missing', NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); - Assert::same( array(), $input->getSelectedItems() ); + Assert::same( [], $input->getValue() ); + Assert::same( [], $input->getSelectedItems() ); Assert::false( $input->isFilled() ); }); test(function() use ($series) { // disabled key - $_POST = array('disabled' => 'red-dwarf'); + $_POST = ['disabled' => 'red-dwarf']; $form = new Form; $input = $form->addMultiSelect('disabled', NULL, $series) ->setDisabled(); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); + Assert::same( [], $input->getValue() ); }); test(function() use ($series) { // malformed data - $_POST = array('malformed' => array(array(NULL))); + $_POST = ['malformed' => [[NULL]]]; $form = new Form; $input = $form->addMultiSelect('malformed', NULL, $series); Assert::true( $form->isValid() ); - Assert::same( array(), $input->getValue() ); - Assert::same( array(), $input->getSelectedItems() ); + Assert::same( [], $input->getValue() ); + Assert::same( [], $input->getSelectedItems() ); Assert::false( $input->isFilled() ); }); test(function() use ($series) { // validateLength - $_POST = array('multi' => array('red-dwarf', 'unknown', 0)); + $_POST = ['multi' => ['red-dwarf', 'unknown', 0]]; $form = new Form; $input = $form->addMultiSelect('multi', NULL, $series); Assert::true( Validator::validateLength($input, 2) ); Assert::false( Validator::validateLength($input, 3) ); - Assert::false( Validator::validateLength($input, array(3, )) ); - Assert::true( Validator::validateLength($input, array(0, 3)) ); + Assert::false( Validator::validateLength($input, [3, ]) ); + Assert::true( Validator::validateLength($input, [0, 3]) ); }); test(function() use ($series) { // validateEqual - $_POST = array('multi' => array('red-dwarf', 'unknown', 0)); + $_POST = ['multi' => ['red-dwarf', 'unknown', 0]]; $form = new Form; $input = $form->addMultiSelect('multi', NULL, $series); - Assert::true( Validator::validateEqual($input, array('red-dwarf', 0)) ); + Assert::true( Validator::validateEqual($input, ['red-dwarf', 0]) ); Assert::false( Validator::validateEqual($input, 'unknown') ); - Assert::false( Validator::validateEqual($input, array('unknown')) ); - Assert::false( Validator::validateEqual($input, array(0)) ); + Assert::false( Validator::validateEqual($input, ['unknown']) ); + Assert::false( Validator::validateEqual($input, [0]) ); }); test(function() use ($series) { // setItems without keys - $_POST = array('multi' => array('red-dwarf')); + $_POST = ['multi' => ['red-dwarf']]; $form = new Form; $input = $form->addMultiSelect('multi')->setItems(array_keys($series), FALSE); - Assert::same( array( + Assert::same( [ 'red-dwarf' => 'red-dwarf', 'the-simpsons' => 'the-simpsons', 0 => 0, '' => '', - ), $input->getItems() ); + ], $input->getItems() ); Assert::true( $form->isValid() ); - Assert::same( array('red-dwarf'), $input->getValue() ); - Assert::same( array('red-dwarf' => 'red-dwarf'), $input->getSelectedItems() ); + Assert::same( ['red-dwarf'], $input->getValue() ); + Assert::same( ['red-dwarf' => 'red-dwarf'], $input->getSelectedItems() ); Assert::true( $input->isFilled() ); }); @@ -172,22 +172,22 @@ test(function() use ($series) { // setItems without keys test(function() use ($series) { // setItems without keys $form = new Form; $input = $form->addMultiSelect('select')->setItems(range(1, 5), FALSE); - Assert::same( array(1 => 1, 2, 3, 4, 5), $input->getItems() ); + Assert::same( [1 => 1, 2, 3, 4, 5], $input->getItems() ); }); test(function() { // setItems without keys with optgroups - $_POST = array('multi' => array('red-dwarf')); + $_POST = ['multi' => ['red-dwarf']]; $form = new Form; - $input = $form->addMultiSelect('multi')->setItems(array( - 'usa' => array('the-simpsons', 0), - 'uk' => array('red-dwarf'), - ), FALSE); + $input = $form->addMultiSelect('multi')->setItems([ + 'usa' => ['the-simpsons', 0], + 'uk' => ['red-dwarf'], + ], FALSE); Assert::true( $form->isValid() ); - Assert::same( array('red-dwarf'), $input->getValue() ); - Assert::same( array('red-dwarf' => 'red-dwarf'), $input->getSelectedItems() ); + Assert::same( ['red-dwarf'], $input->getValue() ); + Assert::same( ['red-dwarf' => 'red-dwarf'], $input->getSelectedItems() ); Assert::true( $input->isFilled() ); }); @@ -205,39 +205,39 @@ test(function() use ($series) { // setValue() and invalid argument test(function() { // object as value $form = new Form; - $input = $form->addMultiSelect('select', NULL, array('2013-07-05 00:00:00' => 1)) - ->setValue(array(new DateTime('2013-07-05'))); + $input = $form->addMultiSelect('select', NULL, ['2013-07-05 00:00:00' => 1]) + ->setValue([new DateTime('2013-07-05')]); - Assert::same( array('2013-07-05 00:00:00'), $input->getValue() ); + Assert::same( ['2013-07-05 00:00:00'], $input->getValue() ); }); test(function() { // object as item $form = new Form; $input = $form->addMultiSelect('select') - ->setItems(array( - 'group' => array(new DateTime('2013-07-05')), + ->setItems([ + 'group' => [new DateTime('2013-07-05')], new DateTime('2013-07-06'), - ), FALSE) + ], FALSE) ->setValue('2013-07-05 00:00:00'); - Assert::equal( array('2013-07-05 00:00:00' => new DateTime('2013-07-05')), $input->getSelectedItems() ); + Assert::equal( ['2013-07-05 00:00:00' => new DateTime('2013-07-05')], $input->getSelectedItems() ); }); test(function() use ($series) { // disabled one - $_POST = array('select' => array('red-dwarf', 0)); + $_POST = ['select' => ['red-dwarf', 0]]; $form = new Form; $input = $form->addMultiSelect('select', NULL, $series) - ->setDisabled(array('red-dwarf')); + ->setDisabled(['red-dwarf']); - Assert::same( array(0), $input->getValue() ); + Assert::same( [0], $input->getValue() ); unset($form['select']); $input = new Nette\Forms\Controls\MultiSelectBox(NULL, $series); - $input->setDisabled(array('red-dwarf')); + $input->setDisabled(['red-dwarf']); $form['select'] = $input; - Assert::same( array(0), $input->getValue() ); + Assert::same( [0], $input->getValue() ); }); diff --git a/tests/Forms/Controls.MultiSelectBox.render.phpt b/tests/Forms/Controls.MultiSelectBox.render.phpt index 9ac3b8960..cf6ad6b1a 100644 --- a/tests/Forms/Controls.MultiSelectBox.render.phpt +++ b/tests/Forms/Controls.MultiSelectBox.render.phpt @@ -23,10 +23,10 @@ class Translator implements Nette\Localization\ITranslator test(function() { $form = new Form; - $input = $form->addMultiSelect('list', 'Label', array( + $input = $form->addMultiSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); Assert::type('Nette\Utils\Html', $input->getLabel()); Assert::same('', (string) $input->getLabel()); @@ -39,10 +39,10 @@ test(function() { test(function() { // selected $form = new Form; - $input = $form->addMultiSelect('list', 'Label', array( + $input = $form->addMultiSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setValue(0); + ])->setValue(0); Assert::same('', (string) $input->getControl()); }); @@ -50,10 +50,10 @@ test(function() { // selected test(function() { // translator & groups $form = new Form; - $input = $form->addMultiSelect('list', 'Label', array( + $input = $form->addMultiSelect('list', 'Label', [ 'a' => 'First', - 'group' => array('Second', 'Third'), - )); + 'group' => ['Second', 'Third'], + ]); $input->setTranslator(new Translator); Assert::same('', (string) $input->getLabel()); @@ -64,10 +64,10 @@ test(function() { // translator & groups test(function() { // Html with translator & groups $form = new Form; - $input = $form->addMultiSelect('list', Html::el('b', 'Label'), array( + $input = $form->addMultiSelect('list', Html::el('b', 'Label'), [ 'a' => Html::el('option', 'First')->class('class'), - 'group' => array(Html::el('option', 'Second')), - )); + 'group' => [Html::el('option', 'Second')], + ]); $input->setTranslator(new Translator); Assert::same('', (string) $input->getLabel()); @@ -78,10 +78,10 @@ test(function() { // Html with translator & groups test(function() { // validation rules $form = new Form; - $input = $form->addMultiSelect('list', 'Label', array( + $input = $form->addMultiSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setRequired('required'); + ])->setRequired('required'); Assert::same('', (string) $input->getControl()); }); @@ -90,10 +90,10 @@ test(function() { // validation rules test(function() { // container $form = new Form; $container = $form->addContainer('container'); - $input = $container->addMultiSelect('list', 'Label', array( + $input = $container->addMultiSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); Assert::same('', (string) $input->getControl()); }); @@ -101,10 +101,10 @@ test(function() { // container test(function() { // disabled all $form = new Form; - $input = $form->addMultiSelect('list', 'Label', array( + $input = $form->addMultiSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setDisabled(TRUE); + ])->setDisabled(TRUE); Assert::same('', (string) $input->getControl()); }); @@ -112,10 +112,10 @@ test(function() { // disabled all test(function() { // disabled one $form = new Form; - $input = $form->addMultiSelect('list', 'Label', array( + $input = $form->addMultiSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setDisabled(array('a')); + ])->setDisabled(['a']); Assert::same('', (string) $input->getControl()); }); diff --git a/tests/Forms/Controls.RadioList.loadData.phpt b/tests/Forms/Controls.RadioList.loadData.phpt index a1f175119..cbe4bfa54 100644 --- a/tests/Forms/Controls.RadioList.loadData.phpt +++ b/tests/Forms/Controls.RadioList.loadData.phpt @@ -14,20 +14,20 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); -$series = array( +$series = [ 'red-dwarf' => 'Red Dwarf', 'the-simpsons' => 'The Simpsons', 0 => 'South Park', '' => 'Family Guy', -); +]; test(function() use ($series) { // Radio list - $_POST = array('radio' => 'red-dwarf'); + $_POST = ['radio' => 'red-dwarf']; $form = new Form; $input = $form->addRadioList('radio', NULL, $series); @@ -40,7 +40,7 @@ test(function() use ($series) { // Radio list test(function() use ($series) { // Radio list with invalid input - $_POST = array('radio' => 'days-of-our-lives'); + $_POST = ['radio' => 'days-of-our-lives']; $form = new Form; $input = $form->addRadioList('radio', NULL, $series); @@ -53,7 +53,7 @@ test(function() use ($series) { // Radio list with invalid input test(function() use ($series) { // Indexed arrays - $_POST = array('zero' => 0); + $_POST = ['zero' => 0]; $form = new Form; $input = $form->addRadioList('zero', NULL, $series); @@ -67,7 +67,7 @@ test(function() use ($series) { // Indexed arrays test(function() use ($series) { // empty key - $_POST = array('empty' => ''); + $_POST = ['empty' => '']; $form = new Form; $input = $form->addRadioList('empty', NULL, $series); @@ -91,7 +91,7 @@ test(function() use ($series) { // missing key test(function() use ($series) { // disabled key - $_POST = array('disabled' => 'red-dwarf'); + $_POST = ['disabled' => 'red-dwarf']; $form = new Form; $input = $form->addRadioList('disabled', NULL, $series) @@ -104,7 +104,7 @@ test(function() use ($series) { // disabled key test(function() use ($series) { // malformed data - $_POST = array('malformed' => array(NULL)); + $_POST = ['malformed' => [NULL]]; $form = new Form; $input = $form->addRadioList('malformed', NULL, $series); @@ -117,7 +117,7 @@ test(function() use ($series) { // malformed data test(function() use ($series) { // setItems without keys - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form->addRadioList('select')->setItems(array_keys($series), FALSE); @@ -142,7 +142,7 @@ test(function() use ($series) { // setValue() and invalid argument test(function() { // object as value $form = new Form; - $input = $form->addRadioList('radio', NULL, array('2013-07-05 00:00:00' => 1)) + $input = $form->addRadioList('radio', NULL, ['2013-07-05 00:00:00' => 1]) ->setValue(new DateTime('2013-07-05')); Assert::same( '2013-07-05 00:00:00', $input->getValue() ); @@ -152,7 +152,7 @@ test(function() { // object as value test(function() { // object as item $form = new Form; $input = $form->addRadioList('radio') - ->setItems(array(new DateTime('2013-07-05')), FALSE) + ->setItems([new DateTime('2013-07-05')], FALSE) ->setValue(new DateTime('2013-07-05')); Assert::same( '2013-07-05 00:00:00', $input->getValue() ); @@ -160,17 +160,17 @@ test(function() { // object as item test(function() use ($series) { // disabled one - $_POST = array('radio' => 'red-dwarf'); + $_POST = ['radio' => 'red-dwarf']; $form = new Form; $input = $form->addRadioList('radio', NULL, $series) - ->setDisabled(array('red-dwarf')); + ->setDisabled(['red-dwarf']); Assert::null( $input->getValue() ); unset($form['radio']); $input = new Nette\Forms\Controls\RadioList(NULL, $series); - $input->setDisabled(array('red-dwarf')); + $input->setDisabled(['red-dwarf']); $form['radio'] = $input; Assert::null( $input->getValue() ); diff --git a/tests/Forms/Controls.RadioList.render.phpt b/tests/Forms/Controls.RadioList.render.phpt index 9a9940f2a..66adac78d 100644 --- a/tests/Forms/Controls.RadioList.render.phpt +++ b/tests/Forms/Controls.RadioList.render.phpt @@ -23,10 +23,10 @@ class Translator implements Nette\Localization\ITranslator test(function() { $form = new Form; - $input = $form->addRadioList('list', 'Label', array( + $input = $form->addRadioList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); Assert::type('Nette\Utils\Html', $input->getLabel()); Assert::same('', (string) $input->getLabel()); @@ -45,10 +45,10 @@ test(function() { test(function() { // checked $form = new Form; - $input = $form->addRadioList('list', 'Label', array( + $input = $form->addRadioList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setValue(0); + ])->setValue(0); Assert::same('
', (string) $input->getControl()); }); @@ -56,10 +56,10 @@ test(function() { // checked test(function() { // translator $form = new Form; - $input = $form->addRadioList('list', 'Label', array( + $input = $form->addRadioList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); $input->setTranslator(new Translator); Assert::same('', (string) $input->getLabel()); @@ -73,9 +73,9 @@ test(function() { // translator test(function() { // Html $form = new Form; - $input = $form->addRadioList('list', Html::el('b', 'Label'), array( + $input = $form->addRadioList('list', Html::el('b', 'Label'), [ 'a' => Html::el('b', 'First'), - )); + ]); $input->setTranslator(new Translator); Assert::same('', (string) $input->getLabel()); @@ -88,10 +88,10 @@ test(function() { // Html test(function() { // validation rules $form = new Form; - $input = $form->addRadioList('list', 'Label', array( + $input = $form->addRadioList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setRequired('required'); + ])->setRequired('required'); Assert::same('
', (string) $input->getControl()); Assert::same('', (string) $input->getControlPart(0)); @@ -101,10 +101,10 @@ test(function() { // validation rules test(function() { // container $form = new Form; $container = $form->addContainer('container'); - $input = $container->addRadioList('list', 'Label', array( + $input = $container->addRadioList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); Assert::same('
', (string) $input->getControl()); }); @@ -112,9 +112,9 @@ test(function() { // container test(function() { // container prototype $form = new Form; - $input = $form->addRadioList('list', NULL, array( + $input = $form->addRadioList('list', NULL, [ 'a' => 'b', - )); + ]); $input->getSeparatorPrototype()->setName('hr'); $input->getContainerPrototype()->setName('div'); @@ -124,10 +124,10 @@ test(function() { // container prototype test(function() { // disabled all $form = new Form; - $input = $form->addRadioList('list', 'Label', array( + $input = $form->addRadioList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setDisabled(TRUE); + ])->setDisabled(TRUE); Assert::same('
', (string) $input->getControl()); }); @@ -135,10 +135,10 @@ test(function() { // disabled all test(function() { // disabled one $form = new Form; - $input = $form->addRadioList('list', 'Label', array( + $input = $form->addRadioList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setDisabled(array('a')); + ])->setDisabled(['a']); Assert::same('
', (string) $input->getControl()); Assert::same('', (string) $input->getControlPart('a')); @@ -147,9 +147,9 @@ test(function() { // disabled one test(function() { // item label prototype $form = new Form; - $input = $form->addRadioList('list', NULL, array( + $input = $form->addRadioList('list', NULL, [ 'a' => 'b', - )); + ]); $input->getItemLabelPrototype()->class("foo"); Assert::same('', (string) $input->getControl()); @@ -158,10 +158,10 @@ test(function() { // item label prototype test(function() { // forced ID $form = new Form; - $input = $form->addRadioList('list', 'Label', array( + $input = $form->addRadioList('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); $input->generateId = TRUE; Assert::same('
', (string) $input->getControl()); @@ -170,10 +170,10 @@ test(function() { // forced ID test(function() { // numeric key as string & getControlPart $form = new Form; - $input = $form->addRadioList('list', 'Label', array( + $input = $form->addRadioList('list', 'Label', [ 1 => 'First', 2 => 'Second', - ))->setDefaultValue(1); + ])->setDefaultValue(1); Assert::same('', (string) $input->getControlPart('1')); }); diff --git a/tests/Forms/Controls.SelectBox.loadData.phpt b/tests/Forms/Controls.SelectBox.loadData.phpt index 0615e8746..5e74384f9 100644 --- a/tests/Forms/Controls.SelectBox.loadData.phpt +++ b/tests/Forms/Controls.SelectBox.loadData.phpt @@ -14,20 +14,20 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); -$series = array( +$series = [ 'red-dwarf' => 'Red Dwarf', 'the-simpsons' => 'The Simpsons', 0 => 'South Park', '' => 'Family Guy', -); +]; test(function() use ($series) { // Select - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form->addSelect('select', NULL, $series); @@ -40,7 +40,7 @@ test(function() use ($series) { // Select test(function() use ($series) { // Empty select - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form->addSelect('select'); @@ -53,7 +53,7 @@ test(function() use ($series) { // Empty select test(function() use ($series) { // Select with prompt - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form->addSelect('select', NULL, $series)->setPrompt('Select series'); @@ -66,18 +66,18 @@ test(function() use ($series) { // Select with prompt test(function() use ($series) { // Select with optgroups - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; - $input = $form->addSelect('select', NULL, array( - 'usa' => array( + $input = $form->addSelect('select', NULL, [ + 'usa' => [ 'the-simpsons' => 'The Simpsons', 0 => 'South Park', - ), - 'uk' => array( + ], + 'uk' => [ 'red-dwarf' => 'Red Dwarf', - ), - )); + ], + ]); Assert::true( $form->isValid() ); Assert::same( 'red-dwarf', $input->getValue() ); @@ -87,7 +87,7 @@ test(function() use ($series) { // Select with optgroups test(function() use ($series) { // Select with invalid input - $_POST = array('select' => 'days-of-our-lives'); + $_POST = ['select' => 'days-of-our-lives']; $form = new Form; $input = $form->addSelect('select', NULL, $series); @@ -111,7 +111,7 @@ test(function() use ($series) { // Select with prompt and invalid input test(function() use ($series) { // Indexed arrays - $_POST = array('zero' => 0); + $_POST = ['zero' => 0]; $form = new Form; $input = $form->addSelect('zero', NULL, $series); @@ -125,7 +125,7 @@ test(function() use ($series) { // Indexed arrays test(function() use ($series) { // empty key - $_POST = array('empty' => ''); + $_POST = ['empty' => '']; $form = new Form; $input = $form->addSelect('empty', NULL, $series); @@ -149,7 +149,7 @@ test(function() use ($series) { // missing key test(function() use ($series) { // disabled key - $_POST = array('disabled' => 'red-dwarf'); + $_POST = ['disabled' => 'red-dwarf']; $form = new Form; $input = $form->addSelect('disabled', NULL, $series) @@ -161,7 +161,7 @@ test(function() use ($series) { // disabled key test(function() use ($series) { // malformed data - $_POST = array('malformed' => array(NULL)); + $_POST = ['malformed' => [NULL]]; $form = new Form; $input = $form->addSelect('malformed', NULL, $series); @@ -174,16 +174,16 @@ test(function() use ($series) { // malformed data test(function() use ($series) { // setItems without keys - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form->addSelect('select')->setItems(array_keys($series), FALSE); - Assert::same( array( + Assert::same( [ 'red-dwarf' => 'red-dwarf', 'the-simpsons' => 'the-simpsons', 0 => 0, '' => '', - ), $input->getItems() ); + ], $input->getItems() ); Assert::true( $form->isValid() ); Assert::same( 'red-dwarf', $input->getValue() ); @@ -195,18 +195,18 @@ test(function() use ($series) { // setItems without keys test(function() use ($series) { // setItems without keys $form = new Form; $input = $form->addSelect('select')->setItems(range(1, 5), FALSE); - Assert::same( array(1 => 1, 2, 3, 4, 5), $input->getItems() ); + Assert::same( [1 => 1, 2, 3, 4, 5], $input->getItems() ); }); test(function() { // setItems without keys with optgroups - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; - $input = $form->addSelect('select')->setItems(array( - 'usa' => array('the-simpsons', 0), - 'uk' => array('red-dwarf'), - ), FALSE); + $input = $form->addSelect('select')->setItems([ + 'usa' => ['the-simpsons', 0], + 'uk' => ['red-dwarf'], + ], FALSE); Assert::true( $form->isValid() ); Assert::same( 'red-dwarf', $input->getValue() ); @@ -228,7 +228,7 @@ test(function() use ($series) { // setValue() and invalid argument test(function() { // object as value $form = new Form; - $input = $form->addSelect('select', NULL, array('2013-07-05 00:00:00' => 1)) + $input = $form->addSelect('select', NULL, ['2013-07-05 00:00:00' => 1]) ->setValue(new DateTime('2013-07-05')); Assert::same( '2013-07-05 00:00:00', $input->getValue() ); @@ -238,10 +238,10 @@ test(function() { // object as value test(function() { // object as item $form = new Form; $input = $form->addSelect('select') - ->setItems(array( - 'group' => array(new DateTime('2013-07-05')), + ->setItems([ + 'group' => [new DateTime('2013-07-05')], new DateTime('2013-07-06'), - ), FALSE) + ], FALSE) ->setValue('2013-07-05 00:00:00'); Assert::equal( new DateTime('2013-07-05'), $input->getSelectedItem() ); @@ -249,30 +249,30 @@ test(function() { // object as item test(function() use ($series) { // disabled one - $_POST = array('select' => 'red-dwarf'); + $_POST = ['select' => 'red-dwarf']; $form = new Form; $input = $form->addSelect('select', NULL, $series) - ->setDisabled(array('red-dwarf')); + ->setDisabled(['red-dwarf']); Assert::null( $input->getValue() ); unset($form['select']); $input = new Nette\Forms\Controls\SelectBox(NULL, $series); - $input->setDisabled(array('red-dwarf')); + $input->setDisabled(['red-dwarf']); $form['select'] = $input; Assert::null( $input->getValue() ); }); test(function() { - $_POST = array('select' => 1); + $_POST = ['select' => 1]; $form = new Form; - $input = $form->addSelect('select', NULL, array( + $input = $form->addSelect('select', NULL, [ 1 => NULL, 2 => 'Red dwarf' - )); + ]); Assert::same( 1, $input->getValue() ); }); diff --git a/tests/Forms/Controls.SelectBox.render.phpt b/tests/Forms/Controls.SelectBox.render.phpt index 33000faf0..15c0617ef 100644 --- a/tests/Forms/Controls.SelectBox.render.phpt +++ b/tests/Forms/Controls.SelectBox.render.phpt @@ -23,10 +23,10 @@ class Translator implements Nette\Localization\ITranslator test(function() { $form = new Form; - $input = $form->addSelect('list', 'Label', array( + $input = $form->addSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); Assert::type('Nette\Utils\Html', $input->getLabel()); Assert::same('', (string) $input->getLabel()); @@ -39,10 +39,10 @@ test(function() { test(function() { // selected $form = new Form; - $input = $form->addSelect('list', 'Label', array( + $input = $form->addSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setValue(0); + ])->setValue(0); Assert::same('', (string) $input->getControl()); }); @@ -50,10 +50,10 @@ test(function() { // selected test(function() { // translator & groups $form = new Form; - $input = $form->addSelect('list', 'Label', array( + $input = $form->addSelect('list', 'Label', [ 'a' => 'First', - 'group' => array('Second', 'Third'), - ))->setPrompt('Prompt'); + 'group' => ['Second', 'Third'], + ])->setPrompt('Prompt'); $input->setTranslator(new Translator); Assert::same('', (string) $input->getLabel()); @@ -64,10 +64,10 @@ test(function() { // translator & groups test(function() { // Html with translator & groups $form = new Form; - $input = $form->addSelect('list', Html::el('b', 'Label'), array( + $input = $form->addSelect('list', Html::el('b', 'Label'), [ 'a' => Html::el('option', 'First')->class('class'), - 'group' => array(Html::el('option', 'Second')), - ))->setPrompt(Html::el('option', 'Prompt')->class('class')); + 'group' => [Html::el('option', 'Second')], + ])->setPrompt(Html::el('option', 'Prompt')->class('class')); $input->setTranslator(new Translator); Assert::same('', (string) $input->getLabel()); @@ -78,10 +78,10 @@ test(function() { // Html with translator & groups test(function() { // validation rules $form = new Form; - $input = $form->addSelect('list', 'Label', array( + $input = $form->addSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setRequired('required'); + ])->setRequired('required'); Assert::same('', (string) $input->getControl()); }); @@ -90,10 +90,10 @@ test(function() { // validation rules test(function() { // container $form = new Form; $container = $form->addContainer('container'); - $input = $container->addSelect('list', 'Label', array( + $input = $container->addSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - )); + ]); Assert::same('', (string) $input->getControl()); }); @@ -101,10 +101,10 @@ test(function() { // container test(function() { // disabled all $form = new Form; - $input = $form->addSelect('list', 'Label', array( + $input = $form->addSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setDisabled(TRUE); + ])->setDisabled(TRUE); Assert::same('', (string) $input->getControl()); }); @@ -112,10 +112,10 @@ test(function() { // disabled all test(function() { // disabled one $form = new Form; - $input = $form->addSelect('list', 'Label', array( + $input = $form->addSelect('list', 'Label', [ 'a' => 'First', 0 => 'Second', - ))->setDisabled(array('a')); + ])->setDisabled(['a']); Assert::same('', (string) $input->getControl()); }); diff --git a/tests/Forms/Controls.TestBase.validators.phpt b/tests/Forms/Controls.TestBase.validators.phpt index 42ccff8d8..e32b449de 100644 --- a/tests/Forms/Controls.TestBase.validators.phpt +++ b/tests/Forms/Controls.TestBase.validators.phpt @@ -35,13 +35,13 @@ test(function() { $control = new TextInput(); $control->value = ''; Assert::true( Validator::validateLength($control, 0) ); - Assert::true( Validator::validateLength($control, array(0, 0)) ); + Assert::true( Validator::validateLength($control, [0, 0]) ); $control->value = 'aaa'; Assert::true( Validator::validateLength($control, 3) ); Assert::false( Validator::validateLength($control, 4) ); - Assert::true( Validator::validateLength($control, array(3, )) ); - Assert::false( Validator::validateLength($control, array(5, 6)) ); + Assert::true( Validator::validateLength($control, [3, ]) ); + Assert::false( Validator::validateLength($control, [5, 6]) ); }); diff --git a/tests/Forms/Controls.TextArea.render.phpt b/tests/Forms/Controls.TextArea.render.phpt index f97edf1cb..f32dc3d15 100644 --- a/tests/Forms/Controls.TextArea.render.phpt +++ b/tests/Forms/Controls.TextArea.render.phpt @@ -62,7 +62,7 @@ test(function() { // Html with translator test(function() { // validation rule LENGTH $form = new Form; $input = $form->addTextArea('text') - ->addRule($form::LENGTH, NULL, array(10, 20)); + ->addRule($form::LENGTH, NULL, [10, 20]); Assert::same('', (string) $input->getControl()); }); diff --git a/tests/Forms/Controls.TextBase.loadData.phpt b/tests/Forms/Controls.TextBase.loadData.phpt index e7bae1219..ce032ccde 100644 --- a/tests/Forms/Controls.TextBase.loadData.phpt +++ b/tests/Forms/Controls.TextBase.loadData.phpt @@ -13,12 +13,12 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST = $_FILES = array(); + $_POST = $_FILES = []; }); test(function() { // trim & new lines - $_POST = array('text' => " a\r b \n c "); + $_POST = ['text' => " a\r b \n c "]; $form = new Form; $input = $form->addText('text'); @@ -29,7 +29,7 @@ test(function() { // trim & new lines test(function() { // trim & new lines in textarea - $_POST = array('text' => " a\r b \n c "); + $_POST = ['text' => " a\r b \n c "]; $form = new Form; $input = $form->addTextArea('text'); @@ -39,7 +39,7 @@ test(function() { // trim & new lines in textarea test(function() { // empty value - $_POST = array('url' => 'nette.org'); + $_POST = ['url' => 'nette.org']; $form = new Form; $input = $form->addText('url') @@ -50,7 +50,7 @@ test(function() { // empty value test(function() { // empty value - $_POST = array('phone' => '+420 '); + $_POST = ['phone' => '+420 ']; $form = new Form; $input = $form->addText('phone') @@ -61,7 +61,7 @@ test(function() { // empty value test(function() { // invalid UTF - $_POST = array('invalidutf' => "invalid\xAA\xAA\xAAutf"); + $_POST = ['invalidutf' => "invalid\xAA\xAA\xAAutf"]; $form = new Form; $input = $form->addText('invalidutf'); @@ -79,7 +79,7 @@ test(function() { // missing data test(function() { // malformed data - $_POST = array('malformed' => array(NULL)); + $_POST = ['malformed' => [NULL]]; $form = new Form; $input = $form->addText('malformed'); @@ -90,20 +90,20 @@ test(function() { // malformed data test(function() { // setValue() and invalid argument - $_POST = array('text' => " a\r b \n c "); + $_POST = ['text' => " a\r b \n c "]; $form = new Form; $input = $form->addText('text'); $input->setValue(NULL); Assert::exception(function() use ($input) { - $input->setValue(array()); + $input->setValue([]); }, 'Nette\InvalidArgumentException', "Value must be scalar or NULL, array given in field 'text'."); }); test(function() { // float - $_POST = array('number' => ' 10,5 '); + $_POST = ['number' => ' 10,5 ']; $form = new Form; $input = $form->addText('number') @@ -117,7 +117,7 @@ test(function() { // float test(function() { // float in condition - $_POST = array('number' => ' 10,5 '); + $_POST = ['number' => ' 10,5 ']; $form = new Form; $input = $form->addText('number'); @@ -130,7 +130,7 @@ test(function() { // float in condition test(function() { // non float - $_POST = array('number' => ' 10,5 '); + $_POST = ['number' => ' 10,5 ']; $form = new Form; $input = $form->addText('number') @@ -142,7 +142,7 @@ test(function() { // non float test(function() { // URL - $_POST = array('url' => 'nette.org'); + $_POST = ['url' => 'nette.org']; $form = new Form; $input = $form->addText('url') @@ -163,7 +163,7 @@ test(function() { // object test(function() { // filter - $_POST = array('text' => 'hello'); + $_POST = ['text' => 'hello']; $form = new Form; $input = $form->addText('text') @@ -176,7 +176,7 @@ test(function() { // filter test(function() { // filter in condition - $_POST = array('text' => 'hello'); + $_POST = ['text' => 'hello']; $form = new Form; $input = $form->addText('text'); diff --git a/tests/Forms/Controls.TextInput.render.phpt b/tests/Forms/Controls.TextInput.render.phpt index d8bcb8d07..5245ba60c 100644 --- a/tests/Forms/Controls.TextInput.render.phpt +++ b/tests/Forms/Controls.TextInput.render.phpt @@ -75,7 +75,7 @@ test(function() { // validation rule required & PATTERN ->setRequired('required') ->addRule($form::PATTERN, 'error message', '[0-9]+'); - foreach (array('text', 'search', 'tel', 'url', 'email') as $type) { + foreach (['text', 'search', 'tel', 'url', 'email'] as $type) { $input->setType($type); Assert::same('', (string) $input->getControl()); } @@ -110,7 +110,7 @@ test(function() { // validation rule LENGTH $form = new Form; $input = $form->addText('text') ->setMaxLength(30) - ->addRule($form::LENGTH, NULL, array(10, 20)); + ->addRule($form::LENGTH, NULL, [10, 20]); Assert::same('', (string) $input->getControl()); }); @@ -130,10 +130,10 @@ test(function() { // validation rule RANGE without setType $minInput = $form->addText('min'); $maxInput = $form->addText('max'); $input = $form->addText('count') - ->addRule(Form::RANGE, 'Must be in range from %d to %d', array(0, 100)) + ->addRule(Form::RANGE, 'Must be in range from %d to %d', [0, 100]) ->addRule(Form::MIN, 'Must be greater than or equal to %d', 1) ->addRule(Form::MAX, 'Must be less than or equal to %d', 101) - ->addRule(Form::RANGE, 'Must be in range from %d to %d', array($minInput, $maxInput)); + ->addRule(Form::RANGE, 'Must be in range from %d to %d', [$minInput, $maxInput]); Assert::same('', (string) $input->getControl()); }); @@ -145,10 +145,10 @@ test(function() { // validation rule RANGE with setType $maxInput = $form->addText('max'); $input = $form->addText('count') ->setType('number') - ->addRule(Form::RANGE, 'Must be in range from %d to %d', array(0, 100)) + ->addRule(Form::RANGE, 'Must be in range from %d to %d', [0, 100]) ->addRule(Form::MIN, 'Must be greater than or equal to %d', 1) ->addRule(Form::MAX, 'Must be less than or equal to %d', 101) - ->addRule(Form::RANGE, 'Must be in range from %d to %d', array($minInput, $maxInput)); + ->addRule(Form::RANGE, 'Must be in range from %d to %d', [$minInput, $maxInput]); Assert::same('', (string) $input->getControl()); }); diff --git a/tests/Forms/Controls.UploadControl.loadData.phpt b/tests/Forms/Controls.UploadControl.loadData.phpt index bdb058724..ae5aa8516 100644 --- a/tests/Forms/Controls.UploadControl.loadData.phpt +++ b/tests/Forms/Controls.UploadControl.loadData.phpt @@ -15,44 +15,44 @@ require __DIR__ . '/../bootstrap.php'; $_SERVER['REQUEST_METHOD'] = 'POST'; -$_FILES = array( - 'avatar' => array( +$_FILES = [ + 'avatar' => [ 'name' => 'license.txt', 'type' => 'text/plain', 'tmp_name' => __DIR__ . '/files/logo.gif', 'error' => 0, 'size' => 3013, - ), - 'container' => array( - 'name' => array('avatar' => "invalid\xAA\xAA\xAAutf"), - 'type' => array('avatar' => 'text/plain'), - 'tmp_name' => array('avatar' => 'C:\\PHP\\temp\\php1D5C.tmp'), - 'error' => array('avatar' => 0), - 'size' => array('avatar' => 3013), - ), - 'multiple' => array( - 'name' => array('avatar' => array('image.gif', 'image.png')), - 'type' => array('avatar' => array('a', 'b')), - 'tmp_name' => array('avatar' => array(__DIR__ . '/files/logo.gif', __DIR__ . '/files/logo.gif')), - 'error' => array('avatar' => array(0, 0)), - 'size' => array('avatar' => array(100, 200)), - ), - 'empty' => array( - 'name' => array(''), - 'type' => array(''), - 'tmp_name' => array(''), - 'error' => array(UPLOAD_ERR_NO_FILE), - 'size' => array(0), - ), - 'invalid1' => array( - 'name' => array(NULL), - 'type' => array(NULL), - 'tmp_name' => array(NULL), - 'error' => array(NULL), - 'size' => array(NULL), - ), + ], + 'container' => [ + 'name' => ['avatar' => "invalid\xAA\xAA\xAAutf"], + 'type' => ['avatar' => 'text/plain'], + 'tmp_name' => ['avatar' => 'C:\\PHP\\temp\\php1D5C.tmp'], + 'error' => ['avatar' => 0], + 'size' => ['avatar' => 3013], + ], + 'multiple' => [ + 'name' => ['avatar' => ['image.gif', 'image.png']], + 'type' => ['avatar' => ['a', 'b']], + 'tmp_name' => ['avatar' => [__DIR__ . '/files/logo.gif', __DIR__ . '/files/logo.gif']], + 'error' => ['avatar' => [0, 0]], + 'size' => ['avatar' => [100, 200]], + ], + 'empty' => [ + 'name' => [''], + 'type' => [''], + 'tmp_name' => [''], + 'error' => [UPLOAD_ERR_NO_FILE], + 'size' => [0], + ], + 'invalid1' => [ + 'name' => [NULL], + 'type' => [NULL], + 'tmp_name' => [NULL], + 'error' => [NULL], + 'size' => [NULL], + ], 'invalid2' => '', -); +]; test(function() { @@ -60,13 +60,13 @@ test(function() { $input = $form->addUpload('avatar'); Assert::true( $form->isValid() ); - Assert::equal( new FileUpload(array( + Assert::equal( new FileUpload([ 'name' => 'license.txt', 'type' => '', 'size' => 3013, 'tmp_name' => __DIR__ . '/files/logo.gif', 'error' => 0, - )), $input->getValue() ); + ]), $input->getValue() ); Assert::true( $input->isFilled() ); }); @@ -76,13 +76,13 @@ test(function() { // container $input = $form->addContainer('container')->addUpload('avatar'); Assert::true( $form->isValid() ); - Assert::equal( new FileUpload(array( + Assert::equal( new FileUpload([ 'name' => '', 'type' => '', 'size' => 3013, 'tmp_name' => 'C:\\PHP\\temp\\php1D5C.tmp', 'error' => 0, - )), $input->getValue() ); + ]), $input->getValue() ); Assert::true( $input->isFilled() ); }); @@ -92,19 +92,19 @@ test(function() { // multiple (in container) $input = $form->addContainer('multiple')->addMultiUpload('avatar'); Assert::true( $form->isValid() ); - Assert::equal( array(new FileUpload(array( + Assert::equal( [new FileUpload([ 'name' => 'image.gif', 'type' => '', 'size' => 100, 'tmp_name' => __DIR__ . '/files/logo.gif', 'error' => 0, - )), new FileUpload(array( + ]), new FileUpload([ 'name' => 'image.png', 'type' => '', 'size' => 200, 'tmp_name' => __DIR__ . '/files/logo.gif', 'error' => 0, - ))), $input->getValue() ); + ])], $input->getValue() ); Assert::true( $input->isFilled() ); }); @@ -115,7 +115,7 @@ test(function() { // missing data ->setRequired(); Assert::false( $form->isValid() ); - Assert::equal( array(), $input->getValue() ); + Assert::equal( [], $input->getValue() ); Assert::false( $input->isFilled() ); }); @@ -126,7 +126,7 @@ test(function() { // empty data ->setRequired(); Assert::false( $form->isValid() ); - Assert::equal( new FileUpload(array()), $input->getValue() ); + Assert::equal( new FileUpload([]), $input->getValue() ); Assert::false( $input->isFilled() ); }); @@ -136,28 +136,28 @@ test(function() { // malformed data $input = $form->addUpload('invalid1'); Assert::true( $form->isValid() ); - Assert::equal( new FileUpload(array()), $input->getValue() ); + Assert::equal( new FileUpload([]), $input->getValue() ); Assert::false( $input->isFilled() ); $form = new Form; $input = $form->addUpload('invalid2'); Assert::true( $form->isValid() ); - Assert::equal( new FileUpload(array()), $input->getValue() ); + Assert::equal( new FileUpload([]), $input->getValue() ); Assert::false( $input->isFilled() ); $form = new Form; $input = $form->addMultiUpload('avatar'); Assert::true( $form->isValid() ); - Assert::equal( array(), $input->getValue() ); + Assert::equal( [], $input->getValue() ); Assert::false( $input->isFilled() ); $form = new Form; $input = $form->addContainer('multiple')->addUpload('avatar'); Assert::true( $form->isValid() ); - Assert::equal( new FileUpload(array()), $input->getValue() ); + Assert::equal( new FileUpload([]), $input->getValue() ); Assert::false( $input->isFilled() ); }); @@ -174,8 +174,8 @@ test(function() { // validators Assert::true( Validator::validateMimeType($input, 'image/*') ); Assert::false( Validator::validateMimeType($input, 'text/*') ); Assert::true( Validator::validateMimeType($input, 'text/css,image/*') ); - Assert::true( Validator::validateMimeType($input, array('text/css', 'image/*')) ); - Assert::false( Validator::validateMimeType($input, array()) ); + Assert::true( Validator::validateMimeType($input, ['text/css', 'image/*']) ); + Assert::false( Validator::validateMimeType($input, []) ); Assert::true( Validator::validateImage($input) ); }); @@ -193,8 +193,8 @@ test(function() { // validators on multiple files Assert::true( Validator::validateMimeType($input, 'image/*') ); Assert::false( Validator::validateMimeType($input, 'text/*') ); Assert::true( Validator::validateMimeType($input, 'text/css,image/*') ); - Assert::true( Validator::validateMimeType($input, array('text/css', 'image/*')) ); - Assert::false( Validator::validateMimeType($input, array()) ); + Assert::true( Validator::validateMimeType($input, ['text/css', 'image/*']) ); + Assert::false( Validator::validateMimeType($input, []) ); Assert::true( Validator::validateImage($input) ); }); diff --git a/tests/Forms/Controls.translate().phpt b/tests/Forms/Controls.translate().phpt index 9ea3c142d..9f11fa00e 100644 --- a/tests/Forms/Controls.translate().phpt +++ b/tests/Forms/Controls.translate().phpt @@ -69,10 +69,10 @@ test(function() { $name = $form->addText('name', 'Your name'); $name->addError("Error message"); $name->addError($w = new StringWrapper('Your name')); - Assert::same(array( + Assert::same([ 'Error message', $w - ), $name->getErrors()); + ], $name->getErrors()); }); @@ -85,11 +85,11 @@ test(function() { ->addRule($form::EMAIL, 'error'); Assert::match('', (string) $email->getControl()); $email->validate(); - Assert::same(array('error'), $email->getErrors()); + Assert::same(['error'], $email->getErrors()); $email2 = $form->addText('email2') ->addRule($form::EMAIL, new StringWrapper('Your name')); Assert::match('', (string) $email2->getControl()); $email2->validate(); - Assert::same(array('StringWrapper'), $email2->getErrors()); + Assert::same(['StringWrapper'], $email2->getErrors()); }); diff --git a/tests/Forms/Forms.callbackParameters.phpt b/tests/Forms/Forms.callbackParameters.phpt index 0b737572b..1933d4b3d 100644 --- a/tests/Forms/Forms.callbackParameters.phpt +++ b/tests/Forms/Forms.callbackParameters.phpt @@ -17,11 +17,11 @@ $form = new Form(); $form->addText('text'); $form->addSubmit('submit'); -$types = array(); +$types = []; class TestFormCallbackParameters { - public static $results = array(); + public static $results = []; public static function doSomething($form, $values) { @@ -37,13 +37,13 @@ class TestFormCallbackParameters } // Test the method second parameter to be an ArrayHash instance by default -$m1 = array('TestFormCallbackParameters', 'doSomething'); +$m1 = ['TestFormCallbackParameters', 'doSomething']; // Test the method second parameter to be an array by type-hint -$m2 = array('TestFormCallbackParameters', 'doSomethingWithArray'); +$m2 = ['TestFormCallbackParameters', 'doSomethingWithArray']; // Test the method second parameter to be an ArrayHash instance by default again -$m3 = array('TestFormCallbackParameters', 'doSomething'); +$m3 = ['TestFormCallbackParameters', 'doSomething']; // Test the closure second parameter to be an ArrayHash instance by default $f1 = function ($form, $values) use (& $types) { @@ -67,19 +67,19 @@ $f3 = function ($form, $values) use (& $types) { $f4 = function ($form, $values) use (& $types) { $values->text = 'b'; }; -$arrayHashIsImmutable = array(); +$arrayHashIsImmutable = []; $f5 = function ($form, $values) use (& $arrayHashIsImmutable) { $arrayHashIsImmutable[] = $values->text === 'a'; }; -foreach (array($m1, $m2, $m3, $f1, $f2, $f3, $f4, $f5) as $f) { +foreach ([$m1, $m2, $m3, $f1, $f2, $f3, $f4, $f5] as $f) { $form->onSuccess[] = $f; } -foreach (array($m1, $m2, $m3, $f1, $f2, $f3, $f4, $f5) as $f) { +foreach ([$m1, $m2, $m3, $f1, $f2, $f3, $f4, $f5] as $f) { $form->onValidate[] = $f; } $form->fireEvents(); -Assert::same(TestFormCallbackParameters::$results, array(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)); -Assert::same($types, array(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)); -Assert::same($arrayHashIsImmutable, array(TRUE, TRUE)); +Assert::same(TestFormCallbackParameters::$results, [TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE]); +Assert::same($types, [TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE]); +Assert::same($arrayHashIsImmutable, [TRUE, TRUE]); diff --git a/tests/Forms/Forms.getHttpData.get.2.phpt b/tests/Forms/Forms.getHttpData.get.2.phpt index 90c1170f4..d90e7612a 100644 --- a/tests/Forms/Forms.getHttpData.get.2.phpt +++ b/tests/Forms/Forms.getHttpData.get.2.phpt @@ -13,12 +13,12 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'GET'; - $_GET = $_POST = $_FILES = array(); + $_GET = $_POST = $_FILES = []; }); test(function() { - $_GET = array('item'); + $_GET = ['item']; $_SERVER['REQUEST_URI'] = '/?' . http_build_query($_GET); $form = new Form; @@ -26,6 +26,6 @@ test(function() { $form->addSubmit('send', 'Send'); Assert::truthy( $form->isSubmitted() ); - Assert::same( array('item'), $form->getHttpData() ); - Assert::same( array(), $form->getValues(TRUE) ); + Assert::same( ['item'], $form->getHttpData() ); + Assert::same( [], $form->getValues(TRUE) ); }); diff --git a/tests/Forms/Forms.getHttpData.get.phpt b/tests/Forms/Forms.getHttpData.get.phpt index 7da96f715..5920efabb 100644 --- a/tests/Forms/Forms.getHttpData.get.phpt +++ b/tests/Forms/Forms.getHttpData.get.phpt @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'GET'; - $_GET = $_POST = $_FILES = array(); + $_GET = $_POST = $_FILES = []; }); @@ -24,8 +24,8 @@ test(function() { Assert::false( $form->isSubmitted() ); Assert::false( $form->isSuccess() ); - Assert::same( array(), $form->getHttpData() ); - Assert::same( array(), $form->getValues(TRUE) ); + Assert::same( [], $form->getHttpData() ); + Assert::same( [], $form->getValues(TRUE) ); }); @@ -34,14 +34,14 @@ test(function() { $form->addSubmit('send', 'Send'); Assert::false( $form->isSubmitted() ); - Assert::same( array(), $form->getHttpData() ); - Assert::same( array(), $form->getValues(TRUE) ); + Assert::same( [], $form->getHttpData() ); + Assert::same( [], $form->getValues(TRUE) ); }); test(function() { $name = 'name'; - $_GET = array(Form::TRACKER_ID => $name); + $_GET = [Form::TRACKER_ID => $name]; $_SERVER['REQUEST_URI'] = '/?' . http_build_query($_GET); $form = new Form($name); @@ -49,7 +49,7 @@ test(function() { $form->addSubmit('send', 'Send'); Assert::truthy( $form->isSubmitted() ); - Assert::same( array(Form::TRACKER_ID => $name), $form->getHttpData() ); - Assert::same( array(), $form->getValues(TRUE) ); + Assert::same( [Form::TRACKER_ID => $name], $form->getHttpData() ); + Assert::same( [], $form->getValues(TRUE) ); Assert::same( $name, $form[Form::TRACKER_ID]->getValue() ); }); diff --git a/tests/Forms/Forms.getHttpData.post.phpt b/tests/Forms/Forms.getHttpData.post.phpt index 7b3ccaa72..5335356c6 100644 --- a/tests/Forms/Forms.getHttpData.post.phpt +++ b/tests/Forms/Forms.getHttpData.post.phpt @@ -14,7 +14,7 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_GET = $_POST = $_FILES = array(); + $_GET = $_POST = $_FILES = []; }); @@ -24,8 +24,8 @@ test(function() { Assert::truthy( $form->isSubmitted() ); Assert::true( $form->isSuccess() ); - Assert::same( array(), $form->getHttpData() ); - Assert::same( array(), $form->getValues(TRUE) ); + Assert::same( [], $form->getHttpData() ); + Assert::same( [], $form->getValues(TRUE) ); }); @@ -36,21 +36,21 @@ test(function() { Assert::false( $form->isSubmitted() ); Assert::false( $form->isSuccess() ); - Assert::same( array(), $form->getHttpData() ); - Assert::same( array(), $form->getValues(TRUE) ); + Assert::same( [], $form->getHttpData() ); + Assert::same( [], $form->getValues(TRUE) ); }); test(function() { $name = 'name'; - $_POST = array(Form::TRACKER_ID => $name); + $_POST = [Form::TRACKER_ID => $name]; $form = new Form($name); $form->addSubmit('send', 'Send'); Assert::truthy( $form->isSubmitted() ); - Assert::same( array(Form::TRACKER_ID => $name), $form->getHttpData() ); - Assert::same( array(), $form->getValues(TRUE) ); + Assert::same( [Form::TRACKER_ID => $name], $form->getHttpData() ); + Assert::same( [], $form->getValues(TRUE) ); Assert::same( $name, $form[Form::TRACKER_ID]->getValue() ); }); @@ -61,7 +61,7 @@ test(function() { Assert::false( $input->isSubmittedBy() ); Assert::false( Validator::validateSubmitted($input) ); - $_POST = array('send' => ''); + $_POST = ['send' => '']; $form = new Form; $input = $form->addSubmit('send', 'Send'); Assert::true( $input->isSubmittedBy() ); diff --git a/tests/Forms/Forms.isValid.phpt b/tests/Forms/Forms.isValid.phpt index f2c83fbba..3f608a22e 100644 --- a/tests/Forms/Forms.isValid.phpt +++ b/tests/Forms/Forms.isValid.phpt @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_GET = $_POST = $_FILES = array(); + $_GET = $_POST = $_FILES = []; }); @@ -24,26 +24,26 @@ test(function() { Assert::true( $form->isSubmitted() ); Assert::true( $form->isValid() ); Assert::true( $form->isSuccess() ); - Assert::same( array(), $form->getErrors() ); + Assert::same( [], $form->getErrors() ); $form['item']->addError('1'); Assert::true( $form->isSubmitted() ); Assert::false( $form->isValid() ); Assert::false( $form->isSuccess() ); - Assert::same( array('1'), $form->getErrors() ); + Assert::same( ['1'], $form->getErrors() ); $form['item']->addError('2'); Assert::true( $form->isSubmitted() ); Assert::false( $form->isValid() ); - Assert::same( array('1', '2'), $form->getErrors() ); + Assert::same( ['1', '2'], $form->getErrors() ); $form->validate(); Assert::true( $form->isSubmitted() ); Assert::true( $form->isValid() ); - Assert::same( array(), $form->getErrors() ); + Assert::same( [], $form->getErrors() ); }); @@ -55,7 +55,7 @@ test(function() { Assert::true( $form->isSubmitted() ); Assert::false( $form->isValid() ); - Assert::same( array('1'), $form->getErrors() ); + Assert::same( ['1'], $form->getErrors() ); }); @@ -67,7 +67,7 @@ test(function() { Assert::true( $form->isSubmitted() ); Assert::false( $form->isValid() ); - Assert::same( array('1'), $form->getErrors() ); + Assert::same( ['1'], $form->getErrors() ); }); @@ -80,7 +80,7 @@ test(function() { Assert::true( $form->isSubmitted() ); Assert::false( $form->isValid() ); - Assert::same( array('1', '2'), $form->getErrors() ); + Assert::same( ['1', '2'], $form->getErrors() ); }); @@ -94,5 +94,5 @@ test(function() { Assert::true( $form->isSubmitted() ); Assert::false( $form->isValid() ); - Assert::same( array('1', '2'), $form->getErrors() ); + Assert::same( ['1', '2'], $form->getErrors() ); }); diff --git a/tests/Forms/Forms.omittedValue.phpt b/tests/Forms/Forms.omittedValue.phpt index 7a345a901..d30d89c7d 100644 --- a/tests/Forms/Forms.omittedValue.phpt +++ b/tests/Forms/Forms.omittedValue.phpt @@ -18,4 +18,4 @@ $form->addText('input'); $form->addText('omittedInput') ->setOmitted(); -Assert::same(array('input' => ''), $form->getValues(TRUE)); +Assert::same(['input' => ''], $form->getValues(TRUE)); diff --git a/tests/Forms/Forms.onSuccess.phpt b/tests/Forms/Forms.onSuccess.phpt index b2cd358e8..081039cd9 100644 --- a/tests/Forms/Forms.onSuccess.phpt +++ b/tests/Forms/Forms.onSuccess.phpt @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php'; $_SERVER['REQUEST_METHOD'] = 'POST'; -$called = array(); +$called = []; $form = new Form; $form->addText('name'); $form->addSubmit('submit'); @@ -34,10 +34,10 @@ $form->onError[] = function() use (& $called) { $called[] = 'err'; }; $form->fireEvents(); -Assert::same(array(1, 2, 'err'), $called); +Assert::same([1, 2, 'err'], $called); -$called = array(); +$called = []; $form = new Form; $form->addText('name'); $form->addSubmit('submit'); @@ -52,4 +52,4 @@ $form->onError[] = function() use (& $called) { $called[] = 'err'; }; $form->fireEvents(); -Assert::same(array(1, 2, 'err'), $called); +Assert::same([1, 2, 'err'], $called); diff --git a/tests/Forms/Forms.renderer.1.phpt b/tests/Forms/Forms.renderer.1.phpt index 4298fc17d..e34240699 100644 --- a/tests/Forms/Forms.renderer.1.phpt +++ b/tests/Forms/Forms.renderer.1.phpt @@ -13,24 +13,24 @@ require __DIR__ . '/../bootstrap.php'; $_SERVER['REQUEST_METHOD'] = 'POST'; -$_POST = array('name'=>'John Doe ','age'=>'','email'=>' @ ','send'=>'on','street'=>'','city'=>'','country'=>'HU','password'=>'xxx','password2'=>'','note'=>'','submit1'=>'Send','userid'=>'231',); +$_POST = ['name'=>'John Doe ','age'=>'','email'=>' @ ','send'=>'on','street'=>'','city'=>'','country'=>'HU','password'=>'xxx','password2'=>'','note'=>'','submit1'=>'Send','userid'=>'231',]; -$countries = array( - 'Europe' => array( +$countries = [ + 'Europe' => [ 'CZ' => 'Czech Republic', 'SK' => 'Slovakia', 'GB' => 'United Kingdom', - ), + ], 'CA' => 'Canada', 'US' => 'United States', '?' => 'other', -); +]; -$sex = array( +$sex = [ 'm' => 'male', 'f' => 'female', -); +]; $form = new Form; @@ -46,7 +46,7 @@ $form->addText('name', 'Your name:') $form->addText('age', 'Your age:') ->addRule(Form::FILLED, 'Enter your age') ->addRule(Form::INTEGER, 'Age must be numeric value') - ->addRule(Form::RANGE, 'Age must be in range from %d to %d', array(10, 100)); + ->addRule(Form::RANGE, 'Age must be in range from %d to %d', [10, 100]); $form->addRadioList('gender', 'Your gender:', $sex); @@ -113,11 +113,11 @@ $form->addSubmit('submit', 'Send'); $form->addButton('cancel', 'Cancel'); -$defaults = array( +$defaults = [ 'name' => 'John Doe', 'userid' => 231, 'country' => 'CZ', -); +]; $form->setDefaults($defaults); $form->fireEvents(); diff --git a/tests/Forms/Forms.renderer.2.phpt b/tests/Forms/Forms.renderer.2.phpt index 885e67e67..27604bc84 100644 --- a/tests/Forms/Forms.renderer.2.phpt +++ b/tests/Forms/Forms.renderer.2.phpt @@ -13,24 +13,24 @@ require __DIR__ . '/../bootstrap.php'; $_SERVER['REQUEST_METHOD'] = 'POST'; -$_POST = array('name'=>'John Doe ','age'=>'9.9','email'=>'@','street'=>'','city'=>'Troubsko','country'=>'0','password'=>'xx','password2'=>'xx','note'=>'','submit1'=>'Send','userid'=>'231',); +$_POST = ['name'=>'John Doe ','age'=>'9.9','email'=>'@','street'=>'','city'=>'Troubsko','country'=>'0','password'=>'xx','password2'=>'xx','note'=>'','submit1'=>'Send','userid'=>'231',]; -$countries = array( - 'Europe' => array( +$countries = [ + 'Europe' => [ 'CZ' => 'Czech Republic', 'SK' => 'Slovakia', 'GB' => 'United Kingdom', - ), + ], 'CA' => 'Canada', 'US' => 'United States', '?' => 'other', -); +]; -$sex = array( +$sex = [ 'm' => Html::el('option', 'male')->style('color: #248bd3'), 'f' => Html::el('option', 'female')->style('color: #e948d4'), -); +]; $form = new Form; @@ -57,7 +57,7 @@ $form->addText('name', 'Your name') $form->addText('age', 'Your age') ->addRule(Form::FILLED, 'Enter your age') ->addRule(Form::INTEGER, 'Age must be numeric value') - ->addRule(Form::RANGE, 'Age must be in range from %d to %d', array(10, 100)); + ->addRule(Form::RANGE, 'Age must be in range from %d to %d', [10, 100]); $form->addSelect('gender', 'Your gender', $sex); @@ -114,11 +114,11 @@ $form->addGroup(); $form->addSubmit('submit', 'Send'); -$defaults = array( +$defaults = [ 'name' => 'John Doe', 'userid' => 231, 'country' => 'CZ', -); +]; $form->setDefaults($defaults); $form->fireEvents(); diff --git a/tests/Forms/Forms.submittedBy.phpt b/tests/Forms/Forms.submittedBy.phpt index 863524959..93280a970 100644 --- a/tests/Forms/Forms.submittedBy.phpt +++ b/tests/Forms/Forms.submittedBy.phpt @@ -13,13 +13,13 @@ require __DIR__ . '/../bootstrap.php'; before(function() { $_SERVER['REQUEST_METHOD'] = 'POST'; - $_GET = $_POST = $_FILES = array(); + $_GET = $_POST = $_FILES = []; }); test(function() { $name = 'name'; - $_POST = array(Form::TRACKER_ID => $name, 'send2' => ''); + $_POST = [Form::TRACKER_ID => $name, 'send2' => '']; $form = new Form($name); $btn1 = $form->addSubmit('send1'); @@ -33,7 +33,7 @@ test(function() { test(function() { $name = 'name'; - $_POST = array(Form::TRACKER_ID => $name, 'send2' => array('x' => 1, 'y' => 1)); + $_POST = [Form::TRACKER_ID => $name, 'send2' => ['x' => 1, 'y' => 1]]; $form = new Form($name); $btn1 = $form->addImage('send1'); diff --git a/tests/Forms/Forms.toggle.phpt b/tests/Forms/Forms.toggle.phpt index 17c6f93a9..c8d2986a6 100644 --- a/tests/Forms/Forms.toggle.phpt +++ b/tests/Forms/Forms.toggle.phpt @@ -21,10 +21,10 @@ test(function() { // AND ->addConditionOn($form['2'], Form::EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => FALSE, 'b' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -38,10 +38,10 @@ test(function() { ->addConditionOn($form['2'], Form::NOT_EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => FALSE, 'b' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -55,10 +55,10 @@ test(function() { ->addConditionOn($form['2'], Form::EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -72,10 +72,10 @@ test(function() { ->addConditionOn($form['2'], Form::NOT_EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -90,10 +90,10 @@ test(function() { // OR ->addConditionOn($form['2'], Form::EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => FALSE, 'b' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -108,10 +108,10 @@ test(function() { ->addConditionOn($form['2'], Form::NOT_EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => FALSE, 'b' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -126,10 +126,10 @@ test(function() { ->addConditionOn($form['2'], Form::EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -144,10 +144,10 @@ test(function() { ->addConditionOn($form['2'], Form::NOT_EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -160,10 +160,10 @@ test(function() { // OR & two components ->addCondition(Form::EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => FALSE, 'b' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -176,10 +176,10 @@ test(function() { ->addCondition(Form::NOT_EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => FALSE, 'b' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -192,10 +192,10 @@ test(function() { ->addCondition(Form::EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -208,10 +208,10 @@ test(function() { ->addCondition(Form::NOT_EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -224,9 +224,9 @@ test(function() { // OR & multiple used ID ->addCondition(Form::EQUAL, 'x') ->toggle('a'); - Assert::same( array( + Assert::same( [ 'a' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -239,9 +239,9 @@ test(function() { ->addCondition(Form::NOT_EQUAL, 'x') ->toggle('a'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -254,9 +254,9 @@ test(function() { ->addCondition(Form::EQUAL, 'x') ->toggle('a'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -269,9 +269,9 @@ test(function() { ->addCondition(Form::NOT_EQUAL, 'x') ->toggle('a'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -285,9 +285,9 @@ test(function() { // AND & multiple used ID ->addConditionOn($form['2'], Form::EQUAL, 'x') ->toggle('a'); - Assert::same( array( + Assert::same( [ 'a' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -301,9 +301,9 @@ test(function() { ->addConditionOn($form['2'], Form::NOT_EQUAL, 'x') ->toggle('a'); - Assert::same( array( + Assert::same( [ 'a' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -317,9 +317,9 @@ test(function() { ->addConditionOn($form['2'], Form::EQUAL, 'x') ->toggle('a'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -333,9 +333,9 @@ test(function() { ->addConditionOn($form['2'], Form::NOT_EQUAL, 'x') ->toggle('a'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -349,10 +349,10 @@ test(function() { // $hide = FALSE ->addConditionOn($form['2'], Form::NOT_EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -366,10 +366,10 @@ test(function() { ->addConditionOn($form['2'], Form::NOT_EQUAL, 'x') ->toggle('b', FALSE); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -383,10 +383,10 @@ test(function() { ->addConditionOn($form['2'], Form::EQUAL, 'x') ->toggle('b', FALSE); - Assert::same( array( + Assert::same( [ 'a' => FALSE, 'b' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -399,10 +399,10 @@ test(function() { ->addCondition(Form::NOT_EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -415,10 +415,10 @@ test(function() { ->addCondition(Form::NOT_EQUAL, 'x') ->toggle('b', FALSE); - Assert::same( array( + Assert::same( [ 'a' => FALSE, 'b' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -431,10 +431,10 @@ test(function() { ->addCondition(Form::EQUAL, 'x') ->toggle('b', FALSE); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -448,9 +448,9 @@ test(function() { // $hide = FALSE & multiple used ID ->addConditionOn($form['2'], Form::NOT_EQUAL, 'x') ->toggle('a'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -464,9 +464,9 @@ test(function() { ->addConditionOn($form['2'], Form::NOT_EQUAL, 'x') ->toggle('a', FALSE); - Assert::same( array( + Assert::same( [ 'a' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -480,9 +480,9 @@ test(function() { ->addConditionOn($form['2'], Form::EQUAL, 'x') ->toggle('a', FALSE); - Assert::same( array( + Assert::same( [ 'a' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -495,10 +495,10 @@ test(function() { ->addCondition(Form::NOT_EQUAL, 'x') ->toggle('b'); - Assert::same( array( + Assert::same( [ 'a' => TRUE, 'b' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -511,10 +511,10 @@ test(function() { ->addCondition(Form::NOT_EQUAL, 'x') ->toggle('b', FALSE); - Assert::same( array( + Assert::same( [ 'a' => FALSE, 'b' => FALSE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -527,9 +527,9 @@ test(function() { ->addCondition(Form::EQUAL, 'x') ->toggle('a', FALSE); - Assert::same( array( + Assert::same( [ 'a' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); @@ -542,7 +542,7 @@ test(function() { ->addCondition(Form::NOT_EQUAL, 'x') ->toggle('a', FALSE); - Assert::same( array( + Assert::same( [ 'a' => TRUE, - ), $form->getToggles() ); + ], $form->getToggles() ); }); diff --git a/tests/Forms/Forms.userValidator.phpt b/tests/Forms/Forms.userValidator.phpt index 888fe19ae..d688ea66e 100644 --- a/tests/Forms/Forms.userValidator.phpt +++ b/tests/Forms/Forms.userValidator.phpt @@ -11,11 +11,11 @@ use Nette\Forms\Form, require __DIR__ . '/../bootstrap.php'; -$datasets = array( - array(11, array('Value 11 is not allowed!')), - array(22, array()), - array(1, array('Value 22 is required!')), -); +$datasets = [ + [11, ['Value 11 is not allowed!']], + [22, []], + [1, ['Value 22 is required!']], +]; function myValidator1($item, $arg) { diff --git a/tests/Forms/Forms.validationScope.phpt b/tests/Forms/Forms.validationScope.phpt index 3f4cdd472..014481c60 100644 --- a/tests/Forms/Forms.validationScope.phpt +++ b/tests/Forms/Forms.validationScope.phpt @@ -11,13 +11,13 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$datasets = array( - array('send1', array('name', 'age', 'age2')), - array('send2', array()), - array('send3', array('name')), - array('send4', array('age')), - array('send5', array('age', 'age2')), -); +$datasets = [ + ['send1', ['name', 'age', 'age2']], + ['send2', []], + ['send3', ['name']], + ['send4', ['age']], + ['send5', ['age', 'age2']], +]; foreach ($datasets as $case) { @@ -30,9 +30,9 @@ foreach ($datasets as $case) { $form->addSubmit('send1'); $form->addSubmit('send2')->setValidationScope(FALSE); - $form->addSubmit('send3')->setValidationScope(array($form['name'])); - $form->addSubmit('send4')->setValidationScope(array($form['details']['age'])); - $form->addSubmit('send5')->setValidationScope(array($form['details'])); + $form->addSubmit('send3')->setValidationScope([$form['name']]); + $form->addSubmit('send4')->setValidationScope([$form['details']['age']]); + $form->addSubmit('send5')->setValidationScope([$form['details']]); $form->setSubmittedBy($form[$case[0]]); diff --git a/tests/Forms/Helpers.createInputList.phpt b/tests/Forms/Helpers.createInputList.phpt index 1b43780c9..6b1d97173 100644 --- a/tests/Forms/Helpers.createInputList.phpt +++ b/tests/Forms/Helpers.createInputList.phpt @@ -15,50 +15,50 @@ require __DIR__ . '/../bootstrap.php'; test(function() { Assert::same( '', - Helpers::createInputList(array()) + Helpers::createInputList([]) ); Assert::same( '', - Helpers::createInputList(array('a')) + Helpers::createInputList(['a']) ); Assert::same( '', Helpers::createInputList( - array('a' => 'First', 'b' => 'Second') + ['a' => 'First', 'b' => 'Second'] ) ); Assert::same( '', Helpers::createInputList( - array('a' => 'First', 'b' => 'Second'), - array('type' => 'checkbox'), - array('class' => 'button') + ['a' => 'First', 'b' => 'Second'], + ['type' => 'checkbox'], + ['class' => 'button'] ) ); Assert::same( '', Helpers::createInputList( - array('a' => 'First', 'b' => 'Second'), - array( - 'type:' => array('a' => 'checkbox', 'b' => 'radio'), - 'checked?' => array('a'), + ['a' => 'First', 'b' => 'Second'], + [ + 'type:' => ['a' => 'checkbox', 'b' => 'radio'], + 'checked?' => ['a'], 'title' => 'Hello', - ), - array( - 'class:' => array('a' => array('class1', 'class2')), - 'style' => array('color' => 'blue'), - ) + ], + [ + 'class:' => ['a' => ['class1', 'class2']], + 'style' => ['color' => 'blue'], + ] ) ); Assert::same( '
', Helpers::createInputList( - array('a' => 'First', 'b' => 'Second'), + ['a' => 'First', 'b' => 'Second'], NULL, NULL, '
' @@ -68,7 +68,7 @@ test(function() { Assert::same( '
', Helpers::createInputList( - array('a' => 'First', 'b' => 'Second'), + ['a' => 'First', 'b' => 'Second'], NULL, NULL, Html::el('div') @@ -78,7 +78,7 @@ test(function() { Assert::same( '', Helpers::createInputList( - array('a' => 'First', 'b' => 'Second'), + ['a' => 'First', 'b' => 'Second'], NULL, NULL, Html::el(NULL) diff --git a/tests/Forms/Helpers.createSelectBox.phpt b/tests/Forms/Helpers.createSelectBox.phpt index c11da94d6..402a82bbc 100644 --- a/tests/Forms/Helpers.createSelectBox.phpt +++ b/tests/Forms/Helpers.createSelectBox.phpt @@ -15,64 +15,64 @@ require __DIR__ . '/../bootstrap.php'; test(function() { Assert::type( 'Nette\Utils\Html', - Helpers::createSelectBox(array()) + Helpers::createSelectBox([]) ); Assert::same( '', - (string) Helpers::createSelectBox(array()) + (string) Helpers::createSelectBox([]) ); Assert::same( '', - (string) Helpers::createSelectBox(array('a')) + (string) Helpers::createSelectBox(['a']) ); Assert::same( '', (string) Helpers::createSelectBox( - array('a' => 'First', 'b' => 'Second') + ['a' => 'First', 'b' => 'Second'] ) ); Assert::same( '', (string) Helpers::createSelectBox( - array( + [ 'a' => 'First', - 'Group' => array('A', 'B'), - ) + 'Group' => ['A', 'B'], + ] ) ); Assert::same( '', (string) Helpers::createSelectBox( - array( + [ 'a' => Html::el('', 'Hello')->id('item-a'), - 'Group' => array(Html::el('', 'World')->id('item-b')), - ) + 'Group' => [Html::el('', 'World')->id('item-b')], + ] ) ); Assert::same( '', (string) Helpers::createSelectBox( - array('a' => 'First', 'b' => 'Second'), - array( - 'disabled:' => array('b' => TRUE), - 'selected?' => array('a'), + ['a' => 'First', 'b' => 'Second'], + [ + 'disabled:' => ['b' => TRUE], + 'selected?' => ['a'], 'title' => 'Hello', - 'style' => array('color' => 'blue'), - ) + 'style' => ['color' => 'blue'], + ] ) ); Assert::same( '', (string) Helpers::createSelectBox( - array('a' => 'First', 'b' => 'Second'), - array('disabled:' => TRUE, 'selected?' => 'b') + ['a' => 'First', 'b' => 'Second'], + ['disabled:' => TRUE, 'selected?' => 'b'] ) ); }); diff --git a/tests/Forms/Helpers.extractHttpData.phpt b/tests/Forms/Helpers.extractHttpData.phpt index f18f23b44..52af33a55 100644 --- a/tests/Forms/Helpers.extractHttpData.phpt +++ b/tests/Forms/Helpers.extractHttpData.phpt @@ -13,77 +13,77 @@ require __DIR__ . '/../bootstrap.php'; test(function() { // non-multiple - Assert::same('jim', Helpers::extractHttpData(array('name' => 'jim'), 'name', Form::DATA_LINE)); - Assert::same('jim', Helpers::extractHttpData(array('name' => 'jim'), 'name', Form::DATA_TEXT)); + Assert::same('jim', Helpers::extractHttpData(['name' => 'jim'], 'name', Form::DATA_LINE)); + Assert::same('jim', Helpers::extractHttpData(['name' => 'jim'], 'name', Form::DATA_TEXT)); - Assert::same('jim', Helpers::extractHttpData(array( - 'first' => array('name' => 'jim'), - ), 'first[name]', Form::DATA_LINE)); + Assert::same('jim', Helpers::extractHttpData([ + 'first' => ['name' => 'jim'], + ], 'first[name]', Form::DATA_LINE)); - Assert::same('0', Helpers::extractHttpData(array('zero' => '0'), 'zero', Form::DATA_LINE)); - Assert::same('', Helpers::extractHttpData(array('empty' => ''), 'empty', Form::DATA_LINE)); + Assert::same('0', Helpers::extractHttpData(['zero' => '0'], 'zero', Form::DATA_LINE)); + Assert::same('', Helpers::extractHttpData(['empty' => ''], 'empty', Form::DATA_LINE)); - Assert::null( Helpers::extractHttpData(array(), 'missing', Form::DATA_LINE)); - Assert::null( Helpers::extractHttpData(array('invalid' => '1'), 'invalid[name]', Form::DATA_LINE)); - Assert::null( Helpers::extractHttpData(array('invalid' => array('')), 'invalid', Form::DATA_LINE)); - Assert::null( Helpers::extractHttpData(array('invalid' => array('')), 'invalid', Form::DATA_TEXT)); + Assert::null( Helpers::extractHttpData([], 'missing', Form::DATA_LINE)); + Assert::null( Helpers::extractHttpData(['invalid' => '1'], 'invalid[name]', Form::DATA_LINE)); + Assert::null( Helpers::extractHttpData(['invalid' => ['']], 'invalid', Form::DATA_LINE)); + Assert::null( Helpers::extractHttpData(['invalid' => ['']], 'invalid', Form::DATA_TEXT)); - Assert::same('a b c', Helpers::extractHttpData(array('text' => " a\r b \n c "), 'text', Form::DATA_LINE)); - Assert::same(" a\n b \n c ", Helpers::extractHttpData(array('text' => " a\r b \n c "), 'text', Form::DATA_TEXT)); + Assert::same('a b c', Helpers::extractHttpData(['text' => " a\r b \n c "], 'text', Form::DATA_LINE)); + Assert::same(" a\n b \n c ", Helpers::extractHttpData(['text' => " a\r b \n c "], 'text', Form::DATA_TEXT)); }); test(function() { // multiple - Assert::same(array('1', '2'), Helpers::extractHttpData(array('multi' => array('1', '2')), 'multi[]', Form::DATA_LINE)); - Assert::same(array('1', '2'), Helpers::extractHttpData(array('multi' => array('1', '2')), 'multi[]', Form::DATA_TEXT)); - Assert::same(array('1', '2'), Helpers::extractHttpData(array('multi' => array('x' => '1', 2 => '2')), 'multi[]', Form::DATA_TEXT)); - Assert::same(array('x' => '1', 2 => '2'), Helpers::extractHttpData(array('multi' => array('x' => '1', 2 => '2')), 'multi[]', Form::DATA_KEYS | Form::DATA_TEXT)); + Assert::same(['1', '2'], Helpers::extractHttpData(['multi' => ['1', '2']], 'multi[]', Form::DATA_LINE)); + Assert::same(['1', '2'], Helpers::extractHttpData(['multi' => ['1', '2']], 'multi[]', Form::DATA_TEXT)); + Assert::same(['1', '2'], Helpers::extractHttpData(['multi' => ['x' => '1', 2 => '2']], 'multi[]', Form::DATA_TEXT)); + Assert::same(['x' => '1', 2 => '2'], Helpers::extractHttpData(['multi' => ['x' => '1', 2 => '2']], 'multi[]', Form::DATA_KEYS | Form::DATA_TEXT)); - Assert::same(array('3', '4'), Helpers::extractHttpData(array( - 'container' => array('image' => array('3', '4')), - ), 'container[image][]', Form::DATA_LINE)); + Assert::same(['3', '4'], Helpers::extractHttpData([ + 'container' => ['image' => ['3', '4']], + ], 'container[image][]', Form::DATA_LINE)); - Assert::same(array('0'), Helpers::extractHttpData(array('zero' => array(0)), 'zero[]', Form::DATA_LINE)); - Assert::same(array(''), Helpers::extractHttpData(array('empty' => array('')), 'empty[]', Form::DATA_LINE)); + Assert::same(['0'], Helpers::extractHttpData(['zero' => [0]], 'zero[]', Form::DATA_LINE)); + Assert::same([''], Helpers::extractHttpData(['empty' => ['']], 'empty[]', Form::DATA_LINE)); - Assert::same(array(), Helpers::extractHttpData(array(), 'missing[]', Form::DATA_LINE)); - Assert::same(array(), Helpers::extractHttpData(array('invalid' => 'red-dwarf'), 'invalid[]', Form::DATA_LINE)); - Assert::same(array(), Helpers::extractHttpData(array('invalid' => array(array(''))), 'invalid[]', Form::DATA_LINE)); + Assert::same([], Helpers::extractHttpData([], 'missing[]', Form::DATA_LINE)); + Assert::same([], Helpers::extractHttpData(['invalid' => 'red-dwarf'], 'invalid[]', Form::DATA_LINE)); + Assert::same([], Helpers::extractHttpData(['invalid' => [['']]], 'invalid[]', Form::DATA_LINE)); - Assert::same(array('a b c'), Helpers::extractHttpData(array('text' => array(" a\r b \n c ")), 'text[]', Form::DATA_LINE)); - Assert::same(array(" a\n b \n c "), Helpers::extractHttpData(array('text' => array(" a\r b \n c ")), 'text[]', Form::DATA_TEXT)); + Assert::same(['a b c'], Helpers::extractHttpData(['text' => [" a\r b \n c "]], 'text[]', Form::DATA_LINE)); + Assert::same([" a\n b \n c "], Helpers::extractHttpData(['text' => [" a\r b \n c "]], 'text[]', Form::DATA_TEXT)); }); test(function() { // files - $file = new Nette\Http\FileUpload(array( + $file = new Nette\Http\FileUpload([ 'name' => 'license.txt', 'type' => NULL, 'size' => 3013, 'tmpName' => 'tmp', 'error' => 0, - )); + ]); - Assert::equal($file, Helpers::extractHttpData(array('avatar' => $file), 'avatar', Form::DATA_FILE)); + Assert::equal($file, Helpers::extractHttpData(['avatar' => $file], 'avatar', Form::DATA_FILE)); - Assert::null( Helpers::extractHttpData(array(), 'missing', Form::DATA_FILE)); - Assert::null( Helpers::extractHttpData(array('invalid' => NULL), 'invalid', Form::DATA_FILE)); - Assert::null( Helpers::extractHttpData(array('invalid' => array(NULL)), 'invalid', Form::DATA_FILE)); - Assert::null( Helpers::extractHttpData(array( - 'multiple' => array('avatar' => array($file, $file)), - ), 'multiple[avatar]', Form::DATA_FILE)); + Assert::null( Helpers::extractHttpData([], 'missing', Form::DATA_FILE)); + Assert::null( Helpers::extractHttpData(['invalid' => NULL], 'invalid', Form::DATA_FILE)); + Assert::null( Helpers::extractHttpData(['invalid' => [NULL]], 'invalid', Form::DATA_FILE)); + Assert::null( Helpers::extractHttpData([ + 'multiple' => ['avatar' => [$file, $file]], + ], 'multiple[avatar]', Form::DATA_FILE)); - Assert::equal(array($file, $file), Helpers::extractHttpData(array( - 'multiple' => array('avatar' => array('x' => $file, NULL, $file)), - ), 'multiple[avatar][]', Form::DATA_FILE)); + Assert::equal([$file, $file], Helpers::extractHttpData([ + 'multiple' => ['avatar' => ['x' => $file, NULL, $file]], + ], 'multiple[avatar][]', Form::DATA_FILE)); - Assert::equal(array('x' => $file, $file), Helpers::extractHttpData(array( - 'multiple' => array('avatar' => array('x' => $file, $file)), - ), 'multiple[avatar][]', Form::DATA_KEYS | Form::DATA_FILE)); + Assert::equal(['x' => $file, $file], Helpers::extractHttpData([ + 'multiple' => ['avatar' => ['x' => $file, $file]], + ], 'multiple[avatar][]', Form::DATA_KEYS | Form::DATA_FILE)); - Assert::same(array(), Helpers::extractHttpData(array(), 'missing[]', Form::DATA_FILE)); - Assert::same(array(), Helpers::extractHttpData(array('invalid' => NULL), 'invalid[]', Form::DATA_FILE)); - Assert::same(array(), Helpers::extractHttpData(array('invalid' => $file), 'invalid[]', Form::DATA_FILE)); - Assert::same(array(), Helpers::extractHttpData(array('invalid' => array(NULL)), 'invalid[]', Form::DATA_FILE)); + Assert::same([], Helpers::extractHttpData([], 'missing[]', Form::DATA_FILE)); + Assert::same([], Helpers::extractHttpData(['invalid' => NULL], 'invalid[]', Form::DATA_FILE)); + Assert::same([], Helpers::extractHttpData(['invalid' => $file], 'invalid[]', Form::DATA_FILE)); + Assert::same([], Helpers::extractHttpData(['invalid' => [NULL]], 'invalid[]', Form::DATA_FILE)); }); diff --git a/tests/Forms/Rules.dynamic.phpt b/tests/Forms/Rules.dynamic.phpt index 2bfd8cfd9..57c1e0c14 100644 --- a/tests/Forms/Rules.dynamic.phpt +++ b/tests/Forms/Rules.dynamic.phpt @@ -11,12 +11,12 @@ use Nette\Forms\Form, require __DIR__ . '/../bootstrap.php'; -$datasets = array( - array(array('min' => '10', 'max' => '20', 'value' => 5), FALSE), - array(array('min' => '10', 'max' => '20', 'value' => 15), TRUE), - array(array('min' => '10', 'max' => '', 'value' => 15), TRUE), - array(array('min' => '10', 'max' => '', 'value' => 5), FALSE), -); +$datasets = [ + [['min' => '10', 'max' => '20', 'value' => 5], FALSE], + [['min' => '10', 'max' => '20', 'value' => 15], TRUE], + [['min' => '10', 'max' => '', 'value' => 15], TRUE], + [['min' => '10', 'max' => '', 'value' => 5], FALSE], +]; foreach ($datasets as $case) { @@ -24,7 +24,7 @@ foreach ($datasets as $case) { $form->addText('min'); $form->addText('max'); - $form->addText('value')->addRule(Form::RANGE, NULL, array($form['min'], $form['max'])); + $form->addText('value')->addRule(Form::RANGE, NULL, [$form['min'], $form['max']]); $form->setValues($case[0]); Assert::equal($case[1], $form->isValid()); diff --git a/tests/Forms/Rules.formatMessage.phpt b/tests/Forms/Rules.formatMessage.phpt index 8a3c84e8b..a68f9e902 100644 --- a/tests/Forms/Rules.formatMessage.phpt +++ b/tests/Forms/Rules.formatMessage.phpt @@ -13,10 +13,10 @@ require __DIR__ . '/../bootstrap.php'; $form = new Form; $form->addText('args1') - ->addRule(Form::RANGE, '%d %d', array(1, 5)); + ->addRule(Form::RANGE, '%d %d', [1, 5]); $form->addText('args2') - ->addRule(Form::RANGE, '%2$d %1$d', array(1, 5)); + ->addRule(Form::RANGE, '%2$d %1$d', [1, 5]); $form->addText('args3') ->addRule(Form::LENGTH, '%d %d', 1); @@ -29,16 +29,16 @@ $form->validate(); Assert::true( $form->hasErrors() ); -Assert::same( array('1 5', '5 1', '1 ', 'Label xyz is invalid [field special] xyz'), $form->getErrors() ); +Assert::same( ['1 5', '5 1', '1 ', 'Label xyz is invalid [field special] xyz'], $form->getErrors() ); -Assert::same( array(), $form->getOwnErrors() ); +Assert::same( [], $form->getOwnErrors() ); -Assert::same( array('1 5'), $form['args1']->getErrors() ); +Assert::same( ['1 5'], $form['args1']->getErrors() ); -Assert::same( array('5 1'), $form['args2']->getErrors() ); +Assert::same( ['5 1'], $form['args2']->getErrors() ); -Assert::same( array('1 '), $form['args3']->getErrors() ); +Assert::same( ['1 '], $form['args3']->getErrors() ); -Assert::same( array('Label xyz is invalid [field special] xyz'), $form['special']->getErrors() ); +Assert::same( ['Label xyz is invalid [field special] xyz'], $form['special']->getErrors() ); Assert::match('%A%data-nette-rules=\'[{"op":":email","msg":"Label %value is invalid [field special] %0"%A%', $form->__toString(TRUE)); diff --git a/tests/Forms/Rules.required.phpt b/tests/Forms/Rules.required.phpt index 95a195b25..4f46aab44 100644 --- a/tests/Forms/Rules.required.phpt +++ b/tests/Forms/Rules.required.phpt @@ -38,7 +38,7 @@ test(function() { // Rules Assert::false( $items[0]->isNegative ); Assert::false( $rules->validate() ); - Assert::same( array('This field is required.'), $input->getErrors() ); + Assert::same( ['This field is required.'], $input->getErrors() ); }); @@ -63,7 +63,7 @@ test(function() { // 'required' is always the first rule Assert::same( Form::EMAIL, $items[1]->validator ); Assert::false( $rules->validate() ); - Assert::same( array('Please enter a valid email address.'), $input->getErrors() ); + Assert::same( ['Please enter a valid email address.'], $input->getErrors() ); }); @@ -81,7 +81,7 @@ test(function() { // setRequired(FALSE) Assert::same( Form::EMAIL, $items[0]->validator ); Assert::false( $rules->validate() ); - Assert::same( array('Please enter a valid email address.'), $input->getErrors() ); + Assert::same( ['Please enter a valid email address.'], $input->getErrors() ); });