ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilCtrlArrayClassPathTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once __DIR__ . '/ilCtrlPathTestBase.php';
22
28{
29 public function testArrayPathWithEmptyTargets(): void
30 {
32 $this->structure,
33 $this->createMock(ilCtrlContextInterface::class),
34 []
35 );
36
37 $this->assertNotNull($path->getException());
38 $this->expectException(ilCtrlException::class);
39 $this->expectExceptionMessage(ilCtrlArrayClassPath::class . '::getCidPathByArray must be provided with a list of classes.');
40 throw $path->getException();
41 }
42
44 {
45 $invalid_class = ilCtrlInvalidGuiClass::class;
47 $this->structure,
48 $this->createMock(ilCtrlContextInterface::class),
49 [$invalid_class]
50 );
51
52 $this->assertNotNull($path->getException());
53 $this->expectException(ilCtrlException::class);
54 $this->expectExceptionMessage("Class '$invalid_class' was not found in the control structure, try `composer du` to read artifacts.");
55 throw $path->getException();
56 }
57
58 public function testArrayPathWithUnrelatedTargets(): void
59 {
60 $parent_class = ilCtrlBaseClass2TestGUI::class;
61 $child_class = ilCtrlCommandClass2TestGUI::class;
63 $this->structure,
64 $this->createMock(ilCtrlContextInterface::class),
65 [$parent_class, $child_class]
66 );
67
68 $this->assertNotNull($path->getException());
69 $this->expectException(ilCtrlException::class);
70 $this->expectExceptionMessage("Class '$child_class' is not a child of '$parent_class'.");
71 throw $path->getException();
72 }
73
74 public function testArrayPathWithoutBaseClass(): void
75 {
76 // mocked context that will return path without cid-path.
77 $context = $this->createMock(ilCtrlContextInterface::class);
79 ->method('getPath')
80 ->willReturn($this->getPath(null));
81
82 $first_target_class = ilCtrlCommandClass1TestGUI::class;
83 $second_target_class = ilCtrlCommandClass2TestGUI::class;
85 $this->structure,
87 [$first_target_class, $second_target_class]
88 );
89
90 $this->assertNotNull($path->getException());
91 $this->expectException(ilCtrlException::class);
92 $this->expectExceptionMessage("Class '$first_target_class' is not a baseclass and the current context doesn't have one either.");
93 throw $path->getException();
94 }
95
96 public function testArrayPathWithProvidedBaseClass(): void
97 {
98 // mocked context that will return path without cid-path.
99 $context = $this->createMock(ilCtrlContextInterface::class);
101 ->method('getPath')
102 ->willReturn($this->getPath(null));
103
104 $base_class = ilCtrlBaseClass2TestGUI::class;
105 $first_target_class = ilCtrlCommandClass1TestGUI::class;
106 $second_target_class = ilCtrlCommandClass2TestGUI::class;
108 $this->structure,
109 $context,
110 [$base_class, $first_target_class, $second_target_class]
111 );
112
113 $this->assertEquals('1:2:3', $path->getCidPath());
114 }
115
116 public function testArrayPathWithContextBaseClass(): void
117 {
118 // mocked context that will return path with base-class.
119 $context = $this->createMock(ilCtrlContextInterface::class);
121 ->method('getPath')
122 ->willReturn($this->getPath('1:4'));
123
124 $first_target_class = ilCtrlCommandClass1TestGUI::class;
125 $second_target_class = ilCtrlCommandClass2TestGUI::class;
127 $this->structure,
128 $context,
129 [$first_target_class, $second_target_class]
130 );
131
132 $this->assertEquals('1:2:3', $path->getCidPath());
133 }
134
136 {
137 // mocked context that will return path with first base-class
138 // that can call command class 1-
139 $context = $this->createMock(ilCtrlContextInterface::class);
141 ->method('getPath')
142 ->willReturn($this->getPath('0:2'));
143
144 $new_base_class = ilCtrlBaseClass2TestGUI::class;
145 $first_target_class = ilCtrlCommandClass1TestGUI::class;
146 $second_target_class = ilCtrlCommandClass2TestGUI::class;
148 $this->structure,
149 $context,
150 [$new_base_class, $first_target_class, $second_target_class]
151 );
152
153 $this->assertEquals('1:2:3', $path->getCidPath());
154 }
155}
Class ilCtrlArrayClassPathTest.
Class ilCtrlArrayClassPath.
Class ilCtrlPathTestBase.
getPath(?string $cid_path=null)
$path
Definition: ltiservices.php:30
$context
Definition: webdav.php:31