ILIAS  release_7 Revision v7.30-3-g800a261c036
InterruptiveTest.php
Go to the documentation of this file.
1<?php
2
3require_once(__DIR__ . '/ModalBase.php');
4
5use \ILIAS\UI\Component as C;
6use \ILIAS\UI\Implementation as I;
7
14{
15 public function test_get_title()
16 {
17 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
18 $this->assertEquals('myTitle', $interruptive->getTitle());
19 }
20
21 public function test_get_message()
22 {
23 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
24 $this->assertEquals('myMessage', $interruptive->getMessage());
25 }
26
27 public function test_get_form_action()
28 {
29 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
30 $this->assertEquals('myFormAction', $interruptive->getFormAction());
31 }
32
33 public function test_get_affected_items()
34 {
35 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
36 $items = [$this->getInterruptiveItem(), $this->getInterruptiveItem()];
37 $interruptive = $interruptive->withAffectedItems($items);
38 $this->assertEquals($items, $interruptive->getAffectedItems());
39 }
40
41 public function test_with_form_action()
42 {
43 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
44 $interruptive2 = $interruptive->withFormAction('myFormAction2');
45 $this->assertEquals('myFormAction', $interruptive->getFormAction());
46 $this->assertEquals('myFormAction2', $interruptive2->getFormAction());
47 }
48
49 public function test_with_affected_items()
50 {
51 $interruptive = $this->getModalFactory()->interruptive('myTitle', 'myMessage', 'myFormAction');
52 $items = [$this->getInterruptiveItem(), $this->getInterruptiveItem()];
53 $interruptive2 = $interruptive->withAffectedItems($items);
54 $this->assertEquals(0, count($interruptive->getAffectedItems()));
55 $this->assertEquals($items, $interruptive2->getAffectedItems());
56 }
57
58 public function test_simple_rendering()
59 {
60 $interruptive = $this->getModalFactory()->interruptive('Title', 'Message', 'myAction.php');
61 $expected = $this->normalizeHTML($this->getExpectedHTML());
62 $actual = $this->normalizeHTML($this->getDefaultRenderer()->render($interruptive));
63 $this->assertEquals($expected, $actual);
64 }
65
66 protected function getInterruptiveItem()
67 {
68 return new InterruptiveItemMock();
69 }
70
71 protected function getExpectedHTML()
72 {
73 $expected = <<<EOT
74<div class="modal fade il-modal-interruptive" tabindex="-1" role="dialog" id="id_1">
75 <div class="modal-dialog" role="document">
76 <form action="myAction.php" method="POST">
77 <div class="modal-content">
78 <div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close">
79 <span aria-hidden="true"></span></button><span class="modal-title">Title</span>
80 </div>
81 <div class="modal-body">
82 <div class="alert alert-warning il-modal-interruptive-message" role="alert">Message</div>
83 </div>
84 <div class="modal-footer">
85 <input type="submit" class="btn btn-primary" value="delete">
86 <button class="btn btn-default" data-dismiss="modal">cancel</button>
87 </div>
88 </div>
89 </form>
90 </div>
91</div>
92EOT;
93 return $expected;
94 }
95
96
97 public function testLabels()
98 {
99 $action_label = 'actionlabel';
100 $cancel_label = 'cancellabel';
101 $interruptive = $this->getModalFactory()->interruptive('Title', 'Message', 'someaction')
102 ->withActionButtonLabel($action_label)
103 ->withCancelButtonLabel($cancel_label);
104
105 $this->assertEquals(
106 $action_label,
107 $interruptive->getActionButtonLabel()
108 );
109 $this->assertEquals(
110 $cancel_label,
111 $interruptive->getCancelButtonLabel()
112 );
113 }
114}
115
117{
118 public function getId()
119 {
120 return 1;
121 }
122
123 public function getTitle()
124 {
125 return 'title';
126 }
127
128 public function getDescription()
129 {
130 return 'description';
131 }
132
133 public function getIcon()
134 {
135 return null;
136 }
137}
An exception for terminatinating execution or to throw for unit testing.
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
Tests on implementation for the interruptive modal.
Base class for modal tests.
Definition: ModalBase.php:14
normalizeHTML($html)
Definition: ModalBase.php:46
getModalFactory()
Definition: ModalBase.php:31
Title class.
Definition: Title.php:37