*/ protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; protected function setUp(): void { parent::setUp(); $this->enableCsrfToken(); } protected function hash(string $char, Poll $poll): string { return VoteService::participantHash(str_repeat($char, 32), $poll->id); } /** * Poll with a public choice, a public open question, anonymous feedback and an internal scale with comments. * * @return array{0: \App\Model\Entity\Poll, 1: string} */ protected function pollWithPrivateSlides(): array { [$poll, $token] = $this->createPoll('Teamrunde'); $votes = new VoteService(); $choice = $this->createSlide($poll, Slide::TYPE_CHOICE, ['question' => 'Pizza oder Pasta?'], ['Pizza', 'Pasta']); $open = $this->createSlide($poll, Slide::TYPE_OPEN, ['question' => 'Wünsche?']); $anonymous = $this->createSlide($poll, Slide::TYPE_OPEN, [ 'question' => 'Was läuft schief?', 'settings' => ['private' => true], ]); $scale = $this->createSlide($poll, Slide::TYPE_SCALE, [ 'question' => 'Wie zufrieden bist du?', 'settings' => ['scale_min' => 1, 'scale_max' => 5, 'private' => true, 'comments' => true], ]); $poll = $this->goLive($poll, $choice); $votes->submit($poll, $choice, $this->hash('a', $poll), ['option_id' => $choice->slide_options[0]->id]); $poll = $this->goLive($poll, $open); $votes->submit($poll, $open, $this->hash('a', $poll), ['text' => 'Mehr ']); $poll = $this->goLive($poll, $anonymous); $votes->submit($poll, $anonymous, $this->hash('a', $poll), ['text' => 'Geheime Kritik']); $poll = $this->goLive($poll, $scale); $votes->submit($poll, $scale, $this->hash('a', $poll), ['value' => 2, 'comment' => 'Interner Kommentar']); $votes->submit($poll, $scale, $this->hash('b', $poll), ['value' => 5]); return [$poll, $token]; } public function testDownloadsPdf(): void { [$poll, $token] = $this->pollWithPrivateSlides(); $this->exportHtml($token); $this->assertHeaderContains('Content-Disposition', 'attachment'); $this->assertHeaderContains('Content-Disposition', 'plenario-' . $poll->join_code . '-' . date('Ymd') . '.pdf'); $this->assertHeader('Cache-Control', 'no-store, private'); $this->assertHeader('Referrer-Policy', 'no-referrer'); } public function testPublicVersionLeavesOutInternalContent(): void { [, $token] = $this->pollWithPrivateSlides(); $html = $this->exportHtml($token); $this->assertStringContainsString('Pizza oder Pasta?', $html); $this->assertStringContainsString('Mehr <Pausen>', $html); $this->assertStringContainsString('Fassung ohne interne Inhalte', $html); // Private slides are listed with their number of participants only. $this->assertStringContainsString('Was läuft schief?', $html); $this->assertStringContainsString('Wie zufrieden bist du?', $html); $this->assertStringContainsString('2 Personen haben teilgenommen', $html); $this->assertStringNotContainsString('Geheime Kritik', $html); $this->assertStringNotContainsString('Interner Kommentar', $html); $this->assertStringNotContainsString('Bewertung 2', $html); $this->assertStringNotContainsString('3,5', $html); $this->assertStringNotContainsString('Vertraulich', $html); } public function testCompleteVersionContainsInternalContent(): void { [, $token] = $this->pollWithPrivateSlides(); $html = $this->exportHtml($token, true); $this->assertHeaderContains('Content-Disposition', '-intern.pdf'); $this->assertStringContainsString('Vertraulich', $html); $this->assertStringContainsString('Geheime Kritik', $html); $this->assertStringContainsString('Interner Kommentar', $html); $this->assertStringContainsString('Bewertung 2', $html); $this->assertStringContainsString('3,5', $html, 'average of 2 and 5'); $this->assertStringContainsString('Mehr <Pausen>', $html); } public function testInternalFlagWithoutPrivateSlidesIsIgnored(): void { [$poll, $token] = $this->createPoll(); $this->createSlide($poll, Slide::TYPE_CHOICE); $html = $this->exportHtml($token, true); $this->assertHeaderContains('Content-Disposition', 'plenario-' . $poll->join_code . '-' . date('Ymd') . '.pdf'); $this->assertStringNotContainsString('Vertraulich', $html); $this->assertStringNotContainsString('Fassung', $html); } public function testUnfinishedQuizRevealsNothing(): void { [$poll, $token] = $this->createPoll(); $quiz = $this->createSlide($poll, Slide::TYPE_QUIZ, ['question' => 'Hauptstadt?', 'is_voting_open' => false], ['Berlin', 'Bonn']); $poll = $this->goLive($poll, $quiz); $this->post("/admin/$token/control", ['action' => 'open']); $quiz = $this->slidesTable()->get($quiz->id, contain: ['SlideOptions']); $this->assertSame(Slide::QUIZ_RUNNING, $quiz->quizPhase()); (new VoteService())->submit($poll, $quiz, $this->hash('a', $poll), ['option_id' => $quiz->slide_options[0]->id]); $html = $this->exportHtml($token, true); $this->assertStringContainsString('Hauptstadt?', $html); $this->assertStringContainsString('nicht beendet', $html); $this->assertStringNotContainsString('✓', $html); $this->assertStringNotContainsString('richtig beantwortet', $html); // Once finished, the solution and counts are part of the report. $this->post("/admin/$token/control", ['action' => 'close']); $html = $this->exportHtml($token); $this->assertStringContainsString('✓ Berlin', $html); $this->assertStringContainsString('1 von 1', $html); } public function testDashboardOffersVersionsOnlyWithPrivateSlides(): void { [$poll, $token] = $this->createPoll(); $this->createSlide($poll, Slide::TYPE_CHOICE); $this->get("/admin/$token"); $this->assertResponseContains('PDF herunterladen'); $this->assertResponseContains("/admin/$token/export.pdf"); $this->assertResponseNotContains('name="internal"'); $this->assertResponseNotContains('CSV'); $this->createSlide($poll, Slide::TYPE_OPEN, ['settings' => ['private' => true]]); $this->get("/admin/$token"); $this->assertResponseContains('name="internal" value="1"'); $this->assertResponseContains('Ohne interne Inhalte'); } }