18declare(strict_types=1);
24use PHPUnit\Framework\MockObject\MockObject;
26require_once(__DIR__ .
"/../../../../../../../vendor/composer/vendor/autoload.php");
27require_once(__DIR__ .
"/../../../Base.php");
28require_once(__DIR__ .
"/InputTest.php");
47 protected function setUp(): void
56 $this->menu_factory = $this->createMock(
Component\
Menu\Factory::class);
57 $this->menu_factory->method(
'drilldown')->willReturn($this->drilldown_stub);
64 array $with_stub_renderings = [],
65 array $with_additional_contexts = [],
67 $with_stub_renderings = array_merge($with_stub_renderings, [
69 $this->drilldown_stub,
70 $this->breadcrumbs_stub,
73 return parent::getDefaultRenderer($js_binding, $with_stub_renderings, $with_additional_contexts);
81 $glyph_factory->method($this->anything())->willReturn($glyph_mock);
83 $symbol_factory->method(
'icon')->willReturn($icon_factory);
86 $button_factory->method(
'bulky')->willReturn($this->bulky_stub);
88 $link_factory = $this->createMock(
Component\
Link\Factory::class);
89 $link_factory->method(
'standard')->willReturn($this->link_stub);
91 $node_factory = $this->createMock(Field\Node\Factory::class);
92 $field_factory = $this->createMock(Field\Factory::class);
93 $field_factory->method(
'node')->willReturn($node_factory);
94 $input_factory = $this->createMock(
Component\
Input\Factory::class);
95 $input_factory->method(
'field')->willReturn($field_factory);
103 $this->breadcrumbs_stub,
116 return $this->button_factory;
120 return $this->breadcrumbs;
124 return $this->symbol_factory;
128 return $this->link_factory;
132 return $this->input_factory;
136 return $this->menu_factory;
144 $node_retrieval = $this->getNodeRetrieval();
145 $component = $this->getFieldFactory()->treeSelect($node_retrieval,
'');
146 $this->expectException(InvalidArgumentException::class);
147 $component = $component->withValue($value);
153 $node_retrieval = $this->getNodeRetrieval();
154 $component = $this->getFieldFactory()->treeSelect($node_retrieval,
'');
155 $component = $component->withValue($value);
156 $this->assertEquals([$value], $component->getValue());
161 $node_id =
'some-existing-node-id';
162 $node_name =
'some existing node';
164 [$leaf_stub,] = $this->getLeafStub($node_id, $node_name);
166 $node_retrieval = $this->getNodeRetrieval([], [$leaf_stub]);
168 $component = $this->getFieldFactory()->treeSelect($node_retrieval,
'');
169 $component = $component->withValue($node_id);
171 $renderer = $this->getDefaultRenderer(
null, [$leaf_stub]);
173 $expected_html = <<<HTML
174<li data-node-
id=
"$node_id">
175 <span data-node-name>$node_name</span>
176 <
button data-action=
"remove" type=
"button" class=
"close" aria-label=
"unselect_node">
177 <span aria-hidden=
"true">×</span>
179 <input
id=
"id_2" type=
"hidden" value=
"$node_id" />
183 $actual_html =
$renderer->render($component);
187 $this->brutallyTrimHTML($actual_html),
188 $this->brutallyTrimHTML($expected_html),
195 $node_retrieval = $this->getNodeRetrieval();
197 $component = $this->getFieldFactory()->treeSelect($node_retrieval,
'');
198 $component = $component->withDisabled(
true);
202 $expected_html = <<<HTML
203<input
id=
"id_2" type=
"button" aria-label=
"select" value=
"select" disabled>
206 $actual_html =
$renderer->render($component);
210 $this->brutallyTrimHTML($actual_html),
211 $this->brutallyTrimHTML($expected_html),
218 $node_retrieval = $this->getNodeRetrieval();
220 $component = $this->getFieldFactory()->treeSelect($node_retrieval,
'');
221 $component = $component->withRequired(
true);
225 $expected_html = <<<HTML
226<label
for=
"id_2"><span
class=
"asterisk" aria-label=
"required_field">*</span></label>
229 $actual_html =
$renderer->render($component);
233 $this->brutallyTrimHTML($actual_html),
234 $this->brutallyTrimHTML($expected_html),
241 $this->menu_factory = $this->getMenuFactory();
243 [$leaf_stub, $leaf_html] = $this->getLeafStub();
245 $tree_select_label =
'some tree select label';
247 $node_retrieval = $this->getNodeRetrieval([$leaf_stub]);
249 $component = $this->getFieldFactory()->treeSelect($node_retrieval, $tree_select_label);
252 $renderer = $this->getDefaultRenderer(
null, [$leaf_stub]);
254 $expected_html = <<<HTML
255<fieldset
class=
"c-input" data-il-
ui-component=
"tree-select-field-input" data-il-
ui-input-name=
"name_0">
256 <label
for=
"id_3">some tree select label</label>
257 <div
class=
"c-input__field">
258 <div
class=
"c-input-tree_select">
259 <dialog
class=
"c-modal">
260 <div
class=
"modal-dialog" role=
"document">
261 <div
class=
"modal-content">
262 <div
class=
"modal-header">
263 <
button data-action=
"close" type=
"button" class=
"close" aria-label=
"close">
264 <span aria-hidden=
"true">×</span>
266 <h1
class=
"modal-title">$tree_select_label</h1>
268 <div
class=
"modal-body">
269 <
template>$this->breadcrumbs_html</
template>
270 $this->breadcrumbs_html
271 <section
class=
"c-drilldown" id=
"id_2">
272 <
header class=
"c-drilldown__header--showbacknav">
275 <div
class=
"c-drilldown__backnav"> $this->bulky_html</div>
277 <div
class=
"c-drilldown__menu">
278 <ul aria-live=
"polite" aria-label=
"$tree_select_label">
280 <li
class=
"c-drilldown__menu--no-items"> drilldown_no_items</li>
285 <div
class=
"modal-footer">
286 <
button data-action=
"close" type=
"button" class=
"btn btn-default" aria-label=
"close">
close</
button>
287 <
button data-action=
"close" type=
"button" class=
"btn btn-primary" aria-label=
"select">select</
button>
292 <ul
class=
"c-input-tree_select__selection">
295 <span data-node-name></span>
296 <
button data-action=
"remove" type=
"button" class=
"close" aria-label=
"">
297 <span aria-hidden=
"true">×</span>
299 <input
id=
"id_1" type=
"hidden" name=
"name_0[input_0][]" value=
"" /></li>
302 <input
id=
"id_3" type=
"button" aria-label=
"select" value=
"select">
308 $actual_html =
$renderer->render($component);
311 $this->brutallyTrimHTML($expected_html),
312 $this->brutallyTrimHTML($actual_html),
347 ($node_factory) ?: $this->createMock(Field\Node\Factory::class),
349 $this->signal_generator,
351 $this->getRefinery(),
362 $node_retrieval = $this->createMock(NodeRetrieval::class);
363 $node_retrieval->method(
'getNodes')->willReturnCallback(
static fn() => yield
from $node_stubs);
364 $node_retrieval->method(
'getNodesAsLeaf')->willReturnCallback(
static fn() => yield
from $leaf_stubs);
365 return $node_retrieval;
371 $stub = $this->createMock(Field\Node\Leaf::class);
372 $html = sha1(Field\Node\Leaf::class);
373 $stub->method(
'getCanonicalName')->willReturn($html);
374 $stub->method(
'getId')->willReturn(
$id);
375 $stub->method(
'getName')->willReturn($name);
376 return [$stub, $html];
388 return $this->createSimpleRenderingStub(
Component\
Menu\Drilldown::class);
394 return $this->createSimpleRenderingStub(
Component\
Link\Standard::class);
400 return $this->createSimpleRenderingStub(
Component\
Button\Bulky::class);
406 $stub = $this->createMock($class_name);
407 $html = sha1($class_name);
408 $stub->method(
'getCanonicalName')->willReturn($html);
409 $stub->method($this->anything())->willReturnSelf();
410 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.
createSimpleRenderingStub(string $class_name)
getNodeRetrieval(array $node_stubs=[], array $leaf_stubs=[])
Component Link Standard &MockObject $link_stub
Component Menu Factory $menu_factory
static getValidArgumentsForWithValue()
testWithValueForValidArguments(string|int|null $value)
@dataProvider getValidArgumentsForWithValue
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='')
testWithValueForInvalidArguments(mixed $value)
@dataProvider getInvalidArgumentsForWithValue
Component Breadcrumbs Breadcrumbs &MockObject $breadcrumbs_stub
Component Menu Drilldown &MockObject $drilldown_stub
testRenderDrilldownMenu()
Component Button Bulky &MockObject $bulky_stub
static getInvalidArgumentsForWithValue()
Component SignalGeneratorInterface $signal_generator
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)