ILIAS  release_8 Revision v8.24
RoundTripTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . '/ModalBase.php');
22
29{
30 public function test_get_title(): void
31 {
32 $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $this->getDummyComponent());
33 $this->assertEquals('myTitle', $roundtrip->getTitle());
34 }
35
36 public function test_get_content(): void
37 {
38 $content = $this->getDummyComponent();
39 $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $content);
40 $this->assertEquals([$content], $roundtrip->getContent());
41 $content = [$this->getDummyComponent(), $this->getDummyComponent()];
42 $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $content);
43 $this->assertEquals($content, $roundtrip->getContent());
44 }
45
46 public function test_get_action_buttons(): void
47 {
48 $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $this->getDummyComponent());
49 $action_buttons = [
50 $this->getButtonFactory()->primary('Action 1', ''),
51 $this->getButtonFactory()->standard('Action 2', ''),
52 ];
53 $roundtrip = $roundtrip->withActionButtons($action_buttons);
54 $this->assertEquals($action_buttons, $roundtrip->getActionButtons());
55 }
56
57 public function test_with_action_buttons(): void
58 {
59 $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $this->getDummyComponent());
60 $action_buttons = [
61 $this->getButtonFactory()->primary('Action 1', ''),
62 $this->getButtonFactory()->standard('Action 2', ''),
63 ];
64 $roundtrip2 = $roundtrip->withActionButtons($action_buttons);
65 $this->assertCount(0, $roundtrip->getActionButtons());
66 $this->assertCount(2, $roundtrip2->getActionButtons());
67 $this->assertEquals($action_buttons, $roundtrip2->getActionButtons());
68 }
69
70 public function test_simple_rendering(): void
71 {
72 $roundtrip = $this->getModalFactory()->roundtrip('Title', $this->getUIFactory()->legacy('Content'))
73 ->withActionButtons([
74 $this->getButtonFactory()->primary('Action 1', ''),
75 $this->getButtonFactory()->standard('Action 2', ''),
76 ]);
77 $expected = $this->brutallyTrimHTML($this->getExpectedHTML());
78 $actual = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($roundtrip));
79 $this->assertHTMLEquals($expected, $actual);
80 }
81
82 protected function getExpectedHTML(): string
83 {
84 return <<<EOT
85<div class="modal fade il-modal-roundtrip" tabindex="-1" role="dialog" id="id_1">
86 <div class="modal-dialog" role="document" data-replace-marker="component">
87 <div class="modal-content">
88 <div class="modal-header">
89 <button type="button" class="close" data-dismiss="modal" aria-label="close"><span aria-hidden="true"></span></button><span class="modal-title">Title</span>
90 </div>
91 <div class="modal-body">Content</div>
92 <div class="modal-footer">
93 <button class="btn btn-default btn-primary" data-action="">Action 1</button>
94 <button class="btn btn-default" data-action="">Action 2</button>
95 <button class="btn btn-default" data-dismiss="modal">cancel</button>
96 </div>
97 </div>
98 </div>
99</div>
100EOT;
101 }
102}
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
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
Base class for modal tests.
Definition: ModalBase.php:35
getButtonFactory()
Definition: ModalBase.php:62
getUIFactory()
Definition: ModalBase.php:36
getModalFactory()
Definition: ModalBase.php:51
getDummyComponent()
Definition: ModalBase.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Title class.
Definition: Title.php:27
standard()
This is an example, of how the Notification Slate is generated by assigning Notification Items to it.
Definition: standard.php:16