*/ protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; protected function setUp(): void { parent::setUp(); $this->enableCsrfToken(); } /** * @return array */ protected function state(string $token): array { $this->get("/admin/$token/state"); $this->assertResponseOk(); return json_decode((string)$this->_response->getBody(), true); } public function testSpeakerPageDoesNotStartThePresentation(): void { [$poll, $token] = $this->createPoll(); $this->createSlide($poll, Slide::TYPE_CHOICE); for ($i = 0; $i < 2; $i++) { $this->get("/admin/$token/speaker"); $this->assertResponseOk(); $this->assertResponseContains('data-next'); $this->assertNull($this->pollsTable()->get($poll->id)->current_slide_id); } $this->get("/admin/$token/present"); $this->assertResponseNotContains('data-next-question'); } public function testSpeakerPageNeedsTheToken(): void { $this->get('/admin/' . str_repeat('x', 30) . '/speaker'); $this->assertResponseCode(404); } public function testNextIsTheSlideBehindTheLiveOne(): void { [$poll, $token] = $this->createPoll(); $first = $this->createSlide($poll, Slide::TYPE_CHOICE); $second = $this->createSlide($poll, Slide::TYPE_CHOICE, ['question' => 'Zweite?']); $hidden = $this->createSlide($poll, Slide::TYPE_CONTENT); $hidden->is_hidden = true; $this->slidesTable()->saveOrFail($hidden); $this->createSlide($poll, Slide::TYPE_WORDCLOUD, ['question' => 'Letzte?']); $this->assertSame($first->id, $this->state($token)['next']['id'], 'before the start: the first slide'); $this->goLive($poll, $first); $next = $this->state($token)['next']; $this->assertSame($second->id, $next['id']); $this->assertSame('Zweite?', $next['question']); $this->assertSame(['Ja', 'Nein'], $next['options']); $this->goLive($poll, $second); $this->assertSame('Letzte?', $this->state($token)['next']['question'], 'hidden slides are skipped'); $last = $this->slidesTable()->find()->where(['poll_id' => $poll->id, 'type' => Slide::TYPE_WORDCLOUD])->firstOrFail(); $this->goLive($poll, $last); $this->assertNull($this->state($token)['next'], 'nothing after the last slide'); } public function testPreviewRevealsNoSolution(): void { [$poll, $token] = $this->createPoll(); $first = $this->createSlide($poll, Slide::TYPE_CONTENT); $this->createSlide($poll, Slide::TYPE_QUIZ, [], ['Richtig', 'Falsch']); $this->createSlide($poll, Slide::TYPE_ORDER, [], ['Eins', 'Zwei', 'Drei']); $this->goLive($poll, $first); $quiz = $this->state($token)['next']; $this->assertSame(['Richtig', 'Falsch'], $quiz['options']); $this->assertStringNotContainsString('is_correct', json_encode($quiz)); $order = $this->slidesTable()->find()->where(['poll_id' => $poll->id, 'type' => Slide::TYPE_ORDER])->firstOrFail(); $quizSlide = $this->slidesTable()->find()->where(['poll_id' => $poll->id, 'type' => Slide::TYPE_QUIZ])->firstOrFail(); $this->goLive($poll, $quizSlide); $this->assertSame([], $this->state($token)['next']['options'], 'the stored order is the solution'); $this->assertSame($order->id, $this->state($token)['next']['id']); } }