ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCtrlStructureReaderTest Class Reference
+ Inheritance diagram for ilCtrlStructureReaderTest:
+ Collaboration diagram for ilCtrlStructureReaderTest:

Public Member Functions

 testSmoke ()
 
 testReadSmoke ()
 
 testReadClassScriptIsAsExpected ()
 
 testReadClassChildsIsAsExpected ()
 
 testReadRemovesDuplicateCallsInDatabase ()
 
 testReadRemovesDuplicateFilesInDatabaseIfCompPrefixIsSet ()
 
 testShouldDescendToDirectory ()
 
 testFilesInDir ()
 
 testIsInterestingFile ()
 
 testGetGUIClassNameFromClassPath ()
 
 testGetIlCtrlCallsNoContent ()
 
 testGetIlCtrlCallsWithContent ()
 
 testGetIlCtrlIsCalledByNoContent ()
 
 testGetIlCtrlIsCalledByWithContent ()
 
 testContainsClassDefinitionFor ()
 
 testDoesNotContainClassDefinitionFor ()
 
 testGetIlCtrlCallsWithNamespaces ()
 
 testGetIlCtrlIsCalledByWithNamespaces ()
 

Protected Member Functions

 setUp ()
 

Detailed Description

Definition at line 20 of file ilCtrlStructureReaderTest.php.

Member Function Documentation

◆ setUp()

ilCtrlStructureReaderTest::setUp ( )
protected

Definition at line 22 of file ilCtrlStructureReaderTest.php.

22  : void
23  {
24  $this->db = $this->createMock(\ilDBInterface::class);
25  $this->reader = (new class() extends ilCtrlStructureReader {
26  public function _shouldDescendToDirectory(string $dir)
27  {
28  return $this->shouldDescendToDirectory($dir);
29  }
30  public function _getFilesIn(string $dir)
31  {
32  return $this->getFilesIn($dir);
33  }
34  public function _isInterestingFile(string $file)
35  {
36  return $this->isInterestingFile($file);
37  }
38  public function _getGUIClassNameFromClassPath(string $file)
39  {
40  return $this->getGUIClassNameFromClassPath($file);
41  }
42  public function _getIlCtrlCalls(string $content)
43  {
44  return $this->getIlCtrlCalls($content);
45  }
46  public function _getIlCtrlIsCalledBy(string $content)
47  {
48  return $this->getIlCtrlIsCalledBy($content);
49  }
50  public function _containsClassDefinitionFor(string $class, string $content)
51  {
52  return $this->containsClassDefinitionFor($class, $content);
53  }
54  protected function getILIASAbsolutePath() : string
55  {
56  return "";
57  }
58  public function _readDirTo(string $a_cdir, \ilCtrlStructure $cs = null) : \ilCtrlStructure
59  {
60  return $this->readDirTo($a_cdir, $cs ?? new \ilCtrlStructure());
61  }
62  protected function normalizePath(string $path) : string
63  {
64  return $path;
65  }
66  })
67  ->withDB($this->db);
68  }
The CtrlStructure knows how GUIs call each other and where the code of the guis is located...
Class ilCtrlStructureReader.

◆ testContainsClassDefinitionFor()

ilCtrlStructureReaderTest::testContainsClassDefinitionFor ( )

Definition at line 323 of file ilCtrlStructureReaderTest.php.

