ILIAS  release_7 Revision v7.30-3-g800a261c036
DeckTest.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 card()
23 {
24 return new I\Component\Card\Factory();
25 }
26 public function deck(array $cards)
27 {
28 return new I\Component\Deck\Deck($cards, I\Component\Deck\Deck::SIZE_S);
29 }
30 };
31 return $factory;
32 }
33
35 {
36 $f = $this->getFactory();
37
38 $this->assertInstanceOf("ILIAS\\UI\\Factory", $f);
39 $c = $f->card()->standard("Card Title");
40 $this->assertInstanceOf("ILIAS\\UI\\Component\\Deck\\Deck", $f->deck(array($c)));
41 }
42
43 public function test_get_cards()
44 {
45 $f = $this->getFactory();
46 $c = $f->card()->standard("Card Title");
47 $d = $f->deck(array($c));
48
49 $this->assertEquals($d->getCards(), array($c));
50 }
51
52 public function test_with_cards()
53 {
54 $f = $this->getFactory();
55 $c = $f->card()->standard("Card Title");
56 $d = $f->deck(array($c));
57
58 $d = $d->withCards(array($c,$c));
59 $this->assertEquals($d->getCards(), array($c,$c));
60 }
61
62 public function test_get_size()
63 {
64 $f = $this->getFactory();
65
66 $c = $f->card()->standard("Card Title");
67 $d = $f->deck(array($c));
68
69 $this->assertEquals($d->getCardsSize(), C\Deck\Deck::SIZE_S);
70 }
71
72 public function test_with_size()
73 {
74 $f = $this->getFactory();
75
76 $c = $f->card()->standard("Card Title");
77 $d = $f->deck(array($c));
78
79 $d = $d->withExtraSmallCardsSize();
80 $this->assertEquals($d->getCardsSize(), C\Deck\Deck::SIZE_XS);
81
82 $d = $d->withSmallCardsSize();
83 $this->assertEquals($d->getCardsSize(), C\Deck\Deck::SIZE_S);
84
85 $d = $d->withNormalCardsSize();
86 $this->assertEquals($d->getCardsSize(), C\Deck\Deck::SIZE_M);
87
88 $d = $d->withLargeCardsSize();
89 $this->assertEquals($d->getCardsSize(), C\Deck\Deck::SIZE_L);
90
91 $d = $d->withExtraLargeCardsSize();
92 $this->assertEquals($d->getCardsSize(), C\Deck\Deck::SIZE_XL);
93
94 $d = $d->withFullSizedCardsSize();
95 $this->assertEquals($d->getCardsSize(), C\Deck\Deck::SIZE_FULL);
96 }
97
98 public function test_render_content()
99 {
100 $r = $this->getDefaultRenderer();
101 $f = $this->getFactory();
102 $c = $f->card()->standard("Card Title");
103 $d = $f->deck(array($c));
104
105 $d = $d->withCards(array($c,$c,$c,$c,$c,$c,$c))->withLargeCardsSize();
106
107 $html = $this->brutallyTrimHTML($r->render($d));
108
109 $expected_html =
110 '<div class="il-deck"><div class="row row-eq-height">
111 <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"><div class="il-card thumbnail"><div class="card-no-highlight"></div><div class="caption card-title">Card Title</div></div></div>
112 <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"><div class="il-card thumbnail"><div class="card-no-highlight"></div><div class="caption card-title">Card Title</div></div></div>
113 <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"><div class="il-card thumbnail"><div class="card-no-highlight"></div><div class="caption card-title">Card Title</div></div></div>
114 <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"><div class="il-card thumbnail"><div class="card-no-highlight"></div><div class="caption card-title">Card Title</div></div></div>
115 <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"><div class="il-card thumbnail"><div class="card-no-highlight"></div><div class="caption card-title">Card Title</div></div></div>
116 <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"><div class="il-card thumbnail"><div class="card-no-highlight"></div><div class="caption card-title">Card Title</div></div></div>
117 <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"><div class="il-card thumbnail"><div class="card-no-highlight"></div><div class="caption card-title">Card Title</div></div></div>
118 </div>
119 </div>';
120
121 $this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
122 }
123}
An exception for terminatinating execution or to throw for unit testing.
Test on deck implementation.
Definition: DeckTest.php:15
test_with_size()
Definition: DeckTest.php:72
test_with_cards()
Definition: DeckTest.php:52
getFactory()
Definition: DeckTest.php:19
test_implements_factory_interface()
Definition: DeckTest.php:34
test_get_size()
Definition: DeckTest.php:62
test_get_cards()
Definition: DeckTest.php:43
test_render_content()
Definition: DeckTest.php:98
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
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$factory
Definition: metadata.php:58