ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
LinearWorkflowTest.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
25
27{
28 protected string $title;
29 protected array $steps;
30 protected Workflow\Linear $wf;
31
32 protected function buildFactory(): Workflow\Factory
33 {
35 }
36
37 public function setUp(): void
38 {
39 $f = $this->buildFactory();
40 $this->title = 'title';
41 $this->steps = [
42 $f->step(''),
43 $f->step('')
44 ];
45 $this->wf = $f->linear($this->title, $this->steps);
46 }
47
48 public function testImplementsFactoryInterface(): void
49 {
50 $this->assertInstanceOf(Workflow\Workflow::class, $this->wf);
51 }
52
53 public function testConstructorParams(): void
54 {
55 $this->assertEquals($this->title, $this->wf->getTitle());
56 $this->assertEquals($this->steps, $this->wf->getSteps());
57 $this->assertEquals(0, $this->wf->getActive());
58 }
59
60 public function testConstructor(): void
61 {
62 $this->assertEquals($this->title, $this->wf->getTitle());
63 $this->assertEquals($this->steps, $this->wf->getSteps());
64 $this->assertEquals(0, $this->wf->getActive());
65 }
66
67 public function testAmountOfSteps(): void
68 {
69 $this->assertEquals(count($this->steps), $this->wf->getAmountOfSteps());
70 }
71
72 public function testActive(): void
73 {
74 $wf = $this->wf->withActive(1);
75 $this->assertEquals(1, $wf->getActive());
76 }
77
78 public function testWithActiveThrows(): void
79 {
80 $raised = false;
81 try {
82 $this->wf->withActive(-1);
83 $this->assertFalse("This should not happen.");
84 } catch (InvalidArgumentException $e) {
85 $raised = true;
86 }
87 $this->assertTrue($raised);
88
89 $raised = false;
90 try {
91 $this->wf->withActive(2);
92 $this->assertFalse("This should not happen.");
93 } catch (InvalidArgumentException $e) {
94 $raised = true;
95 }
96 $this->assertTrue($raised);
97 }
98
99 public function testLinearWorkflowRendering(): void
100 {
101 $expected = <<<EOT
102 <div class="il-workflow linear" id="id_1">
103 <div class="il-workflow-header">
104 <h3 class="il-workflow-title">title</h3>
105 </div>
106 <ul class="il-workflow-container">
107 <li class="il-workflow-step first available not-started">
108 <div class="text">
109 <span class="il-workflow-step-label"></span>
110 <span class="il-workflow-step-description"></span>
111 </div>
112 </li>
113 <li class="il-workflow-step last active not-started">
114 <div class="text">
115 <span class="il-workflow-step-label"></span>
116 <span class="il-workflow-step-description"></span>
117 </div>
118 </li>
119 </ul>
120 </div>
121EOT;
122 $actual = $this->getDefaultRenderer()->render($wf = $this->wf->withActive(1));
123 $this->assertEquals(
124 $this->brutallyTrimHTML($expected),
125 $this->brutallyTrimHTML($actual),
126 );
127 }
128}
Provides common functionality for UI tests.
Definition: Base.php:337
This is the interface for a workflow factory.
Definition: Factory.php:29
withActive(int $active)
The step at this position is set to active.
getActive()
This is the index of the active step.