ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
LinkTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
27 
32 {
33  public function getLinkFactory(): I\Link\Factory
34  {
35  return new I\Link\Factory();
36  }
37 
38  public function testImplementsFactoryInterface(): void
39  {
40  $f = $this->getLinkFactory();
41 
42  $this->assertInstanceOf("ILIAS\\UI\\Component\\Link\\Factory", $f);
43  $this->assertInstanceOf(
44  "ILIAS\\UI\\Component\\Link\\Standard",
45  $f->standard("label", "http://www.ilias.de")
46  );
47  }
48 
49  public function testGetLabel(): void
50  {
51  $f = $this->getLinkFactory();
52  $c = $f->standard("label", "http://www.ilias.de");
53 
54  $this->assertEquals("label", $c->getLabel());
55  }
56 
57  public function testGetAction(): void
58  {
59  $f = $this->getLinkFactory();
60  $c = $f->standard("label", "http://www.ilias.de");
61 
62  $this->assertEquals("http://www.ilias.de", $c->getAction());
63  }
64 
65  public function testRenderLink(): void
66  {
67  $f = $this->getLinkFactory();
68  $r = $this->getDefaultRenderer();
69 
70  $c = $f->standard("label", "http://www.ilias.de");
71 
72  $html = $r->render($c);
73 
74  $expected_html =
75  '<a href="http://www.ilias.de">label</a>';
76 
77  $this->assertHTMLEquals($expected_html, $html);
78  }
79 
80  public function testRenderWithNewViewport(): void
81  {
82  $f = $this->getLinkFactory();
83  $r = $this->getDefaultRenderer();
84 
85  $c = $f->standard("label", "http://www.ilias.de")->withOpenInNewViewport(true);
86 
87  $html = $r->render($c);
88 
89  $expected_html =
90  '<a href="http://www.ilias.de" target="_blank" rel="noopener">label</a>';
91 
92  $this->assertHTMLEquals($expected_html, $html);
93  }
94 
95  public function testRenderWithLanguage(): void
96  {
97  $language = $this->getMockBuilder(LanguageTag::class)->getMock();
98  $language->method('__toString')->willReturn('en');
99  $reference = $this->getMockBuilder(LanguageTag::class)->getMock();
100  $reference->method('__toString')->willReturn('fr');
101 
102  $f = $this->getLinkFactory();
103  $r = $this->getDefaultRenderer();
104 
105  $c = $f->standard("label", "http://www.ilias.de")
106  ->withContentLanguage($language)
107  ->withLanguageOfReferencedContent($reference);
108 
109  $html = $r->render($c);
110 
111  $expected_html =
112  '<a lang="en" hreflang="fr" href="http://www.ilias.de">label</a>';
113 
114  $this->assertHTMLEquals($expected_html, $html);
115  }
116 
117  public function testRenderWithHelpTopic(): void
118  {
119  $f = $this->getLinkFactory();
120  $r = $this->getDefaultRenderer();
121  $c = $f->standard("label", "http://www.ilias.de")
122  ->withHelpTopics(new \ILIAS\UI\Help\Topic("a"));
123 
124  $html = $r->render($c);
125 
126  $expected_html = ''
127  . '<div class="c-tooltip__container">'
128  . '<a href="http://www.ilias.de" id="id_2" aria-describedby="id_1">label</a>'
129  . '<div id="id_1" role="tooltip" class="c-tooltip c-tooltip--hidden"><p>tooltip: a</p></div>'
130  . '</div>';
131 
132  $this->assertHTMLEquals($expected_html, $html);
133  }
134 
135  public function testRenderWithRelationships(): void
136  {
137  $f = $this->getLinkFactory();
138  $r = $this->getDefaultRenderer();
139  $c = $f->standard("label", "http://www.ilias.de")
140  ->withAdditionalRelationshipToReferencedResource(Relationship::LICENSE)
141  ->withAdditionalRelationshipToReferencedResource(Relationship::NOOPENER);
142 
143  $expected_html =
144  '<a href="http://www.ilias.de" rel="license noopener">label</a>';
145 
146  $html = $r->render($c);
147  $this->assertHTMLEquals($expected_html, $html);
148  }
149 
150  public function testRenderWithDuplicateRelationship(): void
151  {
152  $f = $this->getLinkFactory();
153  $r = $this->getDefaultRenderer();
154  $c = $f->standard("label", "http://www.ilias.de")
155  ->withAdditionalRelationshipToReferencedResource(Relationship::LICENSE)
156  ->withAdditionalRelationshipToReferencedResource(Relationship::NOOPENER)
157  ->withAdditionalRelationshipToReferencedResource(Relationship::LICENSE);
158 
159  $expected_html =
160  '<a href="http://www.ilias.de" rel="license noopener">label</a>';
161 
162  $html = $r->render($c);
163  $this->assertHTMLEquals($expected_html, $html);
164  }
165 
166  public function testLinkRenderWithDisabled(): void
167  {
168  $f = $this->getLinkFactory();
169  $r = $this->getDefaultRenderer();
170  $c = $f->standard("label", "http://www.ilias.de")
171  ->withDisabled(true);
172 
173  $expected_html = '<a aria-disabled="true">label</a>';
174  $this->assertHTMLEquals($expected_html, $r->render($c));
175  }
176 }
testGetAction()
Definition: LinkTest.php:57
Interface Observer Contains several chained tasks and infos about them.
getLinkFactory()
Definition: LinkTest.php:33
testLinkRenderWithDisabled()
Definition: LinkTest.php:166
$c
Definition: deliver.php:25
testRenderWithHelpTopic()
Definition: LinkTest.php:117
testRenderWithNewViewport()
Definition: LinkTest.php:80
Test on link implementation.
Definition: LinkTest.php:31
testRenderWithLanguage()
Definition: LinkTest.php:95
testGetLabel()
Definition: LinkTest.php:49
testRenderLink()
Definition: LinkTest.php:65
testImplementsFactoryInterface()
Definition: LinkTest.php:38
testRenderWithDuplicateRelationship()
Definition: LinkTest.php:150
testRenderWithRelationships()
Definition: LinkTest.php:135
$r