‪TYPO3CMS  11.5
HtmlViewHelperTest.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 
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 class ‪HtmlViewHelperTest extends FunctionalTestCase
28 {
30 
31  protected const ‪LANGUAGE_PRESETS = [
32  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8', 'iso' => 'en', 'hrefLang' => 'en-US', 'direction' => ''],
33  ];
34 
35  protected ‪$backupGlobals = true;
36 
37  protected function ‪setUp(): void
38  {
39  parent::setUp();
40  $this->importCsvDataSet(__DIR__ . '/../../../../../core/Tests/Functional/Fixtures/pages.csv');
42  'typo3-localhost',
43  $this->‪buildSiteConfiguration(1, 'https://typo3.localhost/'),
44  [$this->‪buildDefaultLanguageConfiguration('EN', '/')]
45  );
46 
47  // A nullsite is used, so PageLinkBuilder does not "detect" the default site (from TSFE) as the same
48  // site making all links absolute for our tests
49  $rootPageSite = new ‪NullSite();
50  ‪$GLOBALS['TYPO3_REQUEST'] = (new ‪ServerRequest('https://typo3-2.localhost/', 'GET'))
51  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE)
52  ->withAttribute('site', $rootPageSite)
53  ->withAttribute('language', $rootPageSite->getDefaultLanguage());
54  }
55 
56  public static function ‪isTransformedDataProvider(): array
57  {
58  return [
59  'empty string' => [
60  '',
61  '',
62  ],
63  'any HTML tag' => [
64  '<p>value a</p><p>value b</p>',
65  '<p>value a</p><p>value b</p>',
66  ],
67  'unknown HTML tag' => [
68  '<unknown>value</unknown>',
69  '<unknown>value</unknown>',
70  ],
71  'empty' => [
72  '<a href>visit</a>',
73  '<a href>visit</a>',
74  ],
75  'invalid' => [
76  '<a href="#">visit</a>',
77  '<a href="#">visit</a>',
78  ],
79  'tel anchor' => [
80  '<a href="tel:+123456789" class="phone voice">call</a>',
81  '<a href="tel:+123456789" class="phone voice">call</a>',
82  ],
83  'mailto anchor' => [
84  '<a href="mailto:test@typo3.localhost?subject=Test" class="mailto">send mail</a>',
85  '<a href="mailto:test@typo3.localhost?subject=Test" class="mailto">send mail</a>',
86  ],
87  'https anchor' => [
88  '<a href="https://typo3.localhost/path/visit.html" class="page">visit</a>',
89  '<a href="https://typo3.localhost/path/visit.html" class="page">visit</a>',
90  ],
91  'absolute anchor' => [
92  '<a href="/path/visit.html" class="page">visit</a>',
93  '<a href="/path/visit.html" class="page">visit</a>',
94  ],
95  'relative anchor' => [
96  '<a href="path/visit.html" class="page">visit</a>',
97  '<a href="path/visit.html" class="page">visit</a>',
98  ],
99  't3-page anchor' => [
100  '<a href="t3://page?uid=1" class="page">visit</a>',
101  '<a href="https://typo3.localhost/" class="page">visit</a>',
102  ],
103  't3-page without uid anchor' => [
104  '<a href="t3://page">visit</a>',
105  '<a href="https://typo3.localhost/">visit</a>',
106  ],
107  ];
108  }
109 
116  public function ‪isTransformed(string $payload, string $expectation): void
117  {
118  $view = new ‪StandaloneView();
119  $view->setTemplateSource(sprintf('<f:transform.html>%s</f:transform.html>', $payload));
120  self::assertSame($expectation, $view->render());
121  }
122 
123  public static function ‪isTransformedWithSelectorDataProvider(): array
124  {
125  return [
126  'a.href' => [
127  'a.href',
128  '<a href="t3://page?uid=1" class="page">visit</a>',
129  '<a href="https://typo3.localhost/" class="page">visit</a>',
130  ],
131  '.href' => [
132  '.href',
133  '<a href="t3://page?uid=1" class="page">visit</a>',
134  '<a href="https://typo3.localhost/" class="page">visit</a>',
135  ],
136  'div.data-uri' => [
137  'div.data-uri',
138  '<div data-uri="t3://page?uid=1" class="page">visit</div>',
139  '<div data-uri="https://typo3.localhost/" class="page">visit</div>',
140  ],
141  'a.href,div.data-uri' => [
142  'a.href,div.data-uri',
143  '<a href="t3://page?uid=1">visit</a><div data-uri="t3://page?uid=1">visit</div>',
144  '<a href="https://typo3.localhost/">visit</a><div data-uri="https://typo3.localhost/">visit</div>',
145  ],
146  ];
147  }
148 
156  public function ‪isTransformedWithSelector(string $selector, string $payload, string $expectation): void
157  {
158  $view = new ‪StandaloneView();
159  $view->setTemplateSource(sprintf('<f:transform.html selector="%s">%s</f:transform.html>', $selector, $payload));
160  self::assertSame($expectation, $view->render());
161  }
162 
163  public static function ‪isTransformedWithOnFailureDataProvider(): array
164  {
165  return [
166  't3-page invalid uid anchor (default)' => [
167  null,
168  '<a href="t3://page?uid=9876">visit</a>',
169  'visit',
170  ],
171  't3-page invalid uid anchor ("removeEnclosure")' => [
172  'removeEnclosure',
173  '<a href="t3://page?uid=9876">visit</a>',
174  'visit',
175  ],
176  't3-page invalid uid anchor ("removeTag")' => [
177  'removeTag',
178  '<a href="t3://page?uid=9876">visit</a>',
179  '',
180  ],
181  't3-page invalid uid anchor ("removeAttr")' => [
182  'removeAttr',
183  '<a href="t3://page?uid=9876">visit</a>',
184  '<a>visit</a>',
185  ],
186  't3-page invalid uid anchor ("null")' => [
187  'null',
188  '<a href="t3://page?uid=9876">visit</a>',
189  '<a href="t3://page?uid=9876">visit</a>',
190  ],
191  't3-page invalid uid anchor ("")' => [
192  '',
193  '<a href="t3://page?uid=9876">visit</a>',
194  '<a href="t3://page?uid=9876">visit</a>',
195  ],
196  ];
197  }
198 
206  public function ‪isTransformedWithOnFailure(?string $onFailure, string $payload, string $expectation): void
207  {
208  $view = new ‪StandaloneView();
209  $view->setTemplateSource(sprintf(
210  '<f:transform.html %s>%s</f:transform.html>',
211  $onFailure !== null ? 'onFailure="' . $onFailure . '"' : '',
212  $payload
213  ));
214  self::assertSame($expectation, $view->render());
215  }
216 }
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:36
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:58
‪TYPO3\CMS\Core\Site\Entity\NullSite
Definition: NullSite.php:32
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform\HtmlViewHelperTest\isTransformedWithOnFailure
‪isTransformedWithOnFailure(?string $onFailure, string $payload, string $expectation)
Definition: HtmlViewHelperTest.php:205
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform\HtmlViewHelperTest\$backupGlobals
‪$backupGlobals
Definition: HtmlViewHelperTest.php:34
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform\HtmlViewHelperTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: HtmlViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform\HtmlViewHelperTest\isTransformedDataProvider
‪static isTransformedDataProvider()
Definition: HtmlViewHelperTest.php:55
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪array buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:126
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform\HtmlViewHelperTest\isTransformedWithSelector
‪isTransformedWithSelector(string $selector, string $payload, string $expectation)
Definition: HtmlViewHelperTest.php:155
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform\HtmlViewHelperTest\isTransformedWithOnFailureDataProvider
‪static isTransformedWithOnFailureDataProvider()
Definition: HtmlViewHelperTest.php:162
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform\HtmlViewHelperTest
Definition: HtmlViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform\HtmlViewHelperTest\isTransformed
‪isTransformed(string $payload, string $expectation)
Definition: HtmlViewHelperTest.php:115
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform\HtmlViewHelperTest\setUp
‪setUp()
Definition: HtmlViewHelperTest.php:36
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:111
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform
Definition: HtmlViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform\HtmlViewHelperTest\isTransformedWithSelectorDataProvider
‪static isTransformedWithSelectorDataProvider()
Definition: HtmlViewHelperTest.php:122