ILIAS  release_8 Revision v8.24
InterruptiveTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . '/ModalBase.php');
22
25
32{
33 public function test_get_title(): void
34 {
35 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
36 $this->assertEquals('myTitle', $interruptive->getTitle());
37 }
38
39 public function test_get_message(): void
40 {
41 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
42 $this->assertEquals('myMessage', $interruptive->getMessage());
43 }
44
45 public function test_get_form_action(): void
46 {
47 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
48 $this->assertEquals('myFormAction', $interruptive->getFormAction());
49 }
50
51 public function test_get_affected_items(): void
52 {
53 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
54 $items = [$this->getInterruptiveItem(), $this->getInterruptiveItem()];
55 $interruptive = $interruptive->withAffectedItems($items);
56 $this->assertEquals($items, $interruptive->getAffectedItems());
57 }
58
59 public function test_with_form_action(): void
60 {
61 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
62 $interruptive2 = $interruptive->withFormAction('myFormAction2');
63 $this->assertEquals('myFormAction', $interruptive->getFormAction());
64 $this->assertEquals('myFormAction2', $interruptive2->getFormAction());
65 }
66
67 public function test_with_affected_items(): void
68 {
69 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
70 $items = [$this->getInterruptiveItem(), $this->getInterruptiveItem()];
71 $interruptive2 = $interruptive->withAffectedItems($items);
72 $this->assertEquals(0, count($interruptive->getAffectedItems()));
73 $this->assertEquals($items, $interruptive2->getAffectedItems());
74 }
75
76 public function test_simple_rendering(): void
77 {
78 $interruptive = $this->getModalFactory()->interruptive('Title', 'Message', 'myAction.php');
79 $expected = $this->brutallyTrimHTML($this->getExpectedHTML());
80 $actual = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($interruptive));
81 $this->assertEquals($expected, $actual);
82 }
83
85 {
86 return new InterruptiveItemMock();
87 }
88
89 protected function getExpectedHTML(): string
90 {
91 $expected = <<<EOT
92<div class="modal fade il-modal-interruptive" tabindex="-1" role="dialog" id="id_1">
93 <div class="modal-dialog" role="document">
94 <form action="myAction.php" method="POST">
95 <div class="modal-content">
96 <div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="cancel">
97 <span aria-hidden="true">&times;</span></button><span class="modal-title">Title</span>
98 </div>
99 <div class="modal-body">
100 <div class="alert alert-warning il-modal-interruptive-message" role="alert">Message</div>
101 </div>
102 <div class="modal-footer">
103 <input type="submit" class="btn btn-primary" value="delete" name="cmd[delete]">
104 <button class="btn btn-default" data-dismiss="modal">cancel</button>
105 </div>
106 </div>
107 </form>
108 </div>
109</div>
110EOT;
111 return $expected;
112 }
113
114
115 public function testLabels(): void
116 {
117 $action_label = 'actionlabel';
118 $cancel_label = 'cancellabel';
119 $interruptive = $this->getModalFactory()->interruptive('Title', 'Message', 'someaction')
120 ->withActionButtonLabel($action_label)
121 ->withCancelButtonLabel($cancel_label);
122
123 $this->assertEquals(
124 $action_label,
125 $interruptive->getActionButtonLabel()
126 );
127 $this->assertEquals(
128 $cancel_label,
129 $interruptive->getCancelButtonLabel()
130 );
131 }
132}
133
135{
136 public function getId(): string
137 {
138 return '1';
139 }
140
141 public function getTitle(): string
142 {
143 return 'title';
144 }
145
146 public function getDescription(): string
147 {
148 return 'description';
149 }
150
151 public function getIcon(): C\Image\Image
152 {
153 return new I\Component\Image\Image(C\Image\Image::STANDARD, '', '');
154 }
155}
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Base class for modal tests.
Definition: ModalBase.php:35
getModalFactory()
Definition: ModalBase.php:51
Title class.
Definition: Title.php:27
form( $class_path, string $cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...