*/ protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; protected function setUp(): void { parent::setUp(); $this->enableCsrfToken(); } public function testResetOnlyDeletesResponses(): void { [$poll, $token] = $this->createPoll(); [$other] = $this->createPoll('Andere'); $choice = $this->createSlide($poll, Slide::TYPE_CHOICE); $quiz = $this->createSlide($poll, Slide::TYPE_QUIZ, ['is_voting_open' => false], ['Richtig', 'Falsch']); $order = $this->createSlide($poll, Slide::TYPE_ORDER, [], ['A', 'B', 'C']); $qa = $this->createSlide($poll, Slide::TYPE_QA); $foreign = $this->createSlide($other, Slide::TYPE_CHOICE); $votes = new VoteService(); $hash = VoteService::participantHash(str_repeat('a', 32), $poll->id); $poll = $this->goLive($poll, $choice); $votes->submit($poll, $choice, $hash, ['option_id' => $choice->slide_options[0]->id]); $other = $this->goLive($other, $foreign); $votes->submit($other, $foreign, VoteService::participantHash(str_repeat('a', 32), $other->id), [ 'option_id' => $foreign->slide_options[0]->id, ]); // Quiz played and finished, ordering revealed, Q&A in discussion. $quiz->setVotingOpen(true); $quiz->is_voting_open = false; $order->is_voting_open = false; $qa->stage = Slide::QA_DISCUSS; $qa->is_voting_open = false; $this->slidesTable()->saveManyOrFail([$quiz, $order, $qa]); $poll->pause(); $this->pollsTable()->saveOrFail($poll); $this->post("/admin/$token/reset"); $this->assertRedirect(['_name' => 'admin', 'token' => $token]); $this->assertFlashMessage('Alle Antworten wurden gelöscht.'); $responses = TableRegistry::getTableLocator()->get('Responses'); $this->assertSame(0, $responses->find()->where(['slide_id IN' => [$choice->id, $quiz->id, $order->id, $qa->id]])->count()); $this->assertSame(1, $responses->find()->where(['slide_id' => $foreign->id])->count(), 'other polls stay untouched'); // The presentation stays where it is (paused on the choice slide). $poll = $this->pollsTable()->get($poll->id); $this->assertNull($poll->current_slide_id); $this->assertSame($choice->id, $poll->paused_slide_id); $slides = $this->slidesTable(); $this->assertSame(Slide::QUIZ_READY, $slides->get($quiz->id)->quizPhase()); $this->assertNull($slides->get($quiz->id)->voting_started_at); $this->assertFalse($slides->get($order->id)->is_voting_open, 'open/closed is kept'); $this->assertSame(Slide::QA_COLLECT, $slides->get($qa->id)->qaStage()); $this->assertTrue($slides->get($qa->id)->is_voting_open); $this->assertTrue($slides->get($choice->id)->is_voting_open); // Idempotent: a second reset changes nothing and does not fail. $this->post("/admin/$token/reset"); $this->assertRedirect(['_name' => 'admin', 'token' => $token]); $this->assertSame($choice->id, $this->pollsTable()->get($poll->id)->paused_slide_id); } public function testResetRequiresPost(): void { [, $token] = $this->createPoll(); $this->get("/admin/$token/reset"); $this->assertResponseCode(404); } public function testDashboardOffersResetOnlyWithSomethingToReset(): void { [$poll, $token] = $this->createPoll(); $slide = $this->createSlide($poll, Slide::TYPE_CHOICE); $this->get("/admin/$token"); $this->assertResponseNotContains("/admin/$token/reset\""); $this->assertResponseContains('Noch nichts zurückzusetzen'); $poll = $this->goLive($poll, $slide); (new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('a', 32), $poll->id), [ 'option_id' => $slide->slide_options[0]->id, ]); $this->get("/admin/$token"); $this->assertResponseContains("/admin/$token/reset\""); } }