ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LSLocatorBuilderTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Data\Factory as DataFactory;
23use ILIAS\UI\Implementation\Component\BreadCrumbs\Breadcrumbs;
24
25require_once('IliasMocks.php');
26require_once(__DIR__ . "/../../../../components/ILIAS/UI/tests/Base.php");
27
29{
30 use IliasMocks;
31
33
34 public function stripHTML(string $html): string
35 {
36 $html = $this->normalizeHTML($html);
37 return preg_replace('!\s+!', ' ', $html);
38 }
39
40 public function setUp(): void
41 {
42 $cb = $this->createMock(LSControlBuilder::class);
43 $this->lb = new LSLocatorBuilder('cmd', $cb);
44 }
45
46 public function testConstruction(): void
47 {
48 $this->assertInstanceOf(LSLocatorBuilder::class, $this->lb);
49 }
50
51 public function testItemCreation(): void
52 {
53 $this->lb
54 ->item('item 1', 1)
55 ->item('item 2', 2)
56 ->item('item 3', 3);
57
58 $this->assertCount(3, $this->lb->getItems());
59 }
60
61 public function testItemStruct(): void
62 {
63 $this->lb
64 ->item('item 1', 1)
65 ->item('item 2', 2);
66
67 $expected = [
68 [ 'label' => 'item 1',
69 'command' => 'cmd',
70 'parameter' => 1
71 ],
72 [ 'label' => 'item 2',
73 'command' => 'cmd',
74 'parameter' => 2
75 ]
76 ];
77
78 $this->assertEquals($expected, $this->lb->getItems());
79 }
80
81 public function testEnd(): void
82 {
83 $cb = $this->lb->end();
84 $this->assertInstanceOf(ControlBuilder::class, $cb);
85 }
86
87 public function testGUI(): void
88 {
89 $data_factory = new DataFactory();
90 $uri = $data_factory->uri('https://ilias.de/somepath');
91 $url_builder = new LSUrlBuilder($uri);
92 $ui_factory = $this->mockUIFactory();
93
94 $items = $this->lb
95 ->item('item 1', 1)
96 ->getItems();
97
98 $gui = new ilLSLocatorGUI($url_builder, $ui_factory);
99 $out = $gui->withItems($items)->getComponent();
100
101 $this->assertInstanceOf(Breadcrumbs::class, $out);
102
103 $expected = $this->stripHTML(
104 '<nav aria-label="breadcrumbs_aria_label" class="breadcrumb_wrapper"> ' .
105 ' <div class="breadcrumb"> ' .
106 ' <span class="crumb"> ' .
107 ' <a href="https://ilias.de/somepath?lsocmd=cmd&lsov=1">item 1</a>' .
108 ' </span> ' .
109 ' </div>' .
110 '</nav>'
111 );
112
113 $renderer = $this->getDefaultRenderer();
114 $html = $this->stripHTML($renderer->render($out));
115 $this->assertEquals($expected, $html);
116 }
117}
$out
Definition: buildRTE.php:24
$renderer
Builds data types.
Definition: Factory.php:36
Provides common functionality for UI tests.
Definition: Base.php:337
GUI for Locator element.
Build controls for the view.