344  {

◆ testDoesNotContainClassDefinitionFor()

ilCtrlStructureReaderTest::testDoesNotContainClassDefinitionFor ( )

Definition at line 335 of file ilCtrlStructureReaderTest.php.

Referenced by testGetIlCtrlCallsWithNamespaces().

344  {
345  $res = $this->reader->_containsClassDefinitionFor(
foreach($_POST as $key=> $value) $res
+ Here is the caller graph for this function:

◆ testFilesInDir()

ilCtrlStructureReaderTest::testFilesInDir ( )

Definition at line 186 of file ilCtrlStructureReaderTest.php.

References $result.

187  {
188  $dir = __DIR__ . "/test_dir";
189  $expected = [
190  ["class.ilMyTestingGUI.php", "$dir/class.ilMyTestingGUI.php"],
191  ["test_file", "$dir/sub_test_dir/test_file"]
192  ];
193  $result = iterator_to_array($this->reader->_getFilesIn($dir));
194  sort($expected);
195  sort($result);
196  $this->assertEquals($expected, $result);
197  }
$result

◆ testGetGUIClassNameFromClassPath()

ilCtrlStructureReaderTest::testGetGUIClassNameFromClassPath ( )

Definition at line 210 of file ilCtrlStructureReaderTest.php.

211  {
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"));
233  }

◆ testGetIlCtrlCallsNoContent()

ilCtrlStructureReaderTest::testGetIlCtrlCallsNoContent ( )

Definition at line 235 of file ilCtrlStructureReaderTest.php.

References PHP.

236  {
237  $gen = $this->reader->_getIlCtrlCalls(
238  <<<"PHP"
239 class SomeRandomClass {
240 }
241 PHP
242  );
243  $this->assertNull($gen);
244  }
PHP
Definition: index.php:3

◆ testGetIlCtrlCallsWithContent()

ilCtrlStructureReaderTest::testGetIlCtrlCallsWithContent ( )

Definition at line 246 of file ilCtrlStructureReaderTest.php.

References PHP.

247  {
248  list($parent, $children) = $this->reader->_getIlCtrlCalls(
249  <<<"PHP"
250 <?php
251 /* Copyright (c) 2020 ILIAS open source, Extended GPL, see docs/LICENSE */
252 
253 
254 require_once "./Services/Container/classes/class.ilContainerGUI.php";
255 
267 class ilObjCourseGUI extends ilContainerGUI
268 {
269 }
270 PHP
271  );
272  $expected = [
273  "ilcourseregistrationgui",
274  "ilcourseobjectivesgui",
275  "ilobjcoursegroupinggui",
276  "ilinfoscreengui",
277  "illearningprogressgui",
PHP
Definition: index.php:3
Class ilObjCourseGUI.
Class ilContainerGUI.

◆ testGetIlCtrlCallsWithNamespaces()

ilCtrlStructureReaderTest::testGetIlCtrlCallsWithNamespaces ( )

Definition at line 348 of file ilCtrlStructureReaderTest.php.

References $res, PHP, and testDoesNotContainClassDefinitionFor().

348  {
349 }
350 PHP
351  );
352  $this->assertTrue($res);
353  }
354 
355  public function testDoesNotContainClassDefinitionFor()
356  {
357  $res = $this->reader->_containsClassDefinitionFor(
358  "SomeRandomClass",
359  <<<"PHP"
360 class fooSomeRandomClass {
361 }
362 PHP
363  );
364  $this->assertFalse($res);
365  }
366 
367 
368  public function testGetIlCtrlCallsWithNamespaces() : void
369  {
370  list($parent, $children) = $this->reader->_getIlCtrlCalls(
PHP
Definition: index.php:3
foreach($_POST as $key=> $value) $res
+ Here is the call graph for this function:

◆ testGetIlCtrlIsCalledByNoContent()

ilCtrlStructureReaderTest::testGetIlCtrlIsCalledByNoContent ( )

Definition at line 279 of file ilCtrlStructureReaderTest.php.

290  {

◆ testGetIlCtrlIsCalledByWithContent()

ilCtrlStructureReaderTest::testGetIlCtrlIsCalledByWithContent ( )

Definition at line 290 of file ilCtrlStructureReaderTest.php.

References PHP.

290  {
291  $gen = $this->reader->_getIlCtrlIsCalledBy(
292  <<<"PHP"
293 class SomeRandomClass {
294 }
295 PHP
296  );
297  $this->assertNull($gen);
298  }
299 
300  public function testGetIlCtrlIsCalledByWithContent()
301  {
302  list($parent, $children) = $this->reader->_getIlCtrlIsCalledBy(
303  <<<"PHP"
304 <?php
305 /* Copyright (c) 2020 ILIAS open source, Extended GPL, see docs/LICENSE */
306 
307 
308 require_once "./Services/Container/classes/class.ilContainerGUI.php";
309 
321 class ilObjCourseGUI extends ilContainerGUI
PHP
Definition: index.php:3
Class ilObjCourseGUI.
Class ilContainerGUI.

◆ testGetIlCtrlIsCalledByWithNamespaces()

ilCtrlStructureReaderTest::testGetIlCtrlIsCalledByWithNamespaces ( )

Definition at line 373 of file ilCtrlStructureReaderTest.php.

396  : void

◆ testIsInterestingFile()

ilCtrlStructureReaderTest::testIsInterestingFile ( )

Definition at line 199 of file ilCtrlStructureReaderTest.php.

200  {
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"));
208  }

◆ testReadClassChildsIsAsExpected()

ilCtrlStructureReaderTest::testReadClassChildsIsAsExpected ( )

Definition at line 96 of file ilCtrlStructureReaderTest.php.

References $result.

97  {
98  $dir = __DIR__ . "/test_dir/";
99  $result = $this->reader->_readDirTo($dir);
100 
101  $expected_class_childs = [
102  "ilmytestinggui" => [
103  "ilmyothertestinggui"
104  ],
105  "ilmythirdtestinggui" => [
106  "ilmytestinggui"
107  ]
108  ];
109  $this->assertEquals(
110  $expected_class_childs,
111  iterator_to_array($result->getClassChildren())
112  );
113  }
$result

◆ testReadClassScriptIsAsExpected()

ilCtrlStructureReaderTest::testReadClassScriptIsAsExpected ( )

Definition at line 82 of file ilCtrlStructureReaderTest.php.

References $result.

83  {
84  $dir = __DIR__ . "/test_dir";
85  $result = $this->reader->_readDirTo($dir);
86 
87  $expected_class_script = [
88  "ilmytestinggui" => "$dir/class.ilMyTestingGUI.php"
89  ];
90  $this->assertEquals(
91  $expected_class_script,
92  iterator_to_array($result->getClassScripts())
93  );
94  }
$result

◆ testReadRemovesDuplicateCallsInDatabase()

ilCtrlStructureReaderTest::testReadRemovesDuplicateCallsInDatabase ( )

Definition at line 115 of file ilCtrlStructureReaderTest.php.

References Vendor\Package\$f, and $result.

116  {
117  $this->expectException(\Exception::class);
118 
119  $dir = __DIR__ . "/test_dir/";
120 
121  $this->reader->comp_prefix = "";
122  $ctrl_structure = new \ilCtrlStructure([
123  "ilmytestinggui" => "/some/other/dir/class.ilMyTestingGUI.php"
124  ]);
125  $this->db
126  ->method("quote")
127  ->will($this->returnCallback(function ($v, $_) {
128  return "\"$v\"";
129  }));
130  $this->db
131  ->method("equals")
132  ->will($this->returnCallback(function ($f, $v, $_, $__) {
133  return "$f = \"$v\"";
134  }));
135  $this->db->expects($this->exactly(4))
136  ->method("manipulate")
137  ->withConsecutive(
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"]
142  );
143 
144  $result = $this->reader->_readDirTo($dir, $ctrl_structure);
145  }
$result

◆ testReadRemovesDuplicateFilesInDatabaseIfCompPrefixIsSet()

ilCtrlStructureReaderTest::testReadRemovesDuplicateFilesInDatabaseIfCompPrefixIsSet ( )

Definition at line 147 of file ilCtrlStructureReaderTest.php.

References Vendor\Package\$f, and $result.

148  {
149  $this->expectException(\Exception::class);
150 
151  $dir = __DIR__ . "/test_dir/";
152  $my_comp_prefix = "mcp";
153 
154  $this->reader->comp_prefix = $my_comp_prefix;
155  $ctrl_structure = new \ilCtrlStructure([
156  "ilmytestinggui" => "/some/other/dir/class.ilMyTestingGUI.php"
157  ]);
158  $this->db
159  ->method("quote")
160  ->will($this->returnCallback(function ($v, $_) {
161  return "\"$v\"";
162  }));
163  $this->db
164  ->method("equals")
165  ->will($this->returnCallback(function ($f, $v, $_, $__) {
166  return "$f = \"$v\"";
167  }));
168  $this->db->expects($this->exactly(2))
169  ->method("manipulate")
170  ->withConsecutive(
171  ["DELETE FROM ctrl_classfile WHERE comp_prefix = \"$my_comp_prefix\""],
172  ["DELETE FROM ctrl_calls WHERE comp_prefix = \"$my_comp_prefix\""]
173  );
174 
175  $result = $this->reader->_readDirTo($dir, $ctrl_structure);
176  }
$result

◆ testReadSmoke()

ilCtrlStructureReaderTest::testReadSmoke ( )

Definition at line 75 of file ilCtrlStructureReaderTest.php.

References $result.

76  {
77  $dir = __DIR__ . "/test_dir";
78  $result = $this->reader->_readDirTo($dir);
79  $this->assertInstanceOf(\ilCtrlStructure::class, $result);
80  }
$result

◆ testShouldDescendToDirectory()

ilCtrlStructureReaderTest::testShouldDescendToDirectory ( )

Definition at line 178 of file ilCtrlStructureReaderTest.php.

179  {
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"));
184  }

◆ testSmoke()

ilCtrlStructureReaderTest::testSmoke ( )

Definition at line 70 of file ilCtrlStructureReaderTest.php.

71  {
72  $this->assertInstanceOf(ilCtrlStructureReader::class, $this->reader);
73  }

The documentation for this class was generated from the following file: