ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
10 
14 class CardTest extends ILIAS_UI_TestBase {
15 
19  public function getFactory() {
20  return new \ILIAS\UI\Implementation\Factory();
21  }
22 
24  $f = $this->getFactory();
25 
26  $this->assertInstanceOf("ILIAS\\UI\\Factory", $f);
27  $this->assertInstanceOf( "ILIAS\\UI\\Component\\Card\\Card", $f->card("Card Title"));
28  }
29 
30  public function test_get_title() {
31  $f = $this->getFactory();
32  $c = $f->card("Card Title");
33 
34  $this->assertEquals($c->getTitle(), "Card Title");
35  }
36 
37  public function test_with_title() {
38  $f = $this->getFactory();
39 
40  $c = $f->card("Card Title");
41  $c = $c->withTitle("Card Title New");
42 
43  $this->assertEquals($c->getTitle(), "Card Title New");
44  }
45 
46  public function test_get_image() {
47  $f = $this->getFactory();
48 
49  $image = $f->image()->standard("src","str");
50  $c = $f->card("Card Title",$image);
51 
52  $this->assertEquals($c->getImage(), $image);
53  }
54 
55  public function test_with_image() {
56  $f = $this->getFactory();
57 
58  $image = $f->image()->standard("src","str");
59  $c = $f->card("Card Title",$image);
60 
61  $image_new = $f->image()->standard("src/new","str");
62 
63  $c = $c->withImage($image_new);
64 
65  $this->assertEquals($c->getImage(), $image_new);
66  }
67 
68  public function test_with_section() {
69  $f = $this->getFactory();
70 
71  $c = $f->card("Card Title");
72 
73  $content = $f->legacy("Random Content");
74 
75  $c = $c->withSections(array($content));
76 
77  $this->assertEquals($c->getSections(), array($content));
78  }
79 
80  public function test_render_content_empty() {
81  $f = $this->getFactory();
82  $r = $this->getDefaultRenderer();
83 
84  $c = $f->card("Card Title");
85 
86  $html = $r->render($c);
87 
88  $expected_html =
89  "<div class=\"il-card thumbnail\">".
90  " <div class=\"caption\">".
91  " <h5 class=\"card-title\">Card Title</h5>".
92  " </div>".
93  "</div>";
94 
95  $this->assertHTMLEquals($expected_html, $html);
96  }
97 
98  public function test_render_content_full() {
99  $f = $this->getFactory();
100  $r = $this->getDefaultRenderer();
101 
102  $image = $f->image()->standard("src","alt");
103 
104  $c = $f->card("Card Title",$image);
105 
106  $content = $f->legacy("Random Content");
107 
108  $c = $c->withSections(array($content));
109 
110  $html = $r->render($c);
111 
112  $expected_html =
113  "<div class=\"il-card thumbnail\">".
114  " <img src=\"src\" class=\"img-standard\" alt=\"alt\" />".
115  " <div class=\"caption\">".
116  " <h5 class=\"card-title\">Card Title</h5>".
117  " </div>".
118  " <div class=\"caption\">Random Content</div>".
119  "</div>";
120 
121  $this->assertHTMLEquals($expected_html, $html);
122  }
123 }
test_render_content_full()
Definition: CardTest.php:98
test_with_image()
Definition: CardTest.php:55
test_with_section()
Definition: CardTest.php:68
test_with_title()
Definition: CardTest.php:37
test_render_content_empty()
Definition: CardTest.php:80
Test on card implementation.
Definition: CardTest.php:14
test_get_image()
Definition: CardTest.php:46
getFactory()
Definition: CardTest.php:19
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:69
test_get_title()
Definition: CardTest.php:30
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:118
Create styles array
The data for the language used.
test_implements_factory_interface()
Definition: CardTest.php:23
getDefaultRenderer()
Definition: Base.php:100
$html
Definition: example_001.php:87