*/ protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; protected function setUp(): void { parent::setUp(); $this->enableCsrfToken(); } public function testCopiesSlidesButNoResponses(): void { [$poll, $token] = $this->createPoll(); $first = $this->createSlide($poll, Slide::TYPE_CHOICE, ['description' => '*Wichtig*'], ['Rot', 'Grün']); $quiz = $this->createSlide($poll, Slide::TYPE_QUIZ, [], ['Richtig', 'Falsch']); $hidden = $this->createSlide($poll, Slide::TYPE_OPEN); $hidden->is_hidden = true; $this->slidesTable()->saveOrFail($hidden); $poll = $this->goLive($poll, $first); (new VoteService())->submit($poll, $first, VoteService::participantHash(str_repeat('a', 32), $poll->id), [ 'option_id' => $first->slide_options[0]->id, ]); $this->post("/admin/$token/clone"); $polls = $this->pollsTable()->find()->orderBy(['id' => 'ASC'])->all()->toList(); $this->assertCount(2, $polls); $copy = $polls[1]; $this->assertNotSame($poll->join_code, $copy->join_code); $this->assertSame($poll->email, $copy->email); $this->assertStringEndsWith('(Kopie)', $copy->title); $this->assertNull($copy->current_slide_id, 'copy is not started'); $this->assertSame($first->id, $this->pollsTable()->get($poll->id)->current_slide_id, 'original stays live'); $slides = $this->slidesTable()->listForPoll($copy->id); $this->assertSame([1, 2, 3], array_map(fn($s) => $s->position, $slides)); $this->assertSame( [$first->question, $quiz->question, $hidden->question], array_map(fn($s) => $s->question, $slides), ); $this->assertSame('*Wichtig*', $slides[0]->description); $this->assertSame(['Rot', 'Grün'], array_map(fn($o) => $o->label, $slides[0]->slide_options)); $this->assertSame([true, false], array_map(fn($o) => $o->is_correct, $slides[1]->slide_options)); $this->assertTrue($slides[2]->is_hidden); $this->assertSame(Slide::QUIZ_READY, $slides[1]->quizPhase()); $responses = TableRegistry::getTableLocator()->get('Responses'); $this->assertSame(0, $responses->find()->matching('Slides', fn($q) => $q->where(['Slides.poll_id' => $copy->id]))->count()); $this->assertSame(1, $responses->find()->where(['slide_id' => $first->id])->count(), 'original keeps its votes'); $this->assertCount(3, $this->slidesTable()->listForPoll($poll->id)); } public function testRedirectsToAdminOfTheCopyOnlyViaPost(): void { [, $token] = $this->createPoll(); $this->get("/admin/$token/clone"); $this->assertResponseCode(404); $this->post("/admin/$token/clone"); $this->assertResponseCode(302); $this->assertRedirectContains('/admin/'); $this->assertHeaderNotContains('Location', $token); } public function testDashboardOffersCloneAndMenu(): void { [, $token] = $this->createPoll(); $this->get("/admin/$token"); $this->assertResponseContains("/admin/$token/clone"); $this->assertResponseContains('data-drawer-toggle'); } }