ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
TreeSelectTest Class Reference
+ Inheritance diagram for TreeSelectTest:
+ Collaboration diagram for TreeSelectTest:

Public Member Functions

 getDefaultRenderer (?JavaScriptBinding $js_binding=null, array $with_stub_renderings=[], array $with_additional_contexts=[],)
 
 getUIFactory ()
 
 testWithValueForInvalidArguments (mixed $value)
 
 testWithValueForValidArguments (string|int $value)
 
 testWithValueForNull ()
 
 testRenderWithValue ()
 
 testRenderWithDisabled ()
 
 testRenderWithRequired ()
 
 testRenderDrilldownMenu ()
 

Static Public Member Functions

static getInvalidArgumentsForWithValue ()
 
static getValidArgumentsForWithValue ()
 

Protected Member Functions

 setUp ()
 
 getMenuFactory ()
 
 getFieldFactory (?Field\Node\Factory $node_factory=null)
 
 getNodeRetrieval (array $node_stubs=[], array $leaf_stubs=[])
 
 getLeafStub (string|int $id='', string $name='')
 
 getBreadcrumbsStub ()
 
 getDrilldownStub ()
 
 getLinkStub ()
 
 getBulkyStub ()
 
 createSimpleRenderingStub (string $class_name)
 

Protected Attributes

Component Button Bulky &MockObject $bulky_stub
 
string $bulky_html
 
Component Link Standard &MockObject $link_stub
 
string $link_html
 
Component Menu Drilldown &MockObject $drilldown_stub
 
string $drilldown_html
 
Component Breadcrumbs Breadcrumbs &MockObject $breadcrumbs_stub
 
string $breadcrumbs_html
 
Component SignalGeneratorInterface $signal_generator
 
Component Menu Factory $menu_factory
 

Detailed Description

Author
Thibeau Fuhrer thibe.nosp@m.au@s.nosp@m.r.sol.nosp@m.utio.nosp@m.ns

Definition at line 34 of file TreeSelectTest.php.

Member Function Documentation

◆ createSimpleRenderingStub()

TreeSelectTest::createSimpleRenderingStub ( string  $class_name)
protected
Returns
array{0: ILIAS\UI\Component\Component & MockObject, 1: string}

Definition at line 412 of file TreeSelectTest.php.

412 : array
413 {
414 $stub = $this->createMock($class_name);
415 $html = sha1($class_name);
416 $stub->method('getCanonicalName')->willReturn($html);
417 $stub->method($this->anything())->willReturnSelf();
418 return [$stub, $html];
419 }

◆ getBreadcrumbsStub()

TreeSelectTest::getBreadcrumbsStub ( )
protected
Returns
array{0: Component\Breadcrumbs\Breadcrumbs & MockObject, 1: string}

Definition at line 388 of file TreeSelectTest.php.

388 : array
389 {
390 return $this->createSimpleRenderingStub(Component\Breadcrumbs\Breadcrumbs::class);
391 }
createSimpleRenderingStub(string $class_name)

Referenced by setUp().

+ Here is the caller graph for this function:

◆ getBulkyStub()

TreeSelectTest::getBulkyStub ( )
protected
Returns
array{0: Component\Button\Bulky & MockObject, 1: string}

Definition at line 406 of file TreeSelectTest.php.

406 : array
407 {
408 return $this->createSimpleRenderingStub(Component\Button\Bulky::class);
409 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21

Referenced by setUp().

+ Here is the caller graph for this function:

◆ getDefaultRenderer()

TreeSelectTest::getDefaultRenderer ( ?JavaScriptBinding  $js_binding = null,
array  $with_stub_renderings = [],
array  $with_additional_contexts = [] 
)

Definition at line 63 of file TreeSelectTest.php.

68 $with_stub_renderings = array_merge($with_stub_renderings, [
69 $this->bulky_stub,
70 $this->drilldown_stub,
71 $this->breadcrumbs_stub,
72 ]);
73
74 return parent::getDefaultRenderer($js_binding, $with_stub_renderings, $with_additional_contexts);
75 }

◆ getDrilldownStub()

TreeSelectTest::getDrilldownStub ( )
protected
Returns
array{0: Component\Menu\Drilldown & MockObject, 1: string}

Definition at line 394 of file TreeSelectTest.php.

394 : array
395 {
396 return $this->createSimpleRenderingStub(Component\Menu\Drilldown::class);
397 }

