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