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