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