ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilComponentBuildPluginInfoObjectiveTest.php
Go to the documentation of this file.
1 <?php
19 
21 {
23 
24  protected function setUp(): void
25  {
26  $this->scanned = [];
27  $this->dirs = [];
28  $this->read = [];
29  $this->files = [];
30  $this->added = [];
31  $this->builder = new class ($this) extends ilComponentBuildPluginInfoObjective {
32  protected const BASE_PATH = "";
34  public function __construct($test)
35  {
36  $this->test = $test;
37  }
38  protected function scanDir(string $dir): array
39  {
40  $this->test->scanned[] = $dir;
41  return $this->test->dirs[$dir] ?? [];
42  }
43  public function _scanDir(string $dir): array
44  {
45  return parent::scanDir($dir);
46  }
47  protected function isDir(string $dir): bool
48  {
49  return true;
50  }
51  public function _isDir(string $dir): bool
52  {
53  return parent::isDir($dir);
54  }
55  public function _isDotFile(string $file): bool
56  {
57  return parent::isDotFile($file);
58  }
59  protected function buildPluginPath(string $type, string $component, string $slot, string $plugin): string
60  {
61  return $this->test->files[parent::buildPluginPath($type, $component, $slot, $plugin)];
62  }
63 
64  public function _buildPluginPath(string $type, string $component, string $slot, string $plugin): string
65  {
66  return parent::buildPluginPath($type, $component, $slot, $plugin);
67  }
68  protected function addPlugin(array &$data, string $type, string $component, string $slot, string $plugin): void
69  {
70  $this->test->added[] = "$type/$component/$slot/$plugin";
71  }
72  public function _addPlugin(array &$data, string $type, string $component, string $slot, string $plugin): void
73  {
74  parent::addPlugin($data, $type, $component, $slot, $plugin);
75  }
76  };
77  }
78 
79  public function testScanningTopLevel(): void
80  {
81  $this->builder->build();
82 
83  $expected = ["Modules", "Services"];
84  sort($expected);
85  sort($this->scanned);
86  $this->assertEquals($expected, $this->scanned);
87  }
88 
89  public function testScanningComplete(): void
90  {
91  $this->dirs = [
92  "Modules" => ["Module1", "Module2"],
93  "Services" => ["Service1"],
94  "Modules/Module1" => ["Slot1", "Slot2"],
95  "Modules/Module2" => [],
96  "Services/Service1" => ["Slot3",".DS_Store"] // .DS_Store should be skipped
97  ];
98 
99  $this->builder->build();
100 
101  $expected = ["Modules", "Services", "Modules/Module1", "Modules/Module2",
102  "Services/Service1", "Modules/Module1/Slot1", "Modules/Module1/Slot2",
103  "Services/Service1/Slot3"];
104  sort($expected);
105  sort($this->scanned);
106  $this->assertEquals($expected, $this->scanned);
107  }
108 
109  public function testPluginsAdded(): void
110  {
111  $this->dirs = [
112  "Modules" => ["Module1"],
113  "Services" => ["Service1"],
114  "Modules/Module1" => ["Slot1"],
115  "Services/Service1" => ["Slot2"],
116  "Modules/Module1/Slot1" => ["Plugin1", "Plugin2"],
117  "Services/Service1/Slot2" => ["Plugin3"]
118  ];
119 
120  $this->builder->build();
121 
122  $expected = [
123  "Modules/Module1/Slot1/Plugin1",
124  "Modules/Module1/Slot1/Plugin2",
125  "Services/Service1/Slot2/Plugin3"
126  ];
127  sort($expected);
128  sort($this->added);
129  $this->assertEquals($expected, $this->added);
130  }
131 
132  public function testScanDir(): void
133  {
134  // Use the component directory without artifacts, because this should be mostly stable.
135  $expected = ["ROADMAP.md", "classes", "exceptions", "maintenance.json", "service.xml", "test"];
136  $actual = array_values(
137  array_diff(
138  $this->builder->_scanDir(__DIR__ . "/../.."),
139  ["artifacts", ".DS_Store"] // .DS_Store is a macOS artifact which is not relevant for the test.
140  )
141  );
142  $this->assertEquals($expected, $actual);
143  }
144 
145  public function testIsDir(): void
146  {
147  // Use the component directory, because this should be mostly stable.
148  $expected = true;
149  $actual = $this->builder->_isDir(__DIR__ . "/../..");
150  $this->assertEquals($expected, $actual);
151  }
152 
153  public function testIsDotFile(): void
154  {
155  $expected = true;
156  $actual = $this->builder->_isDotFile(".DS_Store");
157  $this->assertEquals($expected, $actual);
158  }
159 
160  public function testAddPlugins(): void
161  {
162  $data = [];
163  $this->files["Modules/Module1/Slot1/Plugin1/"] = __DIR__ . "/";
164  $this->builder->_addPlugin($data, "Modules", "Module1", "Slot1", "Plugin1");
165 
166  $expected = [
167  "tstplg" => [
168  "Modules",
169  "Module1",
170  "Slot1",
171  "Plugin1",
172  "1.9.1",
173  "8.0",
174  "8.999",
175  "Richard Klees",
176  "richard.klees@concepts-and-training.de",
177  true,
178  false,
179  null
180  ]
181  ];
182  $this->assertEquals($expected, $data);
183  }
184 
185  public function testBuildPluginPath(): void
186  {
187  $this->assertEquals("TYPE/COMPONENT/SLOT/PLUGIN/", $this->builder->_buildPluginPath("TYPE", "COMPONENT", "SLOT", "PLUGIN"));
188  }
189 }
$type
__construct(Container $dic, ilPlugin $plugin)