ILIAS  release_7 Revision v7.30-3-g800a261c036
CardTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \ILIAS\UI\Component as C;
9use \ILIAS\UI\Implementation as I;
10
15{
19 public function getFactory()
20 {
21 $factory = new class extends NoUIFactory {
22 public function legacy($content)
23 {
24 $f = new I\Component\Legacy\Factory(new I\Component\SignalGenerator());
25 return $f->legacy($content);
26 }
27 };
28 return $factory;
29 }
30
31 private function getCardFactory()
32 {
33 return new \ILIAS\UI\Implementation\Component\Card\Factory();
34 }
35
36 private function getBaseCard()
37 {
38 $cf = $this->getCardFactory();
39 $image = new I\Component\Image\Image("standard", "src", "alt");
40
41 return $cf->standard("Card Title", $image);
42 }
43
45 {
46 $this->assertInstanceOf("ILIAS\\UI\\Component\\Card\\Standard", $this->getBaseCard());
47 }
48
49 public function test_get_title()
50 {
51 $c = $this->getBaseCard();
52
53 $this->assertEquals($c->getTitle(), "Card Title");
54 }
55
56 public function test_with_title()
57 {
58 $c = $this->getBaseCard();
59 $c = $c->withTitle("Card Title New");
60
61 $this->assertEquals($c->getTitle(), "Card Title New");
62 }
63
65 {
66 $c = $this->getBaseCard();
67 $c = $c->withTitleAction("newAction");
68 $this->assertEquals("newAction", $c->getTitleAction());
69 }
70
72 {
73 $c = $this->getBaseCard();
74 $signal = $this->createMock(C\Signal::class);
75 $c = $c->withTitleAction($signal);
76 $this->assertEquals([$signal], $c->getTitleAction());
77 }
78
79 public function test_with_highlight()
80 {
81 $c = $this->getBaseCard();
82 $c = $c->withHighlight(true);
83 $this->assertTrue($c->isHighlighted());
84 }
85
86 public function test_get_image()
87 {
88 $card = $this->getBaseCard();
89 $image = new I\Component\Image\Image("standard", "src", "alt");
90
91 $this->assertEquals($card->getImage(), $image);
92 }
93
94 public function test_with_image()
95 {
96 $card = $this->getBaseCard();
97 $image_new = new I\Component\Image\Image("standard", "src/new", "alt");
98 $c = $card->withImage($image_new);
99
100 $this->assertEquals($c->getImage(), $image_new);
101 }
102
103 public function test_with_section()
104 {
105 $f = $this->getFactory();
106 $c = $this->getBaseCard();
107 $content = $f->legacy("Random Content");
108 $c = $c->withSections(array($content));
109
110 $this->assertEquals($c->getSections(), array($content));
111 }
112
113 public function test_render_content_full()
114 {
115 $r = $this->getDefaultRenderer();
116 $c = $this->getBaseCard();
117 $content = $this->getFactory()->legacy("Random Content");
118
119 $c = $c->withSections(array($content));
120
121 $html = $this->brutallyTrimHTML($r->render($c));
122
123 $expected_html =
124 "<div class=\"il-card thumbnail\">" .
125 " <div class=\"il-card-image-container\"><img src=\"src\" class=\"img-standard\" alt=\"alt\" /></div>" .
126 " <div class=\"card-no-highlight\"></div>" .
127 " <div class=\"caption card-title\">Card Title</div>" .
128 " <div class=\"caption\">Random Content</div>" .
129 "</div>";
130
131 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
132 }
133
135 {
136 $r = $this->getDefaultRenderer();
137 $c = $this->getBaseCard();
138 $c = $c->withHighlight(true);
139
140 $html = $this->brutallyTrimHTML($r->render($c));
141
142 $expected_html =
143 "<div class=\"il-card thumbnail\">" .
144 " <div class=\"il-card-image-container\"><img src=\"src\" class=\"img-standard\" alt=\"alt\" /></div>" .
145 " <div class=\"card-highlight\"></div>" .
146 " <div class=\"caption card-title\">Card Title</div>" .
147 "</div>";
148
149 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
150 }
151}
An exception for terminatinating execution or to throw for unit testing.
Test on card implementation.
Definition: CardTest.php:15
test_with_image()
Definition: CardTest.php:94
getFactory()
Definition: CardTest.php:19
getBaseCard()
Definition: CardTest.php:36
test_get_image()
Definition: CardTest.php:86
test_with_title()
Definition: CardTest.php:56
test_with_string_title_action()
Definition: CardTest.php:64
test_with_signal_title_action()
Definition: CardTest.php:71
test_implements_factory_interface()
Definition: CardTest.php:44
test_with_section()
Definition: CardTest.php:103
test_render_content_full()
Definition: CardTest.php:113
getCardFactory()
Definition: CardTest.php:31
test_with_highlight()
Definition: CardTest.php:79
test_render_content_with_highlight()
Definition: CardTest.php:134
test_get_title()
Definition: CardTest.php:49
Provides common functionality for UI tests.
Definition: Base.php:263
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
$c
Definition: cli.php:37
legacy()
Definition: legacy.php:3
$factory
Definition: metadata.php:58