ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
LightboxTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . '/ModalBase.php');
22 
23 use ILIAS\UI\Component as C;
25 
31 class LightboxTest extends ModalBase
32 {
33  public function testGetSinglePage(): void
34  {
35  $page = $this->getLightboxPage();
36  $lightbox = $this->getModalFactory()->lightbox($page);
37  $this->assertEquals([$page], $lightbox->getPages());
38  }
39 
40  public function testGetMultiplePage(): void
41  {
42  $pages = [$this->getLightboxPage(), $this->getLightboxPage()];
43  $lightbox = $this->getModalFactory()->lightbox($pages);
44  $this->assertEquals($pages, $lightbox->getPages());
45  }
46 
50  public function testSimplePageRendering(string $method, array $args, string $expected_html): void
51  {
52  $lightbox = $this->getModalFactory()->lightbox($this->getModalFactory()->$method(...$args));
53  $expected = $this->normalizeHTML($expected_html);
54  $actual = $this->normalizeHTML($this->getDefaultRenderer()->render($lightbox));
55  $this->assertEquals($expected, $actual);
56  }
57 
58  public static function getPageProvider(): array
59  {
60  $image = new I\Component\Image\Image("responsive", 'src/fake/image.jpg', 'description');
61  $card = new I\Component\Card\Card('foo');
62 
63  return [
64  'Render image page' => ['lightboxImagePage', [$image, 'title'], self::getExpectedImagePageHTML()],
65  'Render text page' => ['lightboxTextPage', ['HelloWorld', 'title'], self::getExpectedTextPageHTML()],
66  'Render card page' => ['lightboxCardPage', [$card], self::getExpectedCardPageHTML()],
67  ];
68  }
69 
70  public function testDifferentPageTypeRendering(): void
71  {
72  $image1 = new I\Component\Image\Image("responsive", 'src/fake/image.jpg', 'description');
73 
74  $pages = [
75  $this->getModalFactory()->lightboxTextPage('HelloWorld', 'title'),
76  $this->getModalFactory()->lightboxImagePage($image1, 'title'),
77  ];
78 
79  $lightbox = $this->getModalFactory()->lightbox($pages);
80  $expected = $this->normalizeHTML($this->getExpectedMixedPagesHTML());
81  $actual = $this->normalizeHTML($this->getDefaultRenderer()->render($lightbox));
82  $this->assertEquals($expected, $actual);
83  }
84 
85  protected function getLightboxPage(): LightboxMockPage
86  {
87  return new LightboxMockPage();
88  }
89 
90  protected static function getExpectedTextPageHTML(): string
91  {
92  return <<<EOT
93 <dialog class="c-modal c-modal--lightbox il-modal-lightbox il-modal-lightbox-bright" tabindex="-1" id="id_1">
94  <div class="modal-dialog modal-lg" role="document">
95  <div class="modal-content il-modal-lightbox-page">
96  <div class="modal-header">
97  <form><button formmethod="dialog" class="close" aria-label="close"><span aria-hidden="true"></span></button></form>
98  <h1 class="modal-title">title</h1>
99  </div>
100  <div class="modal-body">
101  <div id="id_1_carousel" class="carousel slide" data-ride="carousel" data-interval="false">
102 
103  <div class="carousel-inner" role="listbox">
104  <div class="item active text-only" data-title="title">
105  <div class="item-content ">
106  HelloWorld
107  </div>
108  </div>
109  </div>
110 
111  </div>
112  </div>
113  </div>
114  </div>
115 </dialog>
116 EOT;
117  }
119  protected static function getExpectedImagePageHTML(): string
120  {
121  return <<<EOT
122 <dialog class="c-modal c-modal--lightbox il-modal-lightbox il-modal-lightbox-dark" tabindex="-1" id="id_1">
123  <div class="modal-dialog modal-lg" role="document">
124  <div class="modal-content il-modal-lightbox-page">
125  <div class="modal-header">
126  <form><button formmethod="dialog" class="close" aria-label="close"><span aria-hidden="true"></span></button></form>
127  <h1 class="modal-title">title</h1>
128  </div>
129  <div class="modal-body">
130  <div id="id_1_carousel" class="carousel slide" data-ride="carousel" data-interval="false">
131 
132  <div class="carousel-inner" role="listbox">
133 
134  <div class="item active" data-title="title">
135  <div class="item-content ">
136  <img src="src/fake/image.jpg" class="img-responsive" alt="description" />
137  </div>
138  <div class="carousel-caption">
139  description
140  </div>
141  </div>
142 
143  </div>
144 
145  </div>
146  </div>
147  </div>
148  </div>
149 </dialog>
150 EOT;
151  }
152 
153  protected static function getExpectedMixedPagesHTML(): string
154  {
155  return <<<EOT
156 <dialog class="c-modal c-modal--lightbox il-modal-lightbox il-modal-lightbox-dark" tabindex="-1" id="id_1">
157  <div class="modal-dialog modal-lg" role="document">
158  <div class="modal-content il-modal-lightbox-page">
159  <div class="modal-header">
160  <form><button formmethod="dialog" class="close" aria-label="close"><span aria-hidden="true"></span></button></form>
161  <h1 class="modal-title">title</h1>
162  </div>
163  <div class="modal-body">
164  <div id="id_1_carousel" class="carousel slide" data-ride="carousel" data-interval="false">
165 
166  <ol class="carousel-indicators">
167  <li data-target="#id_1_carousel" data-slide-to="0" class="active"></li>
168  <li data-target="#id_1_carousel" data-slide-to="1" class=""></li>
169  </ol>
170 
171  <div class="carousel-inner" role="listbox">
172  <div class="item active text-only" data-title="title">
173  <div class="item-content ">
174  HelloWorld
175  </div>
176  </div>
177 
178  <div class="item " data-title="title">
179  <div class="item-content ">
180  <img src="src/fake/image.jpg" class="img-responsive" alt="description" />
181  </div>
182  <div class="carousel-caption">
183  description
184  </div>
185  </div>
186  </div>
187 
188  <button class="left carousel-control btn-link" href="#id_1_carousel" role="button" data-slide="prev">
189  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
190  <span class="sr-only">Previous</span>
191  </button>
192  <button class="right carousel-control btn-link" href="#id_1_carousel" role="button" data-slide="next">
193  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
194  <span class="sr-only">Next</span>
195  </button>
196 
197  </div>
198  </div>
199  </div>
200  </div>
201 </dialog>
202 EOT;
203  }
204 
205  private static function getExpectedCardPageHTML(): string
206  {
207  return <<<EOT
208 <dialog class="c-modal c-modal--lightbox il-modal-lightbox il-modal-lightbox-bright" tabindex="-1" id="id_1">
209  <div class="modal-dialog modal-lg" role="document">
210  <div class="modal-content il-modal-lightbox-page">
211  <div class="modal-header">
212  <form><button formmethod="dialog" class="close" aria-label="close"><span aria-hidden="true"></span></button></form>
213  <h1 class="modal-title">foo</h1>
214  </div>
215  <div class="modal-body">
216  <div id="id_1_carousel" class="carousel slide" data-ride="carousel" data-interval="false">
217  <div class="carousel-inner" role="listbox">
218  <div class="item active" data-title="foo">
219  <div class="item-content item-vertical"></div>
220  </div>
221  </div>
222  </div>
223  </div>
224  </div>
225  </div>
226 </dialog>
227 EOT;
228  }
229 }
230 
231 class LightboxMockPage implements C\Modal\LightboxPage
232 {
233  public function getTitle(): string
234  {
235  return 'title';
236  }
237 
238  public function getComponent(): C\Component
239  {
240  return new ComponentDummy();
241  }
242 }
button(string $caption, string $cmd)
static getExpectedImagePageHTML()
testSimplePageRendering(string $method, array $args, string $expected_html)
getPageProvider
static getExpectedMixedPagesHTML()
static getExpectedTextPageHTML()
static getExpectedCardPageHTML()
static getPageProvider()
Base class for modal tests.
Definition: ModalBase.php:34
normalizeHTML(string $html)
Definition: ModalBase.php:75
getModalFactory()
Definition: ModalBase.php:50
Tests on implementation for the lightbox modal.
testDifferentPageTypeRendering()
form( $class_path, string $cmd, string $submit_caption="")
Some very basic component implementation.
Definition: HelloWorld.php:26
to(\GdImage $image, ?int $quality=null)
Currently this is the only way to make a FileStream from a GD image resource.