Referenced by setUp().

+ Here is the caller graph for this function:

◆ getFieldFactory()

TreeSelectTest::getFieldFactory ( ?Field\Node\Factory  $node_factory = null)
protected

Definition at line 352 of file TreeSelectTest.php.

352 : Field\Factory
353 {
354 return new Field\Factory(
355 ($node_factory) ?: $this->createMock(Field\Node\Factory::class),
356 $this->createMock(Component\Input\UploadLimitResolver::class),
357 $this->signal_generator,
358 $this->getDataFactory(),
359 $this->getRefinery(),
360 $this->getLanguage(),
361 );
362 }
This implements commonalities between inputs.
Definition: Input.php:43
getLanguage()

References ILIAS\UI\Implementation\Component\Input\getDataFactory(), and getLanguage().

+ Here is the call graph for this function:

◆ getInvalidArgumentsForWithValue()

static TreeSelectTest::getInvalidArgumentsForWithValue ( )
static

Definition at line 325 of file TreeSelectTest.php.

325 : array
326 {
327 return [
328 [true],
329 [new stdClass()],
330 [1.000],
331 [[1, 2, 3]],
332 [[]],
333 ];
334 }

◆ getLeafStub()

TreeSelectTest::getLeafStub ( string|int  $id = '',
string  $name = '' 
)
protected
Returns
array{0: Field\Node\Leaf & MockObject, 1: string}

Definition at line 377 of file TreeSelectTest.php.

