*/ 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 { $this->assertSame(Slide::SCALE_VIEW_BOTH, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, [])['scale_view']); $this->assertSame(Slide::SCALE_VIEW_BOTH, $this->presenterResults([])['view']); } public function testUnknownViewFallsBackToBoth(): void { $settings = SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['scale_view' => 'nothing']); $this->assertSame(Slide::SCALE_VIEW_BOTH, $settings['scale_view']); } public function testOnlyOnePartKeepsTheDataComplete(): void { $results = $this->presenterResults(['scale_view' => Slide::SCALE_VIEW_CHART]); $this->assertSame(Slide::SCALE_VIEW_CHART, $results['view']); // The data stays complete (evaluation, PDF), only the presentation hides a part. $this->assertEqualsWithDelta(4.0, $results['average'], 0.001); $this->assertSame(1, $results['participants']); } public function testFormSavesView(): void { [$poll, $token] = $this->createPoll(); $this->get("/admin/$token/slides/add?type=scale"); $this->assertResponseContains('name="settings[scale_view]"'); $this->post("/admin/$token/slides/add?type=scale", [ 'type' => 'scale', 'question' => 'Wie fandest du den Abend?', 'settings' => ['scale_min' => '1', 'scale_max' => '5', 'scale_view' => Slide::SCALE_VIEW_AVERAGE], ]); $slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail(); $this->assertSame(Slide::SCALE_VIEW_AVERAGE, $slide->setting('scale_view')); } }