|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace Tests\Cases\Grid; |
| 4 | + |
| 5 | +use Contributte\FormsBootstrap\BootstrapForm; |
| 6 | +use Contributte\Tester\Toolkit; |
| 7 | +use Mockery; |
| 8 | +use Nette\Application\UI\Presenter; |
| 9 | +use Nette\InvalidArgumentException; |
| 10 | +use Tester\Assert; |
| 11 | + |
| 12 | +require __DIR__ . '/../../bootstrap.php'; |
| 13 | + |
| 14 | +Toolkit::test(function (): void { |
| 15 | + $form = new BootstrapForm(); |
| 16 | + $row = $form->addRow(); |
| 17 | + $cell = $row->addCell(12); |
| 18 | + $form->setParent(Mockery::mock(Presenter::class)->shouldIgnoreMissing()); |
| 19 | + |
| 20 | + $cell->addHtmlClass('new-class'); |
| 21 | + Assert::same('<div class="new-class col-sm-12"></div>', $cell->render()->render()); |
| 22 | +}); |
| 23 | + |
| 24 | +Toolkit::test(function (): void { |
| 25 | + $form = new BootstrapForm(); |
| 26 | + $row = $form->addRow(); |
| 27 | + $cell = $row->addCell(12); |
| 28 | + $form->setParent(Mockery::mock(Presenter::class)->shouldIgnoreMissing()); |
| 29 | + |
| 30 | + $cell->addSubmit('first', 'First'); |
| 31 | + $cell->addSubmit('second', 'Second'); |
| 32 | + |
| 33 | + ob_start(); |
| 34 | + $form->render(); |
| 35 | + $output = ob_get_clean(); |
| 36 | + |
| 37 | + Assert::same(file_get_contents(__DIR__ . '/../../data/cell_with_2_submits.html'), $output); |
| 38 | +}); |
| 39 | + |
| 40 | +Toolkit::test(function (): void { |
| 41 | + $form = new BootstrapForm(); |
| 42 | + $row = $form->addRow(); |
| 43 | + |
| 44 | + Assert::exception(function () use ($row): void { |
| 45 | + $row->addCell(15); |
| 46 | + }, InvalidArgumentException::class); |
| 47 | +}); |
| 48 | + |
| 49 | +Toolkit::test(function (): void { |
| 50 | + $form = new BootstrapForm(); |
| 51 | + $row = $form->addRow(); |
| 52 | + $cell = $row->addCell(12); |
| 53 | + $form->setParent(Mockery::mock(Presenter::class)->shouldIgnoreMissing()); |
| 54 | + |
| 55 | + $first = $form->addGroup('first'); |
| 56 | + $first->add($form->addText('a')); |
| 57 | + $form->addGroup('second'); |
| 58 | + $cell->setCurrentGroup($first); |
| 59 | + |
| 60 | + Assert::same($first, $cell->getCurrentGroup()); |
| 61 | +}); |
0 commit comments