377 : array
378 {
379 $stub = $this->createMock(Field\Node\Leaf::class);
380 $html = sha1(Field\Node\Leaf::class);
381 $stub->method('getCanonicalName')->willReturn($html);
382 $stub->method('getId')->willReturn($id);
383 $stub->method('getName')->willReturn($name);
384 return [$stub, $html];
385 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

◆ getLinkStub()

TreeSelectTest::getLinkStub ( )
protected
Returns
array{0: Component\Link\Standard & MockObject, 1: string}

Definition at line 400 of file TreeSelectTest.php.

400 : array
401 {
402 return $this->createSimpleRenderingStub(Component\Link\Standard::class);
403 }

Referenced by setUp().

+ Here is the caller graph for this function:

◆ getMenuFactory()

TreeSelectTest::getMenuFactory ( )
protected

Definition at line 347 of file TreeSelectTest.php.

347 : Component\Menu\Factory
348 {
349 return new Component\Menu\Factory($this->signal_generator);
350 }

◆ getNodeRetrieval()

TreeSelectTest::getNodeRetrieval ( array  $node_stubs = [],
array  $leaf_stubs = [] 
)
protected
Parameters
Field\Node\Node[]$node_stubsto yield from NodeRetrieval::getNodes()
Field\Node\Leaf[]$leaf_stubsto yield from NodeRetrieval::getNodesAsLeaf()

Definition at line 368 of file TreeSelectTest.php.

368 : NodeRetrieval & MockObject
369 {
370 $node_retrieval = $this->createMock(NodeRetrieval::class);
371 $node_retrieval->method('getNodes')->willReturnCallback(static fn() => yield from $node_stubs);
372 $node_retrieval->method('getNodesAsLeaf')->willReturnCallback(static fn() => yield from $leaf_stubs);
373 return $node_retrieval;
374 }

References ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from().

+ Here is the call graph for this function:

◆ getUIFactory()

TreeSelectTest::getUIFactory ( )

Definition at line 77 of file TreeSelectTest.php.

78 {
79 $icon_factory = $this->createMock(Component\Symbol\Icon\Factory::class);
80 $glyph_factory = $this->createMock(Component\Symbol\Glyph\Factory::class);
81 $glyph_mock = $this->createMock(Component\Symbol\Glyph\Glyph::class);
82 $glyph_factory->method($this->anything())->willReturn($glyph_mock);
83 $symbol_factory = $this->createMock(Component\Symbol\Factory::class);
84 $symbol_factory->method('icon')->willReturn($icon_factory);
85
86 $button_factory = $this->createMock(Component\Button\Factory::class);
87 $button_factory->method('bulky')->willReturn($this->bulky_stub);
88
89 $link_factory = $this->createMock(Component\Link\Factory::class);
90 $link_factory->method('standard')->willReturn($this->link_stub);
91
92 $node_factory = $this->createMock(Field\Node\Factory::class);
93 $field_factory = $this->createMock(Field\Factory::class);
94 $field_factory->method('node')->willReturn($node_factory);
95 $input_factory = $this->createMock(Component\Input\Factory::class);
96 $input_factory->method('field')->willReturn($field_factory);
97
98 return new class (
99 $button_factory,
100 $symbol_factory,
101 $link_factory,
102 $input_factory,
105 ) extends \NoUIFactory {
106 public function __construct(
107 protected Component\Button\Factory $button_factory,
108 protected Component\Symbol\Factory $symbol_factory,
109 protected Component\Link\Factory $link_factory,
110 protected Component\Input\Factory $input_factory,
112 protected Component\Breadcrumbs\Breadcrumbs $breadcrumbs,
113 ) {
114 }
115 public function button(): Component\Button\Factory
116 {
117 return $this->button_factory;
118 }
119 public function breadcrumbs(array $crumbs): Component\Breadcrumbs\Breadcrumbs
120 {
121 return $this->breadcrumbs;
122 }
123 public function symbol(): Component\Symbol\Factory
124 {
125 return $this->symbol_factory;
126 }
127 public function link(): Component\Link\Factory
128 {
129 return $this->link_factory;
130 }
131 public function input(): Component\Input\Factory
132 {
133 return $this->input_factory;
134 }
135 public function menu(): Component\Menu\Factory
136 {
137 return $this->menu_factory;
138 }
139 };
140 }
Factory for Date Formats.
Definition: Factory.php:27
Component Menu Factory $menu_factory
Component Breadcrumbs Breadcrumbs &MockObject $breadcrumbs_stub
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
button(string $caption, string $cmd)
link(string $caption, string $href, bool $new_viewport=false)

References ILIAS\GlobalScreen\Provider\__construct(), ILIAS\UI\examples\Breadcrumbs\breadcrumbs(), ILIAS\Repository\button(), ILIAS\Repository\link(), and ILIAS\Repository\symbol().

+ Here is the call graph for this function:

◆ getValidArgumentsForWithValue()

static TreeSelectTest::getValidArgumentsForWithValue ( )
static

Definition at line 336 of file TreeSelectTest.php.

336 : array
337 {
338 return [
339 [1],
340 [-1],
341 ['1'],
342 [''],
343 [' '],
344 ];
345 }

◆ setUp()

TreeSelectTest::setUp ( )
protected

Definition at line 48 of file TreeSelectTest.php.

48 : void
49 {
54
55 $this->signal_generator = new IncrementalSignalGenerator();
56
57 $this->menu_factory = $this->createMock(Component\Menu\Factory::class);
58 $this->menu_factory->method('drilldown')->willReturn($this->drilldown_stub);
59
61 }
Component Link Standard &MockObject $link_stub
string $breadcrumbs_html
Component Menu Drilldown &MockObject $drilldown_stub
string $drilldown_html
Component Button Bulky &MockObject $bulky_stub

References $breadcrumbs_html, $breadcrumbs_stub, $bulky_html, $bulky_stub, $drilldown_html, $drilldown_stub, $link_html, $link_stub, getBreadcrumbsStub(), getBulkyStub(), getDrilldownStub(), getLinkStub(), and setUp().

+ Here is the call graph for this function:

◆ testRenderDrilldownMenu()

TreeSelectTest::testRenderDrilldownMenu ( )

Definition at line 248 of file TreeSelectTest.php.

248 : void
249 {
250 $this->menu_factory = $this->getMenuFactory();
251
252 [$leaf_stub, $leaf_html] = $this->getLeafStub();
253
254 $tree_select_label = 'some tree select label';
255
256 $node_retrieval = $this->getNodeRetrieval([$leaf_stub]);
257
258 $component = $this->getFieldFactory()->treeSelect($node_retrieval, $tree_select_label);
259 $component = $component->withNameFrom(new DefNamesource());
260
261 $renderer = $this->getDefaultRenderer(null, [$leaf_stub]);
262
263 $expected_html = <<<HTML
264<fieldset class="c-input" data-il-ui-component="tree-select-field-input" data-il-ui-input-name="name_0">
265 <label for="id_3">some tree select label</label>
266 <div class="c-input__field">
267 <div class="c-input-tree_select">
268 <dialog class="c-modal">
269 <div class="modal-dialog" role="document">
270 <div class="modal-content">
271 <div class="modal-header">
272 <button data-action="close" type="button" class="close" aria-label="close">
273 <span aria-hidden="true">&times;</span>
274 </button>
275 <h1 class="modal-title">$tree_select_label</h1>
276 </div>
277 <div class="modal-body">
278 <template>$this->breadcrumbs_html</template>
279 $this->breadcrumbs_html
280 <section class="c-drilldown" id="id_2">
281 <header class="c-drilldown__header--showbacknav">
282 <div></div>
283 <div></div>
284 <div class="c-drilldown__backnav"> $this->bulky_html</div>
285 </header>
286 <div class="c-drilldown__menu">
287 <ul aria-live="polite" aria-label="$tree_select_label">
288 $leaf_html
289 <li class="c-drilldown__menu--no-items"> drilldown_no_items</li>
290 </ul>
291 </div>
292 </section>
293 </div>
294 <div class="modal-footer">
295 <button data-action="close" type="button" class="btn btn-default" aria-label="close">close</button>
296 <button data-action="close" type="button" class="btn btn-primary" aria-label="select">select</button>
297 </div>
298 </div>
299 </div>
300 </dialog>
301 <ul class="c-input-tree_select__selection">
302 <template>
303 <li data-node-id="">
304 <span data-node-name></span>
305 <button data-action="remove" type="button" class="close" aria-label="">
306 <span aria-hidden="true">&times;</span>
307 </button>
308 <input id="id_1" type="hidden" name="name_0[input_0][]" value="" /></li>
309 </template>
310 </ul>
311 <input id="id_3" type="button" aria-label="select" value="select">
312 </div>
313 </div>
314</fieldset>
315HTML;
316
317 $actual_html = $renderer->render($component);
318
319 $this->assertEquals(
320 $this->brutallyTrimHTML($expected_html),
321 $this->brutallyTrimHTML($actual_html),
322 );
323 }
$renderer
getNodeRetrieval(array $node_stubs=[], array $leaf_stubs=[])
getFieldFactory(?Field\Node\Factory $node_factory=null)
getDefaultRenderer(?JavaScriptBinding $js_binding=null, array $with_stub_renderings=[], array $with_additional_contexts=[],)
getLeafStub(string|int $id='', string $name='')

References $renderer, ILIAS\Repository\button(), ILIAS\UI\examples\Symbol\Glyph\Close\close(), ILIAS\UI\examples\Symbol\Glyph\Header\header(), and ILIAS\Repository\ui().

+ Here is the call graph for this function:

◆ testRenderWithDisabled()

TreeSelectTest::testRenderWithDisabled ( )

Definition at line 202 of file TreeSelectTest.php.

202 : void
203 {
204 $node_retrieval = $this->getNodeRetrieval();
205
206 $component = $this->getFieldFactory()->treeSelect($node_retrieval, '');
207 $component = $component->withDisabled(true);
208
209 $renderer = $this->getDefaultRenderer();
210
211 $expected_html = <<<HTML
212<input id="id_2" type="button" aria-label="select" value="select" disabled>
213HTML;
214
215 $actual_html = $renderer->render($component);
216
217 $this->assertTrue(
218 str_contains(
219 $this->brutallyTrimHTML($actual_html),
220 $this->brutallyTrimHTML($expected_html),
221 )
222 );
223 }

References $renderer, and ILIAS\UI\examples\Input\Field\Checkbox\disabled().

+ Here is the call graph for this function:

◆ testRenderWithRequired()

TreeSelectTest::testRenderWithRequired ( )

Definition at line 225 of file TreeSelectTest.php.

225 : void
226 {
227 $node_retrieval = $this->getNodeRetrieval();
228
229 $component = $this->getFieldFactory()->treeSelect($node_retrieval, '');
230 $component = $component->withRequired(true);
231
232 $renderer = $this->getDefaultRenderer();
233
234 $expected_html = <<<HTML
235<label for="id_2"><span class="sr-only">required_field</span><span class="asterisk" aria-hidden="true">*</span></label>
236HTML;
237
238 $actual_html = $renderer->render($component);
239
240 $this->assertTrue(
241 str_contains(
242 $this->brutallyTrimHTML($actual_html),
243 $this->brutallyTrimHTML($expected_html),
244 )
245 );
246 }

References $renderer.

◆ testRenderWithValue()

TreeSelectTest::testRenderWithValue ( )

Definition at line 168 of file TreeSelectTest.php.

168 : void
169 {
170 $node_id = 'some-existing-node-id';
171 $node_name = 'some existing node';
172
173 [$leaf_stub,] = $this->getLeafStub($node_id, $node_name);
174
175 $node_retrieval = $this->getNodeRetrieval([], [$leaf_stub]);
176
177 $component = $this->getFieldFactory()->treeSelect($node_retrieval, '');
178 $component = $component->withValue($node_id);
179
180 $renderer = $this->getDefaultRenderer(null, [$leaf_stub]);
181
182 $expected_html = <<<HTML
183<li data-node-id="$node_id">
184 <span data-node-name>$node_name</span>
185 <button data-action="remove" type="button" class="close" aria-label="unselect_node">
186 <span aria-hidden="true">&times;</span>
187 </button>
188 <input id="id_2" type="hidden" value="$node_id" />
189</li>
190HTML;
191
192 $actual_html = $renderer->render($component);
193
194 $this->assertTrue(
195 str_contains(
196 $this->brutallyTrimHTML($actual_html),
197 $this->brutallyTrimHTML($expected_html),
198 )
199 );
200 }

References $renderer, and ILIAS\Repository\button().

+ Here is the call graph for this function:

◆ testWithValueForInvalidArguments()

TreeSelectTest::testWithValueForInvalidArguments ( mixed  $value)

Definition at line 143 of file TreeSelectTest.php.

143 : void
144 {
145 $node_retrieval = $this->getNodeRetrieval();
146 $component = $this->getFieldFactory()->treeSelect($node_retrieval, '');
147 $this->expectException(InvalidArgumentException::class);
148 $component = $component->withValue($value);
149 }

◆ testWithValueForNull()

TreeSelectTest::testWithValueForNull ( )

Definition at line 160 of file TreeSelectTest.php.

160 : void
161 {
162 $node_retrieval = $this->getNodeRetrieval();
163 $component = $this->getFieldFactory()->treeSelect($node_retrieval, '');
164 $component = $component->withValue(null);
165 $this->assertEquals([], $component->getValue());
166 }

◆ testWithValueForValidArguments()

TreeSelectTest::testWithValueForValidArguments ( string|int  $value)

Definition at line 152 of file TreeSelectTest.php.

152 : void
153 {
154 $node_retrieval = $this->getNodeRetrieval();
155 $component = $this->getFieldFactory()->treeSelect($node_retrieval, '');
156 $component = $component->withValue($value);
157 $this->assertEquals([$value], $component->getValue());
158 }

Field Documentation

◆ $breadcrumbs_html

string TreeSelectTest::$breadcrumbs_html
protected

Definition at line 43 of file TreeSelectTest.php.

Referenced by setUp().

◆ $breadcrumbs_stub

Component Breadcrumbs Breadcrumbs& MockObject TreeSelectTest::$breadcrumbs_stub
protected

Definition at line 42 of file TreeSelectTest.php.

Referenced by setUp().

◆ $bulky_html

string TreeSelectTest::$bulky_html
protected

Definition at line 37 of file TreeSelectTest.php.

Referenced by setUp().

◆ $bulky_stub

Component Button Bulky& MockObject TreeSelectTest::$bulky_stub
protected

Definition at line 36 of file TreeSelectTest.php.

Referenced by setUp().

◆ $drilldown_html

string TreeSelectTest::$drilldown_html
protected

Definition at line 41 of file TreeSelectTest.php.

Referenced by setUp().

◆ $drilldown_stub

Component Menu Drilldown& MockObject TreeSelectTest::$drilldown_stub
protected

Definition at line 40 of file TreeSelectTest.php.

Referenced by setUp().

◆ $link_html

string TreeSelectTest::$link_html
protected

Definition at line 39 of file TreeSelectTest.php.

Referenced by setUp().

◆ $link_stub

Component Link Standard& MockObject TreeSelectTest::$link_stub
protected

Definition at line 38 of file TreeSelectTest.php.

Referenced by setUp().

◆ $menu_factory

Component Menu Factory TreeSelectTest::$menu_factory
protected

Definition at line 46 of file TreeSelectTest.php.

◆ $signal_generator

Component SignalGeneratorInterface TreeSelectTest::$signal_generator
protected

Definition at line 45 of file TreeSelectTest.php.


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