ILIAS  release_7 Revision v7.30-3-g800a261c036
RoundTripTest.php
Go to the documentation of this file.
1<?php
2
3require_once(__DIR__ . '/ModalBase.php');
4
11{
12 public function test_get_title()
13 {
14 $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $this->getDummyComponent());
15 $this->assertEquals('myTitle', $roundtrip->getTitle());
16 }
17
18 public function test_get_content()
19 {
20 $content = $this->getDummyComponent();
21 $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $content);
22 $this->assertEquals([$content], $roundtrip->getContent());
23 $content = [$this->getDummyComponent(), $this->getDummyComponent()];
24 $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $content);
25 $this->assertEquals($content, $roundtrip->getContent());
26 }
27
28 public function test_get_action_buttons()
29 {
30 $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $this->getDummyComponent());
31 $action_buttons = [
32 $this->getButtonFactory()->primary('Action 1', ''),
33 $this->getButtonFactory()->standard('Action 2', ''),
34 ];
35 $roundtrip = $roundtrip->withActionButtons($action_buttons);
36 $this->assertEquals($action_buttons, $roundtrip->getActionButtons());
37 }
38
39 public function test_with_action_buttons()
40 {
41 $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $this->getDummyComponent());
42 $action_buttons = [
43 $this->getButtonFactory()->primary('Action 1', ''),
44 $this->getButtonFactory()->standard('Action 2', ''),
45 ];
46 $roundtrip2 = $roundtrip->withActionButtons($action_buttons);
47 $this->assertEquals(0, count($roundtrip->getActionButtons()));
48 $this->assertEquals(2, count($roundtrip2->getActionButtons()));
49 $this->assertEquals($action_buttons, $roundtrip2->getActionButtons());
50 }
51
52
53 public function test_simple_rendering()
54 {
55 $roundtrip = $this->getModalFactory()->roundtrip('Title', $this->getUIFactory()->legacy('Content'))
56 ->withActionButtons([
57 $this->getButtonFactory()->primary('Action 1', ''),
58 $this->getButtonFactory()->standard('Action 2', ''),
59 ]);
60 $expected = $this->normalizeHTML($this->getExpectedHTML());
61 $actual = $this->normalizeHTML($this->getDefaultRenderer()->render($roundtrip));
62 $this->assertHTMLEquals($expected, $actual);
63 }
64
65
66 protected function getExpectedHTML()
67 {
68 $expected = <<<EOT
69<div class="modal fade il-modal-roundtrip" tabindex="-1" role="dialog" id="id_1">
70 <div class="modal-dialog" role="document" data-replace-marker="component">
71 <div class="modal-content">
72 <div class="modal-header">
73 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"></span></button><span class="modal-title">Title</span>
74 </div>
75 <div class="modal-body">Content</div>
76 <div class="modal-footer">
77 <button class="btn btn-default btn-primary" data-action="">Action 1</button><button class="btn btn-default" data-action="">Action 2</button><button class="btn btn-default" data-dismiss="modal" aria-label="Close">cancel</button>
78 </div>
79 </div>
80 </div>
81</div>
82EOT;
83 return $expected;
84 }
85}
An exception for terminatinating execution or to throw for unit testing.
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
Base class for modal tests.
Definition: ModalBase.php:14
getButtonFactory()
Definition: ModalBase.php:36
normalizeHTML($html)
Definition: ModalBase.php:46
getUIFactory()
Definition: ModalBase.php:15
getModalFactory()
Definition: ModalBase.php:31
getDummyComponent()
Definition: ModalBase.php:41
Tests on implementation for the roundtrip modal.
Title class.
Definition: Title.php:37
legacy()
Definition: legacy.php:3
standard()
This is an example, of how the Notification Slate is generated by assigning Notification Items to it.
Definition: standard.php:11