‪TYPO3CMS  ‪main
TypolinkViewHelperTest.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;
24 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 final class ‪TypolinkViewHelperTest extends FunctionalTestCase
28 {
30 
34  protected const ‪LANGUAGE_PRESETS = [
35  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
36  ];
37 
38  protected array ‪$configurationToUseInTestInstance = [
39  'FE' => [
40  'cacheHash' => [
41  'enforceValidation' => false,
42  ],
43  ],
44  ];
45 
46  protected function ‪setUp(): void
47  {
48  parent::setUp();
49  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/pages.csv');
51  'test',
52  $this->‪buildSiteConfiguration(1, '/'),
53  [
54  $this->‪buildDefaultLanguageConfiguration('EN', '/en/'),
55  ]
56  );
57  }
58 
59  public static function ‪renderDataProvider(): array
60  {
61  return [
62  'uri: default' => [
63  '<f:uri.typolink parameter="1" />',
64  '/en/',
65  ],
66  'uri: with add query string' => [
67  '<f:uri.typolink parameter="1" addQueryString="untrusted" />',
68  '/en/?foo=bar&amp;temp=test&amp;cHash=286759dfcd3f566fa21091a0d77e9831',
69  ],
70  'uri: with add query string and exclude' => [
71  '<f:uri.typolink parameter="1" addQueryString="untrusted" addQueryStringExclude="temp" />',
72  '/en/?foo=bar&amp;cHash=afa4b37588ab917af3cfe2cd4464029d',
73  ],
74  't3://url uri: default' => [
75  '<f:uri.typolink parameter="t3://url?url=https://example.org?param=1&other=dude" />',
76  'https://example.org?param=1',
77  ],
78  't3://url uri: with add query string' => [
79  '<f:uri.typolink parameter="t3://url?url=https://example.org?param=1&other=dude" addQueryString="untrusted" />',
80  'https://example.org?param=1',
81  ],
82  't3://url uri: with add query string and exclude' => [
83  '<f:uri.typolink parameter="t3://url?url=https://example.org?param=1&other=dude" addQueryString="untrusted" addQueryStringExclude="temp" />',
84  'https://example.org?param=1',
85  ],
86  'mailto: uri: default' => [
87  '<f:uri.typolink parameter="mailto:foo@typo3.org" />',
88  'mailto:foo@typo3.org',
89  ],
90  'mailto: uri: with add query string' => [
91  '<f:uri.typolink parameter="mailto:foo@typo3.org" addQueryString="untrusted" />',
92  'mailto:foo@typo3.org',
93  ],
94  'mailto: uri: with add query string and exclude' => [
95  '<f:uri.typolink parameter="mailto:foo@typo3.org" addQueryString="untrusted" addQueryStringExclude="temp" />',
96  'mailto:foo@typo3.org',
97  ],
98  'http://: uri: default' => [
99  '<f:uri.typolink parameter="http://typo3.org/foo/?foo=bar" />',
100  'http://typo3.org/foo/?foo=bar',
101  ],
102  'http://: uri: with add query string' => [
103  '<f:uri.typolink parameter="http://typo3.org/foo/?foo=bar" addQueryString="untrusted" />',
104  'http://typo3.org/foo/?foo=bar',
105  ],
106  'http://: uri: with add query string and exclude' => [
107  '<f:uri.typolink parameter="http://typo3.org/foo/?foo=bar" addQueryString="untrusted" addQueryStringExclude="temp" />',
108  'http://typo3.org/foo/?foo=bar',
109  ],
110  ];
111  }
112 
113  #[DataProvider('renderDataProvider')]
114  #[Test]
115  public function ‪render(string $template, string $expected): void
116  {
117  (new ‪ConnectionPool())->getConnectionForTable('sys_template')->insert('sys_template', [
118  'pid' => 1,
119  'root' => 1,
120  'clear' => 1,
121  'config' => <<<EOT
122 page = PAGE
123 page.10 = FLUIDTEMPLATE
124 page.10 {
125  template = TEXT
126  template.value = $template
127 }
128 EOT
129  ]);
130  $response = $this->executeFrontendSubRequest(
131  (new InternalRequest())
132  ->withPageId(1)
133  ->withQueryParameter('foo', 'bar')
134  ->withQueryParameter('temp', 'test')
135  );
136  self::assertStringContainsString($expected, (string)$response->getBody());
137  }
138 }
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Uri
Definition: ActionViewHelperTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46