abterphp /
bootstrap4-website
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace AbterPhp\Bootstrap4Website\Decorator; |
||
| 6 | |||
| 7 | use AbterPhp\Framework\Constant\Html5; |
||
| 8 | use AbterPhp\Framework\Form\Container\CheckboxGroup; |
||
| 9 | use AbterPhp\Framework\Form\Container\FormGroup; |
||
| 10 | use AbterPhp\Framework\Form\Element\IElement; |
||
| 11 | use AbterPhp\Framework\Form\Element\Input; |
||
| 12 | use AbterPhp\Framework\Form\Element\Select; |
||
| 13 | use AbterPhp\Framework\Form\Element\Textarea; |
||
| 14 | use AbterPhp\Framework\Form\Extra\DefaultButtons; |
||
| 15 | use AbterPhp\Framework\Form\Label\Label; |
||
| 16 | use AbterPhp\Framework\Html\Component\Button; |
||
| 17 | use AbterPhp\Framework\Html\INode; |
||
| 18 | use PHPUnit\Framework\TestCase; |
||
| 19 | |||
| 20 | class FormTest extends TestCase |
||
| 21 | { |
||
| 22 | /** @var Form - System Under Test */ |
||
| 23 | protected $sut; |
||
| 24 | |||
| 25 | public function setUp(): void |
||
| 26 | { |
||
| 27 | $this->sut = new Form(); |
||
| 28 | |||
| 29 | $this->sut->init(); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @return array |
||
| 34 | */ |
||
| 35 | public function decorateProvider(): array |
||
| 36 | { |
||
| 37 | return [ |
||
| 38 | 'label' => [new Label(''), Form::DEFAULT_LABEL_CLASS], |
||
| 39 | 'textarea' => [new Textarea('', ''), Form::DEFAULT_INPUT_CLASS], |
||
| 40 | 'select' => [new Select('', ''), Form::DEFAULT_INPUT_CLASS], |
||
| 41 | 'form-group' => [ |
||
| 42 | new FormGroup( |
||
| 43 | $this->createMock(IElement::class), |
||
| 44 | $this->createMock(Label::class) |
||
| 45 | ), |
||
| 46 | Form::DEFAULT_FORM_GROUP_CLASS, |
||
| 47 | ], |
||
| 48 | 'default-buttons' => [new DefaultButtons(''), Form::DEFAULT_BUTTONS_CLASS], |
||
| 49 | 'buttons' => [new Button(null, [Button::INTENT_FORM]), Form::DEFAULT_BUTTON_CLASS], |
||
| 50 | ]; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @dataProvider decorateProvider |
||
| 55 | * |
||
| 56 | * @param INode $node |
||
| 57 | * @param string $contains |
||
| 58 | */ |
||
| 59 | public function testDecorate(INode $node, string $contains) |
||
| 60 | { |
||
| 61 | $this->sut->decorate([$node]); |
||
| 62 | |||
| 63 | $this->assertStringContainsString($contains, (string)$node); |
||
| 64 | } |
||
| 65 | |||
| 66 | public function testDecorateCheckboxGroup() |
||
| 67 | { |
||
| 68 | $inputMock = $this->createMock(Input::class); |
||
| 69 | $inputMock |
||
| 70 | ->expects($this->once()) |
||
| 71 | ->method('unsetAttribute') |
||
| 72 | ->with(Html5::ATTR_CLASS); |
||
| 73 | |||
| 74 | $labelMock = $this->createMock(Label::class); |
||
| 75 | $labelMock |
||
| 76 | ->expects($this->once()) |
||
| 77 | ->method('setAttribute') |
||
| 78 | ->with(Html5::ATTR_CLASS, Form::CHECKBOX_LABEL_CLASS); |
||
| 79 | |||
| 80 | $node = new CheckboxGroup($inputMock, $labelMock); |
||
| 81 | |||
| 82 | $this->sut->decorate([$node]); |
||
| 83 | |||
| 84 | $this->assertStringContainsString( |
||
| 85 | Form::CHECKBOX_GROUP_CLASS, |
||
| 86 | $node->getAttribute(Html5::ATTR_CLASS) |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 87 | ); |
||
| 88 | } |
||
| 89 | } |
||
| 90 |