ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
PathConditionsCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 
32 class PathConditionsCollectionTest extends TestCase
33 {
35  {
36  return new class (new NullFactory(), $path, $this) extends PathConditionsCollection {
37  public function __construct(
38  PathFactory $path_factory,
39  PathInterface $path,
40  protected PathConditionsCollectionTest $path_conditions_collection_test
41  ) {
42  parent::__construct($path_factory, $path);
43  }
44 
45  protected function buildPathFromSteps(array $steps, bool $is_relative, bool $leads_to_exactly_one): PathInterface
46  {
47  return $this->path_conditions_collection_test->getMockPath($steps, $is_relative, $leads_to_exactly_one);
48  }
49  };
50  }
51 
52  public function getMockStep(string|StepToken $name): StepInterface
53  {
54  return new class ($name) extends NullStep {
55  public function __construct(protected string|StepToken $name)
56  {
57  }
58 
59  public function name(): string|StepToken
60  {
61  return $this->name;
62  }
63  };
64  }
65 
69  public function getMockPath(
70  array $steps,
71  bool $is_relative,
72  bool $leads_exactly_to_one
73  ): PathInterface {
74  return new class ($steps, $is_relative, $leads_exactly_to_one) extends NullPath {
78  public function __construct(
79  protected array $steps,
80  protected bool $is_relative,
81  protected bool $leads_exactly_to_one
82  ) {
83  }
84 
85  public function isRelative(): bool
86  {
87  return $this->is_relative;
88  }
89 
90  public function leadsToExactlyOneElement(): bool
91  {
92  return $this->leads_exactly_to_one;
93  }
94 
95  public function steps(): \Generator
96  {
97  yield from $this->steps;
98  }
99 
100  public function toString(): string
101  {
102  $step_string = '';
103  foreach ($this->steps as $step) {
104  $step_string .= '/' . ($step->name() instanceof StepToken ? $step->name()->value : $step->name());
105  }
106  return $step_string;
107  }
108  };
109  }
110 
111  public function testPathWithoutConditions_001(): void
112  {
113  $path_conditions = $this->getPartiallyMockedPathConditionsCollection($this->getMockPath(
114  [
115  $this->getMockStep('general'),
116  $this->getMockStep('keyword'),
117  $this->getMockStep('string')
118  ],
119  false,
120  false
121  ));
122  $this->assertSame(
123  '/general/keyword/string',
124  $path_conditions->getPathWithoutConditions()->toString(),
125  );
126  $this->assertSame(
127  '',
128  $path_conditions->getConditionPathByStepName('general')->toString(),
129  );
130  $this->assertSame(
131  '',
132  $path_conditions->getConditionPathByStepName('keyword')->toString(),
133  );
134  $this->assertSame(
135  '',
136  $path_conditions->getConditionPathByStepName('string')->toString(),
137  );
138  $this->assertSame(
139  '',
140  $path_conditions->getConditionPathByStepName('not_a_step')->toString(),
141  );
142  }
143 
144  public function testPathWithoutConditions_002(): void
145  {
146  $path_conditions = $this->getPartiallyMockedPathConditionsCollection($this->getMockPath(
147  [],
148  false,
149  false
150  ));
151  $this->assertSame(
152  '',
153  $path_conditions->getPathWithoutConditions()->toString(),
154  );
155  $this->assertSame(
156  '',
157  $path_conditions->getConditionPathByStepName('not_a_step')->toString(),
158  );
159  }
160 
161  public function testPathWithNestedConditions_001(): void
162  {
163  $path_conditions = $this->getPartiallyMockedPathConditionsCollection($this->getMockPath(
164  [
165  $this->getMockStep('start'),
166  $this->getMockStep('step_1'),
167  $this->getMockStep('condition'),
168  $this->getMockStep('nested_condition'),
171  $this->getMockStep('target')
172  ],
173  false,
174  false
175  ));
176  $this->assertSame(
177  '/start/step_1/target',
178  $path_conditions->getPathWithoutConditions()->toString(),
179  );
180  $this->assertSame(
181  '',
182  $path_conditions->getConditionPathByStepName('start')->toString(),
183  );
184  $this->assertSame(
185  '/condition/nested_condition/^/^',
186  $path_conditions->getConditionPathByStepName('step_1')->toString(),
187  );
188  $this->assertSame(
189  '',
190  $path_conditions->getConditionPathByStepName('target')->toString(),
191  );
192  $this->assertSame(
193  '',
194  $path_conditions->getConditionPathByStepName('not_a_step')->toString(),
195  );
196  }
197 
198  public function testPathWithNestedConditions_002(): void
199  {
200  $path_conditions = $this->getPartiallyMockedPathConditionsCollection($this->getMockPath(
201  [
202  $this->getMockStep('start'),
203  $this->getMockStep('step_1'),
204  $this->getMockStep('condition'),
205  $this->getMockStep('nested_condition'),
206  $this->getMockStep('nested_nested_condition'),
210  $this->getMockStep('target')
211  ],
212  false,
213  false
214  ));
215  $this->assertSame(
216  '/start/step_1/target',
217  $path_conditions->getPathWithoutConditions()->toString(),
218  );
219  $this->assertSame(
220  '',
221  $path_conditions->getConditionPathByStepName('start')->toString(),
222  );
223  $this->assertSame(
224  '/condition/nested_condition/nested_nested_condition/^/^/^',
225  $path_conditions->getConditionPathByStepName('step_1')->toString(),
226  );
227  $this->assertSame(
228  '',
229  $path_conditions->getConditionPathByStepName('target')->toString(),
230  );
231  $this->assertSame(
232  '',
233  $path_conditions->getConditionPathByStepName('not_a_step')->toString(),
234  );
235  }
236 
237  public function testPathWithChainedConditions_001(): void
238  {
239  $path_conditions = $this->getPartiallyMockedPathConditionsCollection($this->getMockPath(
240  [
241  $this->getMockStep('start'),
242  $this->getMockStep('step_1'),
243  $this->getMockStep('condition'),
245  $this->getMockStep('target')
246  ],
247  false,
248  false
249  ));
250  $this->assertSame(
251  '/start/step_1/target',
252  $path_conditions->getPathWithoutConditions()->toString(),
253  );
254  $this->assertSame(
255  '',
256  $path_conditions->getConditionPathByStepName('start')->toString(),
257  );
258  $this->assertSame(
259  '/condition/^',
260  $path_conditions->getConditionPathByStepName('step_1')->toString(),
261  );
262  $this->assertSame(
263  '',
264  $path_conditions->getConditionPathByStepName('target')->toString(),
265  );
266  $this->assertSame(
267  '',
268  $path_conditions->getConditionPathByStepName('not_a_step')->toString(),
269  );
270  }
271 
272  public function testPathWithChainedConditions_002(): void
273  {
274  $path_conditions = $this->getPartiallyMockedPathConditionsCollection($this->getMockPath(
275  [
276  $this->getMockStep('start'),
277  $this->getMockStep('step_1'),
278  $this->getMockStep('condition_1'),
280  $this->getMockStep('step_2'),
281  $this->getMockStep('condition_2'),
283  $this->getMockStep('condition_3'),
285  $this->getMockStep('target')
286  ],
287  false,
288  false
289  ));
290  $this->assertSame(
291  '/start/step_1/step_2/target',
292  $path_conditions->getPathWithoutConditions()->toString(),
293  );
294  $this->assertSame(
295  '',
296  $path_conditions->getConditionPathByStepName('start')->toString(),
297  );
298  $this->assertSame(
299  '/condition_1/^',
300  $path_conditions->getConditionPathByStepName('step_1')->toString(),
301  );
302  $this->assertSame(
303  '/condition_2/^/condition_3/^',
304  $path_conditions->getConditionPathByStepName('step_2')->toString(),
305  );
306  $this->assertSame(
307  '',
308  $path_conditions->getConditionPathByStepName('target')->toString(),
309  );
310  $this->assertSame(
311  '',
312  $path_conditions->getConditionPathByStepName('not_a_step')->toString(),
313  );
314  }
315 
317  {
318  $path_conditions = $this->getPartiallyMockedPathConditionsCollection($this->getMockPath(
319  [
320  $this->getMockStep('start'),
321  $this->getMockStep('condition_1'),
322  $this->getMockStep('nested_condition_1'),
325  $this->getMockStep('step_1'),
326  $this->getMockStep('condition_2'),
328  $this->getMockStep('step_2'),
329  $this->getMockStep('condition_3'),
331  $this->getMockStep('condition_4'),
332  $this->getMockStep('nested_condition_4'),
333  $this->getMockStep('nested_nested_condition_4'),
337  $this->getMockStep('target')
338  ],
339  false,
340  false
341  ));
342  $this->assertSame(
343  '/start/step_1/step_2/target',
344  $path_conditions->getPathWithoutConditions()->toString(),
345  );
346  $this->assertSame(
347  '/condition_1/nested_condition_1/^/^',
348  $path_conditions->getConditionPathByStepName('start')->toString(),
349  );
350  $this->assertSame(
351  '/condition_2/^',
352  $path_conditions->getConditionPathByStepName('step_1')->toString(),
353  );
354  $this->assertSame(
355  '/condition_3/^/condition_4/nested_condition_4/nested_nested_condition_4/^/^/^',
356  $path_conditions->getConditionPathByStepName('step_2')->toString(),
357  );
358  $this->assertSame(
359  '',
360  $path_conditions->getConditionPathByStepName('target')->toString(),
361  );
362  $this->assertSame(
363  '',
364  $path_conditions->getConditionPathByStepName('not_a_step')->toString(),
365  );
366  }
367 
369  {
370  $path_conditions = $this->getPartiallyMockedPathConditionsCollection($this->getMockPath(
371  [
372  $this->getMockStep('start'),
373  $this->getMockStep('condition_1'),
374  $this->getMockStep('nested_condition_1'),
377  $this->getMockStep('step_1'),
378  $this->getMockStep('condition_2'),
380  $this->getMockStep('step_2'),
381  $this->getMockStep('condition_3'),
383  $this->getMockStep('condition_4'),
384  $this->getMockStep('nested_condition_4'),
385  $this->getMockStep('nested_nested_condition_4'),
389  $this->getMockStep('target'),
390  $this->getMockStep('condition_5'),
391  $this->getMockStep('nested_condition_5'),
394  ],
395  false,
396  false
397  ));
398  $this->assertSame(
399  '/start/step_1/step_2/target',
400  $path_conditions->getPathWithoutConditions()->toString(),
401  );
402  $this->assertSame(
403  '/condition_1/nested_condition_1/^/^',
404  $path_conditions->getConditionPathByStepName('start')->toString(),
405  );
406  $this->assertSame(
407  '/condition_2/^',
408  $path_conditions->getConditionPathByStepName('step_1')->toString(),
409  );
410  $this->assertSame(
411  '/condition_3/^/condition_4/nested_condition_4/nested_nested_condition_4/^/^/^',
412  $path_conditions->getConditionPathByStepName('step_2')->toString(),
413  );
414  $this->assertSame(
415  '/condition_5/nested_condition_5/^/^',
416  $path_conditions->getConditionPathByStepName('target')->toString(),
417  );
418  $this->assertSame(
419  '',
420  $path_conditions->getConditionPathByStepName('not_a_step')->toString(),
421  );
422  }
423 }
$path
Definition: ltiservices.php:29
getMockPath(array $steps, bool $is_relative, bool $leads_exactly_to_one)
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
StepToken
The string representation of these tokens must not occur as names of metadata elements.
Definition: StepToken.php:27
__construct(Container $dic, ilPlugin $plugin)