ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
CardTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
24 use ILIAS\UI\Component as C;
27 
32 {
33  public function getFactory(): NoUIFactory
34  {
35  return new class () extends NoUIFactory {
36  public function legacy($content): C\Legacy\Legacy
37  {
38  $f = new I\Component\Legacy\Factory(new I\Component\SignalGenerator());
39  return $f->legacy($content);
40  }
41  };
42  }
43 
44  private function getCardFactory(): I\Component\Card\Factory
45  {
46  return new Factory();
47  }
48 
49  private function getBaseCard(): I\Component\Card\Standard
50  {
51  $cf = $this->getCardFactory();
52  $image = new I\Component\Image\Image("standard", "src", "alt");
53 
54  return $cf->standard("Card Title", $image);
55  }
56 
57  public function test_implements_factory_interface(): void
58  {
59  $this->assertInstanceOf("ILIAS\\UI\\Component\\Card\\Standard", $this->getBaseCard());
60  }
61 
62  public function test_factory_with_shy_button(): void
63  {
64  $button_factory = new I\Component\Button\Factory();
65  $button = $button_factory->shy("Card Title New", "");
66 
67  $cf = $this->getCardFactory();
68  $image = new I\Component\Image\Image("standard", "src", "alt");
69 
70  $this->assertEquals($button, $cf->standard($button, $image)->getTitle());
71  }
72 
73  public function test_get_title(): void
74  {
75  $c = $this->getBaseCard();
76 
77  $this->assertEquals("Card Title", $c->getTitle());
78  }
79 
80  public function test_with_title(): void
81  {
82  $c = $this->getBaseCard();
83  $c = $c->withTitle("Card Title New");
84 
85  $this->assertEquals("Card Title New", $c->getTitle());
86  }
87 
88  public function test_with_title_as_shy_button(): void
89  {
90  $c = $this->getBaseCard();
91  $button_factory = new I\Component\Button\Factory();
92  $button = $button_factory->shy("Card Title New", "");
93 
94  $c = $c->withTitle($button);
95  $this->assertEquals($button, $c->getTitle());
96  }
97 
98  public function test_with_string_title_action(): void
99  {
100  $c = $this->getBaseCard();
101  $c = $c->withTitleAction("newAction");
102  $this->assertEquals("newAction", $c->getTitleAction());
103  }
104 
105  public function test_with_signal_title_action(): void
106  {
107  $c = $this->getBaseCard();
108  $signal = $this->createMock(C\Signal::class);
109  $c = $c->withTitleAction($signal);
110  $this->assertEquals([$signal], $c->getTitleAction());
111  }
112 
113  public function test_with_highlight(): void
114  {
115  $c = $this->getBaseCard();
116  $c = $c->withHighlight(true);
117  $this->assertTrue($c->isHighlighted());
118  }
119 
120  public function test_get_image(): void
121  {
122  $card = $this->getBaseCard();
123  $image = new I\Component\Image\Image("standard", "src", "alt");
124 
125  $this->assertEquals($card->getImage(), $image);
126  }
127 
128  public function test_with_image(): void
129  {
130  $card = $this->getBaseCard();
131  $image_new = new I\Component\Image\Image("standard", "src/new", "alt");
132  $c = $card->withImage($image_new);
133 
134  $this->assertEquals($c->getImage(), $image_new);
135  }
136 
137  public function test_with_section(): void
138  {
139  $f = $this->getFactory();
140  $c = $this->getBaseCard();
141  $content = $f->legacy("Random Content");
142  $c = $c->withSections(array($content));
143 
144  $this->assertEquals($c->getSections(), array($content));
145  }
146 
147  public function test_render_content_full(): void
148  {
149  $r = $this->getDefaultRenderer();
150  $c = $this->getBaseCard();
151  $content = $this->getFactory()->legacy("Random Content");
152 
153  $c = $c->withSections(array($content));
154 
155  $html = $this->brutallyTrimHTML($r->render($c));
156 
157  $expected_html =
158  "<div class=\"il-card thumbnail\">" .
159  " <div class=\"il-card-image-container\"><img src=\"src\" class=\"img-standard\" alt=\"open Card Title\" /></div>" .
160  " <div class=\"card-no-highlight\"></div>" .
161  " <div class=\"caption card-title\">Card Title</div>" .
162  " <div class=\"caption\">Random Content</div>" .
163  "</div>";
164 
165  $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
166  }
167 
168  public function test_render_content_with_highlight(): void
169  {
170  $r = $this->getDefaultRenderer();
171  $c = $this->getBaseCard();
172  $c = $c->withHighlight(true);
173 
174  $html = $this->brutallyTrimHTML($r->render($c));
175 
176  $expected_html =
177  "<div class=\"il-card thumbnail\">" .
178  " <div class=\"il-card-image-container\"><img src=\"src\" class=\"img-standard\" alt=\"open Card Title\" /></div>" .
179  " <div class=\"card-highlight\"></div>" .
180  " <div class=\"caption card-title\">Card Title</div>" .
181  "</div>";
182 
183  $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
184  }
185 
187  {
188  $r = $this->getDefaultRenderer();
189  $c = $this->getBaseCard();
190  $title = new I\Component\Button\Shy('Card Title', '');
191  $c = $c->withTitle($title);
192 
193  $html = $this->brutallyTrimHTML($r->render($c));
194 
195  $expected_html =
196  "<div class=\"il-card thumbnail\">" .
197  " <div class=\"il-card-image-container\"><img src=\"src\" class=\"img-standard\" alt=\"open Card Title\" /></div>" .
198  " <div class=\"card-no-highlight\"></div>" .
199  " <div class=\"caption card-title\">" . $r->render($title) . "</div>" .
200  "</div>";
201 
202  $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
203  }
204 }
test_render_content_full()
Definition: CardTest.php:147
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
test_with_image()
Definition: CardTest.php:128
$c
Definition: cli.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
test_with_section()
Definition: CardTest.php:137
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
test_with_string_title_action()
Definition: CardTest.php:98
getBaseCard()
Definition: CardTest.php:49
test_factory_with_shy_button()
Definition: CardTest.php:62
getCardFactory()
Definition: CardTest.php:44
test_with_signal_title_action()
Definition: CardTest.php:105
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
test_with_title()
Definition: CardTest.php:80
Test on card implementation.
Definition: CardTest.php:31
test_get_image()
Definition: CardTest.php:120
test_render_content_with_highlight()
Definition: CardTest.php:168
getFactory()
Definition: CardTest.php:33
Provides common functionality for UI tests.
Definition: Base.php:298
test_get_title()
Definition: CardTest.php:73
test_with_highlight()
Definition: CardTest.php:113
test_implements_factory_interface()
Definition: CardTest.php:57
test_with_title_as_shy_button()
Definition: CardTest.php:88
test_render_content_with_component_title()
Definition: CardTest.php:186