ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
CounterTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
24 use ILIAS\UI\Component as C;
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 
51  public function testStatusCounter(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 testNoveltyCounter(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 testKnownCountersOnly(): void
77  {
78  $this->expectException(InvalidArgumentException::class);
79  new Counter("FOO", 1);
80  }
81 
85  public function testIntNumbersOnly($no_number): void
86  {
87  $this->expectException(TypeError::class);
88  $f = $this->getCounterFactory();
89  $f->status($no_number);
90  }
91 
92  public static function getNumberProvider(): array
93  {
94  return [
95  [-13],
96  [0],
97  [23],
98  [4]
99  ];
100  }
101 
102  public static function getNoNumberProvider(): 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 testRenderStatus(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 static function getCounterTypeAndNumberProvider(): array
134  {
135  return [
136  ["status", 42],
137  ["novelty", 13],
138  ["status", 1],
139  ["novelty", 23],
140  ];
141  }
142 }
static getNumberProvider()
Definition: CounterTest.php:92
static array $canonical_css_classes
testRenderStatus(string $type, int $number)
getCounterTypeAndNumberProvider
testNoveltyCounter(int $number)
getNumberProvider
Definition: CounterTest.php:65
$c
Definition: deliver.php:25
testImplementsFactoryInterface()
Definition: CounterTest.php:38
static getCounterTypeAndNumberProvider()
testKnownCountersOnly()
Definition: CounterTest.php:76
static getNoNumberProvider()
testIntNumbersOnly($no_number)
getNoNumberProvider
Definition: CounterTest.php:85
Defines tests that a counter implementation should pass.
Definition: CounterTest.php:31
testStatusCounter(int $number)
getNumberProvider
Definition: CounterTest.php:51
$r