ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
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 }
$type
test_render_status($type, $number)
counter_type_and_number_provider
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
normalizeHTML($html)
Definition: Base.php:261
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:191
no_number_provider()
Definition: CounterTest.php:90
test_known_counters_only()
Definition: CounterTest.php:58
counter_type_and_number_provider()
test_int_numbers_only($no_number)
no_number_provider
Definition: CounterTest.php:70
test_implements_factory_interface()
Definition: CounterTest.php:20
static $canonical_css_classes
Definition: CounterTest.php:99
Defines tests that a counter implementation should pass.
Definition: CounterTest.php:13
test_status_counter($number)
number_provider
Definition: CounterTest.php:33
$html
Definition: example_001.php:87
test_novelty_counter($number)
number_provider
Definition: CounterTest.php:47