ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
CardTest.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 
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 testImplementsFactoryInterface(): void
58  {
59  $this->assertInstanceOf("ILIAS\\UI\\Component\\Card\\Standard", $this->getBaseCard());
60  }
61 
62  public function testFactoryWithShyButton(): 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 testGetTitle(): void
74  {
75  $c = $this->getBaseCard();
76 
77  $this->assertEquals("Card Title", $c->getTitle());
78  }
79 
80  public function testWithTitle(): 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 testWithTitleAsShyButton(): 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 testWithStringTitleAction(): void
99  {
100  $c = $this->getBaseCard();
101  $c = $c->withTitleAction("newAction");
102  $this->assertEquals("newAction", $c->getTitleAction());
103  }
104 
105  public function testWithSignalTitleAction(): 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 testWithHighlight(): void
114  {
115  $c = $this->getBaseCard();
116  $c = $c->withHighlight(true);
117  $this->assertTrue($c->isHighlighted());
118  }
119 
120  public function testGetImage(): 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 testWithImage(): void
129  {
130  $card = $this->getBaseCard();
131  $image_new = new I\Component\Image\Image("standard", "components/ILIAS/new", "alt");
132  $c = $card->withImage($image_new);
133 
134  $this->assertEquals($c->getImage(), $image_new);
135  }
136 
137  public function testWithSection(): 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 testRenderContentFull(): 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 testRenderContentWithHighlight(): 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 }
testWithImage()
Definition: CardTest.php:128
testFactoryWithShyButton()
Definition: CardTest.php:62
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getBaseCard()
Definition: CardTest.php:49
getCardFactory()
Definition: CardTest.php:44
testGetTitle()
Definition: CardTest.php:73
$c
Definition: deliver.php:9
Test on card implementation.
Definition: CardTest.php:31
testImplementsFactoryInterface()
Definition: CardTest.php:57
testWithSignalTitleAction()
Definition: CardTest.php:105
Implementation of factory for cards.
Definition: Factory.php:31
getFactory()
Definition: CardTest.php:33
testRenderContentFull()
Definition: CardTest.php:147
testWithTitle()
Definition: CardTest.php:80
testWithSection()
Definition: CardTest.php:137
testGetImage()
Definition: CardTest.php:120
legacy()
expected output: > ILIAS shows the rendered Component.
Definition: legacy.php:13
testWithHighlight()
Definition: CardTest.php:113
testRenderContentWithHighlight()
Definition: CardTest.php:168
testWithTitleAsShyButton()
Definition: CardTest.php:88
testWithStringTitleAction()
Definition: CardTest.php:98
test_render_content_with_component_title()
Definition: CardTest.php:186
$r