ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
RoundTripTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . '/ModalBase.php');
22 
28 class RoundTripTest extends ModalBase
29 {
30  public function testGetTitle(): void
31  {
32  $roundtrip = $this->getModalFactory()->roundtrip('myTitle', $this->getDummyComponent());
33  $this->assertEquals('myTitle', $roundtrip->getTitle());
34  }
35 
36  public function testGetContent(): 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 testGetActionButtons(): 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 testWithActionButtons(): 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 testSimpleRendering(): void
71  {
72  $roundtrip = $this->getModalFactory()->roundtrip('Title', $this->getUIFactory()->legacy()->content('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 <dialog class="c-modal il-modal-roundtrip" tabindex="-1" 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  <form><button formmethod="dialog" class="close" aria-label="close"><span aria-hidden="true">&times;</span></button></form>
90  <h1 class="modal-title">Title</h1>
91  </div>
92  <div class="modal-body">Content</div>
93  <div class="modal-footer">
94  <form>
95  <button class="btn btn-default btn-primary" data-action="">Action 1</button>
96  <button class="btn btn-default" data-action="">Action 2</button>
97  <button formmethod="dialog" class="btn btn-default" data-dismiss="modal">cancel</button>
98  </form>
99  </div>
100  </div>
101  </div>
102 </dialog>
103 EOT;
104  }
105 }
button(string $caption, string $cmd)
getButtonFactory()
Definition: ModalBase.php:65
standard()
description: > This is an example, of how the Notification Slate is generated by assigning Notificat...
Definition: standard.php:38
Title class.
Definition: Title.php:41
getUIFactory()
Definition: ModalBase.php:36
getDummyComponent()
Definition: ModalBase.php:70
Base class for modal tests.
Definition: ModalBase.php:34
legacy()
expected output: > ILIAS shows the rendered Component.
Definition: legacy.php:29
getModalFactory()
Definition: ModalBase.php:50
form( $class_path, string $cmd, string $submit_caption="")
Tests on implementation for the roundtrip modal.