ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
CounterTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once("libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \ILIAS\UI\Component as C;
9
14{
15 public function getCounterFactory()
16 {
17 return new \ILIAS\UI\Implementation\Component\Counter\Factory();
18 }
19
21 {
22 $f = $this->getCounterFactory();
23
24 $this->assertInstanceOf("ILIAS\\UI\\Component\\Counter\\Factory", $f);
25
26 $this->assertInstanceOf("ILIAS\\UI\\Component\\Counter\\Counter", $f->status(0));
27 $this->assertInstanceOf("ILIAS\\UI\\Component\\Counter\\Counter", $f->novelty(0));
28 }
29
33 public function test_status_counter($number)
34 {
35 $f = $this->getCounterFactory();
36
37 $c = $f->status($number);
38
39 $this->assertNotNull($c);
40 $this->assertEquals(C\Counter\Counter::STATUS, $c->getType());
41 $this->assertEquals($number, $c->getNumber());
42 }
43
47 public function test_novelty_counter($number)
48 {
49 $f = $this->getCounterFactory();
50
51 $c = $f->novelty($number);
52
53 $this->assertNotNull($c);
54 $this->assertEquals(C\Counter\Counter::NOVELTY, $c->getType());
55 $this->assertEquals($number, $c->getNumber());
56 }
57
58 public function test_known_counters_only()
59 {
60 $this->expectException(\InvalidArgumentException::class);
61 new \ILIAS\UI\Implementation\Component\Counter\Counter("FOO", 1);
62 }
63
67 public function test_int_numbers_only($no_number)
68 {
69 $this->expectException(\InvalidArgumentException::class);
70 $f = $this->getCounterFactory();
71 $f->status($no_number);
72 }
73
74 public function number_provider()
75 {
76 return array( array(-13)
77 , array(0)
78 , array(23)
79 , array(42)
80 );
81 }
82
83 public function no_number_provider()
84 {
85 return array( array("foo")
86 , array(9.1)
87 , array(array())
88 , array(new stdClass())
89 );
90 }
91
92 public static $canonical_css_classes = array( "status" => "badge badge-notify il-counter-status"
93 , "novelty" => "badge badge-notify il-counter-novelty"
94 );
95
99 public function test_render_status($type, $number)
100 {
101 $f = $this->getCounterFactory();
102 $r = $this->getDefaultRenderer();
103 $c = $f->$type($number);
104
105 $html = $this->normalizeHTML($r->render($c));
106
107 $css_classes = self::$canonical_css_classes[$type];
108 $expected = "<span class=\"il-counter\"><span class=\"$css_classes\">$number</span></span>";
109 $this->assertHTMLEquals($expected, $html);
110 }
111
113 {
114 return array( array("status", 42)
115 , array("novelty", 13)
116 , array("status", 1)
117 , array("novelty", 23)
118 );
119 }
120}
An exception for terminatinating execution or to throw for unit testing.
Defines tests that a counter implementation should pass.
Definition: CounterTest.php:14
no_number_provider()
Definition: CounterTest.php:83
test_implements_factory_interface()
Definition: CounterTest.php:20
test_status_counter($number)
@dataProvider number_provider
Definition: CounterTest.php:33
test_int_numbers_only($no_number)
@dataProvider no_number_provider
Definition: CounterTest.php:67
counter_type_and_number_provider()
test_novelty_counter($number)
@dataProvider number_provider
Definition: CounterTest.php:47
test_render_status($type, $number)
@dataProvider counter_type_and_number_provider
Definition: CounterTest.php:99
static $canonical_css_classes
Definition: CounterTest.php:92
test_known_counters_only()
Definition: CounterTest.php:58
Provides common functionality for UI tests.
Definition: Base.php:225
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:326
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
normalizeHTML($html)
Definition: Base.php:317
$type