ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
BreadcrumbsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
24 use ILIAS\UI\Component as C;
26 
31 {
32  public function getFactory(): NoUIFactory
33  {
34  return new class () extends NoUIFactory {
35  public function breadcrumbs(array $crumbs): C\Breadcrumbs\Breadcrumbs
36  {
37  return new I\Component\Breadcrumbs\Breadcrumbs($crumbs);
38  }
39  };
40  }
41 
42  public function testImplementsFactoryInterface(): void
43  {
44  $f = $this->getFactory();
45 
46  $this->assertInstanceOf("ILIAS\\UI\\Factory", $f);
47  $this->assertInstanceOf(
48  "ILIAS\\UI\\Component\\Breadcrumbs\\Breadcrumbs",
49  $f->breadcrumbs(array())
50  );
51  }
52 
53  public function testCrumbs(): void
54  {
55  $f = $this->getFactory();
56  $crumbs = array(
57  new I\Component\Link\Standard("label", '#'),
58  new I\Component\Link\Standard("label2", '#')
59  );
60 
61  $c = $f->breadcrumbs($crumbs);
62  $this->assertEquals($crumbs, $c->getItems());
63  }
64 
65  public function testAppending(): void
66  {
67  $f = $this->getFactory();
68  $crumb = new I\Component\Link\Standard("label2", '#');
69 
70  $c = $f->Breadcrumbs(array())
71  ->withAppendedItem($crumb);
72  $this->assertEquals(array($crumb), $c->getItems());
73  }
74 
75  public function testRendering(): void
76  {
77  $f = $this->getFactory();
78  $r = $this->getDefaultRenderer();
79 
80  $crumbs = array(
81  new I\Component\Link\Standard("label", '#'),
82  new I\Component\Link\Standard("label2", '#')
83  );
84  $c = $f->Breadcrumbs($crumbs);
85 
86  $html = $this->normalizeHTML($r->render($c));
87  $expected = '<nav aria-label="breadcrumbs_aria_label" class="breadcrumb-wrapper">'
88  . ' <div class="breadcrumb" dir="rtl">'
89  . ' <span class="breadcrumb-crumb" dir="ltr">'
90  . ' <a href="#">label2</a>'
91  . ' </span>'
92  . ' <span class="breadcrumb-separator" dir="rtl">&#9247;</span>'
93  . ' <span class="breadcrumb-crumb" dir="ltr">'
94  . ' <a href="#">label</a>'
95  . ' </span>'
96  . ' </div>'
97  . '</nav>';
98 
99  $this->assertHTMLEquals($expected, $html);
100  }
101 
102  public function testRenderingWithSpecialCharacters(): void
103  {
104  $f = $this->getFactory();
105  $r = $this->getDefaultRenderer();
106 
107  $label = "label without special characters";
108  $label2 = "label with special characters + –...+}*@ç%#&/($";
109 
110  $crumbs = [
111  new I\Component\Link\Standard($label, '#'),
112  new I\Component\Link\Standard($label2, '#')
113  ];
114  $c = $f->Breadcrumbs($crumbs);
115 
116  $html = $this->brutallyTrimHTML($r->render($c));
117  $expected = '<nav aria-label="breadcrumbs_aria_label" class="breadcrumb-wrapper">'
118  . ' <div class="breadcrumb" dir="rtl">'
119  . ' <span class="breadcrumb-crumb" dir="ltr">'
120  . ' <a href="#">label with special characters + –...+}*@ç%#&/($</a>'
121  . ' </span>'
122  . ' <span class="breadcrumb-separator" dir="rtl">&#9247;</span>'
123  . ' <span class="breadcrumb-crumb" dir="ltr">'
124  . ' <a href="#">label without special characters</a>'
125  . ' </span>'
126  . ' </div>'
127  . '</nav>';
128 
129  $this->assertEquals($this->brutallyTrimHTML($expected), $html);
130  }
131 }
Tests for the Breadcrumbs-component.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: deliver.php:9
breadcrumbs()
description: > Example showing how to construct Breadcrumbs with an array of Links and extending the...
Definition: breadcrumbs.php:17
$r