ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CounterTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/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 testImplementsFactoryInterface(): 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
48 #[\PHPUnit\Framework\Attributes\DataProvider('getNumberProvider')]
49 public function testStatusCounter(int $number): void
50 {
51 $f = $this->getCounterFactory();
52
53 $c = $f->status($number);
54
55 $this->assertNotNull($c);
56 $this->assertEquals(C\Counter\Counter::STATUS, $c->getType());
57 $this->assertEquals($number, $c->getNumber());
58 }
59
60 #[\PHPUnit\Framework\Attributes\DataProvider('getNumberProvider')]
61 public function testNoveltyCounter(int $number): void
62 {
63 $f = $this->getCounterFactory();
64
65 $c = $f->novelty($number);
66
67 $this->assertNotNull($c);
68 $this->assertEquals(C\Counter\Counter::NOVELTY, $c->getType());
69 $this->assertEquals($number, $c->getNumber());
70 }
71
72 public function testKnownCountersOnly(): void
73 {
74 $this->expectException(InvalidArgumentException::class);
75 new Counter("FOO", 1);
76 }
77
78 #[\PHPUnit\Framework\Attributes\DataProvider('getNoNumberProvider')]
79 public function testIntNumbersOnly($no_number): void
80 {
81 $this->expectException(TypeError::class);
82 $f = $this->getCounterFactory();
83 $f->status($no_number);
84 }
85
86 public static function getNumberProvider(): array
87 {
88 return [
89 [-13],
90 [0],
91 [23],
92 [4]
93 ];
94 }
95
96 public static function getNoNumberProvider(): array
97 {
98 return [
99 ["foo"],
100 [9.1],
101 [array()],
102 [new stdClass()]
103 ];
104 }
105
106 public static array $canonical_css_classes = [
107 "status" => "badge badge-notify il-counter-status",
108 "novelty" => "badge badge-notify il-counter-novelty"
109 ];
110
111 #[\PHPUnit\Framework\Attributes\DataProvider('getCounterTypeAndNumberProvider')]
112 public function testRenderStatus(string $type, int $number): void
113 {
114 $f = $this->getCounterFactory();
115 $r = $this->getDefaultRenderer();
116 $c = $f->$type($number);
117
118 $html = $this->normalizeHTML($r->render($c));
119
120 $css_classes = self::$canonical_css_classes[$type];
121 $expected = "<span class=\"il-counter\"><span class=\"$css_classes\">$number</span></span>";
122 $this->assertHTMLEquals($expected, $html);
123 }
124
125 public static function getCounterTypeAndNumberProvider(): array
126 {
127 return [
128 ["status", 42],
129 ["novelty", 13],
130 ["status", 1],
131 ["novelty", 23],
132 ];
133 }
134}
Defines tests that a counter implementation should pass.
Definition: CounterTest.php:32
static getNoNumberProvider()
Definition: CounterTest.php:96
static array $canonical_css_classes
testStatusCounter(int $number)
Definition: CounterTest.php:49
static getNumberProvider()
Definition: CounterTest.php:86
testIntNumbersOnly($no_number)
Definition: CounterTest.php:79
testRenderStatus(string $type, int $number)
testNoveltyCounter(int $number)
Definition: CounterTest.php:61
testKnownCountersOnly()
Definition: CounterTest.php:72
testImplementsFactoryInterface()
Definition: CounterTest.php:38
static getCounterTypeAndNumberProvider()
Provides common functionality for UI tests.
Definition: Base.php:337
$c
Definition: deliver.php:25