|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Panther project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace Symfony\Component\Panther\Tests\DomCrawler\Field; |
| 15 | + |
| 16 | +use Symfony\Component\DomCrawler\Field\InputFormField; |
| 17 | +use Symfony\Component\Panther\Tests\TestCase; |
| 18 | + |
| 19 | +/** |
| 20 | + * @author Robert Freigang <[email protected]> |
| 21 | + */ |
| 22 | +class InputFormFieldTest extends TestCase |
| 23 | +{ |
| 24 | + /** |
| 25 | + * @dataProvider clientFactoryProvider |
| 26 | + */ |
| 27 | + public function testGetValueWithSomeValueFromTextInput(callable $clientFactory) |
| 28 | + { |
| 29 | + $crawler = $this->request($clientFactory, '/input-form-field.html'); |
| 30 | + $form = $crawler->filter('form')->form(); |
| 31 | + |
| 32 | + /** @var InputFormField */ |
| 33 | + $field = $form['text_input_with_some_value']; |
| 34 | + $this->assertInstanceOf(InputFormField::class, $field); |
| 35 | + $this->assertSame('some_value', $field->getValue()); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @dataProvider clientFactoryProvider |
| 40 | + */ |
| 41 | + public function testGetValueWithNoValueFromTextInput(callable $clientFactory) |
| 42 | + { |
| 43 | + $crawler = $this->request($clientFactory, '/input-form-field.html'); |
| 44 | + $form = $crawler->filter('form')->form(); |
| 45 | + |
| 46 | + /** @var InputFormField */ |
| 47 | + $field = $form['text_input_with_no_value']; |
| 48 | + $this->assertInstanceOf(InputFormField::class, $field); |
| 49 | + $this->assertSame('', $field->getValue()); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @dataProvider clientFactoryProvider |
| 54 | + */ |
| 55 | + public function testSetValueMultipleTimesInTextInput(callable $clientFactory) |
| 56 | + { |
| 57 | + $crawler = $this->request($clientFactory, '/input-form-field.html'); |
| 58 | + $form = $crawler->filter('form')->form(); |
| 59 | + |
| 60 | + /** @var InputFormField */ |
| 61 | + $field = $form['text_input_with_no_value']; |
| 62 | + $this->assertInstanceOf(InputFormField::class, $field); |
| 63 | + |
| 64 | + $field->setValue('first_value'); |
| 65 | + $this->assertSame('first_value', $field->getValue()); |
| 66 | + |
| 67 | + $field->setValue('second_value'); |
| 68 | + $this->assertSame('second_value', $field->getValue()); |
| 69 | + } |
| 70 | +} |
0 commit comments