18use PHPUnit\Framework\TestCase;
20class ilCtrlStructureReaderTest
extends TestCase
22 protected function setUp() : void
24 $this->db = $this->createMock(\ilDBInterface::class);
26 public function _shouldDescendToDirectory(
string $dir)
28 return $this->shouldDescendToDirectory($dir);
30 public function _getFilesIn(
string $dir)
32 return $this->getFilesIn($dir);
34 public function _isInterestingFile(
string $file)
36 return $this->isInterestingFile($file);
38 public function _getGUIClassNameFromClassPath(
string $file)
40 return $this->getGUIClassNameFromClassPath($file);
42 public function _getIlCtrlCalls(
string $content)
44 return $this->getIlCtrlCalls($content);
46 public function _getIlCtrlIsCalledBy(
string $content)
48 return $this->getIlCtrlIsCalledBy($content);
50 public function _containsClassDefinitionFor(
string $class,
string $content)
52 return $this->containsClassDefinitionFor($class, $content);
54 protected function getILIASAbsolutePath() : string
62 protected function normalizePath(
string $path) : string
70 public function testSmoke()
72 $this->assertInstanceOf(ilCtrlStructureReader::class, $this->reader);
75 public function testReadSmoke()
77 $dir = __DIR__ .
"/test_dir";
78 $result = $this->reader->_readDirTo($dir);
79 $this->assertInstanceOf(\ilCtrlStructure::class,
$result);
82 public function testReadClassScriptIsAsExpected()
84 $dir = __DIR__ .
"/test_dir";
85 $result = $this->reader->_readDirTo($dir);
87 $expected_class_script = [
88 "ilmytestinggui" =>
"$dir/class.ilMyTestingGUI.php"
91 $expected_class_script,
92 iterator_to_array(
$result->getClassScripts())
96 public function testReadClassChildsIsAsExpected()
98 $dir = __DIR__ .
"/test_dir/";
99 $result = $this->reader->_readDirTo($dir);
101 $expected_class_childs = [
102 "ilmytestinggui" => [
103 "ilmyothertestinggui"
105 "ilmythirdtestinggui" => [
110 $expected_class_childs,
111 iterator_to_array(
$result->getClassChildren())
115 public function testReadRemovesDuplicateCallsInDatabase()
117 $this->expectException(\Exception::class);
119 $dir = __DIR__ .
"/test_dir/";
121 $this->reader->comp_prefix =
"";
122 $ctrl_structure = new \ilCtrlStructure([
123 "ilmytestinggui" =>
"/some/other/dir/class.ilMyTestingGUI.php"
127 ->will($this->returnCallback(
function ($v, $_) {
132 ->will($this->returnCallback(
function (
$f, $v, $_, $__) {
133 return "$f = \"$v\"";
135 $this->db->expects($this->exactly(4))
136 ->method(
"manipulate")
138 [
"DELETE FROM ctrl_classfile WHERE comp_prefix = \"\""],
139 [
"DELETE FROM ctrl_classfile WHERE comp_prefix = \"\""],
140 [
"DELETE FROM ctrl_calls WHERE comp_prefix = \"\""],
141 [
"DELETE FROM ctrl_calls WHERE comp_prefix IS NULL"]
144 $result = $this->reader->_readDirTo($dir, $ctrl_structure);
147 public function testReadRemovesDuplicateFilesInDatabaseIfCompPrefixIsSet()
149 $this->expectException(\Exception::class);
151 $dir = __DIR__ .
"/test_dir/";
152 $my_comp_prefix =
"mcp";
154 $this->reader->comp_prefix = $my_comp_prefix;
155 $ctrl_structure = new \ilCtrlStructure([
156 "ilmytestinggui" =>
"/some/other/dir/class.ilMyTestingGUI.php"
160 ->will($this->returnCallback(
function ($v, $_) {
165 ->will($this->returnCallback(
function (
$f, $v, $_, $__) {
166 return "$f = \"$v\"";
168 $this->db->expects($this->exactly(2))
169 ->method(
"manipulate")
171 [
"DELETE FROM ctrl_classfile WHERE comp_prefix = \"$my_comp_prefix\""],
172 [
"DELETE FROM ctrl_calls WHERE comp_prefix = \"$my_comp_prefix\""]
175 $result = $this->reader->_readDirTo($dir, $ctrl_structure);
178 public function testShouldDescendToDirectory()
180 $this->assertTrue($this->reader->_shouldDescendToDirectory(
"/foo"));
181 $this->assertTrue($this->reader->_shouldDescendToDirectory(
"/bar"));
182 $this->assertFalse($this->reader->_shouldDescendToDirectory(
"/data"));
183 $this->assertFalse($this->reader->_shouldDescendToDirectory(
"/Customizing"));
186 public function testFilesInDir()
188 $dir = __DIR__ .
"/test_dir";
190 [
"class.ilMyTestingGUI.php",
"$dir/class.ilMyTestingGUI.php"],
191 [
"test_file",
"$dir/sub_test_dir/test_file"]
193 $result = iterator_to_array($this->reader->_getFilesIn($dir));
196 $this->assertEquals($expected,
$result);
199 public function testIsInterestingFile()
201 $this->assertFalse($this->reader->_isInterestingFile(
"ilSCORM13Player.php"));
202 $this->assertTrue($this->reader->_isInterestingFile(
"class.ilSCORM13PlayerGUI.php"));
203 $this->assertTrue($this->reader->_isInterestingFile(
"class.ilMyTestingGUI.php"));
204 $this->assertFalse($this->reader->_isInterestingFile(
"foo.php"));
205 $this->assertFalse($this->reader->_isInterestingFile(
"picture.png"));
206 $this->assertFalse($this->reader->_isInterestingFile(
"icon.svg"));
207 $this->assertFalse($this->reader->_isInterestingFile(
"data.json"));
210 public function testGetGUIClassNameFromClassPath()
212 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"/my/dir/ilSCORM13Player.php"));
213 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"\\my\\dir\\ilSCORM13Player.php"));
214 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"c:\\my\\dir\\ilSCORM13Player.php"));
215 $this->assertEquals(
"ilscorm13playergui", $this->reader->_getGUIClassNameFromClassPath(
"/my/dir/class.ilSCORM13PlayerGUI.php"));
216 $this->assertEquals(
"ilscorm13playergui", $this->reader->_getGUIClassNameFromClassPath(
"\\my\\dir\\class.ilSCORM13PlayerGUI.php"));
217 $this->assertEquals(
"ilscorm13playergui", $this->reader->_getGUIClassNameFromClassPath(
"c:\\my\\dir\\class.ilSCORM13PlayerGUI.php"));
218 $this->assertEquals(
"ilmytestinggui", $this->reader->_getGUIClassNameFromClassPath(
"/my/dir/class.ilMyTestingGUI.php"));
219 $this->assertEquals(
"ilmytestinggui", $this->reader->_getGUIClassNameFromClassPath(
"\\my\\dir\\class.ilMyTestingGUI.php"));
220 $this->assertEquals(
"ilmytestinggui", $this->reader->_getGUIClassNameFromClassPath(
"c:\\my\\dir\\class.ilMyTestingGUI.php"));
221 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"/my/dir/foo.php"));
222 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"\\my\\dir\\foo.php"));
223 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"c:\\my\\dir\\foo.php"));
224 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"/my/dir/picture.png"));
225 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"\\my\\dir\\picture.png"));
226 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"c:\\my\\dir\\picture.png"));
227 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"/my/dir/icon.svg"));
228 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"\\my\\dir\\icon.svg"));
229 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"c:\\my\\dir\\icon.svg"));
230 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"/my/dir/data.json"));
231 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"\\my\\dir\\data.json"));
232 $this->assertNull($this->reader->_getGUIClassNameFromClassPath(
"c:\\my\\dir\\data.json"));
235 public function testGetIlCtrlCallsNoContent()
237 $gen = $this->reader->_getIlCtrlCalls(
239class SomeRandomClass {
243 $this->assertNull($gen);
246 public function testGetIlCtrlCallsWithContent()
248 list($parent, $children) = $this->reader->_getIlCtrlCalls(
254require_once
"./Services/Container/classes/class.ilContainerGUI.php";
273 "ilcourseregistrationgui",
274 "ilcourseobjectivesgui",
275 "ilobjcoursegroupinggui",
277 "illearningprogressgui",
279 "ilrepositorysearchgui"
285 $this->assertEquals(
"ilobjcoursegui", $parent);
286 $this->assertEquals($expected, $children);
289 public function testGetIlCtrlIsCalledByNoContent()
291 $gen = $this->reader->_getIlCtrlIsCalledBy(
293class SomeRandomClass {
297 $this->assertNull($gen);
300 public function testGetIlCtrlIsCalledByWithContent()
302 list($parent, $children) = $this->reader->_getIlCtrlIsCalledBy(
308require_once
"./Services/Container/classes/class.ilContainerGUI.php";
327 "ilcourseregistrationgui",
328 "ilcourseobjectivesgui",
329 "ilobjcoursegroupinggui",
331 "illearningprogressgui",
333 "ilrepositorysearchgui"
339 $this->assertEquals(
"ilobjcoursegui", $parent);
340 $this->assertEquals($expected, $children);
343 public function testContainsClassDefinitionFor()
345 $res = $this->reader->_containsClassDefinitionFor(
348class SomeRandomClass {
352 $this->assertTrue(
$res);
355 public function testDoesNotContainClassDefinitionFor()
357 $res = $this->reader->_containsClassDefinitionFor(
360class fooSomeRandomClass {
364 $this->assertFalse(
$res);
368 public function testGetIlCtrlCallsWithNamespaces() : void
370 list($parent, $children) = $this->reader->_getIlCtrlCalls(
373namespace ILIAS\UICore;
383 $expected = array_map(
"strtolower", [
384 "ilFormPropertyDispatchGUI",
385 "ILIAS\UICore\Test2GUI"
391 $this->assertEquals(strtolower(
"ILIAS\UICore\TestGUI"), $parent);
392 $this->assertEquals($expected, $children);
396 public function testGetIlCtrlIsCalledByWithNamespaces() : void
398 list($parent, $children) = $this->reader->_getIlCtrlIsCalledBy(
401namespace ILIAS\UICore;
411 $expected = array_map(
"strtolower", [
412 "ilUIPluginRouterGUI",
413 "ILIAS\UICore\Test3GUI"
419 $this->assertEquals(strtolower(
"ILIAS\UICore\TestGUI"), $parent);
420 $this->assertEquals($expected, $children);
An exception for terminatinating execution or to throw for unit testing.
Class ilCtrlStructureReader.
The CtrlStructure knows how GUIs call each other and where the code of the guis is located.
Class ChatMainBarProvider \MainMenu\Provider.
foreach($_POST as $key=> $value) $res