ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
InterruptiveTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . '/ModalBase.php');
22
25
30{
31 public function testGetTitle(): void
32 {
33 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
34 $this->assertEquals('myTitle', $interruptive->getTitle());
35 }
36
37 public function testGetMessage(): void
38 {
39 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
40 $this->assertEquals('myMessage', $interruptive->getMessage());
41 }
42
43 public function testGetFormAction(): void
44 {
45 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
46 $this->assertEquals('myFormAction', $interruptive->getFormAction());
47 }
48
49 public function testGetAffectedItems(): void
50 {
51 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
52 $items = [$this->getInterruptiveItem(), $this->getInterruptiveItem()];
53 $interruptive = $interruptive->withAffectedItems($items);
54 $this->assertEquals($items, $interruptive->getAffectedItems());
55 }
56
57 public function testWithFormAction(): void
58 {
59 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
60 $interruptive2 = $interruptive->withFormAction('myFormAction2');
61 $this->assertEquals('myFormAction', $interruptive->getFormAction());
62 $this->assertEquals('myFormAction2', $interruptive2->getFormAction());
63 }
64
65 public function testWithAffectedItems(): void
66 {
67 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
68 $items = [$this->getInterruptiveItem(), $this->getInterruptiveItem()];
69 $interruptive2 = $interruptive->withAffectedItems($items);
70 $this->assertEquals(0, count($interruptive->getAffectedItems()));
71 $this->assertEquals($items, $interruptive2->getAffectedItems());
72 }
73
74 public function testSimpleRendering(): void
75 {
76 $interruptive = $this->getModalFactory()->interruptive('Title', 'Message', 'myAction.php');
77 $expected = $this->brutallyTrimHTML($this->getExpectedHTML());
78 $actual = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($interruptive));
79 $this->assertEquals($expected, $actual);
80 }
81
82 public function testRenderingWithItems(): void
83 {
84 $interruptive = $this->getModalFactory()->interruptive('Title', 'Message', 'myAction.php');
85 $items = [
86 $this->getKeyValueInterruptiveItem('keyvalue1'),
87 $this->getStandardInterruptiveItem('standard1'),
88 $this->getKeyValueInterruptiveItem('keyvalue2'),
89 $this->getKeyValueInterruptiveItem('keyvalue3'),
90 $this->getStandardInterruptiveItem('standard2')
91 ];
92 $interruptive = $interruptive->withAffectedItems($items);
93 $expected = $this->normalizeHTML($this->getExpectedHTML(true));
94 $actual = $this->normalizeHTML($this->getDefaultRenderer(null, $items)->render($interruptive));
95 $this->assertEquals($expected, $actual);
96 }
97
99 {
100 return new InterruptiveItemMock();
101 }
102
103 protected function getStandardInterruptiveItem(string $canonical_name): StandardItemMock
104 {
105 return new StandardItemMock($canonical_name);
106 }
107
108 protected function getKeyValueInterruptiveItem(string $canonical_name): KeyValueItemMock
109 {
110 return new KeyValueItemMock($canonical_name);
111 }
112
113 protected function getExpectedHTML(bool $with_items = false): string
114 {
115 $expected_start = <<<EOT
116<dialog class="c-modal c-modal--interruptive" tabindex="-1" id="id_1">
117 <div class="modal-dialog" role="document">
118 <form action="myAction.php" method="POST">
119 <div class="modal-content">
120 <div class="modal-header">
121 <button formmethod="dialog" class="close" aria-label="cancel"><span aria-hidden="true">&times;</span></button>
122 <h1 class="modal-title">Title</h1>
123 </div>
124 <div class="modal-body">
125 <div class="alert alert-warning c-modal--interruptive__message" role="alert">Message</div>
126EOT;
127 $expected_items = <<<EOT
128 <div class="c-modal--interruptive__items">
129 <table>
130 standard1
131 standard2
132 </table>
133 </div>
134 <div class="c-modal--interruptive__items">
135 <dl>
136 keyvalue1
137 keyvalue2
138 keyvalue3
139 </dl>
140 </div>
141EOT;
142 $expected_end = <<<EOT
143 </div>
144 <div class="modal-footer">
145 <input type="submit" class="btn btn-primary" value="delete"/>
146 <button formmethod="dialog" class="btn btn-default" data-dismiss="modal">cancel</button>
147 </div>
148 </div>
149 </form>
150 </div>
151</dialog>
152EOT;
153 if ($with_items) {
154 return $expected_start . $expected_items . $expected_end;
155 }
156 return $expected_start . $expected_end;
157 }
158
159
160 public function testLabels(): void
161 {
162 $action_label = 'actionlabel';
163 $cancel_label = 'cancellabel';
164 $interruptive = $this->getModalFactory()->interruptive('Title', 'Message', 'someaction')
165 ->withActionButtonLabel($action_label)
166 ->withCancelButtonLabel($cancel_label);
167
168 $this->assertEquals(
169 $action_label,
170 $interruptive->getActionButtonLabel()
171 );
172 $this->assertEquals(
173 $cancel_label,
174 $interruptive->getCancelButtonLabel()
175 );
176 }
177}
178
179class InterruptiveItemMock implements C\Modal\InterruptiveItem\InterruptiveItem
180{
181 use I\Component\ComponentHelper;
182
183 protected string $canonical_name;
184
185 public function __construct(string $canonical_name = '')
186 {
187 $this->canonical_name = $canonical_name;
188 }
189
190 public function getId(): string
191 {
192 return '1';
193 }
194
195 public function getCanonicalName(): string
196 {
197 return $this->canonical_name ?: 'InterruptiveItem';
198 }
199}
200
202{
203 public function getTitle(): string
204 {
205 return 'title';
206 }
207
208 public function getDescription(): string
209 {
210 return 'description';
211 }
212
213 public function getIcon(): C\Image\Image
214 {
215 return new I\Component\Image\Image(C\Image\Image::STANDARD, '', '');
216 }
217}
218
220{
221 public function getKey(): string
222 {
223 return 'key';
224 }
225
226 public function getValue(): string
227 {
228 return 'value';
229 }
230}
__construct(string $canonical_name='')
Tests on implementation for the interruptive modal.
getStandardInterruptiveItem(string $canonical_name)
getKeyValueInterruptiveItem(string $canonical_name)
getExpectedHTML(bool $with_items=false)
Base class for modal tests.
Definition: ModalBase.php:35
normalizeHTML(string $html)
Definition: ModalBase.php:75
getModalFactory()
Definition: ModalBase.php:50
Title class.
Definition: Title.php:42
form( $class_path, string $cmd, string $submit_caption="")
button(string $caption, string $cmd)