ILIAS  release_8 Revision v8.24
CounterTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
27
32{
33 public function getCounterFactory(): Factory
34 {
35 return new Factory();
36 }
37
38 public function test_implements_factory_interface(): void
39 {
40 $f = $this->getCounterFactory();
41
42 $this->assertInstanceOf("ILIAS\\UI\\Component\\Counter\\Factory", $f);
43
44 $this->assertInstanceOf("ILIAS\\UI\\Component\\Counter\\Counter", $f->status(0));
45 $this->assertInstanceOf("ILIAS\\UI\\Component\\Counter\\Counter", $f->novelty(0));
46 }
47
51 public function test_status_counter(int $number): void
52 {
53 $f = $this->getCounterFactory();
54
55 $c = $f->status($number);
56
57 $this->assertNotNull($c);
58 $this->assertEquals(C\Counter\Counter::STATUS, $c->getType());
59 $this->assertEquals($number, $c->getNumber());
60 }
61
65 public function test_novelty_counter(int $number): void
66 {
67 $f = $this->getCounterFactory();
68
69 $c = $f->novelty($number);
70
71 $this->assertNotNull($c);
72 $this->assertEquals(C\Counter\Counter::NOVELTY, $c->getType());
73 $this->assertEquals($number, $c->getNumber());
74 }
75
76 public function test_known_counters_only(): void
77 {
78 $this->expectException(InvalidArgumentException::class);
79 new Counter("FOO", 1);
80 }
81
85 public function test_int_numbers_only($no_number): void
86 {
87 $this->expectException(TypeError::class);
88 $f = $this->getCounterFactory();
89 $f->status($no_number);
90 }
91
92 public function number_provider(): array
93 {
94 return [
95 [-13],
96 [0],
97 [23],
98 [4]
99 ];
100 }
101
102 public function no_number_provider(): array
103 {
104 return [
105 ["foo"],
106 [9.1],
107 [array()],
108 [new stdClass()]
109 ];
110 }
111
112 public static array $canonical_css_classes = [
113 "status" => "badge badge-notify il-counter-status",
114 "novelty" => "badge badge-notify il-counter-novelty"
115 ];
116
120 public function test_render_status(string $type, int $number): void
121 {
122 $f = $this->getCounterFactory();
123 $r = $this->getDefaultRenderer();
124 $c = $f->$type($number);
125
126 $html = $this->normalizeHTML($r->render($c));
127
128 $css_classes = self::$canonical_css_classes[$type];
129 $expected = "<span class=\"il-counter\"><span class=\"$css_classes\">$number</span></span>";
130 $this->assertHTMLEquals($expected, $html);
131 }
132
133 public function counter_type_and_number_provider(): array
134 {
135 return [
136 ["status", 42],
137 ["novelty", 13],
138 ["status", 1],
139 ["novelty", 23],
140 ];
141 }
142}
Defines tests that a counter implementation should pass.
Definition: CounterTest.php:32
static array $canonical_css_classes
test_novelty_counter(int $number)
@dataProvider number_provider
Definition: CounterTest.php:65
test_implements_factory_interface()
Definition: CounterTest.php:38
test_int_numbers_only($no_number)
@dataProvider no_number_provider
Definition: CounterTest.php:85
counter_type_and_number_provider()
test_status_counter(int $number)
@dataProvider number_provider
Definition: CounterTest.php:51
test_render_status(string $type, int $number)
@dataProvider counter_type_and_number_provider
test_known_counters_only()
Definition: CounterTest.php:76
Provides common functionality for UI tests.
Definition: Base.php:299
normalizeHTML(string $html)
Definition: Base.php:422
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
$c
Definition: cli.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type