19declare(strict_types=1);
23require_once(__DIR__ .
"/../../Base.php");
39 protected function setUp(): void
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;
45 $this->message = sha1(
'progress_bar_state_message');
50 public function testIndeterminateConstruction(): void
53 $indeterminate = $this->
getUIFactory()->progress()->state()->bar()->indeterminate($this->message);
55 $this->assertEquals($indeterminate->getStatus()->value, $this->indeterminate_status_value);
56 $this->assertNull($indeterminate->getVisualProgressValue());
57 $this->assertEquals($indeterminate->getMessage(), $this->message);
60 public function testDeterminateConstruction(): void
64 $determinate = $this->
getUIFactory()->progress()->state()->bar()->determinate($progress, $this->message);
66 $this->assertEquals($determinate->getStatus()->value, $this->determinate_status_value);
67 $this->assertEquals($determinate->getVisualProgressValue(), $progress);
68 $this->assertEquals($determinate->getMessage(), $this->message);
73 $invalid_progress = -1;
74 $this->expectException(\InvalidArgumentException::class);
75 $determinate = $this->
getUIFactory()->progress()->state()->bar()->determinate($invalid_progress);
80 $invalid_progress = 100;
81 $this->expectException(\InvalidArgumentException::class);
82 $determinate = $this->
getUIFactory()->progress()->state()->bar()->determinate($invalid_progress);
85 public function testSuccessConstruction(): void
88 $success = $this->
getUIFactory()->progress()->state()->bar()->success($this->message);
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);
95 public function testFailureConstruction(): void
98 $failure = $this->
getUIFactory()->progress()->state()->bar()->failure($this->message);
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);
107 $state = $this->
getUIFactory()->progress()->state()->bar()->indeterminate($this->message);
111 $actual_html =
$renderer->render($state);
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>
122 $this->brutallyTrimHTML($expected_html),
123 $this->brutallyTrimHTML($actual_html),
130 $state = $this->
getUIFactory()->progress()->state()->bar()->determinate($progress, $this->message);
134 $actual_html =
$renderer->render($state);
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>
145 $this->brutallyTrimHTML($expected_html),
146 $this->brutallyTrimHTML($actual_html),
152 $state = $this->
getUIFactory()->progress()->state()->bar()->success($this->message);
156 $actual_html =
$renderer->render($state);
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>
167 $this->brutallyTrimHTML($expected_html),
168 $this->brutallyTrimHTML($actual_html),
174 $state = $this->
getUIFactory()->progress()->state()->bar()->failure($this->message);
178 $actual_html =
$renderer->render($state);
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>
189 $this->brutallyTrimHTML($expected_html),
190 $this->brutallyTrimHTML($actual_html),
196 $bar_state_factory =
new I\Progress\State\Bar\Factory();
198 $state_factory = $this->createMock(
I\Progress\State\Factory::class);
199 $state_factory->method(
'bar')->willReturn($bar_state_factory);
201 $progress_factory = $this->createMock(
I\Progress\Factory::class);
202 $progress_factory->method(
'state')->willReturn($state_factory);
204 return new class ($progress_factory) extends \
NoUIFactory {
206 protected I\Progress\Factory $progress_factory,
209 public function progress(): I\Progress\Factory
211 return $this->progress_factory;
testDeterminateConstructionWithNegativeNumber()
string $success_status_value
string $indeterminate_status_value
testDeterminateConstructionWithMaximumValue()
string $determinate_status_value
string $failure_status_value
testRenderIndeterminate()
Provides common functionality for UI tests.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
@ FAILURE
The progress of the process/task cannot be calculated (yet), but it has started processing.