|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use Nette\Forms\Controls\TextInput; |
| 6 | +use Nette\Forms\Form; |
| 7 | +use Tester\Assert; |
| 8 | + |
| 9 | + |
| 10 | +require __DIR__ . '/../bootstrap.php'; |
| 11 | + |
| 12 | + |
| 13 | +Assert::exception(function () { |
| 14 | + $input = new TextInput('name'); |
| 15 | + $input->getHtmlId(); |
| 16 | +}, Nette\InvalidStateException::class, "Component '' is not attached to ''."); |
| 17 | + |
| 18 | + |
| 19 | +test(function () { |
| 20 | + $container = new Nette\Forms\Container; |
| 21 | + $container->setParent(null, 'second'); |
| 22 | + $input = $container->addText('name'); |
| 23 | + Assert::same('frm-name', $input->getHtmlId()); |
| 24 | +}); |
| 25 | + |
| 26 | + |
| 27 | +test(function () { |
| 28 | + $form = new Form; |
| 29 | + $container = $form->addContainer('second'); |
| 30 | + $input = $container->addText('name'); |
| 31 | + Assert::same('frm-second-name', $input->getHtmlId()); |
| 32 | +}); |
| 33 | + |
| 34 | + |
| 35 | +test(function () { |
| 36 | + $form = new Form; |
| 37 | + $input = $form->addText('name'); |
| 38 | + Assert::same('frm-name', $input->getHtmlId()); |
| 39 | +}); |
| 40 | + |
| 41 | + |
| 42 | +test(function () { |
| 43 | + Nette\Forms\Controls\BaseControl::$idMask = 'frm-%s-%s'; |
| 44 | + |
| 45 | + $form = new Form; |
| 46 | + $input = $form->addText('name'); |
| 47 | + Assert::same('frm-name-', $input->getHtmlId()); |
| 48 | +}); |
| 49 | + |
| 50 | + |
| 51 | +test(function () { |
| 52 | + Nette\Forms\Controls\BaseControl::$idMask = 'frm-%2$s-%1$s'; |
| 53 | + |
| 54 | + $form = new Form('signForm'); |
| 55 | + $input = $form->addText('name'); |
| 56 | + Assert::same('frm-signForm-name', $input->getHtmlId()); |
| 57 | +}); |
0 commit comments