‪TYPO3CMS  ‪main
TestSet.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 
21 {
23 
24  private ?int ‪$targetPageId;
25 
29  private array ‪$applicables;
30 
31  private ?‪Variables ‪$variables = null;
32 
33  public static function ‪create($parentSet = null): self
34  {
35  if (!$parentSet instanceof static) {
36  return new static();
37  }
38  return clone $parentSet;
39  }
40 
41  public function ‪getUrl(): ?‪VariableValue
42  {
43  return ‪$this->url;
44  }
45 
46  public function ‪getTargetPageId(): ?int
47  {
49  }
50 
54  public function ‪getApplicables(string $type = null): array
55  {
56  if ($type === null) {
57  return ‪$this->applicables;
58  }
59  return $this->‪filterApplicables($type);
60  }
61 
62  public function ‪getSingleApplicable(string $type): ?‪Applicable
63  {
64  ‪$applicables = $this->‪filterApplicables($type);
65  if (count(‪$applicables) > 1) {
66  throw new \LogicException(
67  sprintf('Got %dx %s, expected one', count(‪$applicables), $type),
68  1578054920
69  );
70  }
71  return array_values(‪$applicables)[0] ?? null;
72  }
73 
74  public function ‪getVariables(): ?‪Variables
75  {
76  return ‪$this->variables;
77  }
78 
80  {
81  $target = clone $this;
82  foreach (‪$applicables as $applicable) {
83  if (!in_array($applicable, $this->applicables ?? [], true)) {
84  $target->applicables[] = $applicable;
85  }
86  }
87  return $target;
88  }
89 
91  {
92  $target = clone $this;
93  $target->variables = ‪$variables;
94  return $target;
95  }
96 
98  {
99  $target = clone $this;
100  $target->variables = ‪$variables->‪withDefined($target->variables);
101  return $target;
102  }
103 
104  public function ‪withUrl(‪VariableValue ‪$url): self
105  {
106  $target = clone $this;
107  $target->url = ‪$url;
108  return $target;
109  }
110 
111  public function ‪withTargetPageId(int ‪$targetPageId): self
112  {
113  $target = clone $this;
114  $target->targetPageId = ‪$targetPageId;
115  return $target;
116  }
117 
118  public function ‪describe(): string
119  {
120  $descriptions = array_map(
121  static function (‪Applicable $applicable) {
122  return $applicable->‪describe();
123  },
125  );
126  return 'pid: ' . $this->targetPageId . ' | ' . implode(' | ', $descriptions);
127  }
128 
132  private function ‪filterApplicables(string $type): array
133  {
134  ‪$applicables = [];
135  foreach ($this->applicables as $applicable) {
136  if (is_a($applicable, $type)) {
137  ‪$applicables[] = $applicable;
138  } elseif ($applicable instanceof ‪ApplicableConjunction) {
139  ‪$applicables = array_merge(‪$applicables, $applicable->filter($type));
140  }
141  }
142  return ‪$applicables;
143  }
144 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables\withDefined
‪withDefined(?Variables $other)
Definition: Variables.php:55
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\describe
‪describe()
Definition: TestSet.php:118
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\withTargetPageId
‪withTargetPageId(int $targetPageId)
Definition: TestSet.php:111
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\$variables
‪Variables $variables
Definition: TestSet.php:31
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\withUrl
‪withUrl(VariableValue $url)
Definition: TestSet.php:104
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\withVariables
‪withVariables(Variables $variables)
Definition: TestSet.php:90
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables
Definition: Variables.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getVariables
‪getVariables()
Definition: TestSet.php:74
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet
Definition: TestSet.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\$targetPageId
‪int $targetPageId
Definition: TestSet.php:24
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Applicable
Definition: Applicable.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Applicable\describe
‪describe()
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getUrl
‪getUrl()
Definition: TestSet.php:41
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getApplicables
‪Applicable[] getApplicables(string $type=null)
Definition: TestSet.php:54
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getSingleApplicable
‪getSingleApplicable(string $type)
Definition: TestSet.php:62
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\$applicables
‪array $applicables
Definition: TestSet.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\$url
‪VariableValue $url
Definition: TestSet.php:22
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\withMergedVariables
‪withMergedVariables(Variables $variables)
Definition: TestSet.php:97
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder
Definition: Applicable.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getTargetPageId
‪getTargetPageId()
Definition: TestSet.php:46
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\ApplicableConjunction
Definition: ApplicableConjunction.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue
Definition: VariableValue.php:21
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\filterApplicables
‪Applicable[] filterApplicables(string $type)
Definition: TestSet.php:132
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\create
‪static create($parentSet=null)
Definition: TestSet.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\withMergedApplicables
‪withMergedApplicables(Applicable ... $applicables)
Definition: TestSet.php:79