‪TYPO3CMS  ‪main
CacheHashConfigurationTest.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;
22 use PHPUnit\Framework\TestCase;
25 
26 final class ‪CacheHashConfigurationTest extends TestCase
27 {
28  public static function ‪nonArrayValueThrowsExceptionDataProvider(): array
29  {
31  [
36  ],
37  ['true', true, 1, new \stdClass()],
38  ]);
39  }
40 
41  #[DataProvider('nonArrayValueThrowsExceptionDataProvider')]
42  #[Test]
43  public function ‪nonArrayValueThrowsException(string $aspect, mixed $value): void
44  {
45  $this->expectException(\LogicException::class);
46  $this->expectExceptionCode(1580225311);
47  new ‪CacheHashConfiguration([$aspect => $value]);
48  }
49 
50  public static function ‪nonScalarValueThrowsExceptionDataProvider(): array
51  {
53  [
58  ],
59  [null, [], new \stdClass()],
60  ]);
61  }
62 
63  #[DataProvider('nonScalarValueThrowsExceptionDataProvider')]
64  #[Test]
65  public function ‪nonScalarValueThrowsException(string $aspect, mixed $value): void
66  {
67  $this->expectException(\LogicException::class);
68  $this->expectExceptionCode(1580225312);
69  new ‪CacheHashConfiguration([$aspect => [$value]]);
70  }
71 
72  public static function ‪emptyIndicatedValueThrowsExceptionDataProvider(): array
73  {
75  [
80  ],
81  ['=', '^', '~'],
82  ]);
83  }
84 
85  #[DataProvider('emptyIndicatedValueThrowsExceptionDataProvider')]
86  #[Test]
87  public function ‪emptyIndicatedValueThrowsException(string $aspect, string $value): void
88  {
89  $this->expectException(\LogicException::class);
90  $this->expectExceptionCode(1580225313);
91  new ‪CacheHashConfiguration([$aspect => [$value]]);
92  }
93 
94  public static function ‪equalsResolvesParameterValueDataProvider(): array
95  {
97  [
102  ],
103  [['equals-a', '=equals-b', '^equals', '~equals']],
104  [['equals-a', 'equals-b']],
105  [['eq', 'equals', 'other', 'prefixed-equals-other']],
106  ]);
107  }
108 
109  #[DataProvider('equalsResolvesParameterValueDataProvider')]
110  #[Test]
111  public function ‪equalsResolvesParameterValue(string $aspect, array $values, array $positives, array $negatives): void
112  {
113  $configuration = new ‪CacheHashConfiguration([$aspect => $values]);
114  foreach ($positives as $probe) {
115  self::assertTrue($configuration->equals($aspect, $probe), $probe);
116  }
117  foreach ($negatives as $probe) {
118  self::assertFalse($configuration->equals($aspect, $probe), $probe);
119  }
120  }
121 
122  public static function ‪startsWithResolvesParameterValueDataProvider(): array
123  {
125  [
130  ],
131  [['equals-a', '=equals-b', '^equals', '~equals']],
132  [['equals', 'equals-a', 'equals-b', 'equals-other']],
133  [['eq', 'other', 'prefixed-equals-other']],
134  ]);
135  }
136 
137  #[DataProvider('startsWithResolvesParameterValueDataProvider')]
138  #[Test]
139  public function ‪startsWithResolvesParameterValue(string $aspect, array $values, array $positives, array $negatives): void
140  {
141  $configuration = new ‪CacheHashConfiguration([$aspect => $values]);
142  foreach ($positives as $probe) {
143  self::assertTrue($configuration->startsWith($aspect, $probe), $probe);
144  }
145  foreach ($negatives as $probe) {
146  self::assertFalse($configuration->startsWith($aspect, $probe), $probe);
147  }
148  }
149 
150  public static function ‪containsResolvesParameterValueDataProvider(): array
151  {
153  [
158  ],
159  [['equals-a', '=equals-b', '^equals', '~equals']],
160  [['equals', 'equals-a', 'equals-b', 'equals-other', 'prefixed-equals-other']],
161  [['eq', 'other']],
162  ]);
163  }
164 
165  #[DataProvider('containsResolvesParameterValueDataProvider')]
166  #[Test]
167  public function ‪containsResolvesParameterValue(string $aspect, array $values, array $positives, array $negatives): void
168  {
169  $configuration = new ‪CacheHashConfiguration([$aspect => $values]);
170  foreach ($positives as $probe) {
171  self::assertTrue($configuration->contains($aspect, $probe), $probe);
172  }
173  foreach ($negatives as $probe) {
174  self::assertFalse($configuration->contains($aspect, $probe), $probe);
175  }
176  }
177 
178  public static function ‪appliesResolvesParameterValueDataProvider(): array
179  {
180  // Currently using "contains" data provider, could have own test sets as well
182  }
183 
184  #[DataProvider('appliesResolvesParameterValueDataProvider')]
185  #[Test]
186  public function ‪appliesResolvesParameterValue(string $aspect, array $values, array $positives, array $negatives): void
187  {
188  $configuration = new ‪CacheHashConfiguration([$aspect => $values]);
189  foreach ($positives as $probe) {
190  self::assertTrue($configuration->applies($aspect, $probe), $probe);
191  }
192  foreach ($negatives as $probe) {
193  self::assertFalse($configuration->applies($aspect, $probe), $probe);
194  }
195  }
196 }
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\appliesResolvesParameterValue
‪appliesResolvesParameterValue(string $aspect, array $values, array $positives, array $negatives)
Definition: CacheHashConfigurationTest.php:186
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\emptyIndicatedValueThrowsExceptionDataProvider
‪static emptyIndicatedValueThrowsExceptionDataProvider()
Definition: CacheHashConfigurationTest.php:72
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\equalsResolvesParameterValue
‪equalsResolvesParameterValue(string $aspect, array $values, array $positives, array $negatives)
Definition: CacheHashConfigurationTest.php:111
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\emptyIndicatedValueThrowsException
‪emptyIndicatedValueThrowsException(string $aspect, string $value)
Definition: CacheHashConfigurationTest.php:87
‪TYPO3\CMS\Frontend\Page\CacheHashConfiguration\ASPECT_CACHED_PARAMETERS_WHITELIST
‪const ASPECT_CACHED_PARAMETERS_WHITELIST
Definition: CacheHashConfiguration.php:36
‪TYPO3\CMS\Frontend\Page\CacheHashConfiguration\ASPECT_REQUIRED_CACHE_HASH_PRESENCE_PARAMETERS
‪const ASPECT_REQUIRED_CACHE_HASH_PRESENCE_PARAMETERS
Definition: CacheHashConfiguration.php:39
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\containsResolvesParameterValueDataProvider
‪static containsResolvesParameterValueDataProvider()
Definition: CacheHashConfigurationTest.php:150
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\nonArrayValueThrowsExceptionDataProvider
‪static nonArrayValueThrowsExceptionDataProvider()
Definition: CacheHashConfigurationTest.php:28
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\appliesResolvesParameterValueDataProvider
‪static appliesResolvesParameterValueDataProvider()
Definition: CacheHashConfigurationTest.php:178
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\equalsResolvesParameterValueDataProvider
‪static equalsResolvesParameterValueDataProvider()
Definition: CacheHashConfigurationTest.php:94
‪TYPO3\CMS\Frontend\Tests\Unit\Page
Definition: CacheHashCalculatorTest.php:18
‪TYPO3\CMS\Core\Utility\PermutationUtility
Definition: PermutationUtility.php:24
‪TYPO3\CMS\Frontend\Page\CacheHashConfiguration\ASPECT_EXCLUDED_PARAMETERS
‪const ASPECT_EXCLUDED_PARAMETERS
Definition: CacheHashConfiguration.php:37
‪TYPO3\CMS\Core\Utility\PermutationUtility\meltArrayItems
‪static array[] meltArrayItems(array $payload, array $previousResult=[])
Definition: PermutationUtility.php:72
‪TYPO3\CMS\Frontend\Page\CacheHashConfiguration
Definition: CacheHashConfiguration.php:35
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\startsWithResolvesParameterValueDataProvider
‪static startsWithResolvesParameterValueDataProvider()
Definition: CacheHashConfigurationTest.php:122
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest
Definition: CacheHashConfigurationTest.php:27
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\nonScalarValueThrowsExceptionDataProvider
‪static nonScalarValueThrowsExceptionDataProvider()
Definition: CacheHashConfigurationTest.php:50
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\containsResolvesParameterValue
‪containsResolvesParameterValue(string $aspect, array $values, array $positives, array $negatives)
Definition: CacheHashConfigurationTest.php:167
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\startsWithResolvesParameterValue
‪startsWithResolvesParameterValue(string $aspect, array $values, array $positives, array $negatives)
Definition: CacheHashConfigurationTest.php:139
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\nonScalarValueThrowsException
‪nonScalarValueThrowsException(string $aspect, mixed $value)
Definition: CacheHashConfigurationTest.php:65
‪TYPO3\CMS\Frontend\Tests\Unit\Page\CacheHashConfigurationTest\nonArrayValueThrowsException
‪nonArrayValueThrowsException(string $aspect, mixed $value)
Definition: CacheHashConfigurationTest.php:43