ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CardTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
27
32{
33 public function getFactory(): NoUIFactory
34 {
35 return new class () extends NoUIFactory {
36 public function legacy(): I\Component\Legacy\Factory
37 {
38 return new I\Component\Legacy\Factory(new I\Component\SignalGenerator());
39 }
40 };
41 }
42
43 private function getCardFactory(): I\Component\Card\Factory
44 {
45 return new Factory();
46 }
47
48 private function getBaseCard(): I\Component\Card\Standard
49 {
50 $cf = $this->getCardFactory();
51 $image = new I\Component\Image\Image("standard", "src", "alt");
52
53 return $cf->standard("Card Title", $image);
54 }
55
56 public function testImplementsFactoryInterface(): void
57 {
58 $this->assertInstanceOf("ILIAS\\UI\\Component\\Card\\Standard", $this->getBaseCard());
59 }
60
61 public function testFactoryWithShyButton(): void
62 {
63 $button_factory = new I\Component\Button\Factory();
64 $button = $button_factory->shy("Card Title New", "");
65
66 $cf = $this->getCardFactory();
67 $image = new I\Component\Image\Image("standard", "src", "alt");
68
69 $this->assertEquals($button, $cf->standard($button, $image)->getTitle());
70 }
71
72 public function testGetTitle(): void
73 {
74 $c = $this->getBaseCard();
75
76 $this->assertEquals("Card Title", $c->getTitle());
77 }
78
79 public function testWithTitle(): void
80 {
81 $c = $this->getBaseCard();
82 $c = $c->withTitle("Card Title New");
83
84 $this->assertEquals("Card Title New", $c->getTitle());
85 }
86
87 public function testWithTitleAsShyButton(): void
88 {
89 $c = $this->getBaseCard();
90 $button_factory = new I\Component\Button\Factory();
91 $button = $button_factory->shy("Card Title New", "");
92
93 $c = $c->withTitle($button);
94 $this->assertEquals($button, $c->getTitle());
95 }
96
97 public function testWithStringTitleAction(): void
98 {
99 $c = $this->getBaseCard();
100 $c = $c->withTitleAction("newAction");
101 $this->assertEquals("newAction", $c->getTitleAction());
102 }
103
104 public function testWithSignalTitleAction(): void
105 {
106 $c = $this->getBaseCard();
107 $signal = $this->createMock(C\Signal::class);
108 $c = $c->withTitleAction($signal);
109 $this->assertEquals([$signal], $c->getTitleAction());
110 }
111
112 public function testWithHighlight(): void
113 {
114 $c = $this->getBaseCard();
115 $c = $c->withHighlight(true);
116 $this->assertTrue($c->isHighlighted());
117 }
118
119 public function testGetImage(): void
120 {
121 $card = $this->getBaseCard();
122 $image = new I\Component\Image\Image("standard", "src", "alt");
123
124 $this->assertEquals($card->getImage(), $image);
125 }
126
127 public function testWithImage(): void
128 {
129 $card = $this->getBaseCard();
130 $image_new = new I\Component\Image\Image("standard", "components/ILIAS/new", "alt");
131 $c = $card->withImage($image_new);
132
133 $this->assertEquals($c->getImage(), $image_new);
134 }
135
136 public function testWithSection(): void
137 {
138 $f = $this->getFactory();
139 $c = $this->getBaseCard();
140 $content = $f->legacy()->content("Random Content");
141 $c = $c->withSections(array($content));
142
143 $this->assertEquals($c->getSections(), array($content));
144 }
145
146 public function testRenderContentFull(): void
147 {
148 $r = $this->getDefaultRenderer();
149 $c = $this->getBaseCard();
150 $content = $this->getfactory()->legacy()->content("Random Content");
151
152 $c = $c->withSections(array($content));
153
154 $html = $this->brutallyTrimHTML($r->render($c));
155
156 $expected_html =
157 "<div class=\"il-card thumbnail\">" .
158 " <div class=\"il-card-image-container\"><img src=\"src\" class=\"img-standard\" alt=\"open Card Title\" /></div>" .
159 " <div class=\"card-no-highlight\"></div>" .
160 " <div class=\"caption card-title\">Card Title</div>" .
161 " <div class=\"caption\">Random Content</div>" .
162 "</div>";
163
164 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
165 }
166
167 public function testRenderContentWithHighlight(): void
168 {
169 $r = $this->getDefaultRenderer();
170 $c = $this->getBaseCard();
171 $c = $c->withHighlight(true);
172
173 $html = $this->brutallyTrimHTML($r->render($c));
174
175 $expected_html =
176 "<div class=\"il-card thumbnail\">" .
177 " <div class=\"il-card-image-container\"><img src=\"src\" class=\"img-standard\" alt=\"open Card Title\" /></div>" .
178 " <div class=\"card-highlight\"></div>" .
179 " <div class=\"caption card-title\">Card Title</div>" .
180 "</div>";
181
182 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
183 }
184
186 {
187 $r = $this->getDefaultRenderer();
188 $c = $this->getBaseCard();
189 $title = new I\Component\Button\Shy('Card Title', '');
190 $c = $c->withTitle($title);
191
192 $html = $this->brutallyTrimHTML($r->render($c));
193
194 $expected_html =
195 "<div class=\"il-card thumbnail\">" .
196 " <div class=\"il-card-image-container\"><img src=\"src\" class=\"img-standard\" alt=\"open Card Title\" /></div>" .
197 " <div class=\"card-no-highlight\"></div>" .
198 " <div class=\"caption card-title\">" . $r->render($title) . "</div>" .
199 "</div>";
200
201 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
202 }
203}
Test on card implementation.
Definition: CardTest.php:32
testRenderContentWithHighlight()
Definition: CardTest.php:167
getFactory()
Definition: CardTest.php:33
getBaseCard()
Definition: CardTest.php:48
testWithStringTitleAction()
Definition: CardTest.php:97
testImplementsFactoryInterface()
Definition: CardTest.php:56
testWithSignalTitleAction()
Definition: CardTest.php:104
testGetImage()
Definition: CardTest.php:119
testWithImage()
Definition: CardTest.php:127
testWithTitle()
Definition: CardTest.php:79
testRenderContentFull()
Definition: CardTest.php:146
testGetTitle()
Definition: CardTest.php:72
testWithTitleAsShyButton()
Definition: CardTest.php:87
getCardFactory()
Definition: CardTest.php:43
test_render_content_with_component_title()
Definition: CardTest.php:185
testWithSection()
Definition: CardTest.php:136
testWithHighlight()
Definition: CardTest.php:112
testFactoryWithShyButton()
Definition: CardTest.php:61
Provides common functionality for UI tests.
Definition: Base.php:337
$c
Definition: deliver.php:25