ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 
14 {
15 
19  public function getFactory()
20  {
21  return new \ILIAS\UI\Implementation\Factory();
22  }
23 
25  {
26  $f = $this->getFactory();
27 
28  $this->assertInstanceOf("ILIAS\\UI\\Factory", $f);
29  $this->assertInstanceOf("ILIAS\\UI\\Component\\Card\\Card", $f->card("Card Title"));
30  }
31 
32  public function test_get_title()
33  {
34  $f = $this->getFactory();
35  $c = $f->card("Card Title");
36 
37  $this->assertEquals($c->getTitle(), "Card Title");
38  }
39 
40  public function test_with_title()
41  {
42  $f = $this->getFactory();
43 
44  $c = $f->card("Card Title");
45  $c = $c->withTitle("Card Title New");
46 
47  $this->assertEquals($c->getTitle(), "Card Title New");
48  }
49 
50  public function test_with_title_action()
51  {
52  $f = $this->getFactory();
53  $c = $f->card("Card Title");
54  $c = $c->withTitleAction("newAction");
55  $this->assertEquals("newAction", $c->getTitleAction());
56  }
57 
58  public function test_with_highlight()
59  {
60  $f = $this->getFactory();
61  $c = $f->card("Card Title");
62  $c = $c->withHighlight(true);
63  $this->assertTrue($c->isHighlighted());
64  }
65 
66  public function test_get_image()
67  {
68  $f = $this->getFactory();
69 
70  $image = $f->image()->standard("src", "str");
71  $c = $f->card("Card Title", $image);
72 
73  $this->assertEquals($c->getImage(), $image);
74  }
75 
76  public function test_with_image()
77  {
78  $f = $this->getFactory();
79 
80  $image = $f->image()->standard("src", "str");
81  $c = $f->card("Card Title", $image);
82 
83  $image_new = $f->image()->standard("src/new", "str");
84 
85  $c = $c->withImage($image_new);
86 
87  $this->assertEquals($c->getImage(), $image_new);
88  }
89 
90  public function test_with_section()
91  {
92  $f = $this->getFactory();
93 
94  $c = $f->card("Card Title");
95 
96  $content = $f->legacy("Random Content");
97 
98  $c = $c->withSections(array($content));
99 
100  $this->assertEquals($c->getSections(), array($content));
101  }
102 
103  public function test_render_content_empty()
104  {
105  $f = $this->getFactory();
106  $r = $this->getDefaultRenderer();
107 
108  $c = $f->card("Card Title");
109 
110  $html = $r->render($c);
111 
112  $expected_html =
113  "<div class=\"il-card thumbnail\">" .
114  " <div class=\"card-no-highlight\"></div>" .
115  " <div class=\"caption\">" .
116  " <h5 class=\"card-title\">Card Title</h5>" .
117  " </div>" .
118  "</div>";
119 
120  $this->assertHTMLEquals($expected_html, $html);
121  }
122 
123  public function test_render_content_full()
124  {
125  $f = $this->getFactory();
126  $r = $this->getDefaultRenderer();
127 
128  $image = $f->image()->standard("src", "alt");
129 
130  $c = $f->card("Card Title", $image);
131 
132  $content = $f->legacy("Random Content");
133 
134  $c = $c->withSections(array($content));
135 
136  $html = $r->render($c);
137 
138  $expected_html =
139  "<div class=\"il-card thumbnail\">" .
140  " <img src=\"src\" class=\"img-standard\" alt=\"alt\" />" .
141  " <div class=\"card-no-highlight\"></div>" .
142  " <div class=\"caption\">" .
143  " <h5 class=\"card-title\">Card Title</h5>" .
144  " </div>" .
145  " <div class=\"caption\">Random Content</div>" .
146  "</div>";
147 
148  $this->assertHTMLEquals($expected_html, $html);
149  }
150 
152  {
153  $f = $this->getFactory();
154  $r = $this->getDefaultRenderer();
155 
156  $image = $f->image()->standard("src", "alt");
157 
158  $c = $f->card("Card Title", $image)->withHighlight(true);
159 
160  $html = $r->render($c);
161 
162  $expected_html =
163  "<div class=\"il-card thumbnail\">" .
164  " <img src=\"src\" class=\"img-standard\" alt=\"alt\" />" .
165  " <div class=\"card-highlight\"></div>" .
166  " <div class=\"caption\">" .
167  " <h5 class=\"card-title\">Card Title</h5>" .
168  " </div>" .
169  "</div>";
170 
171  $this->assertHTMLEquals($expected_html, $html);
172  }
173 }
test_render_content_full()
Definition: CardTest.php:123
test_with_image()
Definition: CardTest.php:76
test_with_section()
Definition: CardTest.php:90
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
test_with_title()
Definition: CardTest.php:40
test_render_content_empty()
Definition: CardTest.php:103
Test on card implementation.
Definition: CardTest.php:13
test_get_image()
Definition: CardTest.php:66
test_render_content_with_highlight()
Definition: CardTest.php:151
getFactory()
Definition: CardTest.php:19
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:177
test_with_title_action()
Definition: CardTest.php:50
test_get_title()
Definition: CardTest.php:32
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:252
Create styles array
The data for the language used.
test_with_highlight()
Definition: CardTest.php:58
test_implements_factory_interface()
Definition: CardTest.php:24
$html
Definition: example_001.php:87