ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
LightboxTest.php
Go to the documentation of this file.
1 <?php
2 
3 require_once(__DIR__ . '/ModalBase.php');
4 
5 use \ILIAS\UI\Component as C;
6 
12 class LightboxTest extends ModalBase
13 {
14  public function test_get_single_page()
15  {
16  $page = $this->getLightboxPage();
17  $lightbox = $this->getModalFactory()->lightbox($page);
18  $this->assertEquals([$page], $lightbox->getPages());
19  }
20 
21  public function test_get_multiple_page()
22  {
23  $pages = [$this->getLightboxPage(), $this->getLightboxPage()];
24  $lightbox = $this->getModalFactory()->lightbox($pages);
25  $this->assertEquals($pages, $lightbox->getPages());
26  }
27 
28  public function test_simple_rendering()
29  {
30  $image = $this->getUIFactory()->image()->responsive('src/fake/image.jpg', 'description');
31  $lightbox = $this->getModalFactory()->lightbox($this->getUIFactory()->modal()->lightboxImagePage($image, 'title'));
32  $expected = $this->normalizeHTML($this->getExpectedHTML());
33  $actual = $this->normalizeHTML($this->getDefaultRenderer()->render($lightbox));
34  $this->assertEquals($expected, $actual);
35  }
36 
37  protected function getLightboxPage()
38  {
39  return new LightboxMockPage();
40  }
41 
42  protected function getExpectedHTML()
43  {
44  $expected = <<<EOT
45 <div class="modal fade il-modal-lightbox" tabindex="-1" role="dialog" id="id_1">
46  <div class="modal-dialog modal-lg" role="document">
47  <div class="modal-content il-modal-lightbox-page">
48  <div class="modal-header">
49  <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
50  <h4 class="modal-title">title</h4>
51  </div>
52  <div class="modal-body">
53  <div id="id_1_carousel" class="carousel slide" data-ride="carousel" data-interval="false">
54 
55 
56 
57  <div class="carousel-inner" role="listbox">
58 
59  <div class="item active" data-title="title">
60 
61 
62 
63 <img src="src/fake/image.jpg" class="img-responsive" alt="description" />
64 
65  <div class="carousel-caption">
66  description
67  </div>
68  </div>
69 
70  </div>
71 
72 
73 
74  </div>
75  </div>
76  </div>
77  </div>
78 </div>
79 <script>
80  $(function() {
81  $('#id_1').on('shown.bs.modal', function() {
82  $('.modal-backdrop.in').css('opacity', '0.9');
83  });
84  $('#id_1_carousel').on('slid.bs.carousel', function() {
85  var title = $(this).find('.carousel-inner .item.active').attr('data-title');
86  $('#id_1').find('.modal-title').text(title);
87  });
88  });
89 </script>
90 EOT;
91 
92  return $expected;
93  }
94 }
95 
96 class LightboxMockPage implements C\Modal\LightboxPage
97 {
98  public function getTitle()
99  {
100  return 'title';
101  }
102 
103  public function getDescription()
104  {
105  return 'description';
106  }
107 
108  public function getComponent()
109  {
110  return new ComponentDummy();
111  }
112 }
Add some data
test_get_multiple_page()
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
getUIFactory()
Definition: ModalBase.php:14
normalizeHTML($html)
Definition: ModalBase.php:34
Base class for modal tests.
Definition: ModalBase.php:12
getModalFactory()
Definition: ModalBase.php:19
Tests on implementation for the lightbox modal.