*/ protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; protected function setUp(): void { parent::setUp(); $this->enableCsrfToken(); } protected function mockOembed(int $code, string $body = ''): void { // Registering a mock also makes unexpected requests fail instead of hitting the network. $this->mockClientGet('https://www.youtube.com/*', $this->newClientResponse($code, ['Content-Type: application/json'], $body)); } public function testAddSlideUsesTimecodeOfLinkAndVideoTitle(): void { [$poll, $token] = $this->createPoll(); $this->mockOembed(200, '{"title":"Never Gonna Give You Up"}'); $this->post("/admin/$token/slides/add?type=youtube", [ 'type' => 'youtube', 'question' => '', 'settings' => ['url' => 'https://youtu.be/dQw4w9WgXcQ?t=43', 'start' => '', 'autoplay' => '1'], ]); $this->assertRedirect(['_name' => 'admin', 'token' => $token]); $slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail(); $this->assertSame('Never Gonna Give You Up', $slide->question); $this->assertSame(['url' => 'https://youtu.be/dQw4w9WgXcQ?t=43', 'video_id' => 'dQw4w9WgXcQ', 'start' => 43, 'autoplay' => true], $slide->settings); $this->assertFalse($slide->isInteractive()); } public function testEnteredStartWins(): void { [$poll, $token] = $this->createPoll(); $this->mockOembed(200, '{"title":"Video"}'); $this->post("/admin/$token/slides/add?type=youtube", [ 'type' => 'youtube', 'question' => 'Mein Titel', 'settings' => ['url' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=43s', 'start' => '1:30'], ]); $this->assertRedirect(); $slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail(); $this->assertSame('Mein Titel', $slide->question); $this->assertSame(90, $slide->setting('start')); $this->assertFalse($slide->setting('autoplay')); } public function testInvalidLinkAndStartAreRejected(): void { [$poll, $token] = $this->createPoll(); $this->post("/admin/$token/slides/add?type=youtube", [ 'type' => 'youtube', 'question' => 'Video', 'settings' => ['url' => 'https://vimeo.com/123', 'start' => '1:99'], ]); $this->assertResponseOk(); $this->assertResponseContains('kein gültiger YouTube-Link'); $this->assertResponseContains('Startzeit'); $this->assertResponseContains('value="1:99"'); $this->assertSame(0, $this->slidesTable()->find()->where(['poll_id' => $poll->id])->count()); } public function testVideoThatMayNotBeEmbeddedIsRejected(): void { [$poll, $token] = $this->createPoll(); $this->mockOembed(401); $this->post("/admin/$token/slides/add?type=youtube", [ 'type' => 'youtube', 'question' => 'Video', 'settings' => ['url' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'], ]); $this->assertResponseOk(); $this->assertResponseContains('darf nicht eingebettet werden'); $this->assertSame(0, $this->slidesTable()->find()->where(['poll_id' => $poll->id])->count()); } public function testUnreachableYouTubeSavesWithWarning(): void { [$poll, $token] = $this->createPoll(); $this->mockOembed(503); $this->post("/admin/$token/slides/add?type=youtube", [ 'type' => 'youtube', 'question' => 'Video', 'settings' => ['url' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'], ]); $this->assertRedirect(); $this->assertFlashMessageAt(0, 'YouTube war gerade nicht erreichbar, das Video konnte nicht geprüft werden. Bitte teste das Video vor deiner Präsentation.'); $this->assertSame(1, $this->slidesTable()->find()->where(['poll_id' => $poll->id])->count()); } public function testCheckEndpoint(): void { [, $token] = $this->createPoll(); $this->mockOembed(200, '{"title":"Never Gonna Give You Up"}'); $this->post("/admin/$token/slides/youtube-check", ['url' => 'https://youtu.be/dQw4w9WgXcQ?t=90', 'start' => '']); $this->assertResponseOk(); $this->assertHeader('Referrer-Policy', 'no-referrer'); $json = json_decode((string)$this->_response->getBody(), true); $this->assertTrue($json['ok']); $this->assertSame('Never Gonna Give You Up', $json['title']); $this->assertSame('1:30', $json['linkStart']); $this->assertStringContainsString('youtube-nocookie.com/embed/dQw4w9WgXcQ', $json['embedUrl']); $this->assertStringContainsString('start=90', $json['embedUrl']); $this->post("/admin/$token/slides/youtube-check", ['url' => 'kein link']); $json = json_decode((string)$this->_response->getBody(), true); $this->assertFalse($json['ok']); } public function testPresenterGetsEmbedAndParticipantGetsShareLink(): void { [$poll, $token] = $this->createPoll(); $slide = $this->createSlide($poll, Slide::TYPE_YOUTUBE, [ 'question' => 'Ein