ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
LSLocatorBuilderTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 2021 - Nils Haagen <nils.haagen@concepts-and-training.de> - Extended GPL, see LICENSE */
6 
10 
11 require_once('IliasMocks.php');
12 require_once(__DIR__ . "/../../../tests/UI/Base.php");
13 
31 {
32  use IliasMocks;
33 
34  protected LSLocatorBuilder $lb;
35 
36  public function stripHTML(string $html): string
37  {
38  $html = $this->normalizeHTML($html);
39  return preg_replace('!\s+!', ' ', $html);
40  }
41 
42  public function setUp(): void
43  {
44  $cb = $this->createMock(LSControlBuilder::class);
45  $this->lb = new LSLocatorBuilder('cmd', $cb);
46  }
47 
48  public function testConstruction(): void
49  {
50  $this->assertInstanceOf(LSLocatorBuilder::class, $this->lb);
51  }
52 
53  public function testItemCreation(): void
54  {
55  $this->lb
56  ->item('item 1', 1)
57  ->item('item 2', 2)
58  ->item('item 3', 3);
59 
60  $this->assertCount(3, $this->lb->getItems());
61  }
62 
63  public function testItemStruct(): void
64  {
65  $this->lb
66  ->item('item 1', 1)
67  ->item('item 2', 2);
68 
69  $expected = [
70  [ 'label' => 'item 1',
71  'command' => 'cmd',
72  'parameter' => 1
73  ],
74  [ 'label' => 'item 2',
75  'command' => 'cmd',
76  'parameter' => 2
77  ]
78  ];
79 
80  $this->assertEquals($expected, $this->lb->getItems());
81  }
82 
83  public function testEnd(): void
84  {
85  $cb = $this->lb->end();
86  $this->assertInstanceOf(ControlBuilder::class, $cb);
87  }
88 
89  public function testGUI(): void
90  {
91  $data_factory = new DataFactory();
92  $uri = $data_factory->uri('https://ilias.de/somepath');
93  $url_builder = new LSUrlBuilder($uri);
94  $ui_factory = $this->mockUIFactory();
95 
96  $items = $this->lb
97  ->item('item 1', 1)
98  ->getItems();
99 
100  $gui = new ilLSLocatorGUI($url_builder, $ui_factory);
101  $out = $gui->withItems($items)->getComponent();
102 
103  $this->assertInstanceOf(Breadcrumbs::class, $out);
104 
105  $expected = $this->stripHTML(
106  '<nav aria-label="breadcrumbs_aria_label" class="breadcrumb_wrapper"> ' .
107  ' <div class="breadcrumb"> ' .
108  ' <span class="crumb"> ' .
109  ' <a href="https://ilias.de/somepath?lsocmd=cmd&lsov=1" >item 1</a>' .
110  ' </span> ' .
111  ' </div>' .
112  '</nav>'
113  );
114 
115  $renderer = $this->getDefaultRenderer();
116  $html = $this->stripHTML($renderer->render($out));
117  $this->assertEquals($expected, $html);
118  }
119 }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Provides common functionality for UI tests.
Definition: Base.php:298
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$out
Definition: buildRTE.php:24
GUI for Locator element.
normalizeHTML(string $html)
Definition: Base.php:422