|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony WebpackEncoreBundle package. |
| 5 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace Symfony\WebpackEncoreBundle\Tests\Dto; |
| 11 | + |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | +use Symfony\WebpackEncoreBundle\Dto\StimulusControllersDto; |
| 14 | +use Twig\Environment; |
| 15 | +use Twig\Loader\ArrayLoader; |
| 16 | + |
| 17 | +class StimulusControllersDtoTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var StimulusControllersDto |
| 21 | + */ |
| 22 | + private $stimulusControllersDto; |
| 23 | + |
| 24 | + protected function setUp(): void |
| 25 | + { |
| 26 | + $this->stimulusControllersDto = new StimulusControllersDto(new Environment(new ArrayLoader())); |
| 27 | + } |
| 28 | + |
| 29 | + public function testToStringEscapingAttributeValues(): void |
| 30 | + { |
| 31 | + $this->stimulusControllersDto->addController('foo', ['bar' => '"'], ['baz' => '"']); |
| 32 | + $attributesHtml = (string) $this->stimulusControllersDto; |
| 33 | + self::assertSame( |
| 34 | + 'data-controller="foo" '. |
| 35 | + 'data-foo-bar-value=""" '. |
| 36 | + 'data-foo-baz-class="""', |
| 37 | + $attributesHtml |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + public function testToArrayNoEscapingAttributeValues(): void |
| 42 | + { |
| 43 | + $this->stimulusControllersDto->addController('foo', ['bar' => '"'], ['baz' => '"']); |
| 44 | + $attributesArray = $this->stimulusControllersDto->toArray(); |
| 45 | + self::assertSame( |
| 46 | + [ |
| 47 | + 'data-controller' => 'foo', |
| 48 | + 'data-foo-bar-value' => '"', |
| 49 | + 'data-foo-baz-class' => '"', |
| 50 | + ], |
| 51 | + $attributesArray |
| 52 | + ); |
| 53 | + } |
| 54 | +} |
0 commit comments