ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BarStateTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23require_once(__DIR__ . "/../../Base.php");
24
27
32{
34 protected string $determinate_status_value;
35 protected string $success_status_value;
36 protected string $failure_status_value;
37 protected string $message;
38
39 protected function setUp(): void
40 {
41 $this->indeterminate_status_value = I\Progress\State\Bar\Status::INDETERMINATE->value;
42 $this->determinate_status_value = I\Progress\State\Bar\Status::DETERMINATE->value;
43 $this->success_status_value = I\Progress\State\Bar\Status::SUCCESS->value;
44 $this->failure_status_value = I\Progress\State\Bar\Status::FAILURE->value;
45 $this->message = sha1('progress_bar_state_message');
46
47 parent::setUp();
48 }
49
50 public function testIndeterminateConstruction(): void
51 {
53 $indeterminate = $this->getUIFactory()->progress()->state()->bar()->indeterminate($this->message);
54
55 $this->assertEquals($indeterminate->getStatus()->value, $this->indeterminate_status_value);
56 $this->assertNull($indeterminate->getVisualProgressValue());
57 $this->assertEquals($indeterminate->getMessage(), $this->message);
58 }
59
60 public function testDeterminateConstruction(): void
61 {
62 $progress = 55;
64 $determinate = $this->getUIFactory()->progress()->state()->bar()->determinate($progress, $this->message);
65
66 $this->assertEquals($determinate->getStatus()->value, $this->determinate_status_value);
67 $this->assertEquals($determinate->getVisualProgressValue(), $progress);
68 $this->assertEquals($determinate->getMessage(), $this->message);
69 }
70
72 {
73 $invalid_progress = -1;
74 $this->expectException(\InvalidArgumentException::class);
75 $determinate = $this->getUIFactory()->progress()->state()->bar()->determinate($invalid_progress);
76 }
77
79 {
80 $invalid_progress = 100;
81 $this->expectException(\InvalidArgumentException::class);
82 $determinate = $this->getUIFactory()->progress()->state()->bar()->determinate($invalid_progress);
83 }
84
85 public function testSuccessConstruction(): void
86 {
88 $success = $this->getUIFactory()->progress()->state()->bar()->success($this->message);
89
90 $this->assertEquals($success->getStatus()->value, $this->success_status_value);
91 $this->assertEquals($success->getVisualProgressValue(), I\Progress\Bar::MAX_VALUE);
92 $this->assertEquals($success->getMessage(), $this->message);
93 }
94
95 public function testFailureConstruction(): void
96 {
98 $failure = $this->getUIFactory()->progress()->state()->bar()->failure($this->message);
99
100 $this->assertEquals($failure->getStatus()->value, $this->failure_status_value);
101 $this->assertEquals($failure->getVisualProgressValue(), I\Progress\Bar::MAX_VALUE);
102 $this->assertEquals($failure->getMessage(), $this->message);
103 }
104
105 public function testRenderIndeterminate(): void
106 {
107 $state = $this->getUIFactory()->progress()->state()->bar()->indeterminate($this->message);
108
109 $renderer = $this->getDefaultRenderer();
110
111 $actual_html = $renderer->render($state);
112
113 $expected_html = <<<EOT
114<div class="c-progress c-progress-bar--state">
115 <section data-section="progress"><progress max="100"></progress></section>
116 <section data-section="status" data-status="$this->indeterminate_status_value"></section>
117 <section data-section="message">$this->message</section>
118</div>
119EOT;
120
121 $this->assertEquals(
122 $this->brutallyTrimHTML($expected_html),
123 $this->brutallyTrimHTML($actual_html),
124 );
125 }
126
127 public function testRenderDeterminate(): void
128 {
129 $progress = 55;
130 $state = $this->getUIFactory()->progress()->state()->bar()->determinate($progress, $this->message);
131
132 $renderer = $this->getDefaultRenderer();
133
134 $actual_html = $renderer->render($state);
135
136 $expected_html = <<<EOT
137<div class="c-progress c-progress-bar--state">
138 <section data-section="progress"><progress value="$progress" max="100"></progress></section>
139 <section data-section="status" data-status="$this->determinate_status_value"></section>
140 <section data-section="message">$this->message</section>
141</div>
142EOT;
143
144 $this->assertEquals(
145 $this->brutallyTrimHTML($expected_html),
146 $this->brutallyTrimHTML($actual_html),
147 );
148 }
149
150 public function testRenderSuccess(): void
151 {
152 $state = $this->getUIFactory()->progress()->state()->bar()->success($this->message);
153
154 $renderer = $this->getDefaultRenderer();
155
156 $actual_html = $renderer->render($state);
157
158 $expected_html = <<<EOT
159<div class="c-progress c-progress-bar--state">
160 <section data-section="progress"><progress value="100" max="100"></progress></section>
161 <section data-section="status" data-status="$this->success_status_value"></section>
162 <section data-section="message">$this->message</section>
163</div>
164EOT;
165
166 $this->assertEquals(
167 $this->brutallyTrimHTML($expected_html),
168 $this->brutallyTrimHTML($actual_html),
169 );
170 }
171
172 public function testRenderFailure(): void
173 {
174 $state = $this->getUIFactory()->progress()->state()->bar()->failure($this->message);
175
176 $renderer = $this->getDefaultRenderer();
177
178 $actual_html = $renderer->render($state);
179
180 $expected_html = <<<EOT
181<div class="c-progress c-progress-bar--state">
182 <section data-section="progress"><progress value="100" max="100"></progress></section>
183 <section data-section="status" data-status="$this->failure_status_value"></section>
184 <section data-section="message">$this->message</section>
185</div>
186EOT;
187
188 $this->assertEquals(
189 $this->brutallyTrimHTML($expected_html),
190 $this->brutallyTrimHTML($actual_html),
191 );
192 }
193
194 public function getUIFactory(): \NoUIFactory
195 {
196 $bar_state_factory = new I\Progress\State\Bar\Factory();
197
198 $state_factory = $this->createMock(I\Progress\State\Factory::class);
199 $state_factory->method('bar')->willReturn($bar_state_factory);
200
201 $progress_factory = $this->createMock(I\Progress\Factory::class);
202 $progress_factory->method('state')->willReturn($state_factory);
203
204 return new class ($progress_factory) extends \NoUIFactory {
205 public function __construct(
206 protected I\Progress\Factory $progress_factory,
207 ) {
208 }
209 public function progress(): I\Progress\Factory
210 {
211 return $this->progress_factory;
212 }
213 };
214 }
215}
$renderer
Provides common functionality for UI tests.
Definition: Base.php:337
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
@ FAILURE
The progress of the process/task cannot be calculated (yet), but it has started processing.
Definition: Status.php:42