ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 require_once("libs/composer/vendor/autoload.php");
6 require_once(__DIR__."/../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 
14  public function getCounterFactory() {
15  return new \ILIAS\UI\Implementation\Component\Counter\Factory();
16  }
17 
19  $f = $this->getCounterFactory();
20 
21  $this->assertInstanceOf("ILIAS\\UI\\Component\\Counter\\Factory", $f);
22 
23  $this->assertInstanceOf("ILIAS\\UI\\Component\\Counter\\Counter", $f->status(0));
24  $this->assertInstanceOf("ILIAS\\UI\\Component\\Counter\\Counter", $f->novelty(0));
25  }
26 
30  public function test_status_counter($number) {
31  $f = $this->getCounterFactory();
32 
33  $c = $f->status($number);
34 
35  $this->assertNotNull($c);
36  $this->assertEquals(C\Counter\Counter::STATUS, $c->getType());
37  $this->assertEquals($number, $c->getNumber());
38  }
39 
43  public function test_novelty_counter($number) {
44  $f = $this->getCounterFactory();
45 
46  $c = $f->novelty($number);
47 
48  $this->assertNotNull($c);
49  $this->assertEquals(C\Counter\Counter::NOVELTY, $c->getType());
50  $this->assertEquals($number, $c->getNumber());
51  }
52 
53  public function test_known_counters_only() {
54  try {
55  new \ILIAS\UI\Implementation\Component\Counter\Counter("FOO", 1);
56  $this->assertFalse("We should not get here");
57  }
58  catch (\InvalidArgumentException $e) {}
59  }
60 
64  public function test_int_numbers_only($no_number) {
65  $f = $this->getCounterFactory();
66 
67  try {
68  $f->status($no_number);
69  $this->assertFalse("This should not happen");
70  }
71  catch (\InvalidArgumentException $e) {}
72  }
73 
74  public function number_provider() {
75  return array
76  ( array(-13)
77  , array(0)
78  , array(23)
79  , array(42)
80  );
81  }
82 
83  public function no_number_provider() {
84  return array
85  ( array("foo")
86  , array(9.1)
87  , array(array())
88  , array(new stdClass())
89  );
90  }
91 
93  ( "status" => "badge badge-notify il-counter-status"
94  , "novelty" => "badge badge-notify il-counter-novelty"
95  );
96 
100  public function test_render_status($type, $number) {
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=\"$css_classes\">$number</span>";
109  $this->assertEquals($expected, $html);
110  }
111 
113  return array
114  ( array("status", 42)
115  , array("novelty", 13)
116  , array("status", 1)
117  , array("novelty", 23)
118  );
119  }
120 
121 
122 }
test_render_status($type, $number)
counter_type_and_number_provider
normalizeHTML($html)
Definition: Base.php:110
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:69
no_number_provider()
Definition: CounterTest.php:83
test_known_counters_only()
Definition: CounterTest.php:53
counter_type_and_number_provider()
test_int_numbers_only($no_number)
no_number_provider
Definition: CounterTest.php:64
test_implements_factory_interface()
Definition: CounterTest.php:18
Create styles array
The data for the language used.
getDefaultRenderer()
Definition: Base.php:100
static $canonical_css_classes
Definition: CounterTest.php:92
Defines tests that a counter implementation should pass.
Definition: CounterTest.php:13
test_status_counter($number)
number_provider
Definition: CounterTest.php:30
$html
Definition: example_001.php:87
test_novelty_counter($number)
number_provider
Definition: CounterTest.php:43