‪TYPO3CMS  9.5
TestSet.php
Go to the documentation of this file.
1 <?php
2 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 {
23  private ‪$url;
24 
28  private ‪$targetPageId;
29 
33  private ‪$applicables;
34 
38  private ‪$variables;
39 
40  public static function ‪create($parentSet = null): self
41  {
42  if (!$parentSet instanceof static) {
43  return new static();
44  }
45  return clone $parentSet;
46  }
47 
51  public function ‪getUrl(): ?‪VariableValue
52  {
53  return ‪$this->url;
54  }
55 
59  public function ‪getTargetPageId(): ?int
60  {
62  }
63 
68  public function ‪getApplicables(string $type = null): array
69  {
70  if ($type === null) {
71  return ‪$this->applicables;
72  }
73  return $this->‪filterApplicables($type);
74  }
75 
76  public function ‪getSingleApplicable(string $type): ?Applicable
77  {
78  ‪$applicables = $this->‪filterApplicables($type);
79  if (count(‪$applicables) > 1) {
80  throw new \LogicException(
81  sprintf('Got %dx %s, expected one', count(‪$applicables), $type),
82  1578054920
83  );
84  }
85  return array_values(‪$applicables)[0] ?? null;
86  }
87 
91  public function ‪getVariables(): ?‪Variables
92  {
93  return ‪$this->variables;
94  }
95 
97  {
98  $target = clone $this;
99  foreach (‪$applicables as $applicable) {
100  if (!in_array($applicable, $this->applicables ?? [], true)) {
101  $target->applicables[] = $applicable;
102  }
103  }
104  return $target;
105  }
106 
107  public function ‪withVariables(‪Variables ‪$variables): self
108  {
109  $target = clone $this;
110  $target->variables = ‪$variables;
111  return $target;
112  }
113 
114  public function ‪withMergedVariables(‪Variables ‪$variables): self
115  {
116  $target = clone $this;
117  $target->variables = ‪$variables->‪withDefined($target->variables);
118  return $target;
119  }
120 
121  public function ‪withUrl(‪VariableValue ‪$url): self
122  {
123  $target = clone $this;
124  $target->url = ‪$url;
125  return $target;
126  }
127 
128  public function ‪withTargetPageId(int ‪$targetPageId): self
129  {
130  $target = clone $this;
131  $target->targetPageId = ‪$targetPageId;
132  return $target;
133  }
134 
135  public function ‪describe(): string
136  {
137  $descriptions = array_map(
138  function (‪Applicable $applicable) {
139  return $applicable->‪describe();
140  },
142  );
143  return 'pid: ' . $this->targetPageId . ' | ' . implode(' | ', $descriptions);
144  }
145 
150  private function ‪filterApplicables(string $type): array
151  {
152  ‪$applicables = [];
153  foreach ($this->applicables as $applicable) {
154  if (is_a($applicable, $type)) {
155  ‪$applicables[] = $applicable;
156  } elseif ($applicable instanceof ApplicableConjunction) {
157  ‪$applicables = array_merge(‪$applicables, $applicable->filter($type));
158  }
159  }
160  return ‪$applicables;
161  }
162 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables\withDefined
‪withDefined(?Variables $other)
Definition: Variables.php:53
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\describe
‪describe()
Definition: TestSet.php:131
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\withTargetPageId
‪withTargetPageId(int $targetPageId)
Definition: TestSet.php:124
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\$variables
‪Variables $variables
Definition: TestSet.php:34
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\withUrl
‪withUrl(VariableValue $url)
Definition: TestSet.php:117
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\$targetPageId
‪int null $targetPageId
Definition: TestSet.php:26
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\withVariables
‪withVariables(Variables $variables)
Definition: TestSet.php:103
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Variables
Definition: Variables.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\$applicables
‪Applicable[] $applicables
Definition: TestSet.php:30
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet
Definition: TestSet.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\Applicable
Definition: Applicable.php:19
‪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:55
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getVariables
‪Variables getVariables()
Definition: TestSet.php:87
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getApplicables
‪Applicable[] getApplicables(string $type=null)
Definition: TestSet.php:64
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\$url
‪VariableValue null $url
Definition: TestSet.php:22
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getSingleApplicable
‪getSingleApplicable(string $type)
Definition: TestSet.php:72
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\getUrl
‪VariableValue getUrl()
Definition: TestSet.php:47
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\withMergedVariables
‪withMergedVariables(Variables $variables)
Definition: TestSet.php:110
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder
Definition: Applicable.php:3
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\ApplicableConjunction
Definition: ApplicableConjunction.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\VariableValue
Definition: VariableValue.php:19
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\filterApplicables
‪Applicable[] filterApplicables(string $type)
Definition: TestSet.php:146
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\create
‪static create($parentSet=null)
Definition: TestSet.php:36
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Framework\Builder\TestSet\withMergedApplicables
‪withMergedApplicables(Applicable ... $applicables)
Definition: TestSet.php:92