ILIAS  release_8 Revision v8.24
ilCtrlSingleClassPathTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
20require_once __DIR__ . '/ilCtrlPathTestBase.php';
21
28{
29 public function testSinglePathWithUnknownClass(): void
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 testSinglePathWithoutBaseClass(): void
45 {
46 // mocked context that returns no cid-path.
47 $context = $this->createMock(ilCtrlContextInterface::class);
49 ->method('getPath')
50 ->willReturn($this->getPath(null))
51 ;
52
53 $target_class = ilCtrlCommandClass1TestGUI::class;
55 $this->structure,
57 $target_class
58 );
59
60 $this->assertNotNull($path->getException());
61 $this->expectException(ilCtrlException::class);
62 $this->expectExceptionMessage("ilCtrl cannot find a path for '$target_class' that reaches ''");
63 throw $path->getException();
64 }
65
66 public function testSinglePathWithContextBaseClass(): void
67 {
68 // mocked context that returns a cid-path containing a baseclass.
69 $context = $this->createMock(ilCtrlContextInterface::class);
71 ->method('getPath')
72 ->willReturn($this->getPath('0:4'))
73 ;
74
76 $this->structure,
78 ilCtrlCommandClass1TestGUI::class
79 );
80
81 $this->assertEquals('0:2', $path->getCidPath());
82 }
83
85 {
86 // mocked context that returns no cid-path
87 $context = $this->createMock(ilCtrlContextInterface::class);
89 ->method('getPath')
90 ->willReturn($this->getPath(null))
91 ;
92
94 $this->structure,
96 ilCtrlBaseClass1TestGUI::class
97 );
98
99 $this->assertEquals('0', $path->getCidPath());
100 }
101
102 public function testSinglePathWithSameTargetClass(): void
103 {
104 // mocked context that returns a cid-path that already
105 // contains the target class.
106 $context = $this->createMock(ilCtrlContextInterface::class);
108 ->method('getPath')
109 ->willReturn($this->getPath('1:2:3'))
110 ;
111
113 $this->structure,
114 $context,
115 ilCtrlCommandClass2TestGUI::class
116 );
117
118 $this->assertEquals('1:2:3', $path->getCidPath());
119 }
120
122 {
124 $this->structure,
125 $this->createMock(ilCtrlContextInterface::class),
126 ''
127 );
128
129 $this->assertNotNull($path->getException());
130 $this->expectException(ilCtrlException::class);
131 $this->expectExceptionMessage("Class '' was not found in the control structure, try `composer du` to read artifacts.");
132 throw $path->getException();
133 }
134
135 public function testSinglePathBaseclassPriority(): void
136 {
137 // mocked context that returns a cid-path containing a baseclass.
138 $context = $this->createMock(ilCtrlContextInterface::class);
140 ->method('getPath')
141 ->willReturn($this->getPath('0:2')) // ilCtrlBaseClass1TestGUI -> ilCtrlCommandClass1TestGUI
142 ;
143
145 $this->structure,
146 $context,
147 ilCtrlBaseClass2TestGUI::class
148 );
149
150 // baseclasses should have the least priority, therefore the new cid-path
151 // must not be '1' (the cid of ilCtrlBaseClass2TestGUI) but as described,
152 // because the baseclass can also be called by ilCtrlCommandClass1TestGUI.
153 $this->assertEquals('0:2:1', $path->getCidPath());
154 }
155}
Class ilCtrlPathTestBase.
getPath(string $cid_path=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32
$context
Definition: webdav.php:29