‪TYPO3CMS  ‪main
ActionMenuItemViewHelperTest.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\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 use TYPO3Fluid\Fluid\View\TemplateView;
29 
30 final class ‪ActionMenuItemViewHelperTest extends FunctionalTestCase
31 {
32  public static function ‪isRenderedDataProvider(): array
33  {
34  return [
35  'tag syntax' => [
36  '<f:be.menus.actionMenuItem label="{label}" controller="{controller}" action="{action}" />',
37  [
38  'label' => 'label<>&"\'',
39  'controller' => 'controller<>&"\'',
40  'action' => 'action<>&"\'',
41  ],
42  '<option value="">label&lt;&gt;&amp;&quot;&#039;</option>',
43  ],
44  'inline syntax' => [
45  '{f:be.menus.actionMenuItem(label:label, controller:controller, action:action)}',
46  [
47  'label' => 'label<>&"\'',
48  'controller' => 'controller<>&"\'',
49  'action' => 'action<>&"\'',
50  ],
51  '<option value="">label&lt;&gt;&amp;&quot;&#039;</option>',
52  ],
53  'inline syntax with quotes' => [
54  '{f:be.menus.actionMenuItem(label:\'{label}\', controller:\'{controller}\', action:\'{action}\')}',
55  [
56  'label' => 'label<>&"\'',
57  'controller' => 'controller<>&"\'',
58  'action' => 'action<>&"\'',
59  ],
60  '<option value="">label&lt;&gt;&amp;&quot;&#039;</option>',
61  ],
62  ];
63  }
64 
65  #[DataProvider('isRenderedDataProvider')]
66  #[Test]
67  public function ‪isRendered(string $source, array $variables, string $expectation): void
68  {
69  $context = $this->get(RenderingContextFactory::class)->create();
70  $context->getTemplatePaths()->setTemplateSource($source);
71  $serverRequest = (new ‪ServerRequest())->withAttribute('extbase', new ‪ExtbaseRequestParameters())
72  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
73  ‪$GLOBALS['TYPO3_REQUEST'] = $serverRequest;
74  $context->setRequest(new ‪Request($serverRequest));
75  $view = new TemplateView($context);
76  $view->assignMultiple($variables);
77  self::assertSame($expectation, $view->render());
78  }
79 }
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Menus\ActionMenuItemViewHelperTest\isRenderedDataProvider
‪static isRenderedDataProvider()
Definition: ActionMenuItemViewHelperTest.php:32
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Menus\ActionMenuItemViewHelperTest
Definition: ActionMenuItemViewHelperTest.php:31
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Menus
Definition: ActionMenuItemViewHelperTest.php:18
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Menus\ActionMenuItemViewHelperTest\isRendered
‪isRendered(string $source, array $variables, string $expectation)
Definition: ActionMenuItemViewHelperTest.php:67
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters
Definition: ExtbaseRequestParameters.php:35
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:35