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