diff --git a/composer.json b/composer.json index 3b0d626fc..873278898 100644 --- a/composer.json +++ b/composer.json @@ -24,12 +24,12 @@ "nette/application": "^3.0", "nette/di": "^3.0", "nette/tester": "^2.5.2", - "latte/latte": "^2.10.2 || ^3.0.12", + "latte/latte": "^3.0.12", "tracy/tracy": "^2.9", "phpstan/phpstan-nette": "^2.0@stable" }, "conflict": { - "latte/latte": ">=3.0.0 <3.0.12 || >=3.2" + "latte/latte": "<3.0.12 || >=3.2" }, "suggest": { "ext-intl": "to use date/time controls" @@ -47,7 +47,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-master": "4.0-dev" } } } diff --git a/readme.md b/readme.md index 630329eec..45ffe2514 100644 --- a/readme.md +++ b/readme.md @@ -2,8 +2,8 @@ Nette Forms: greatly facilitates web forms ========================================== [![Downloads this Month](https://img.shields.io/packagist/dm/nette/forms.svg)](https://packagist.org/packages/nette/forms) -[![Tests](https://github.com/nette/forms/actions/workflows/tests.yml/badge.svg?branch=v3.2)](https://github.com/nette/forms/actions) -[![Coverage Status](https://coveralls.io/repos/github/nette/forms/badge.svg?branch=v3.2)](https://coveralls.io/github/nette/forms?branch=v3.2) +[![Tests](https://github.com/nette/forms/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/nette/forms/actions) +[![Coverage Status](https://coveralls.io/repos/github/nette/forms/badge.svg?branch=master)](https://coveralls.io/github/nette/forms?branch=master) [![Latest Stable Version](https://poser.pugx.org/nette/forms/v/stable)](https://github.com/nette/forms/releases) [![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/nette/forms/blob/master/license.md) diff --git a/rollup.config.js b/rollup.config.js index 8a3697543..95ba912a3 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -34,21 +34,21 @@ function spaces2tabs() { export default [ - { + { // TODO: consider the possibility of cutting off the UMD versions completely due to collision input: 'src/assets/index.umd.ts', output: [ { format: 'umd', name: 'Nette', - dir: 'src/assets', - entryFileNames: 'netteForms.js', + dir: 'src/assets/dist', + entryFileNames: 'nette-forms.umd.js', generatedCode: 'es2015', }, { format: 'umd', name: 'Nette', - dir: 'src/assets', - entryFileNames: 'netteForms.min.js', + dir: 'src/assets/dist', + entryFileNames: 'nette-forms.umd.min.js', generatedCode: 'es2015', plugins: [ terser(), @@ -65,9 +65,36 @@ export default [ }, { - input: 'src/assets/index.umd.ts', + input: 'src/assets/index.esm.ts', + output: [ + { + format: 'es', + dir: 'src/assets/dist', + entryFileNames: 'nette-forms.esm.js', + generatedCode: 'es2015', + }, + { + format: 'es', + dir: 'src/assets/dist', + entryFileNames: 'nette-forms.esm.min.js', + generatedCode: 'es2015', + plugins: [ + terser(), + ], + }, + ], + plugins: [ + json(), + nodeResolve(), + typescript(), + spaces2tabs(), + ], + }, + + { + input: 'src/assets/index.esm.ts', output: [{ - file: 'src/assets/netteForms.d.ts', + file: 'src/assets/dist/nette-forms.d.ts', format: 'es', }], plugins: [ diff --git a/src/Bridges/FormsLatte/FormMacros.php b/src/Bridges/FormsLatte/FormMacros.php deleted file mode 100644 index 18c889ad2..000000000 --- a/src/Bridges/FormsLatte/FormMacros.php +++ /dev/null @@ -1,330 +0,0 @@ -addMacro('form', [$me, 'macroForm'], 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack));'); - $me->addMacro('formContext', [$me, 'macroFormContext'], 'array_pop($this->global->formsStack);'); - $me->addMacro('formContainer', [$me, 'macroFormContainer'], 'array_pop($this->global->formsStack); $formContainer = end($this->global->formsStack)'); - $me->addMacro('label', [$me, 'macroLabel'], [$me, 'macroLabelEnd'], null, self::AUTO_EMPTY); - $me->addMacro('input', [$me, 'macroInput']); - $me->addMacro('name', [$me, 'macroName'], [$me, 'macroNameEnd'], [$me, 'macroNameAttr']); - $me->addMacro('inputError', [$me, 'macroInputError']); - $me->addMacro('formPrint', [$me, 'macroFormPrint']); - $me->addMacro('formClassPrint', [$me, 'macroFormPrint']); - } - - - /********************* macros ****************d*g**/ - - - /** - * {form ...} - */ - public function macroForm(MacroNode $node, PhpWriter $writer) - { - if ($node->modifiers) { - throw new CompileException('Modifiers are not allowed in ' . $node->getNotation()); - } - - if ($node->prefix) { - throw new CompileException('Did you mean
?'); - } - - $name = $node->tokenizer->fetchWord(); - if ($name == null) { // null or false - throw new CompileException('Missing form name in ' . $node->getNotation()); - } - - $node->replaced = true; - $node->tokenizer->reset(); - return $writer->write( - '$form = $this->global->formsStack[] = ' - . ($name[0] === '$' - ? 'is_object($ʟ_tmp = %node.word) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]' - : '$this->global->uiControl[%node.word]') - . ';' - . 'Nette\Bridges\FormsLatte\Runtime::initializeForm($form);' - . 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, %node.array)' - . " /* line $node->startLine */;", - ); - } - - - /** - * {formContext ...} - */ - public function macroFormContext(MacroNode $node, PhpWriter $writer) - { - if ($node->modifiers) { - throw new CompileException('Modifiers are not allowed in ' . $node->getNotation()); - } - - if ($node->prefix) { - throw new CompileException('Did you mean ?'); - } - - $name = $node->tokenizer->fetchWord(); - if ($name == null) { // null or false - throw new CompileException('Missing form name in ' . $node->getNotation()); - } - - $node->tokenizer->reset(); - return $writer->write( - '$form = $this->global->formsStack[] = ' - . ($name[0] === '$' - ? 'is_object($ʟ_tmp = %node.word) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]' - : '$this->global->uiControl[%node.word]') - . " /* line $node->startLine */;", - ); - } - - - /** - * {formContainer ...} - */ - public function macroFormContainer(MacroNode $node, PhpWriter $writer) - { - if ($node->modifiers) { - throw new CompileException('Modifiers are not allowed in ' . $node->getNotation()); - } - - $name = $node->tokenizer->fetchWord(); - if ($name == null) { // null or false - throw new CompileException('Missing name in ' . $node->getNotation()); - } - - $node->tokenizer->reset(); - return $writer->write( - '$this->global->formsStack[] = $formContainer = ' - . ($name[0] === '$' - ? 'is_object($ʟ_tmp = %node.word) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]' - : 'end($this->global->formsStack)[%node.word]') - . " /* line $node->startLine */;", - ); - } - - - /** - * {label ...} - */ - public function macroLabel(MacroNode $node, PhpWriter $writer) - { - if ($node->modifiers) { - throw new CompileException('Modifiers are not allowed in ' . $node->getNotation()); - } - - $words = $node->tokenizer->fetchWords(); - if (!$words) { - throw new CompileException('Missing name in ' . $node->getNotation()); - } - - $node->replaced = true; - $name = array_shift($words); - return $writer->write( - ($name[0] === '$' - ? '$ʟ_input = is_object($ʟ_tmp = %0.word) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]; if ($ʟ_label = $ʟ_input' - : 'if ($ʟ_label = end($this->global->formsStack)[%0.word]' - ) - . '->%1.raw) echo $ʟ_label' - . ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : ''), - $name, - $words ? ('getLabelPart(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')') : 'getLabel()', - ); - } - - - /** - * {/label} - */ - public function macroLabelEnd(MacroNode $node, PhpWriter $writer) - { - if ($node->content != null) { - $node->openingCode = rtrim($node->openingCode, '?> ') . '->startTag() ?>'; - return $writer->write('if ($ʟ_label) echo $ʟ_label->endTag()'); - } - } - - - /** - * {input ...} - */ - public function macroInput(MacroNode $node, PhpWriter $writer) - { - if ($node->modifiers) { - throw new CompileException('Modifiers are not allowed in ' . $node->getNotation()); - } - - $words = $node->tokenizer->fetchWords(); - if (!$words) { - throw new CompileException('Missing name in ' . $node->getNotation()); - } - - $node->replaced = true; - $name = array_shift($words); - return $writer->write( - ($name[0] === '$' - ? '$ʟ_input = $_input = is_object($ʟ_tmp = %word) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]; echo $ʟ_input' - : 'echo end($this->global->formsStack)[%word]') - . '->%raw' - . ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : '') - . " /* line $node->startLine */;", - $name, - $words ? 'getControlPart(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')' : 'getControl()', - ); - } - - - /** - * , , - - - -
- - - - - - - - -
- - - - - - - - - - - - - - -
- - - -
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- -
- - -
- -
- - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tests/Forms.Latte2/expected/FormMacros.forms.php b/tests/Forms.Latte2/expected/FormMacros.forms.php deleted file mode 100644 index dda078042..000000000 --- a/tests/Forms.Latte2/expected/FormMacros.forms.php +++ /dev/null @@ -1,297 +0,0 @@ -global->formsStack[] = $this->global->uiControl["myForm"]; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, ['id' => 'myForm', 'class'=>"ajax"]) /* line 1 */; - echo "\n"; - $iterations = 0; - foreach (['id', 'username', 'select', 'area', 'send'] as $name) /* line 2 */ { - echo ' '; - $ʟ_input = is_object($ʟ_tmp = $name) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]; - if ($ʟ_label = $ʟ_input->getLabel()) echo $ʟ_label; - echo ' - '; - $ʟ_input = $_input = is_object($ʟ_tmp = $name) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]; - echo $ʟ_input->getControl()->addAttributes(['title' => 'Hello', 'size' => 10]) /* line 4 */; - echo ' - '; - echo LR\Filters::escapeHtmlText($ʟ_input->getError()) /* line 5 */; - echo ' - '; - $ʟ_input = is_object($ʟ_tmp = $name) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]; - echo LR\Filters::escapeHtmlText($ʟ_input->getError()) /* line 6 */; - echo ' - -
- - '; - $ʟ_input = is_object($ʟ_tmp = $form[$name]) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]; - if ($ʟ_label = $ʟ_input->getLabel()) echo $ʟ_label->addAttributes(['title' => 'hello'])->startTag(); - echo ' '; - $ʟ_input = $_input = is_object($ʟ_tmp = $form[$name]) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]; - echo $ʟ_input->getControl()->addAttributes(['title' => 'Hello', 'size' => 10]) /* line 10 */; - echo ' '; - if ($ʟ_label) echo $ʟ_label->endTag(); - echo ' - '; - $ʟ_input = is_object($ʟ_tmp = $form[$name]) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]; - echo LR\Filters::escapeHtmlText($ʟ_input->getError()) /* line 11 */; - echo "\n"; - $iterations++; - } - echo ' - '; - $ʟ_input = is_object($ʟ_tmp = $form['username']) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]; - if ($ʟ_label = $ʟ_input->getLabel()) echo $ʟ_label; - echo ' - - - global->formsStack)["username"]; - echo $ʟ_input->getControlPart()->addAttributes(['value' => null, 'type' => null, 'class' => null])->attributes() /* line 17 */; - echo '> - - global->formsStack)[$ʟ_tmp]; - echo $ʟ_input->getLabelPart()->attributes() /* line 19 */; - echo '> - global->formsStack)[$ʟ_tmp]; - echo $ʟ_input->getLabelPart()->attributes() /* line 20 */; - echo '>'; - echo $ʟ_input->getLabelPart()->getHtml() /* line 20 */; - echo ' - global->formsStack)[$ʟ_tmp]; - echo $ʟ_input->getControlPart()->attributes() /* line 21 */; - echo '> - - '; - if ($ʟ_label = end($this->global->formsStack)["my"]->getLabel()) echo $ʟ_label; - echo end($this->global->formsStack)["my"]->getControl() /* line 23 */; - echo "\n"; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)); - echo ' - - -'; - $form = $this->global->formsStack[] = $this->global->uiControl["myForm"]; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* line 27 */; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)); - echo ' - -'; - $form = $this->global->formsStack[] = $this->global->uiControl["myForm"]; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* line 29 */; - echo "\n"; - $iterations = 0; - foreach ($form['sex']->items as $key => $label) /* line 31 */ { - echo ' '; - if ($ʟ_label = end($this->global->formsStack)["sex"]->getLabelPart($key)) echo $ʟ_label->startTag(); - echo ' '; - echo end($this->global->formsStack)["sex"]->getControlPart($key) /* line 32 */; - echo ' '; - echo LR\Filters::escapeHtmlText($label) /* line 32 */; - if ($ʟ_label) echo $ʟ_label->endTag(); - echo ' - -'; - $iterations++; - } - echo 'global->formsStack)["sex"]; - echo $ʟ_input->getLabelPart()->attributes() /* line 35 */; - echo '> -global->formsStack)["sex"]; - echo $ʟ_input->getLabelPart()->attributes() /* line 36 */; - echo '>'; - echo $ʟ_input->getLabelPart()->getHtml() /* line 36 */; - echo ' - - - -'; - if ($ʟ_label = end($this->global->formsStack)["checkbox"]->getLabelPart("")) echo $ʟ_label->startTag(); - echo ' '; - echo end($this->global->formsStack)["checkbox"]->getControlPart("") /* line 41 */; - echo ' Label'; - if ($ʟ_label) echo $ʟ_label->endTag(); - echo ' - - -global->formsStack)["checkbox"]; - echo $ʟ_input->getLabelPart("")->attributes() /* line 44 */; - echo '>'; - echo $ʟ_input->getLabelPart()->getHtml() /* line 44 */; - echo ' - - - -'; - $iterations = 0; - foreach ($form['checklist']->items as $key => $label) /* line 49 */ { - echo ' '; - if ($ʟ_label = end($this->global->formsStack)["checklist"]->getLabelPart($key)) echo $ʟ_label->startTag(); - echo ' '; - echo end($this->global->formsStack)["checklist"]->getControlPart($key) /* line 50 */; - echo ' '; - echo LR\Filters::escapeHtmlText($label) /* line 50 */; - if ($ʟ_label) echo $ʟ_label->endTag(); - echo ' - global->formsStack)["checklist"]; - echo $ʟ_input->getLabelPart($key)->attributes() /* line 51 */; - echo '> global->formsStack)["checklist"]; - echo $ʟ_input->getControlPart($key)->addAttributes(['title' => null])->attributes() /* line 51 */; - echo '> -'; - $iterations++; - } - echo 'global->formsStack)["checklist"]; - echo $ʟ_input->getLabelPart()->attributes() /* line 53 */; - echo '> -global->formsStack)["checklist"]; - echo $ʟ_input->getLabelPart()->attributes() /* line 54 */; - echo '>'; - echo $ʟ_input->getLabelPart()->getHtml() /* line 54 */; - echo ' - - - -'; - $form = $this->global->formsStack[] = $this->global->uiControl["myForm"] /* line 58 */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - if (1) /* line 58 */ { - echo '
global->formsStack), ['id' => null, 'class' => null], false); - echo '> - global->formsStack)["username"]; - echo $ʟ_input->getControlPart()->attributes() /* line 59 */; - echo '> -'; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false) /* line 58 */; - echo ' -'; - } - echo ' - -'; - $form = $this->global->formsStack[] = $this->global->uiControl["myForm"] /* line 63 */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo 'global->formsStack), ['class' => null], false); - echo '> - global->formsStack)["username"]; - echo $ʟ_input->getControlPart()->addAttributes(['class' => null])->attributes() /* line 64 */; - echo ($ʟ_tmp = array_filter(['nclass'])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line 64 */; - echo '> -'; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false) /* line 63 */; - echo ' - - -'; - $form = $this->global->formsStack[] = is_object($ʟ_tmp = $this->global->uiControl['myForm']) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp] /* line 68 */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo 'global->formsStack), [], false); - echo '> - global->formsStack)["username"]; - echo $ʟ_input->getControlPart()->attributes() /* line 69 */; - echo '> -'; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false) /* line 68 */; - echo ' - - -global->formsStack)["select"]; - echo $ʟ_input->getControlPart()->attributes() /* line 73 */; - echo '>'; - echo $ʟ_input->getControl()->getHtml() /* line 73 */; - echo ' - - - - - -global->formsStack)["select"]; - echo $ʟ_input->getControlPart()->attributes() /* line 79 */; - echo '>'; - echo $ʟ_input->getControl()->getHtml() /* line 79 */; - echo ' -'; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)); - echo ' - - -'; - $form = $this->global->formsStack[] = $this->global->uiControl["myForm"] /* line 83 */; - echo 'global->formsStack)["sex"]; - echo $ʟ_input->getLabelPart()->attributes() /* line 84 */; - echo '>'; - echo $ʟ_input->getLabelPart()->getHtml() /* line 84 */; - echo ' -global->formsStack)["username"]; - echo $ʟ_input->getControlPart()->attributes() /* line 85 */; - echo '> -'; - array_pop($this->global->formsStack); -%A% diff --git a/tests/Forms.Latte2/expected/FormMacros.get.html b/tests/Forms.Latte2/expected/FormMacros.get.html deleted file mode 100644 index e37282817..000000000 --- a/tests/Forms.Latte2/expected/FormMacros.get.html +++ /dev/null @@ -1,5 +0,0 @@ -
- - -
-
\ No newline at end of file diff --git a/tests/Forms.Latte2/expected/FormMacros.get.php b/tests/Forms.Latte2/expected/FormMacros.get.php deleted file mode 100644 index ae17372cd..000000000 --- a/tests/Forms.Latte2/expected/FormMacros.get.php +++ /dev/null @@ -1,19 +0,0 @@ -global->formsStack[] = $this->global->uiControl["myForm"]; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* line 1 */; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)); - echo ' - -'; - $form = $this->global->formsStack[] = $this->global->uiControl["myForm"] /* line 3 */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo 'global->formsStack), [], false); - echo '> -'; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false) /* line 3 */; - echo ' -'; -%A% diff --git a/tests/Forms.Latte2/templates/forms.button.latte b/tests/Forms.Latte2/templates/forms.button.latte deleted file mode 100644 index 8e9969b37..000000000 --- a/tests/Forms.Latte2/templates/forms.button.latte +++ /dev/null @@ -1,9 +0,0 @@ -
- - - - -
global)->getControlPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('send')->getControlPart())->attributes() /* line %d% */; echo '> global)->getControlPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('send')->getControlPart())->attributes() /* line %d% */; echo '>'; echo LR\%a%::escape%a%($ʟ_elem->value) /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* line %d% */; + echo $this->global->forms->renderFormEnd(false) /* line %d% */; echo ' '; - array_pop($this->global->formsStack); + $this->global->forms->end(); %A% diff --git a/tests/Forms.Latte3/expected/forms.formContainer.php b/tests/Forms.Latte3/expected/forms.formContainer.php index 893cc8e3a..6bd65b4e0 100644 --- a/tests/Forms.Latte3/expected/forms.formContainer.php +++ b/tests/Forms.Latte3/expected/forms.formContainer.php @@ -1,46 +1,45 @@ global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* line %d% */; + $this->global->forms->begin($form = $this->global->uiControl['myForm']) /* line %d% */; + echo $this->global->forms->renderFormBegin([]) /* line %d% */; echo ' '; - $this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item('cont1', $this->global) /* line %d% */; + $this->global->forms->begin($formContainer = $this->global->forms->item('cont1')) /* line %d% */; echo ' '; - array_pop($this->global->formsStack); - $formContainer = end($this->global->formsStack); + $this->global->forms->end(); + $formContainer = $this->global->forms->current(); - $this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item('items', $this->global) /* line %d% */; + $this->global->forms->begin($formContainer = $this->global->forms->item('items')) /* line %d% */; echo ' '; - array_pop($this->global->formsStack); - $formContainer = end($this->global->formsStack); + $this->global->forms->end(); + $formContainer = $this->global->forms->current(); echo '
'; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input1', $this->global)->getLabel()) /* line %d% */; + echo ($ʟ_label = $this->global->forms->item('input1')->getLabel()) /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item('input1', $this->global)->getControl() /* line %d% */; + echo $this->global->forms->item('input1')->getControl() /* line %d% */; echo '
'; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input2', $this->global)->getLabel()) /* line %d% */; + echo ($ʟ_label = $this->global->forms->item('input2')->getLabel()) /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item('input2', $this->global)->getControl() /* line %d% */; + echo $this->global->forms->item('input2')->getControl() /* line %d% */; echo '
'; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input3', $this->global)->getLabel()) /* line %d% */; + echo ($ʟ_label = $this->global->forms->item('input3')->getLabel()) /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item('input3', $this->global)->getControl() /* line %d% */; + echo $this->global->forms->item('input3')->getControl() /* line %d% */; echo '
Checkboxes '; - $this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item('cont2', $this->global) /* line %d% */; + $this->global->forms->begin($formContainer = $this->global->forms->item('cont2')) /* line %d% */; echo '
    '; foreach ($formContainer->controls as $name => $field) /* line %d% */ { echo '
  1. '; - echo Nette\Bridges\FormsLatte\Runtime::item($field, $this->global)->getControl() /* line %d% */; + echo $this->global->forms->item($field)->getControl() /* line %d% */; echo '
  2. '; @@ -48,24 +47,24 @@ echo '
