‪TYPO3CMS  ‪main
PageLinkBuilderTest.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;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 final class ‪PageLinkBuilderTest extends UnitTestCase
29 {
30  public static function ‪getQueryArgumentsExcludesParametersDataProvider(): \Generator
31  {
33  yield 'nested exclude from untrusted args' => [
34  $enc('&key1=value1&key2=value2&key3[key31]=value31&key3[key32][key321]=value321&key3[key32][key322]=value322'),
35  'untrusted',
36  [
37  'exclude' => implode(',', ['key1', 'key3[key31]', 'key3[key32][key321]']),
38  ],
39  $enc('&key2=value2&key3[key32][key322]=value322'),
40  ];
41  yield 'URL encoded value' => [
42  '&param=1&param%25=2&param%2525=3',
43  'untrusted',
44  [
45  // internally: URL-decoded representation
46  'exclude' => 'param,param%,param%25',
47  ],
48  '',
49  ];
50  }
51 
52  #[DataProvider('getQueryArgumentsExcludesParametersDataProvider')]
53  #[Test]
54  public function ‪getQueryArgumentsExcludesParameters(string $queryString, string $queryInformation, array $configuration, string $expectedResult): void
55  {
56  parse_str($queryString, $queryParameters);
57  $request = new ‪ServerRequest('https://example.com');
58  $request = $request->withQueryParams($queryParameters);
59  $request = $request->withAttribute('routing', new ‪PageArguments(1, '', $queryParameters, [], []));
60  ‪$GLOBALS['TSFE'] = new \stdClass();
61  $cObj = new ‪ContentObjectRenderer();
62  $cObj->setRequest($request);
63  $subject = $this->getAccessibleMock(PageLinkBuilder::class, null, [], '', false);
64  $subject->_set('contentObjectRenderer', $cObj);
65  $actualResult = $subject->_call('getQueryArguments', $queryInformation, $configuration);
66  self::assertEquals($expectedResult, $actualResult);
67  }
68 
72  private static function ‪rawUrlEncodeSquareBracketsInUrl(string $string): string
73  {
74  return str_replace(['[', ']'], ['%5B', '%5D'], $string);
75  }
76 }
‪TYPO3\CMS\Core\Routing\PageArguments
Definition: PageArguments.php:26
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102