*/ protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; protected function setUp(): void { parent::setUp(); $this->enableCsrfToken(); } /** * @param array $settings Extra settings * @return array Presenter results */ protected function presenterResults(array $settings): array { [$poll, $token] = $this->createPoll(); $slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => $settings + ['scale_min' => 1, 'scale_max' => 5]]); $poll = $this->goLive($poll, $slide); (new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('a', 32), $poll->id), ['value' => 4]); $this->get("/admin/$token/state"); return json_decode((string)$this->_response->getBody(), true)['results']; } public function testBothPartsAreShownByDefault(): void { $settings = SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, []); $this->assertTrue($settings['show_average']); $this->assertTrue($settings['show_distribution']); $results = $this->presenterResults([]); $this->assertTrue($results['showAverage']); $this->assertTrue($results['showDistribution']); } public function testPartsCanBeHidden(): void { $settings = SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['show_average' => '0', 'show_distribution' => '0']); $this->assertFalse($settings['show_average']); $this->assertFalse($settings['show_distribution']); $results = $this->presenterResults(['show_average' => false, 'show_distribution' => false]); $this->assertFalse($results['showAverage']); $this->assertFalse($results['showDistribution']); // The data stays complete (evaluation, PDF), only the presentation hides it. $this->assertEqualsWithDelta(4.0, $results['average'], 0.001); $this->assertSame(1, $results['participants']); } public function testFormSavesParts(): void { [$poll, $token] = $this->createPoll(); $this->get("/admin/$token/slides/add?type=scale"); $this->assertResponseContains('name="settings[show_average]"'); $this->assertResponseContains('name="settings[show_distribution]"'); $this->post("/admin/$token/slides/add?type=scale", [ 'type' => 'scale', 'question' => 'Wie fandest du den Abend?', 'settings' => ['scale_min' => '1', 'scale_max' => '5', 'show_average' => '1', 'show_distribution' => '0'], ]); $slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail(); $this->assertTrue($slide->setting('show_average')); $this->assertFalse($slide->setting('show_distribution')); } }