ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ChartProgressMeterTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23
26
31{
32 protected function getFactory(): C\Chart\ProgressMeter\Factory
33 {
34 return new I\Component\Chart\ProgressMeter\Factory();
35 }
36
37 public function testImplementsFactoryInterface(): void
38 {
39 $progressmeter = $this->getFactory();
40
41 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Factory", $progressmeter);
42 }
43
44 public function testGetInstances(): void
45 {
46 $progressmeter = $this->getFactory();
47
48 $standard = $progressmeter->standard(400, 250);
49 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Standard", $standard);
50
51 $fixedSize = $progressmeter->fixedSize(400, 250);
52 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\FixedSize", $fixedSize);
53
54 $mini = $progressmeter->mini(400, 250);
55 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Mini", $mini);
56 }
57
58 public function testGetValuesOfStandard(): void
59 {
60 $f = $this->getFactory();
61 $standard = $f->standard(400, 250, 300, 200);
62
63 $this->assertEquals(400, $standard->getMaximum());
64 $this->assertEquals(250, $standard->getMainValue());
65 $this->assertEquals(63, $standard->getMainValueAsPercent());
66 $this->assertEquals(300, $standard->getRequired());
67 $this->assertEquals(75, $standard->getRequiredAsPercent());
68 $this->assertEquals(200, $standard->getComparison());
69 $this->assertEquals(50, $standard->getComparisonAsPercent());
70 }
71
72 public function testGetValuesOfFixedSize(): void
73 {
74 $f = $this->getFactory();
75 $fixedSize = $f->fixedSize(400, 250, 300, 200);
76
77 $this->assertEquals(400, $fixedSize->getMaximum());
78 $this->assertEquals(250, $fixedSize->getMainValue());
79 $this->assertEquals(63, $fixedSize->getMainValueAsPercent());
80 $this->assertEquals(300, $fixedSize->getRequired());
81 $this->assertEquals(75, $fixedSize->getRequiredAsPercent());
82 $this->assertEquals(200, $fixedSize->getComparison());
83 $this->assertEquals(50, $fixedSize->getComparisonAsPercent());
84 }
85
86 public function testGetValuesOfMini(): void
87 {
88 $f = $this->getFactory();
89 $mini = $f->mini(400, 250, 300);
90
91 $this->assertEquals(400, $mini->getMaximum());
92 $this->assertEquals(250, $mini->getMainValue());
93 $this->assertEquals(63, $mini->getMainValueAsPercent());
94 $this->assertEquals(300, $mini->getRequired());
95 $this->assertEquals(75, $mini->getRequiredAsPercent());
96 }
97
98 public function testRenderStandardTwoBar(): void
99 {
100 $r = $this->getDefaultRenderer();
101 $f = $this->getFactory();
102 $standard = $f->standard(100, 75, 80, 50);
103
104 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Standard", $standard);
105
106 $html = $r->render($standard);
107
108 $expected_html =
109 '<div class="il-chart-progressmeter-box ">' .
110 '<div class="il-chart-progressmeter-container">' .
111 '<svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">' .
112 '<path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100" ' .
113 'd="M10.4646,37.0354 q-5.858,-5.858 -5.858,-14.142 a1,1 0 1,1 40,0 q0,8.284 -5.858,14.142"></path>' .
114 '<g class="il-chart-progressmeter-multicircle">' .
115 '<path class="il-chart-progressmeter-circle no-success" ' .
116 'd="M9.6514,37.8486 q-6.1948,-6.1948 -6.1948,-14.9552 a1,1 0 1,1 42.30,0 q0,8.7604 -6.1948,14.9552" ' .
117 'stroke-dasharray="75, 100"></path>' .
118 '<path class="il-chart-progressmeter-circle active" ' .
119 'd="M11.2778,36.2222 q-5.5212,-5.5212 -5.5212,-13.3288 a1,1 0 1,1 37.70,0 q0,7.8076 -5.5212,13.3288" ' .
120 'stroke-dasharray="44.4, 100"></path>' .
121 '</g>' .
122 '<g class="il-chart-progressmeter-text">' .
123 '<text class="text-score-info" x="25" y="16"></text>' .
124 '<text class="text-score" x="25" y="25">75 %</text>' .
125 '<text class="text-comparision" x="25" y="31">80 %</text>' .
126 '<text class="text-comparision-info" x="25" y="34"></text>' .
127 '</g>' .
128 '<g class="il-chart-progressmeter-needle " style="transform: rotate(86.5deg)">' .
129 '<polygon class="il-chart-progressmeter-needle-border" points="23.5,0.1 25,2.3 26.5,0.1"></polygon>' .
130 '<polygon class="il-chart-progressmeter-needle-fill" points="23.5,0 25,2.2 26.5,0"></polygon>' .
131 '</g>' .
132 '</svg>' .
133 '</div>' .
134 '</div>';
135
136 $this->assertHTMLEquals($expected_html, $html);
137 }
138
139 public function testRenderFixedSizeOneBar(): void
140 {
141 $r = $this->getDefaultRenderer();
142 $f = $this->getFactory();
143 $fixedSize = $f->fixedSize(100, 75, 80, null, 300);
144
145 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\FixedSize", $fixedSize);
146
147 $html = $r->render($fixedSize);
148
149 $expected_html =
150 '<div class="il-chart-progressmeter-box fixed-size">' .
151 '<div class="il-chart-progressmeter-container">' .
152 '<svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">' .
153 '<path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100" ' .
154 'd="M10.4646,37.0354 q-5.858,-5.858 -5.858,-14.142 a1,1 0 1,1 40,0 q0,8.284 -5.858,14.142"></path>' .
155 '<g class="il-chart-progressmeter-monocircle">' .
156 '<path class="il-chart-progressmeter-circle no-success" stroke-dasharray="71, 100" ' .
157 'd="M10.4646,37.0354 q-5.858,-5.858 -5.858,-14.142 a1,1 0 1,1 40,0 q0,8.284 -5.858,14.142"></path>' .
158 '</g>' .
159 '<g class="il-chart-progressmeter-text">' .
160 '<text class="text-score-info" x="25" y="16"></text>' .
161 '<text class="text-score" x="25" y="25">75 %</text>' .
162 '<text class="text-comparision" x="25" y="31">80 %</text>' .
163 '<text class="text-comparision-info" x="25" y="34"></text>' .
164 '</g>' .
165 '<g class="il-chart-progressmeter-needle " style="transform: rotate(86.5deg)">' .
166 '<polygon class="il-chart-progressmeter-needle-border" points="23.5,0.1 25,2.3 26.5,0.1"></polygon>' .
167 '<polygon class="il-chart-progressmeter-needle-fill" points="23.5,0 25,2.2 26.5,0"></polygon>' .
168 '</g>' .
169 '</svg>' .
170 '</div>' .
171 '</div>';
172
173 $this->assertHTMLEquals($expected_html, $html);
174 }
175
176 public function testRenderMini(): void
177 {
178 $r = $this->getDefaultRenderer();
179 $f = $this->getFactory();
180 $mini = $f->mini(400, 250, 300);
181
182 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Mini", $mini);
183
184 $html = $r->render($mini);
185
186 $expected_html =
187 '<div class="il-chart-progressmeter-box il-chart-progressmeter-mini">' .
188 '<div class="il-chart-progressmeter-container">' .
189 '<svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">' .
190 '<path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100" ' .
191 'd="M9,35 q-4.3934,-4.3934 -4.3934,-10.6066 a1,1 0 1,1 40,0 q0,6.2132 -4.3934,10.6066"></path>' .
192 '<path class="il-chart-progressmeter-circle no-success" stroke-dasharray="54.495, 100" ' .
193 'd="M9,35 q-4.3934,-4.3934 -4.3934,-10.6066 a1,1 0 1,1 40,0 q0,6.2132 -4.3934,10.6066"></path>' .
194 '<path class="il-chart-progressmeter-needle " stroke-dasharray="100, 100" d="M25,10 l0,15" ' .
195 'style="transform: rotate(65.5deg)"></path>' .
196 '</svg>' .
197 '</div>' .
198 '</div>';
199
200 $this->assertHTMLEquals($expected_html, $html);
201 }
202}
Test on ProgressMeter implementation.
Provides common functionality for UI tests.
Definition: Base.php:337