|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace FormLayout; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 8 | +use Symfony\Component\Form\Extension\Core\Type\ColorType; |
| 9 | +use Symfony\Component\Form\Extension\Core\Type\EmailType; |
| 10 | +use Symfony\Component\Form\Extension\Core\Type\IntegerType; |
| 11 | +use Symfony\Component\Form\Extension\Core\Type\NumberType; |
| 12 | +use Symfony\Component\Form\Extension\Core\Type\PasswordType; |
| 13 | +use Symfony\Component\Form\Extension\Core\Type\SearchType; |
| 14 | +use Symfony\Component\Form\Extension\Core\Type\TelType; |
| 15 | +use Symfony\Component\Form\Extension\Core\Type\TextType; |
| 16 | +use Symfony\Component\Form\Extension\Core\Type\UrlType; |
| 17 | +use Symfony\Component\Form\FormError; |
| 18 | +use TalesFromADev\FlowbiteBundle\Tests\AbstractFlowbiteLayoutTestCase; |
| 19 | + |
| 20 | +final class UrlLayoutTest extends AbstractFlowbiteLayoutTestCase |
| 21 | +{ |
| 22 | + public function testInputWithDefaultProtocol() |
| 23 | + { |
| 24 | + $url = 'http://www.example.com?foo1=bar1&foo2=bar2'; |
| 25 | + |
| 26 | + $form = $this->factory->createNamed('name', UrlType::class, $url, ['default_protocol' => 'http']); |
| 27 | + |
| 28 | + $this->assertWidgetMatchesXpath($form->createView(), [], |
| 29 | + '/input |
| 30 | + [@type="text"] |
| 31 | + [@name="name"] |
| 32 | + [@id="name"] |
| 33 | + [@class="bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base block w-full px-3 py-2.5 shadow-xs focus:ring-brand focus:border-brand placeholder:text-body"] |
| 34 | + [@value="http://www.example.com?foo1=bar1&foo2=bar2"] |
| 35 | + [@inputmode="url"] |
| 36 | + ' |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + public function testInputWithoutDefaultProtocol() |
| 41 | + { |
| 42 | + $url = 'http://www.example.com?foo1=bar1&foo2=bar2'; |
| 43 | + |
| 44 | + $form = $this->factory->createNamed('name', UrlType::class, $url, ['default_protocol' => null]); |
| 45 | + |
| 46 | + $this->assertWidgetMatchesXpath($form->createView(), [], |
| 47 | + '/input |
| 48 | + [@type="url"] |
| 49 | + [@name="name"] |
| 50 | + [@id="name"] |
| 51 | + [@class="bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base block w-full px-3 py-2.5 shadow-xs focus:ring-brand focus:border-brand placeholder:text-body"] |
| 52 | + [@value="http://www.example.com?foo1=bar1&foo2=bar2"] |
| 53 | + ' |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + public function testInputError(): void |
| 58 | + { |
| 59 | + $url = 'http://www.example.com?foo1=bar1&foo2=bar2'; |
| 60 | + |
| 61 | + $form = $this->factory->createNamed('name', UrlType::class, $url, ['default_protocol' => null]); |
| 62 | + $form->addError(new FormError('[trans]Error message[/trans]')); |
| 63 | + $form->submit([]); |
| 64 | + |
| 65 | + $this->assertWidgetMatchesXpath($form->createView(), [], |
| 66 | + '/input |
| 67 | + [@type="url"] |
| 68 | + [@name="name"] |
| 69 | + [@id="name"] |
| 70 | + [@class="border text-sm rounded-base block w-full px-3 py-2.5 shadow-xs bg-danger-soft border-danger-subtle text-fg-danger-strong focus:ring-danger focus:border-danger placeholder:text-fg-danger-strong"] |
| 71 | + ' |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + public function testInputDisabled(): void |
| 76 | + { |
| 77 | + $url = 'http://www.example.com?foo1=bar1&foo2=bar2'; |
| 78 | + |
| 79 | + $form = $this->factory->createNamed('name', UrlType::class, $url, ['disabled' => true]); |
| 80 | + $form->submit([]); |
| 81 | + |
| 82 | + $this->assertWidgetMatchesXpath($form->createView(), [], |
| 83 | + '/input |
| 84 | + [@type="url"] |
| 85 | + [@name="name"] |
| 86 | + [@id="name"] |
| 87 | + [@disabled="disabled"] |
| 88 | + [@class="bg-neutral-secondary-medium border border-default-medium text-heading text-sm rounded-base block w-full px-3 py-2.5 shadow-xs focus:ring-brand focus:border-brand placeholder:text-body disabled:text-fg-disabled disabled:cursor-not-allowed"] |
| 89 | + [@value="http://www.example.com?foo1=bar1&foo2=bar2"] |
| 90 | + ' |
| 91 | + ); |
| 92 | + } |
| 93 | +} |
0 commit comments