ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 try {
61 new \ILIAS\UI\Implementation\Component\Counter\Counter("FOO", 1);
62 $this->assertFalse("We should not get here");
63 } catch (\InvalidArgumentException $e) {
64 }
65 }
66
70 public function test_int_numbers_only($no_number)
71 {
72 $f = $this->getCounterFactory();
73
74 try {
75 $f->status($no_number);
76 $this->assertFalse("This should not happen");
77 } catch (\InvalidArgumentException $e) {
78 }
79 }
80
81 public function number_provider()
82 {
83 return array( array(-13)
84 , array(0)
85 , array(23)
86 , array(42)
87 );
88 }
89
90 public function no_number_provider()
91 {
92 return array( array("foo")
93 , array(9.1)
94 , array(array())
95 , array(new stdClass())
96 );
97 }
98
99 public static $canonical_css_classes = array( "status" => "badge badge-notify il-counter-status"
100 , "novelty" => "badge badge-notify il-counter-novelty"
101 );
102
106 public function test_render_status($type, $number)
107 {
108 $f = $this->getCounterFactory();
109 $r = $this->getDefaultRenderer();
110 $c = $f->$type($number);
111
112 $html = $this->normalizeHTML($r->render($c));
113
114 $css_classes = self::$canonical_css_classes[$type];
115 $expected = "<span class=\"$css_classes\">$number</span>";
116 $this->assertEquals($expected, $html);
117 }
118
120 {
121 return array( array("status", 42)
122 , array("novelty", 13)
123 , array("status", 1)
124 , array("novelty", 23)
125 );
126 }
127}
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:90
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:70
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
static $canonical_css_classes
Definition: CounterTest.php:99
test_known_counters_only()
Definition: CounterTest.php:58
Provides common functionality for UI tests.
Definition: Base.php:178
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
$type