*/ protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; protected function setUp(): void { parent::setUp(); $this->enableCsrfToken(); } /** * Choice "Ja/Nein/Vielleicht" (multiple) with two votes and one comment. * * @param array $settings Settings * @return array{0: \App\Model\Entity\Poll, 1: string, 2: \App\Model\Entity\Slide} */ protected function choiceWithVotes(array $settings): array { [$poll, $token] = $this->createPoll(); $slide = $this->createSlide($poll, Slide::TYPE_CHOICE, ['settings' => $settings + ['multiple' => true]], ['Ja', 'Nein', 'Vielleicht']); $poll = $this->goLive($poll, $slide); [$yes, $no, $maybe] = array_map(fn($option) => $option->id, $slide->slide_options); $votes = new VoteService(); $votes->submit($poll, $slide, $this->hash('a', $poll), ['option_ids' => [$yes, $maybe], 'comment' => 'Weil ']); $votes->submit($poll, $slide, $this->hash('b', $poll), ['option_ids' => [$no]]); return [$poll, $token, $slide]; } protected function hash(string $char, Poll $poll): string { return VoteService::participantHash(str_repeat($char, 32), $poll->id); } /** * @return array */ protected function presenterResults(string $token): array { $this->get("/admin/$token/state"); return json_decode((string)$this->_response->getBody(), true)['results']; } public function testSettingsAreSanitized(): void { $settings = SlidesTable::sanitizeSettings(Slide::TYPE_CHOICE, ['private' => '1', 'comments' => '1', 'comment_ratings' => '1']); $this->assertTrue($settings['private']); $this->assertTrue($settings['comments']); $this->assertTrue($settings['comment_ratings']); $settings = SlidesTable::sanitizeSettings(Slide::TYPE_CHOICE, []); $this->assertFalse($settings['private']); $this->assertFalse($settings['comments']); $this->assertFalse($settings['comment_ratings']); [$poll] = $this->createPoll(); $slide = $this->createSlide($poll, Slide::TYPE_CHOICE, ['settings' => ['multiple' => false]]); $this->assertFalse($slide->isPrivate()); $this->assertFalse($slide->hasComments()); } public function testFormOffersFeedbackSettings(): void { [, $token] = $this->createPoll(); $this->get("/admin/$token/slides/add?type=choice"); $this->assertResponseOk(); $this->assertResponseContains('name="settings[comments]"'); $this->assertResponseContains('Gewählte Antwort beim Kommentar'); $this->assertResponseContains('name="settings[private]"'); $this->get("/admin/$token/slides/add?type=scale"); $this->assertResponseOk(); $this->assertResponseContains('Bewertung beim Kommentar'); } public function testCommentIsStoredOnceForMultipleChoice(): void { [, , $slide] = $this->choiceWithVotes(['comments' => true]); $texts = $this->slidesTable()->Responses->find() ->where(['slide_id' => $slide->id, 'text_value IS NOT' => null]) ->all() ->extract('text_value') ->toList(); $this->assertSame(['Weil '], $texts); } public function testCommentIsIgnoredWithoutCommentField(): void { [, , $slide] = $this->choiceWithVotes([]); $this->assertFalse($this->slidesTable()->Responses->exists(['slide_id' => $slide->id, 'text_value IS NOT' => null])); } public function testParticipantPageShowsCommentFieldAndHint(): void { [$poll, , $slide] = $this->choiceWithVotes(['comments' => true, 'private' => true]); $this->slidesTable()->Responses->deleteAll(['slide_id' => $slide->id]); $this->get('/p/' . $poll->join_code); $this->assertResponseContains('name="comment"'); $this->assertResponseContains('Internes Feedback'); } public function testPresenterGetsCommentsWithoutAnswerByDefault(): void { [, $token] = $this->choiceWithVotes(['comments' => true]); $results = $this->presenterResults($token); $this->assertFalse($results['private']); $this->assertSame([1, 1, 1], array_column($results['options'], 'count')); $this->assertSame(['Weil '], array_column($results['comments'], 'text')); $this->assertSame([null], array_column($results['comments'], 'value')); } public function testChosenAnswersNextToCommentAreOptional(): void { [, $token] = $this->choiceWithVotes(['comments' => true, 'comment_ratings' => true]); $this->assertSame(['Ja, Vielleicht'], array_column($this->presenterResults($token)['comments'], 'value')); } public function testParticipantsNeverSeeComments(): void { [$poll] = $this->choiceWithVotes(['comments' => true]); $this->cookie('plenario_pid', str_repeat('a', 32)); $this->get('/p/' . $poll->join_code . '/state'); $state = json_decode((string)$this->_response->getBody(), true); $this->assertNotEmpty($state['results']['options']); $this->assertSame([], $state['results']['comments']); $this->assertResponseNotContains('darum'); } public function testPrivateChoiceShowsOnlyTheCount(): void { [$poll, $token, $slide] = $this->choiceWithVotes(['private' => true, 'comments' => true]); $results = $this->presenterResults($token); $this->assertTrue($results['private']); $this->assertSame([], $results['options']); $this->assertSame([], $results['comments']); $this->assertSame(2, $results['participants']); $this->assertResponseNotContains('darum'); $key = $this->pollsTable()->ensureEmbedKey($poll); $this->get("/e/$key/{$slide->id}/state"); $this->assertResponseNotContains('darum'); $this->cookie('plenario_pid', str_repeat('a', 32)); $this->get('/p/' . $poll->join_code . '/state'); $this->assertNull(json_decode((string)$this->_response->getBody(), true)['results']); } public function testAdminEvaluationShowsVotesAndComments(): void { [, $token, $slide] = $this->choiceWithVotes(['private' => true, 'comments' => true]); $this->get("/admin/$token"); $this->assertResponseContains("/slides/{$slide->id}/answers"); $this->assertResponseContains('intern'); $this->get("/admin/$token/slides/{$slide->id}/answers"); $this->assertResponseOk(); $this->assertResponseContains('2 Personen haben abgestimmt'); $this->assertResponseContains('Internes Feedback'); $this->assertResponseContains('1 Kommentar'); $this->assertResponseContains('Weil <darum>'); $this->assertResponseContains('Antwort: Ja, Vielleicht'); } public function testExportContainsComment(): void { [, $token] = $this->choiceWithVotes(['comments' => true]); $this->get("/admin/$token/export.csv"); $this->assertResponseContains('Ja (Kommentar: Weil )'); $this->assertResponseContains(';Vielleicht;'); } }