ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 use \ILIAS\UI\Implementation as I;
10 
15 {
16 
20  public function getFactory()
21  {
22  return new \ILIAS\UI\Implementation\Factory(
23  $this->createMock(C\Counter\Factory::class),
24  $this->createMock(C\Glyph\Factory::class),
25  $this->createMock(C\Button\Factory::class),
26  $this->createMock(C\Listing\Factory::class),
27  $this->createMock(C\Image\Factory::class),
28  $this->createMock(C\Panel\Factory::class),
29  $this->createMock(C\Modal\Factory::class),
30  $this->createMock(C\Dropzone\Factory::class),
31  $this->createMock(C\Popover\Factory::class),
32  $this->createMock(C\Divider\Factory::class),
33  $this->createMock(C\Link\Factory::class),
34  $this->createMock(C\Dropdown\Factory::class),
35  $this->createMock(C\Item\Factory::class),
36  $this->createMock(C\Icon\Factory::class),
37  $this->createMock(C\ViewControl\Factory::class),
38  $this->createMock(C\Chart\Factory::class),
39  $this->createMock(C\Input\Factory::class),
40  $this->createMock(C\Table\Factory::class),
41  $this->createMock(C\MessageBox\Factory::class),
42  $this->createMock(C\Card\Factory::class)
43  );
44  }
45 
46  private function getCardFactory()
47  {
48  return new \ILIAS\UI\Implementation\Component\Card\Factory();
49  }
50 
51  private function getBaseCard()
52  {
53  $cf = $this->getCardFactory();
54  $image = new I\Component\Image\Image("standard", "src", "alt");
55 
56  return $cf->standard("Card Title", $image);
57  }
58 
60  {
61  $this->assertInstanceOf("ILIAS\\UI\\Component\\Card\\Standard", $this->getBaseCard());
62  }
63 
64  public function test_get_title()
65  {
66  $c = $this->getBaseCard();
67 
68  $this->assertEquals($c->getTitle(), "Card Title");
69  }
70 
71  public function test_with_title()
72  {
73  $c = $this->getBaseCard();
74  $c = $c->withTitle("Card Title New");
75 
76  $this->assertEquals($c->getTitle(), "Card Title New");
77  }
78 
79  public function test_with_title_action()
80  {
81  $c = $this->getBaseCard();
82  $c = $c->withTitleAction("newAction");
83  $this->assertEquals("newAction", $c->getTitleAction());
84  }
85 
86  public function test_with_highlight()
87  {
88  $c = $this->getBaseCard();
89  $c = $c->withHighlight(true);
90  $this->assertTrue($c->isHighlighted());
91  }
92 
93  public function test_get_image()
94  {
95  $card = $this->getBaseCard();
96  $image = new I\Component\Image\Image("standard", "src", "alt");
97 
98  $this->assertEquals($card->getImage(), $image);
99  }
100 
101  public function test_with_image()
102  {
103  $card = $this->getBaseCard();
104  $image_new = new I\Component\Image\Image("standard", "src/new", "alt");
105  $c = $card->withImage($image_new);
106 
107  $this->assertEquals($c->getImage(), $image_new);
108  }
109 
110  public function test_with_section()
111  {
112  $f = $this->getFactory();
113  $c = $this->getBaseCard();
114  $content = $f->legacy("Random Content");
115  $c = $c->withSections(array($content));
116 
117  $this->assertEquals($c->getSections(), array($content));
118  }
119 
120  public function test_with_image_action()
121  {
122  $c = $this->getBaseCard();
123  $action = "https://www.ilias.de";
124  $c = $c->withImageAction($action);
125 
126  $this->assertEquals($c->getImageAction(), $action);
127  }
128 
129  public function test_render_content_full()
130  {
131  $r = $this->getDefaultRenderer();
132 
133  $c = $this->getBaseCard();
134 
135  $content = new I\Component\Legacy\Legacy("Random Content");
136 
137  $c = $c->withSections(array($content));
138 
139  $html = $r->render($c);
140 
141  $expected_html =
142  "<div class=\"il-card thumbnail\">" .
143  " <img src=\"src\" class=\"img-standard\" alt=\"alt\" />" .
144  " <div class=\"card-no-highlight\"></div>" .
145  " <div class=\"caption\">" .
146  " <h5 class=\"card-title\">Card Title</h5>" .
147  " </div>" .
148  " <div class=\"caption\">Random Content</div>" .
149  "</div>";
150 
151  $this->assertHTMLEquals($expected_html, $html);
152  }
153 
155  {
156  $r = $this->getDefaultRenderer();
157  $c = $this->getBaseCard();
158  $c = $c->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:129
test_with_image_action()
Definition: CardTest.php:120
test_with_image()
Definition: CardTest.php:101
$action
test_with_section()
Definition: CardTest.php:110
getBaseCard()
Definition: CardTest.php:51
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
getCardFactory()
Definition: CardTest.php:46
test_with_title()
Definition: CardTest.php:71
Test on card implementation.
Definition: CardTest.php:14
test_get_image()
Definition: CardTest.php:93
test_render_content_with_highlight()
Definition: CardTest.php:154
getFactory()
Definition: CardTest.php:20
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:191
test_with_title_action()
Definition: CardTest.php:79
test_get_title()
Definition: CardTest.php:64
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:270
test_with_highlight()
Definition: CardTest.php:86
test_implements_factory_interface()
Definition: CardTest.php:59
$html
Definition: example_001.php:87