'; - array_pop($this->global->formsStack); - $formContainer = end($this->global->formsStack); + $this->global->forms->end(); + $formContainer = $this->global->forms->current(); echo '
'; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input7', $this->global)->getLabel()) /* line %d% */; + echo ($ʟ_label = $this->global->forms->item('input7')->getLabel()) /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item('input7', $this->global)->getControl() /* line %d% */; + echo $this->global->forms->item('input7')->getControl() /* line %d% */; echo '
Items @@ -73,12 +72,12 @@ $items = [1, 2, 3] /* line %d% */; foreach ($items as $item) /* line %d% */ { if (!isset($formContainer[$item])) /* line %d% */ continue; - $this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item($item, $this->global) /* line %d% */; + $this->global->forms->begin($formContainer = $this->global->forms->item($item)) /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item('input', $this->global)->getControl() /* line %d% */; + echo $this->global->forms->item('input')->getControl() /* line %d% */; echo "\n"; - array_pop($this->global->formsStack); - $formContainer = end($this->global->formsStack); + $this->global->forms->end(); + $formContainer = $this->global->forms->current(); } @@ -86,18 +85,19 @@ echo '
'; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input8', $this->global)->getLabel()) /* line %d% */; + echo ($ʟ_label = $this->global->forms->item('input8')->getLabel()) /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item('input8', $this->global)->getControl() /* line %d% */; + echo $this->global->forms->item('input8')->getControl() /* line %d% */; echo '
'; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)) /* line %d% */; -%A% + echo $this->global->forms->renderFormEnd() /* line %d% */; + $this->global->forms->end(); +%A% \ No newline at end of file diff --git a/tests/Forms.Latte3/expected/forms.get.php b/tests/Forms.Latte3/expected/forms.get.php index 25af74d41..0fd2c1eda 100644 --- a/tests/Forms.Latte3/expected/forms.get.php +++ b/tests/Forms.Latte3/expected/forms.get.php @@ -1,21 +1,20 @@ global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* line %d% */; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)) /* line %d% */; + $this->global->forms->begin($form = $this->global->uiControl['myForm']) /* line %d% */; + echo $this->global->forms->renderFormBegin([]) /* line %d% */; + echo $this->global->forms->renderFormEnd() /* line %d% */; + $this->global->forms->end(); echo ' '; - $form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); + $this->global->forms->begin($form = $this->global->uiControl['myForm']) /* line %d% */; echo 'global->formsStack), [], false) /* line %d% */; + echo $this->global->forms->renderFormBegin([], false) /* line %d% */; echo '> '; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* line %d% */; + echo $this->global->forms->renderFormEnd(false) /* line %d% */; echo ' '; - array_pop($this->global->formsStack); -%A% + $this->global->forms->end(); +%A% \ No newline at end of file diff --git a/tests/Forms.Latte3/expected/forms.html b/tests/Forms.Latte3/expected/forms.html index 8bc003240..30672133c 100644 --- a/tests/Forms.Latte3/expected/forms.html +++ b/tests/Forms.Latte3/expected/forms.html @@ -8,12 +8,12 @@ - + error
- + error @@ -43,11 +43,11 @@ - + - + @@ -89,17 +89,17 @@
- +
- +
- +
@@ -111,9 +111,3 @@ - - - - - - \ No newline at end of file diff --git a/tests/Forms.Latte3/expected/forms.php b/tests/Forms.Latte3/expected/forms.php index 55e8d7350..10fa0b901 100644 --- a/tests/Forms.Latte3/expected/forms.php +++ b/tests/Forms.Latte3/expected/forms.php @@ -1,97 +1,96 @@ global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, ['id' => 'myForm', 'class' => 'ajax']) /* line %d% */; + $this->global->forms->begin($form = $this->global->uiControl['myForm']) /* line %d% */; + echo $this->global->forms->renderFormBegin(['id' => 'myForm', 'class' => 'ajax']) /* line %d% */; echo "\n"; foreach (['id', 'username', 'select', 'area', 'send'] as $name) /* line %d% */ { echo ' '; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item($name, $this->global)->getLabel()) /* line %d% */; + echo ($ʟ_label = $this->global->forms->item($name)->getLabel()) /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item($name, $this->global)->getControl()->addAttributes(['title' => 'Hello', 'size' => 10]) /* line %d% */; + echo $this->global->forms->item($name)->getControl()->addAttributes(['title' => 'Hello', 'size' => 10]) /* line %d% */; echo ' '; - echo LR\%a%::escape%a%(Nette\Bridges\FormsLatte\Runtime::item($name, $this->global)->getError()) /* line %d% */; + echo LR\Filters::escapeHtmlText($this->global->forms->item($name)->getError()) /* line %d% */; echo '
'; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item($form[$name], $this->global)->getLabel())?->addAttributes(['title' => 'hello'])?->startTag() /* line %d% */; + echo ($ʟ_label = $this->global->forms->item($form[$name])->getLabel())?->addAttributes(['title' => 'hello'])?->startTag() /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item($form[$name], $this->global)->getControl()->addAttributes(['title' => 'Hello', 'size' => 10]) /* line %d% */; + echo $this->global->forms->item($form[$name])->getControl()->addAttributes(['title' => 'Hello', 'size' => 10]) /* line %d% */; echo ' '; echo $ʟ_label?->endTag() /* line %d% */; echo ' '; - echo LR\%a%::escape%a%(Nette\Bridges\FormsLatte\Runtime::item($form[$name], $this->global)->getError()) /* line %d% */; + echo LR\Filters::escapeHtmlText($this->global->forms->item($form[$name])->getError()) /* line %d% */; echo "\n"; } echo ' '; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item($form['username'], $this->global)->getLabel()) /* line %d% */; + echo ($ʟ_label = $this->global->forms->item($form['username'])->getLabel()) /* line %d% */; echo ' global)->getLabelPart())->addAttributes(['title' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('username')->getLabelPart())->addAttributes(['title' => null])->attributes() /* line %d% */; echo ' title=hello>Name global)->getControlPart())->addAttributes(['value' => null, 'type' => null, 'class' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('username')->getControlPart())->addAttributes(['value' => null, 'type' => null, 'class' => null])->attributes() /* line %d% */; echo '> global)->getLabelPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item($form['username'])->getLabelPart())->attributes() /* line %d% */; echo '> global)->getLabelPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item($form['username'])->getLabelPart())->attributes() /* line %d% */; echo '>'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' global)->getControlPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item($form['username'])->getControlPart())->attributes() /* line %d% */; echo '> '; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('my', $this->global)->getLabel()) /* line %d% */; - echo Nette\Bridges\FormsLatte\Runtime::item('my', $this->global)->getControl() /* line %d% */; + echo ($ʟ_label = $this->global->forms->item('my')->getLabel()) /* line %d% */; + echo $this->global->forms->item('my')->getControl() /* line %d% */; echo "\n"; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)) /* line %d% */; + echo $this->global->forms->renderFormEnd() /* line %d% */; + $this->global->forms->end(); echo ' '; - $form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* line %d% */; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)) /* line %d% */; + $this->global->forms->begin($form = $this->global->uiControl['myForm']) /* line %d% */; + echo $this->global->forms->renderFormBegin([]) /* line %d% */; + echo $this->global->forms->renderFormEnd() /* line %d% */; + $this->global->forms->end(); echo ' '; - $form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* line %d% */; + $this->global->forms->begin($form = $this->global->uiControl['myForm']) /* line %d% */; + echo $this->global->forms->renderFormBegin([]) /* line %d% */; echo "\n"; foreach ($form['sex']->items as $key => $label) /* line %d% */ { echo ' '; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('sex', $this->global)->getLabelPart($key))?->startTag() /* line %d% */; + echo ($ʟ_label = $this->global->forms->item('sex')->getLabelPart($key))?->startTag() /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item('sex', $this->global)->getControlPart($key) /* line %d% */; + echo $this->global->forms->item('sex')->getControlPart($key) /* line %d% */; echo ' '; echo LR\%a%::escape%a%($label) /* line %d% */; echo $ʟ_label?->endTag() /* line %d% */; echo ' global)->getLabelPart($key))->addAttributes(['title' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('sex')->getLabelPart($key))->addAttributes(['title' => null])->attributes() /* line %d% */; echo ' title=hello> global)->getControlPart($key))->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('sex')->getControlPart($key))->attributes() /* line %d% */; echo '> global)->getLabelPart($key))->addAttributes(['title' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('sex')->getLabelPart($key))->addAttributes(['title' => null])->attributes() /* line %d% */; echo ' title=hello>'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' @@ -100,47 +99,47 @@ } echo 'global)->getLabelPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('sex')->getLabelPart())->attributes() /* line %d% */; echo '> global)->getLabelPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('sex')->getLabelPart())->attributes() /* line %d% */; echo '>'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' global)->getLabelPart())->addAttributes(['title' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('sex')->getLabelPart())->addAttributes(['title' => null])->attributes() /* line %d% */; echo ' title="hello">'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' global)->getControlPart("{$key}"))->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item($form['sex'])->getControlPart("{$key}"))->attributes() /* line %d% */; echo '> '; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('checkbox', $this->global)->getLabelPart(''))?->startTag() /* line %d% */; + echo ($ʟ_label = $this->global->forms->item('checkbox')->getLabelPart(''))?->startTag() /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item('checkbox', $this->global)->getControlPart('') /* line %d% */; + echo $this->global->forms->item('checkbox')->getControlPart('') /* line %d% */; echo ' Label'; echo $ʟ_label?->endTag() /* line %d% */; echo ' global)->getLabelPart(''))->addAttributes(['title' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checkbox')->getLabelPart(''))->addAttributes(['title' => null])->attributes() /* line %d% */; echo ' title=hello> global)->getControlPart(''))->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checkbox')->getControlPart(''))->attributes() /* line %d% */; echo '> global)->getLabelPart())->addAttributes(['title' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checkbox')->getLabelPart())->addAttributes(['title' => null])->attributes() /* line %d% */; echo ' title=hello> global)->getControlPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checkbox')->getControlPart())->attributes() /* line %d% */; echo '> global)->getLabelPart(''))->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checkbox')->getLabelPart(''))->attributes() /* line %d% */; echo '>'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' global)->getLabelPart())->addAttributes(['title' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checkbox')->getLabelPart())->addAttributes(['title' => null])->attributes() /* line %d% */; echo ' title=hello>'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' @@ -149,20 +148,20 @@ '; foreach ($form['checklist']->items as $key => $label) /* line %d% */ { echo ' '; - echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('checklist', $this->global)->getLabelPart($key))?->startTag() /* line %d% */; + echo ($ʟ_label = $this->global->forms->item('checklist')->getLabelPart($key))?->startTag() /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::item('checklist', $this->global)->getControlPart($key) /* line %d% */; + echo $this->global->forms->item('checklist')->getControlPart($key) /* line %d% */; echo ' '; echo LR\%a%::escape%a%($label) /* line %d% */; echo $ʟ_label?->endTag() /* line %d% */; echo ' global)->getLabelPart($key))->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checklist')->getLabelPart($key))->attributes() /* line %d% */; echo '> global)->getControlPart($key))->addAttributes(['title' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checklist')->getControlPart($key))->addAttributes(['title' => null])->attributes() /* line %d% */; echo ' title=hello> global)->getLabelPart($key))->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checklist')->getLabelPart($key))->attributes() /* line %d% */; echo '>'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' @@ -171,15 +170,15 @@ } echo 'global)->getLabelPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checklist')->getLabelPart())->attributes() /* line %d% */; echo '> global)->getLabelPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checklist')->getLabelPart())->attributes() /* line %d% */; echo '>'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' global)->getLabelPart())->addAttributes(['title' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('checklist')->getLabelPart())->addAttributes(['title' => null])->attributes() /* line %d% */; echo ' title="hello">'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' @@ -187,93 +186,73 @@ '; if (1) /* line %d% */ { - $form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); + $this->global->forms->begin($form = $this->global->uiControl['myForm']) /* line %d% */; echo 'global->formsStack), ['id' => null, 'class' => null], false) /* line %d% */; + echo $this->global->forms->renderFormBegin(['id' => null, 'class' => null], false) /* line %d% */; echo ' id="myForm" class="ajax"> global)->getControlPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('username')->getControlPart())->attributes() /* line %d% */; echo '> '; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* line %d% */; + echo $this->global->forms->renderFormEnd(false) /* line %d% */; echo ' '; - array_pop($this->global->formsStack); + $this->global->forms->end(); } echo ' '; - $form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); + $this->global->forms->begin($form = $this->global->uiControl['myForm']) /* line %d% */; echo 'global->formsStack), ['class' => null], false) /* line %d% */; + echo $this->global->forms->renderFormBegin(['class' => null], false) /* line %d% */; echo ($ʟ_tmp = array_filter(['nclass'])) ? ' class="' . LR\%a%::escape%a%(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */; echo '> global)->getControlPart())->addAttributes(['class' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('username')->getControlPart())->addAttributes(['class' => null])->attributes() /* line %d% */; echo ($ʟ_tmp = array_filter(['nclass'])) ? ' class="' . LR\%a%::escape%a%(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */; echo '> '; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* line %d% */; + echo $this->global->forms->renderFormEnd(false) /* line %d% */; echo ' '; - array_pop($this->global->formsStack); + $this->global->forms->end(); echo ' '; - $form = $this->global->formsStack[] = is_object($ʟ_tmp = $this->global->uiControl['myForm']) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp] /* line %d% */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); + $this->global->forms->begin($form = (is_object($ʟ_tmp = $this->global->uiControl['myForm']) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp])) /* line %d% */; echo 'global->formsStack), [], false) /* line %d% */; + echo $this->global->forms->renderFormBegin([], false) /* line %d% */; echo '> global)->getControlPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('username')->getControlPart())->attributes() /* line %d% */; echo '> '; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* line %d% */; + echo $this->global->forms->renderFormEnd(false) /* line %d% */; echo ' '; - array_pop($this->global->formsStack); + $this->global->forms->end(); echo ' global)->getControlPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('select')->getControlPart())->attributes() /* line %d% */; echo '>'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' global)->getControlPart())->addAttributes(['title' => null])->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('area')->getControlPart())->addAttributes(['title' => null])->attributes() /* line %d% */; %A% echo $ʟ_elem->getHtml() /* line %d% */; echo ' global)->getControlPart())->attributes() /* line %d% */; + echo ($ʟ_elem = $this->global->forms->item('select')->getControlPart())->attributes() /* line %d% */; echo '>'; echo $ʟ_elem->getHtml() /* line %d% */; echo ' '; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)) /* line %d% */; - - echo ' - - -'; - $form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); - echo ' -global)->getLabelPart())->attributes() /* line %d% */; - echo '>'; - echo $ʟ_elem->getHtml() /* line %d% */; - echo ' -global)->getControlPart())->attributes() /* line %d% */; - echo '> -'; - array_pop($this->global->formsStack) /* line %d% */; + echo $this->global->forms->renderFormEnd() /* line %d% */; + $this->global->forms->end(); %A% diff --git a/tests/Forms.Latte3/forms.button.phpt b/tests/Forms.Latte3/forms.button.phpt index 136f44bd3..6e8aa59c1 100644 --- a/tests/Forms.Latte3/forms.button.phpt +++ b/tests/Forms.Latte3/forms.button.phpt @@ -8,10 +8,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $form = new Form; $form->addSubmit('send', 'Sign in'); diff --git a/tests/Forms.Latte3/forms.error.phpt b/tests/Forms.Latte3/forms.error.phpt index b18a61a4a..f4a9c7dbf 100644 --- a/tests/Forms.Latte3/forms.error.phpt +++ b/tests/Forms.Latte3/forms.error.phpt @@ -7,10 +7,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); diff --git a/tests/Forms.Latte3/forms.formContainer.phpt b/tests/Forms.Latte3/forms.formContainer.phpt index 51eb27da6..f22b3baae 100644 --- a/tests/Forms.Latte3/forms.formContainer.phpt +++ b/tests/Forms.Latte3/forms.formContainer.phpt @@ -8,10 +8,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $form = new Form; $form->addText('input1', 'Input 1'); diff --git a/tests/Forms.Latte3/forms.get.phpt b/tests/Forms.Latte3/forms.get.phpt index e1dada478..a2fa0ffd8 100644 --- a/tests/Forms.Latte3/forms.get.phpt +++ b/tests/Forms.Latte3/forms.get.phpt @@ -8,10 +8,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $form = new Form; $form->setMethod('get'); diff --git a/tests/Forms.Latte3/forms.phpt b/tests/Forms.Latte3/forms.phpt index 0cc769add..c7724fac7 100644 --- a/tests/Forms.Latte3/forms.phpt +++ b/tests/Forms.Latte3/forms.phpt @@ -8,10 +8,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - class MyControl extends Nette\Forms\Controls\BaseControl { diff --git a/tests/Forms.Latte3/n-name.form.phpt b/tests/Forms.Latte3/n-name.form.phpt index e018bea58..6192700a0 100644 --- a/tests/Forms.Latte3/n-name.form.phpt +++ b/tests/Forms.Latte3/n-name.form.phpt @@ -7,10 +7,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); @@ -19,14 +15,13 @@ $latte->addExtension(new FormsExtension); Assert::match( <<<'XX' %A% - $form = $this->global->formsStack[] = $this->global->uiControl['foo'] /* line 1 */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); + $this->global->forms->begin($form = $this->global->uiControl['foo']) /* line 1 */; echo 'global->formsStack), [], false) /* line 1 */; + echo $this->global->forms->renderFormBegin([], false) /* line 1 */; echo '>'; - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* line 1 */; + echo $this->global->forms->renderFormEnd(false) /* line 1 */; echo ''; - array_pop($this->global->formsStack); + $this->global->forms->end(); %A% XX, $latte->compile('
'), @@ -36,17 +31,16 @@ Assert::match( Assert::match( <<<'XX' %A% - $form = $this->global->formsStack[] = $this->global->uiControl['foo'] /* line 1 */; - Nette\Bridges\FormsLatte\Runtime::initializeForm($form); + $this->global->forms->begin($form = $this->global->uiControl['foo']) /* line 1 */; $ʟ_tag[0] = ''; if (0) /* line 1 */ { %A% - echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), [], false) /* line 1 */; + echo $this->global->forms->renderFormBegin([], false) /* line 1 */; echo '>'; } - echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* line 1 */; + echo $this->global->forms->renderFormEnd(false) /* line 1 */; echo $ʟ_tag[0]; - array_pop($this->global->formsStack); + $this->global->forms->end(); %A% XX, $latte->compile('
'), diff --git a/tests/Forms.Latte3/n-name.input.phpt b/tests/Forms.Latte3/n-name.input.phpt index 0572ddb36..164845451 100644 --- a/tests/Forms.Latte3/n-name.input.phpt +++ b/tests/Forms.Latte3/n-name.input.phpt @@ -7,22 +7,18 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); $latte->addExtension(new FormsExtension); Assert::match( - '%A%echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart())->attributes() %A%', + '%A%echo ($ʟ_elem = $this->global->forms->item(\'foo\')->getControlPart())->attributes() %A%', $latte->compile(''), ); Assert::match( - '%A%echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'\'))->attributes() %A%', + '%A%echo ($ʟ_elem = $this->global->forms->item(\'foo\')->getControlPart(\'\'))->attributes() %A%', $latte->compile(''), ); @@ -33,11 +29,11 @@ Assert::exception( ); Assert::match( - '%A%echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'x\'))->attributes() %A%', + '%A%echo ($ʟ_elem = $this->global->forms->item(\'foo\')->getControlPart(\'x\'))->attributes() %A%', $latte->compile(''), ); Assert::match( - '%A%echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'x\'))->attributes() %A%', + '%A%echo ($ʟ_elem = $this->global->forms->item(\'foo\')->getControlPart(\'x\'))->attributes() %A%', $latte->compile(''), ); diff --git a/tests/Forms.Latte3/templates/forms.latte b/tests/Forms.Latte3/templates/forms.latte index 7196558bc..91153dcfd 100644 --- a/tests/Forms.Latte3/templates/forms.latte +++ b/tests/Forms.Latte3/templates/forms.latte @@ -80,9 +80,3 @@ -{/formContext myForm} diff --git a/tests/Forms.Latte3/{input}.phpt b/tests/Forms.Latte3/{input}.phpt index 798c091ce..02b236220 100644 --- a/tests/Forms.Latte3/{input}.phpt +++ b/tests/Forms.Latte3/{input}.phpt @@ -7,32 +7,28 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); $latte->addExtension(new FormsExtension); Assert::match( - '%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControl() %A%', + '%A%echo $this->global->forms->item(\'foo\')->getControl() %A%', $latte->compile('{input foo}'), ); Assert::match( - '%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControl()->addAttributes([\'class\' => \'foo\']) %A%', + '%A%echo $this->global->forms->item(\'foo\')->getControl()->addAttributes([\'class\' => \'foo\']) %A%', $latte->compile('{input foo class => foo}'), ); Assert::match( - '%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControl()->addAttributes([\'class\' => \'foo\']) %A%', + '%A%echo $this->global->forms->item(\'foo\')->getControl()->addAttributes([\'class\' => \'foo\']) %A%', $latte->compile('{input foo, class => foo}'), ); Assert::match( - '%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'\') %A%', + '%A%echo $this->global->forms->item(\'foo\')->getControlPart(\'\') %A%', $latte->compile('{input foo:}'), ); @@ -43,31 +39,31 @@ Assert::exception( ); Assert::match( - '%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'\') %A%', + '%A%echo $this->global->forms->item(\'foo\')->getControlPart(\'\') %A%', $latte->compile('{input foo:,}'), ); Assert::match( - '%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'\')->addAttributes([\'class\' => \'foo\']) %A%', + '%A%echo $this->global->forms->item(\'foo\')->getControlPart(\'\')->addAttributes([\'class\' => \'foo\']) %A%', $latte->compile('{input foo:, class => foo}'), ); Assert::match( - '%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'x\') %A%', + '%A%echo $this->global->forms->item(\'foo\')->getControlPart(\'x\') %A%', $latte->compile('{input foo:x}'), ); Assert::match( - '%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'x\')->addAttributes([\'class\' => \'foo\']) %A%', + '%A%echo $this->global->forms->item(\'foo\')->getControlPart(\'x\')->addAttributes([\'class\' => \'foo\']) %A%', $latte->compile('{input foo:x, class => foo}'), ); Assert::match( - '%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'x\') %A%', + '%A%echo $this->global->forms->item(\'foo\')->getControlPart(\'x\') %A%', $latte->compile('{input "foo":"x"}'), ); Assert::match( - '%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'x\') %A%', + '%A%echo $this->global->forms->item(\'foo\')->getControlPart(\'x\') %A%', $latte->compile('{input "foo" : "x"}'), ); diff --git a/tests/Forms.Latte3/{label}.phpt b/tests/Forms.Latte3/{label}.phpt index a581a3eb3..b09ceca04 100644 --- a/tests/Forms.Latte3/{label}.phpt +++ b/tests/Forms.Latte3/{label}.phpt @@ -7,32 +7,28 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -if (version_compare(Latte\Engine::VERSION, '3', '<')) { - Tester\Environment::skip('Test for Latte 3'); -} - $latte = new Latte\Engine; $latte->setLoader(new Latte\Loaders\StringLoader); $latte->addExtension(new FormsExtension); Assert::match( - '%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabel()) %A%', + '%A%echo ($ʟ_label = $this->global->forms->item(\'foo\')->getLabel()) %A%', $latte->compile('{label foo /}'), ); Assert::match( - '%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabel())?->addAttributes([\'class\' => \'foo\']) %A%', + '%A%echo ($ʟ_label = $this->global->forms->item(\'foo\')->getLabel())?->addAttributes([\'class\' => \'foo\']) %A%', $latte->compile('{label foo class => foo /}'), ); Assert::match( - '%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabel())?->addAttributes([\'class\' => \'foo\']) %A%', + '%A%echo ($ʟ_label = $this->global->forms->item(\'foo\')->getLabel())?->addAttributes([\'class\' => \'foo\']) %A%', $latte->compile('{label foo, class => foo /}'), ); Assert::match( - '%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'\')) %A%', + '%A%echo ($ʟ_label = $this->global->forms->item(\'foo\')->getLabelPart(\'\')) %A%', $latte->compile('{label foo: /}'), ); @@ -43,31 +39,31 @@ Assert::exception( ); Assert::match( - '%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'\')) %A%', + '%A%echo ($ʟ_label = $this->global->forms->item(\'foo\')->getLabelPart(\'\')) %A%', $latte->compile('{label foo:, /}'), ); Assert::match( - '%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'\'))?->addAttributes([\'class\' => \'foo\']) %A%', + '%A%echo ($ʟ_label = $this->global->forms->item(\'foo\')->getLabelPart(\'\'))?->addAttributes([\'class\' => \'foo\']) %A%', $latte->compile('{label foo:, class => foo /}'), ); Assert::match( - '%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'x\')) %A%', + '%A%echo ($ʟ_label = $this->global->forms->item(\'foo\')->getLabelPart(\'x\')) %A%', $latte->compile('{label foo:x /}'), ); Assert::match( - '%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'x\'))?->addAttributes([\'class\' => \'foo\']) %A%', + '%A%echo ($ʟ_label = $this->global->forms->item(\'foo\')->getLabelPart(\'x\'))?->addAttributes([\'class\' => \'foo\']) %A%', $latte->compile('{label foo:x, class => foo /}'), ); Assert::match( - '%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'x\')) %A%', + '%A%echo ($ʟ_label = $this->global->forms->item(\'foo\')->getLabelPart(\'x\')) %A%', $latte->compile('{label "foo":"x" /}'), ); Assert::match( - '%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'x\')) %A%', + '%A%echo ($ʟ_label = $this->global->forms->item(\'foo\')->getLabelPart(\'x\')) %A%', $latte->compile('{label "foo" : "x" /}'), ); diff --git a/tests/Forms/Container.getControls().phpt b/tests/Forms/Container.getControls().phpt index 5c4d2bef0..3c605a6ef 100644 --- a/tests/Forms/Container.getControls().phpt +++ b/tests/Forms/Container.getControls().phpt @@ -15,22 +15,4 @@ $form->addContainer('cont') ->addText('name'); $controls = $form->getControls(); - -$names = $values = []; -foreach ($controls as $name => $value) { - $names[] = $name; - $values[] = $value; -} - -Assert::same(['name', 'age', 'name'], $names); -Assert::same([$form['name'], $form['age'], $form['cont-name']], $values); - -// again -$names = $values = []; -foreach ($controls as $name => $value) { - $names[] = $name; - $values[] = $value; -} - -Assert::same(['name', 'age', 'name'], $names); -Assert::same([$form['name'], $form['age'], $form['cont-name']], $values); +Assert::same([$form['name'], $form['age'], $form['cont-name']], $controls); diff --git a/tests/Forms/Container.values.mapping.phpt b/tests/Forms/Container.values.mapping.phpt index 043d6cbc7..4e27d1797 100644 --- a/tests/Forms/Container.values.mapping.phpt +++ b/tests/Forms/Container.values.mapping.phpt @@ -11,15 +11,14 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -#[AllowDynamicProperties] -class FormData +class FormData extends stdClass { public string $title; public FormFirstLevel $first; } -class FormFirstLevel +class FormFirstLevel extends stdClass { public string $name; public ?int $age = null; @@ -27,7 +26,7 @@ class FormFirstLevel } -class FormSecondLevel +class FormSecondLevel extends stdClass { public string $city; } diff --git a/tests/Forms/expected/Forms.renderer.1.expect b/tests/Forms/expected/Forms.renderer.1.expect index 4f6276143..3c17482dd 100644 --- a/tests/Forms/expected/Forms.renderer.1.expect +++ b/tests/Forms/expected/Forms.renderer.1.expect @@ -14,7 +14,7 @@ - + Enter your age @@ -54,14 +54,14 @@ - + Enter your shipping address - + Select your country @@ -81,7 +81,7 @@ - + Reenter your password diff --git a/tests/Forms/expected/Forms.renderer.2.expect b/tests/Forms/expected/Forms.renderer.2.expect index 4fbec753b..4b4872f59 100644 --- a/tests/Forms/expected/Forms.renderer.2.expect +++ b/tests/Forms/expected/Forms.renderer.2.expect @@ -13,14 +13,14 @@
-
• +
Age must be numeric value
-
+
Please select a valid option.
@@ -73,7 +73,7 @@
-
(at least 3 characters) +
(at least 3 characters) The password is too short: it must be at least 3 characters
diff --git a/tests/Forms/expected/Forms.renderer.translate.expect b/tests/Forms/expected/Forms.renderer.translate.expect index e1230b986..125b4ac49 100644 --- a/tests/Forms/expected/Forms.renderer.translate.expect +++ b/tests/Forms/expected/Forms.renderer.translate.expect @@ -15,7 +15,7 @@ - + WEAK PASSWORD diff --git a/tests/netteForms/karma.conf.ts b/tests/netteForms/karma.conf.ts index 3712c64dd..059cb3d01 100644 --- a/tests/netteForms/karma.conf.ts +++ b/tests/netteForms/karma.conf.ts @@ -4,7 +4,7 @@ module.exports = function (config) { frameworks: ['jasmine'], browsers: ['ChromeHeadless'], files: [ - '../../src/assets/netteForms.js', + '../../src/assets/dist/nette-forms.umd.js', 'spec/*Spec.js', ], autoWatch: false,