ILIAS  release_8 Revision v8.24
ilCtrlArrayClassPathTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2021 Thibeau Fuhrer <thf@studer-raimann.ch> Extended GPL, see docs/LICENSE */
6
7require_once __DIR__ . '/ilCtrlPathTestBase.php';
8
14{
15 public function testArrayPathWithEmptyTargets(): void
16 {
18 $this->structure,
19 $this->createMock(ilCtrlContextInterface::class),
20 []
21 );
22
23 $this->assertNotNull($path->getException());
24 $this->expectException(ilCtrlException::class);
25 $this->expectExceptionMessage(ilCtrlArrayClassPath::class . '::getCidPathByArray must be provided with a list of classes.');
26 throw $path->getException();
27 }
28
30 {
31 $invalid_class = ilCtrlInvalidGuiClass::class;
33 $this->structure,
34 $this->createMock(ilCtrlContextInterface::class),
35 [$invalid_class]
36 );
37
38 $this->assertNotNull($path->getException());
39 $this->expectException(ilCtrlException::class);
40 $this->expectExceptionMessage("Class '$invalid_class' was not found in the control structure, try `composer du` to read artifacts.");
41 throw $path->getException();
42 }
43
44 public function testArrayPathWithUnrelatedTargets(): void
45 {
46 $parent_class = ilCtrlBaseClass2TestGUI::class;
47 $child_class = ilCtrlCommandClass2TestGUI::class;
49 $this->structure,
50 $this->createMock(ilCtrlContextInterface::class),
51 [$parent_class, $child_class]
52 );
53
54 $this->assertNotNull($path->getException());
55 $this->expectException(ilCtrlException::class);
56 $this->expectExceptionMessage("Class '$child_class' is not a child of '$parent_class'.");
57 throw $path->getException();
58 }
59
60 public function testArrayPathWithoutBaseClass(): void
61 {
62 // mocked context that will return path without cid-path.
63 $context = $this->createMock(ilCtrlContextInterface::class);
65 ->method('getPath')
66 ->willReturn($this->getPath(null));
67
68 $first_target_class = ilCtrlCommandClass1TestGUI::class;
69 $second_target_class = ilCtrlCommandClass2TestGUI::class;
71 $this->structure,
73 [$first_target_class, $second_target_class]
74 );
75
76 $this->assertNotNull($path->getException());
77 $this->expectException(ilCtrlException::class);
78 $this->expectExceptionMessage("Class '$first_target_class' is not a baseclass and the current context doesn't have one either.");
79 throw $path->getException();
80 }
81
82 public function testArrayPathWithProvidedBaseClass(): void
83 {
84 // mocked context that will return path without cid-path.
85 $context = $this->createMock(ilCtrlContextInterface::class);
87 ->method('getPath')
88 ->willReturn($this->getPath(null));
89
90 $base_class = ilCtrlBaseClass2TestGUI::class;
91 $first_target_class = ilCtrlCommandClass1TestGUI::class;
92 $second_target_class = ilCtrlCommandClass2TestGUI::class;
94 $this->structure,
96 [$base_class, $first_target_class, $second_target_class]
97 );
98
99 $this->assertEquals('1:2:3', $path->getCidPath());
100 }
101
102 public function testArrayPathWithContextBaseClass(): void
103 {
104 // mocked context that will return path with base-class.
105 $context = $this->createMock(ilCtrlContextInterface::class);
107 ->method('getPath')
108 ->willReturn($this->getPath('1:4'));
109
110 $first_target_class = ilCtrlCommandClass1TestGUI::class;
111 $second_target_class = ilCtrlCommandClass2TestGUI::class;
113 $this->structure,
114 $context,
115 [$first_target_class, $second_target_class]
116 );
117
118 $this->assertEquals('1:2:3', $path->getCidPath());
119 }
120
122 {
123 // mocked context that will return path with first base-class
124 // that can call command class 1-
125 $context = $this->createMock(ilCtrlContextInterface::class);
127 ->method('getPath')
128 ->willReturn($this->getPath('0:2'));
129
130 $new_base_class = ilCtrlBaseClass2TestGUI::class;
131 $first_target_class = ilCtrlCommandClass1TestGUI::class;
132 $second_target_class = ilCtrlCommandClass2TestGUI::class;
134 $this->structure,
135 $context,
136 [$new_base_class, $first_target_class, $second_target_class]
137 );
138
139 $this->assertEquals('1:2:3', $path->getCidPath());
140 }
141}
Class ilCtrlArrayClassPathTest.
Class ilCtrlArrayClassPath.
Class ilCtrlPathTestBase.
getPath(string $cid_path=null)
$path
Definition: ltiservices.php:32
$context
Definition: webdav.php:29