diff --git a/src/LiveComponent/tests/Integration/LiveController/LiveControllerTest.php b/src/LiveComponent/tests/Integration/LiveController/LiveControllerTest.php new file mode 100644 index 0000000000..73af035b09 --- /dev/null +++ b/src/LiveComponent/tests/Integration/LiveController/LiveControllerTest.php @@ -0,0 +1,32 @@ + + * + * 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'); + + // wait required to run live_controller JS + $client->waitFor('#changed', 10); + + self::assertSelectorAttributeContains('p#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 0000000000..c901763b8b --- /dev/null +++ b/src/LiveComponent/tests/app/src/Twig/Component/WhitespaceClasses.php @@ -0,0 +1,39 @@ + + * + * 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'; + + #[LiveProp] + public bool $changed = false; + + #[LiveAction] + public function click(): void + { + $this->class = 'new'; + $this->changed = true; + } +} 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 0000000000..278ac2a2bc --- /dev/null +++ b/src/LiveComponent/tests/app/templates/components/whitespace_classes.html.twig @@ -0,0 +1,25 @@ + +

+ Class: {{ class }} +

+ + + Remove class and render + + + {% if changed %} +
+ {% endif %} + 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 0000000000..b24e858949 --- /dev/null +++ b/src/LiveComponent/tests/app/templates/whitespace_classes.html.twig @@ -0,0 +1,5 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +{% endblock %}