18declare(strict_types=1);
24use PHPUnit\Framework\MockObject\MockObject;
25use PHPUnit\Framework\Attributes\DataProvider;
27require_once(__DIR__ .
"/../../../../../../../vendor/composer/vendor/autoload.php");
28require_once(__DIR__ .
"/../../../Base.php");
29require_once(__DIR__ .
"/InputTest.php");
48 protected function setUp(): void
57 $this->menu_factory = $this->createMock(
Component\
Menu\Factory::class);
58 $this->menu_factory->method(
'drilldown')->willReturn($this->drilldown_stub);
65 array $with_stub_renderings = [],
66 array $with_additional_contexts = [],
68 $with_stub_renderings = array_merge($with_stub_renderings, [
70 $this->drilldown_stub,
71 $this->breadcrumbs_stub,
74 return parent::getDefaultRenderer($js_binding, $with_stub_renderings, $with_additional_contexts);
82 $glyph_factory->method($this->anything())->willReturn($glyph_mock);
84 $symbol_factory->method(
'icon')->willReturn($icon_factory);
87 $button_factory->method(
'bulky')->willReturn($this->bulky_stub);
89 $link_factory = $this->createMock(
Component\
Link\Factory::class);
90 $link_factory->method(
'standard')->willReturn($this->link_stub);
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);
104 $this->breadcrumbs_stub,
117 return $this->button_factory;
121 return $this->breadcrumbs;
125 return $this->symbol_factory;
129 return $this->link_factory;
133 return $this->input_factory;
137 return $this->menu_factory;
142 #[DataProvider('getInvalidArgumentsForWithValue')]
145 $node_retrieval = $this->getNodeRetrieval();
146 $component = $this->getFieldFactory()->treeMultiSelect($node_retrieval,
'');
147 $this->expectException(InvalidArgumentException::class);
148 $component = $component->withValue($value);
151 #[DataProvider('getValidArgumentsForWithValue')]
154 $node_retrieval = $this->getNodeRetrieval();
155 $component = $this->getFieldFactory()->treeMultiSelect($node_retrieval,
'');
156 $component = $component->withValue($value);
157 $this->assertEquals($value, $component->getValue());
162 $node_id =
'some-existing-node-id';
163 $node_name =
'some existing node';
165 [$leaf_stub,] = $this->getLeafStub($node_id, $node_name);
167 $node_retrieval = $this->getNodeRetrieval([], [$leaf_stub]);
169 $component = $this->getFieldFactory()->treeMultiSelect($node_retrieval,
'');
170 $component = $component->withValue([$node_id]);
172 $renderer = $this->getDefaultRenderer(
null, [$leaf_stub]);
174 $expected_html = <<<HTML
175<li data-node-
id=
"$node_id">
176 <span data-node-name>$node_name</span>
177 <
button data-action=
"remove" type=
"button" class=
"close" aria-label=
"unselect_node">
178 <span aria-hidden=
"true">×</span>
180 <input
id=
"id_2" type=
"hidden" value=
"$node_id" />
184 $actual_html =
$renderer->render($component);
188 $this->brutallyTrimHTML($actual_html),
189 $this->brutallyTrimHTML($expected_html),
196 $node_retrieval = $this->getNodeRetrieval();
198 $component = $this->getFieldFactory()->treeMultiSelect($node_retrieval,
'');
199 $component = $component->withDisabled(
true);
203 $expected_html = <<<HTML
204<input
id=
"id_2" type=
"button" aria-label=
"select" value=
"select" disabled>
207 $actual_html =
$renderer->render($component);
211 $this->brutallyTrimHTML($actual_html),
212 $this->brutallyTrimHTML($expected_html),
219 $node_retrieval = $this->getNodeRetrieval();
221 $component = $this->getFieldFactory()->treeMultiSelect($node_retrieval,
'');
222 $component = $component->withRequired(
true);
226 $expected_html = <<<HTML
227<label
for=
"id_2"><span
class=
"sr-only">required_field</span><span
class=
"asterisk" aria-hidden=
"true">*</span></label>
230 $actual_html =
$renderer->render($component);
234 $this->brutallyTrimHTML($actual_html),
235 $this->brutallyTrimHTML($expected_html),
242 $this->menu_factory = $this->getMenuFactory();
244 [$leaf_stub, $leaf_html] = $this->getLeafStub();
246 $tree_select_label =
'some tree select label';
248 $node_retrieval = $this->getNodeRetrieval([$leaf_stub]);
250 $component = $this->getFieldFactory()->treeMultiSelect($node_retrieval, $tree_select_label);
253 $renderer = $this->getDefaultRenderer(
null, [$leaf_stub]);
255 $expected_html = <<<HTML
256<fieldset
class=
"c-input" data-il-
ui-component=
"tree-multi-select-field-input" data-il-
ui-input-name=
"name_0">
257 <label
for=
"id_3">some tree select label</label>
258 <div
class=
"c-input__field">
259 <div
class=
"c-input-tree_select">
260 <dialog
class=
"c-modal">
261 <div
class=
"modal-dialog" role=
"document">
262 <div
class=
"modal-content">
263 <div
class=
"modal-header">
264 <
button data-action=
"close" type=
"button" class=
"close" aria-label=
"close">
265 <span aria-hidden=
"true">×</span>
267 <h1
class=
"modal-title">$tree_select_label</h1>
269 <div
class=
"modal-body">
270 <
template>$this->breadcrumbs_html</
template>
271 $this->breadcrumbs_html
272 <section
class=
"c-drilldown" id=
"id_2">
273 <
header class=
"c-drilldown__header--showbacknav">
276 <div
class=
"c-drilldown__backnav"> $this->bulky_html</div>
278 <div
class=
"c-drilldown__menu">
279 <ul aria-live=
"polite" aria-label=
"$tree_select_label">
281 <li
class=
"c-drilldown__menu--no-items"> drilldown_no_items</li>
286 <div
class=
"modal-footer">
287 <
button data-action=
"close" type=
"button" class=
"btn btn-default" aria-label=
"close">
close</
button>
288 <
button data-action=
"close" type=
"button" class=
"btn btn-primary" aria-label=
"select">select</
button>
293 <ul
class=
"c-input-tree_select__selection">
296 <span data-node-name></span>
297 <
button data-action=
"remove" type=
"button" class=
"close" aria-label=
"">
298 <span aria-hidden=
"true">×</span>
300 <input
id=
"id_1" type=
"hidden" name=
"name_0[input_0][]" value=
"" /></li>
303 <input
id=
"id_3" type=
"button" aria-label=
"select" value=
"select">
309 $actual_html =
$renderer->render($component);
312 $this->brutallyTrimHTML($expected_html),
313 $this->brutallyTrimHTML($actual_html),
349 ($node_factory) ?: $this->createMock(Field\Node\Factory::class),
351 $this->signal_generator,
353 $this->getRefinery(),
364 $node_retrieval = $this->createMock(NodeRetrieval::class);
365 $node_retrieval->method(
'getNodes')->willReturnCallback(
static fn() => yield
from $node_stubs);
366 $node_retrieval->method(
'getNodesAsLeaf')->willReturnCallback(
static fn() => yield
from $leaf_stubs);
367 return $node_retrieval;
373 $stub = $this->createMock(Field\Node\Leaf::class);
374 $html = sha1(Field\Node\Leaf::class);
375 $stub->method(
'getCanonicalName')->willReturn($html);
376 $stub->method(
'getId')->willReturn(
$id);
377 $stub->method(
'getName')->willReturn($name);
378 return [$stub, $html];
390 return $this->createSimpleRenderingStub(
Component\
Menu\Drilldown::class);
396 return $this->createSimpleRenderingStub(
Component\
Link\Standard::class);
402 return $this->createSimpleRenderingStub(
Component\
Button\Bulky::class);
408 $stub = $this->createMock($class_name);
409 $html = sha1($class_name);
410 $stub->method(
'getCanonicalName')->willReturn($html);
411 $stub->method($this->anything())->willReturnSelf();
412 return [$stub, $html];
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Builds a Color from either hex- or rgb values.
A Link is the often used combination of a label and an URL.
Provides common functionality for UI tests.
static getInvalidArgumentsForWithValue()
testRenderDrilldownMenu()
getNodeRetrieval(array $node_stubs=[], array $leaf_stubs=[])
Component Button Bulky &MockObject $bulky_stub
static getValidArgumentsForWithValue()
getDefaultRenderer(?JavaScriptBinding $js_binding=null, array $with_stub_renderings=[], array $with_additional_contexts=[],)
Component Breadcrumbs Breadcrumbs &MockObject $breadcrumbs_stub
Component Link Standard &MockObject $link_stub
Component Menu Drilldown &MockObject $drilldown_stub
getFieldFactory(?Field\Node\Factory $node_factory=null)
Component Menu Factory $menu_factory
testWithValueForInvalidArguments(mixed $value)
createSimpleRenderingStub(string $class_name)
Component SignalGeneratorInterface $signal_generator
testWithValueForValidArguments(array $value)
getLeafStub(string|int $id='', string $name='')
Provides methods to interface with javascript.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
button(string $caption, string $cmd)
link(string $caption, string $href, bool $new_viewport=false)