ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
LSLocatorBuilderTest.php
Go to the documentation of this file.
1 <?php
2 
7 
8 require_once('IliasMocks.php');
9 require_once(__DIR__ . "/../../../tests/UI/Base.php");
10 
12 {
13  use IliasMocks;
14 
15 
16  public function stripHTML(string $html) : string
17  {
18  $html = $this->normalizeHTML($html);
19  return preg_replace('!\s+!', ' ', $html);
20  }
21 
22  public function setUp()
23  {
24  $cb = $this->createMock(LSControlBuilder::class);
25  $this->lb = new LSLocatorBuilder('cmd', $cb);
26  }
27 
28  public function testConstruction()
29  {
30  $this->assertInstanceOf(LSLocatorBuilder::class, $this->lb);
31  }
32 
33  public function testItemCreation()
34  {
35  $this->lb
36  ->item('item 1', 1)
37  ->item('item 2', 2)
38  ->item('item 3', 3);
39 
40  $this->assertCount(3, $this->lb->getItems());
41  }
42 
43  public function testItemStruct()
44  {
45  $this->lb
46  ->item('item 1', 1)
47  ->item('item 2', 2);
48 
49  $expected = [
50  [ 'label' => 'item 1',
51  'command' => 'cmd',
52  'parameter' => 1
53  ],
54  [ 'label' => 'item 2',
55  'command' => 'cmd',
56  'parameter' => 2
57  ]
58  ];
59 
60  $this->assertEquals($expected, $this->lb->getItems());
61  }
62 
63  public function testEnd()
64  {
65  $cb = $this->lb->end();
66  $this->assertInstanceOf(ControlBuilder::class, $cb);
67  }
68 
69  public function testGUI()
70  {
71  $data_factory = new DataFactory();
72  $uri = $data_factory->uri('http://ilias.de/somepath');
73  $url_builder = new LSUrlBuilder($uri);
74  $ui_factory = $this->mockUIFactory();
75 
76  $items = $this->lb
77  ->item('item 1', 1)
78  ->getItems();
79 
80  $gui = new ilLSLocatorGUI($url_builder, $ui_factory);
81  $out = $gui->withItems($items)->getComponent();
82 
83  $this->assertInstanceOf(Breadcrumbs::class, $out);
84 
85  $expected = $this->stripHTML(
86  '<nav role="navigation" aria-label="breadcrumbs"> ' .
87  ' <ul class="breadcrumb"> ' .
88  ' <li class="crumb"> ' .
89  ' <a href="http://ilias.de/somepath?lsocmd=cmd&lsov=1" >item 1</a>' .
90  ' </li> ' .
91  ' </ul>' .
92  '</nav>'
93  );
94 
95  $renderer = $this->getDefaultRenderer();
96  $html = $this->stripHTML($renderer->render($out));
97  $this->assertEquals($expected, $html);
98  }
99 }
Class LSTOCBuilder.
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
Class LSUrlBuilder.
normalizeHTML($html)
Definition: Base.php:261
Provides common functionality for UI tests.
Definition: Base.php:191
GUI for Locator element.
$html
Definition: example_001.php:87