ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ChartProgressMeterTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Ralph Dittrich <dittrich@qualitus.de> Extended GPL, see docs/LICENSE */
4 
5 require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 use \ILIAS\UI\Implementation as I;
10 
15 {
16  protected function getFactory()
17  {
18  return new I\Component\Chart\ProgressMeter\Factory();
19  }
20 
22  {
23  $progressmeter = $this->getFactory();
24 
25  $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Factory", $progressmeter);
26  }
27 
28  public function test_get_instances()
29  {
30  $progressmeter = $this->getFactory();
31 
32  $standard = $progressmeter->standard(400, 250);
33  $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Standard", $standard);
34 
35  $fixedSize = $progressmeter->fixedSize(400, 250);
36  $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\FixedSize", $fixedSize);
37 
38  $mini = $progressmeter->mini(400, 250);
39  $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Mini", $mini);
40  }
41 
42  public function test_get_values_of_standard()
43  {
44  $f = $this->getFactory();
45  $standard = $f->standard(400, 250, 300, 200);
46 
47  $this->assertEquals($standard->getMaximum(), 400);
48  $this->assertEquals($standard->getMainValue(), 250);
49  $this->assertEquals($standard->getMainValueAsPercent(), 63);
50  $this->assertEquals($standard->getRequired(), 300);
51  $this->assertEquals($standard->getRequiredAsPercent(), 75);
52  $this->assertEquals($standard->getComparison(), 200);
53  $this->assertEquals($standard->getComparisonAsPercent(), 50);
54  }
55 
56  public function test_get_values_of_fixedSize()
57  {
58  $f = $this->getFactory();
59  $fixedSize = $f->fixedSize(400, 250, 300, 200);
60 
61  $this->assertEquals($fixedSize->getMaximum(), 400);
62  $this->assertEquals($fixedSize->getMainValue(), 250);
63  $this->assertEquals($fixedSize->getMainValueAsPercent(), 63);
64  $this->assertEquals($fixedSize->getRequired(), 300);
65  $this->assertEquals($fixedSize->getRequiredAsPercent(), 75);
66  $this->assertEquals($fixedSize->getComparison(), 200);
67  $this->assertEquals($fixedSize->getComparisonAsPercent(), 50);
68  }
69 
70  public function test_get_values_of_mini()
71  {
72  $f = $this->getFactory();
73  $mini = $f->mini(400, 250, 300);
74 
75  $this->assertEquals($mini->getMaximum(), 400);
76  $this->assertEquals($mini->getMainValue(), 250);
77  $this->assertEquals($mini->getMainValueAsPercent(), 63);
78  $this->assertEquals($mini->getRequired(), 300);
79  $this->assertEquals($mini->getRequiredAsPercent(), 75);
80  }
81 
82  public function test_render_standard_two_bar()
83  {
84  $r = $this->getDefaultRenderer();
85  $f = $this->getFactory();
86  $standard = $f->standard(100, 75, 80, 50);
87 
88  $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Standard", $standard);
89 
90  $html = $r->render($standard);
91 
92  $expected_html =
93  '<div class="il-chart-progressmeter-box ">' .
94  '<div class="il-chart-progressmeter-container">' .
95  '<svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">' .
96  '<path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100" ' .
97  '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>' .
98  '<g class="il-chart-progressmeter-multicircle">' .
99  '<path class="il-chart-progressmeter-circle no-success" ' .
100  '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" ' .
101  'stroke-dasharray="75, 100"></path>' .
102  '<path class="il-chart-progressmeter-circle active" ' .
103  '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" ' .
104  'stroke-dasharray="44.4, 100"></path>' .
105  '</g>' .
106  '<g class="il-chart-progressmeter-text">' .
107  '<text class="text-score-info" x="25" y="16"></text>' .
108  '<text class="text-score" x="25" y="25">75 %</text>' .
109  '<text class="text-comparision" x="25" y="31">80 %</text>' .
110  '<text class="text-comparision-info" x="25" y="34"></text>' .
111  '</g>' .
112  '<g class="il-chart-progressmeter-needle " style="transform: rotate(82.8deg)">' .
113  '<polygon class="il-chart-progressmeter-needle-border" points="23.5,0.1 25,2.3 26.5,0.1"></polygon>' .
114  '<polygon class="il-chart-progressmeter-needle-fill" points="23.5,0 25,2.2 26.5,0"></polygon>' .
115  '</g>' .
116  '</svg>' .
117  '</div>' .
118  '</div>';
119 
120  $this->assertHTMLEquals($expected_html, $html);
121  }
122 
124  {
125  $r = $this->getDefaultRenderer();
126  $f = $this->getFactory();
127  $fixedSize = $f->fixedSize(100, 75, 80, null, 300);
128 
129  $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\FixedSize", $fixedSize);
130 
131  $html = $r->render($fixedSize);
132 
133  $expected_html =
134  '<div class="il-chart-progressmeter-box fixed-size">' .
135  '<div class="il-chart-progressmeter-container">' .
136  '<svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">' .
137  '<path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100" ' .
138  '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>' .
139  '<g class="il-chart-progressmeter-monocircle">' .
140  '<path class="il-chart-progressmeter-circle no-success" stroke-dasharray="75, 100" ' .
141  '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>' .
142  '</g>' .
143  '<g class="il-chart-progressmeter-text">' .
144  '<text class="text-score-info" x="25" y="16"></text>' .
145  '<text class="text-score" x="25" y="25">75 %</text>' .
146  '<text class="text-comparision" x="25" y="31">80 %</text>' .
147  '<text class="text-comparision-info" x="25" y="34"></text>' .
148  '</g>' .
149  '<g class="il-chart-progressmeter-needle " style="transform: rotate(82.8deg)">' .
150  '<polygon class="il-chart-progressmeter-needle-border" points="23.5,0.1 25,2.3 26.5,0.1"></polygon>' .
151  '<polygon class="il-chart-progressmeter-needle-fill" points="23.5,0 25,2.2 26.5,0"></polygon>' .
152  '</g>' .
153  '</svg>' .
154  '</div>' .
155  '</div>';
156 
157  $this->assertHTMLEquals($expected_html, $html);
158  }
159 
160  public function test_render_mini()
161  {
162  $r = $this->getDefaultRenderer();
163  $f = $this->getFactory();
164  $mini = $f->mini(400, 250, 300);
165 
166  $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\ProgressMeter\\Mini", $mini);
167 
168  $html = $r->render($mini);
169 
170  $expected_html =
171  '<div class="il-chart-progressmeter-box il-chart-progressmeter-mini">' .
172  '<div class="il-chart-progressmeter-container">' .
173  '<svg viewBox="0 0 50 40" class="il-chart-progressmeter-viewbox">' .
174  '<path class="il-chart-progressmeter-circle-bg" stroke-dasharray="100, 100" ' .
175  '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>' .
176  '<path class="il-chart-progressmeter-circle no-success" stroke-dasharray="54.495, 100" ' .
177  '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>' .
178  '<path class="il-chart-progressmeter-needle " stroke-dasharray="100, 100" d="M25,10 l0,15" ' .
179  'style="transform: rotate(57.5deg)"></path>' .
180  '</svg>' .
181  '</div>' .
182  '</div>';
183 
184  $this->assertHTMLEquals($expected_html, $html);
185  }
186 }
Test on ProgressMeter implementation.
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:191
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:270
$html
Definition: example_001.php:87