ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
PlayerVideoTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
24 use ILIAS\UI\Component as C;
27 
32 {
33  public function getUIFactory(): NoUIFactory
34  {
35  return new class (
36  $this->createMock(I\Component\Modal\InterruptiveItem\Factory::class),
37  $this->createMock(FieldFactory::class),
38  ) extends NoUIFactory {
39  public function __construct(
40  protected I\Component\Modal\InterruptiveItem\Factory $interruptive_item_factory,
41  protected FieldFactory $field_factory,
42  ) {
43  }
44 
45  public function modal(): I\Component\Modal\Factory
46  {
47  return new I\Component\Modal\Factory(
48  new I\Component\SignalGenerator(),
49  $this->interruptive_item_factory,
50  $this->field_factory,
51  );
52  }
53  public function button(): I\Component\Button\Factory
54  {
55  return new I\Component\Button\Factory();
56  }
57  };
58  }
59 
60  public function getFactory(): C\Player\Factory
61  {
62  return new I\Component\Player\Factory();
63  }
64 
65  public function testImplementsFactoryInterface(): void
66  {
67  $f = $this->getFactory();
68 
69  $video = $f->video("/foo");
70 
71  $this->assertInstanceOf("ILIAS\\UI\\Component\\Player\\Video", $video);
72  }
73 
74  public function testGetTitleGetSource(): void
75  {
76  $f = $this->getFactory();
77 
78  $video = $f->video("/foo");
79 
80  $this->assertEquals("/foo", $video->getSource());
81  }
82 
83  public function testGetTitleGetPoster(): void
84  {
85  $f = $this->getFactory();
86 
87  $video = $f->video("/foo")->withPoster("bar.jpg");
88 
89  $this->assertEquals("bar.jpg", $video->getPoster());
90  }
91 
92  public function testGetTitleGetSubtitleFile(): void
93  {
94  $f = $this->getFactory();
95 
96  $video = $f->video("/foo")->withAdditionalSubtitleFile("en", "subtitles.vtt");
97 
98  $this->assertEquals(["en" => "subtitles.vtt"], $video->getSubtitleFiles());
99  }
100 
101  public function testRenderVideo(): void
102  {
103  $f = $this->getFactory();
104  $r = $this->getDefaultRenderer();
105 
106  $video = $f->video("/foo");
107 
108  $html = $r->render($video);
109  $expected = <<<EOT
110 <div class="il-video-container">
111  <video class="il-video-player" id="id_1" src="/foo" style="max-width: 100%;" preload="metadata" >
112  </video>
113 </div>
114 EOT;
115  $this->assertHTMLEquals(
116  $this->brutallyTrimHTML($expected),
117  $this->brutallyTrimHTML($html)
118  );
119  }
120 
121  public function testRenderWithPoster(): void
122  {
123  $f = $this->getFactory();
124  $r = $this->getDefaultRenderer();
125 
126  $video = $f->video("/foo")->withPoster("bar.jpg");
127 
128  $html = $r->render($video);
129 
130  $expected = <<<EOT
131 <div class="il-video-container">
132  <video class="il-video-player" id="id_1" src="/foo" style="max-width: 100%;" preload="metadata" poster="bar.jpg">
133  </video>
134 </div>
135 EOT;
136  $this->assertHTMLEquals(
137  $this->brutallyTrimHTML($expected),
138  $this->brutallyTrimHTML($html)
139  );
140  }
141 
142  public function testRenderWithSubtitles(): void
143  {
144  $f = $this->getFactory();
145  $r = $this->getDefaultRenderer();
146 
147  $video = $f->video("/foo")->withAdditionalSubtitleFile("en", "subtitles.vtt");
148 
149  $html = $r->render($video);
150  $expected = <<<EOT
151 <div class="il-video-container">
152  <video class="il-video-player" id="id_1" src="/foo" style="max-width: 100%;" preload="metadata" >
153  <track kind="subtitles" src="subtitles.vtt" srclang="en" />
154  </video>
155 </div>
156 EOT;
157  $this->assertHTMLEquals(
158  $this->brutallyTrimHTML($expected),
159  $this->brutallyTrimHTML($html)
160  );
161  }
162 }
button(string $caption, string $cmd)
modal(string $title="", string $cancel_label="")
__construct(Container $dic, ilPlugin $plugin)
$r