CshViewHelperTest.php 3.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

declare(strict_types=1);

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

18
namespace TYPO3\CMS\Fluid\Tests\FunctionalDeprecated\ViewHelpers\Be\Labels;
19

20
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
21
use TYPO3\CMS\Core\Utility\GeneralUtility;
22
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
23
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24
use TYPO3Fluid\Fluid\View\TemplateView;
25
26
27

class CshViewHelperTest extends FunctionalTestCase
{
28
    protected bool $initializeDatabase = false;
29

30
31
32
33
    protected function setUp(): void
    {
        parent::setUp();
        if (!isset($GLOBALS['LANG'])) {
34
            $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->create('default');
35
36
37
38
39
40
41
42
43
44
        }
    }

    public function isRenderedDataProvider(): array
    {
        return [
            '#1' => [
                '<f:be.labels.csh table="table" field="field" label="{label}">{variable}</f:be.labels.csh>',
                [
                    'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack',
45
                    'variable' => 'variable<>&"\'',
46
47
48
49
50
51
52
                ],
                '<label>Go back</label>',
            ],
            '#2' => [
                '<f:be.labels.csh table="table" field="field" label="{label}">{variable}</f:be.labels.csh>',
                [
                    'label' => 'label<>&"\'',
53
                    'variable' => 'variable<>&"\'',
54
55
56
57
                ],
                '<label>label&lt;&gt;&amp;&quot;&#039;</label>',
            ],
            '#3' => [
58
                '{f:be.labels.csh(table:\'table\', field:\'field\', label:label)}',
59
60
                [
                    'label' => 'label<>&"\'',
61
                    'variable' => 'variable<>&"\'',
62
63
64
65
                ],
                '<label>label&lt;&gt;&amp;&quot;&#039;</label>',
            ],
            '#4' => [
66
                '{f:be.labels.csh(table:\'table\', field:\'field\', label:\'{label}\')}',
67
68
                [
                    'label' => 'label<>&"\'',
69
                    'variable' => 'variable<>&"\'',
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
                ],
                '<label>label&lt;&gt;&amp;&quot;&#039;</label>',
            ],
        ];
    }

    /**
     * @param string $source
     * @param array $variables
     * @param string $expectation
     *
     * @test
     * @dataProvider isRenderedDataProvider
     */
    public function isRendered(string $source, array $variables, string $expectation): void
    {
86
        $context = $this->get(RenderingContextFactory::class)->create();
87
88
        $context->getTemplatePaths()->setTemplateSource($source);
        $view = new TemplateView($context);
89
90
91
92
93
        $view->getRenderingContext()->getCache()->flush();
        $view->assignMultiple($variables);
        self::assertSame($expectation, $view->render());
    }
}