|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MintyPHP\Tests\Forms; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | + |
| 7 | +use MintyPHP\Form\Form; |
| 8 | +use MintyPHP\Form\Elements as E; |
| 9 | +use MintyPHP\Form\Validator\Validators as V; |
| 10 | + |
| 11 | +class SourceFormTest extends TestCase |
| 12 | +{ |
| 13 | + private function createForm(string $style): Form |
| 14 | + { |
| 15 | + $sources = [ |
| 16 | + 'Ad', |
| 17 | + 'Blog', |
| 18 | + 'Magazine', |
| 19 | + 'Newspaper', |
| 20 | + ]; |
| 21 | + E::$style = $style; |
| 22 | + return E::form([ |
| 23 | + E::field(E::text('sources')->options($sources), E::label('How did you hear about us?'), [V::required('Field cannot be empty')]), |
| 24 | + ]); |
| 25 | + } |
| 26 | + |
| 27 | + public function testRenderForm(): void |
| 28 | + { |
| 29 | + $form = $this->createForm('none'); |
| 30 | + $lines = [ |
| 31 | + '<div>', |
| 32 | + ' <label for="sources">How did you hear about us?</label>', |
| 33 | + ' <div>', |
| 34 | + ' <input id="sources" type="text" name="sources" value="" list="sources-options"/>', |
| 35 | + ' <datalist id="sources-options">', |
| 36 | + ' <option>Ad</option>', |
| 37 | + ' <option>Blog</option>', |
| 38 | + ' <option>Magazine</option>', |
| 39 | + ' <option>Newspaper</option>', |
| 40 | + ' </datalist>', |
| 41 | + ' </div>', |
| 42 | + '</div>', |
| 43 | + ]; |
| 44 | + $this->assertEquals(implode("\n", $lines), $form->toString(false, false)); |
| 45 | + } |
| 46 | + |
| 47 | + public function testRenderBulma(): void |
| 48 | + { |
| 49 | + $form = $this->createForm('bulma'); |
| 50 | + $lines = [ |
| 51 | + '<div class="field">', |
| 52 | + ' <label class="label" for="sources">How did you hear about us?</label>', |
| 53 | + ' <div class="control">', |
| 54 | + ' <input id="sources" class="input" type="text" name="sources" value="" list="sources-options"/>', |
| 55 | + ' <datalist id="sources-options">', |
| 56 | + ' <option>Ad</option>', |
| 57 | + ' <option>Blog</option>', |
| 58 | + ' <option>Magazine</option>', |
| 59 | + ' <option>Newspaper</option>', |
| 60 | + ' </datalist>', |
| 61 | + ' </div>', |
| 62 | + '</div>', |
| 63 | + ]; |
| 64 | + $this->assertEquals(implode("\n", $lines), $form->toString(false, false)); |
| 65 | + } |
| 66 | +} |
0 commit comments