ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilCtrlSingleClassPathTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once __DIR__ . '/ilCtrlPathTestBase.php';
22
29{
30 public function testSinglePathWithUnknownClass(): void
31 {
32 $invalid_class = ilCtrlInvalidGuiClass::class;
34 $this->structure,
35 $this->createMock(ilCtrlContextInterface::class),
36 $invalid_class
37 );
38
39 $this->assertNotNull($path->getException());
40 $this->expectException(ilCtrlException::class);
41 $this->expectExceptionMessage("Class '$invalid_class' was not found in the control structure, try `composer du` to read artifacts.");
42 throw $path->getException();
43 }
44
45 public function testSinglePathWithoutBaseClass(): void
46 {
47 // mocked context that returns no cid-path.
48 $context = $this->createMock(ilCtrlContextInterface::class);
50 ->method('getPath')
51 ->willReturn($this->getPath(null))
52 ;
53
54 $target_class = ilCtrlCommandClass1TestGUI::class;
56 $this->structure,
58 $target_class
59 );
60
61 $this->assertNotNull($path->getException());
62 $this->expectException(ilCtrlException::class);
63 $this->expectExceptionMessage("ilCtrl cannot find a path for '$target_class' that reaches ''");
64 throw $path->getException();
65 }
66
67 public function testSinglePathWithContextBaseClass(): void
68 {
69 // mocked context that returns a cid-path containing a baseclass.
70 $context = $this->createMock(ilCtrlContextInterface::class);
72 ->method('getPath')
73 ->willReturn($this->getPath('0:4'))
74 ;
75
77 $this->structure,
79 ilCtrlCommandClass1TestGUI::class
80 );
81
82 $this->assertEquals('0:2', $path->getCidPath());
83 }
84
86 {
87 // mocked context that returns no cid-path
88 $context = $this->createMock(ilCtrlContextInterface::class);
90 ->method('getPath')
91 ->willReturn($this->getPath(null))
92 ;
93
95 $this->structure,
97 ilCtrlBaseClass1TestGUI::class
98 );
99
100 $this->assertEquals('0', $path->getCidPath());
101 }
102
103 public function testSinglePathWithSameTargetClass(): void
104 {
105 // mocked context that returns a cid-path that already
106 // contains the target class.
107 $context = $this->createMock(ilCtrlContextInterface::class);
109 ->method('getPath')
110 ->willReturn($this->getPath('1:2:3'))
111 ;
112
114 $this->structure,
115 $context,
116 ilCtrlCommandClass2TestGUI::class
117 );
118
119 $this->assertEquals('1:2:3', $path->getCidPath());
120 }
121
123 {
125 $this->structure,
126 $this->createMock(ilCtrlContextInterface::class),
127 ''
128 );
129
130 $this->assertNotNull($path->getException());
131 $this->expectException(ilCtrlException::class);
132 $this->expectExceptionMessage("Class '' was not found in the control structure, try `composer du` to read artifacts.");
133 throw $path->getException();
134 }
135
136 public function testSinglePathBaseclassPriority(): void
137 {
138 // mocked context that returns a cid-path containing a baseclass.
139 $context = $this->createMock(ilCtrlContextInterface::class);
141 ->method('getPath')
142 ->willReturn($this->getPath('0:2')) // ilCtrlBaseClass1TestGUI -> ilCtrlCommandClass1TestGUI
143 ;
144
146 $this->structure,
147 $context,
148 ilCtrlBaseClass2TestGUI::class
149 );
150
151 // baseclasses should have the least priority, therefore the new cid-path
152 // must not be '1' (the cid of ilCtrlBaseClass2TestGUI) but as described,
153 // because the baseclass can also be called by ilCtrlCommandClass1TestGUI.
154 $this->assertEquals('0:2:1', $path->getCidPath());
155 }
156}
Class ilCtrlPathTestBase.
getPath(?string $cid_path=null)
Class ilCtrlSingleClassPathTest.
Class ilCtrlSingleClassPath.
$path
Definition: ltiservices.php:30
$context
Definition: webdav.php:31