‪TYPO3CMS  ‪main
JavaScriptRendererTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
22 use TYPO3\CMS\Core\Page\JavaScriptRenderer;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
25 final class ‪JavaScriptRendererTest extends FunctionalTestCase
26 {
30  #[Test]
31  public function ‪textContentIsEncoded(): void
32  {
33  $subject = JavaScriptRenderer::create('anything.js');
34  $subject->addJavaScriptModuleInstruction(
35  ‪JavaScriptModuleInstruction::create('@typo3/test/module.js')
36  ->invoke('test*/', 'arg*/')
37  );
38  $subject->addGlobalAssignment(['section*/' => ['key*/' => 'value*/']]);
39  self::assertSame(
40  '<script src="anything.js" async="async">'
41  . '/* [{"type":"globalAssignment","payload":{"section*\/":{"key*\/":"value*\/"}}},'
42  . '{"type":"javaScriptModuleInstruction","payload":{"name":"@typo3\/test\/module.js","exportName":null,'
43  . '"flags":2,"items":[{"type":"invoke","method":"test*\/","args":["arg*\/"]}]}}] */</script>',
44  trim($subject->render())
45  );
46  }
47 }
‪TYPO3\CMS\Core\Tests\Functional\Page\JavaScriptRendererTest\textContentIsEncoded
‪textContentIsEncoded()
Definition: JavaScriptRendererTest.php:31
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Core\Tests\Functional\Page\JavaScriptRendererTest
Definition: JavaScriptRendererTest.php:26
‪TYPO3\CMS\Core\Tests\Functional\Page
Definition: JavaScriptRendererTest.php:18