From 268b2df6920db5d76189ac485e919a50d1e5f51a Mon Sep 17 00:00:00 2001 From: Alexander Hofbauer Date: Mon, 13 May 2024 14:25:26 +0200 Subject: [PATCH] [LiveComponent] Tests class merging with whitespaces --- .../LiveController/LiveControllerTest.php | 29 +++++++++++++++ .../src/Twig/Component/WhitespaceClasses.php | 35 +++++++++++++++++++ .../components/whitespace_classes.html.twig | 21 +++++++++++ .../templates/whitespace_classes.html.twig | 5 +++ 4 files changed, 90 insertions(+) create mode 100644 src/LiveComponent/tests/Integration/LiveController/LiveControllerTest.php create mode 100644 src/LiveComponent/tests/app/src/Twig/Component/WhitespaceClasses.php create mode 100644 src/LiveComponent/tests/app/templates/components/whitespace_classes.html.twig create mode 100644 src/LiveComponent/tests/app/templates/whitespace_classes.html.twig diff --git a/src/LiveComponent/tests/Integration/LiveController/LiveControllerTest.php b/src/LiveComponent/tests/Integration/LiveController/LiveControllerTest.php new file mode 100644 index 00000000000..bb59fc4fe31 --- /dev/null +++ b/src/LiveComponent/tests/Integration/LiveController/LiveControllerTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\UX\LiveComponent\Tests\Integration\LiveController; + +use Symfony\Component\Panther\PantherTestCase; + +/** + * @author Alexander Hofbauer + */ +class LiveControllerTest extends PantherTestCase +{ + public function testWhitespaceClasses(): void + { + $client = self::createPantherClient(); + $client->request('GET', '/whitespace-classes'); + $client->clickLink('Remove class and render'); + + self::assertSelectorAttributeContains('p[id="content"]', 'class', 'second new'); + } +} diff --git a/src/LiveComponent/tests/app/src/Twig/Component/WhitespaceClasses.php b/src/LiveComponent/tests/app/src/Twig/Component/WhitespaceClasses.php new file mode 100644 index 00000000000..4ab0a1d2cc7 --- /dev/null +++ b/src/LiveComponent/tests/app/src/Twig/Component/WhitespaceClasses.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace App\Twig\Component; + +use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; +use Symfony\UX\LiveComponent\Attribute\LiveAction; +use Symfony\UX\LiveComponent\Attribute\LiveProp; +use Symfony\UX\LiveComponent\DefaultActionTrait; + +/** + * @author Alexander Hofbauer + */ +#[AsLiveComponent('whitespace_classes')] +final class WhitespaceClasses +{ + use DefaultActionTrait; + + #[LiveProp] + public string $class = 'third'; + + #[LiveAction] + public function click(): void + { + $this->class = 'new'; + } +} diff --git a/src/LiveComponent/tests/app/templates/components/whitespace_classes.html.twig b/src/LiveComponent/tests/app/templates/components/whitespace_classes.html.twig new file mode 100644 index 00000000000..4085b35c3e5 --- /dev/null +++ b/src/LiveComponent/tests/app/templates/components/whitespace_classes.html.twig @@ -0,0 +1,21 @@ + +

+ Class: {{ class }} +

+ + + Remove class and render + + diff --git a/src/LiveComponent/tests/app/templates/whitespace_classes.html.twig b/src/LiveComponent/tests/app/templates/whitespace_classes.html.twig new file mode 100644 index 00000000000..b24e8589496 --- /dev/null +++ b/src/LiveComponent/tests/app/templates/whitespace_classes.html.twig @@ -0,0 +1,5 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +{% endblock %}