Quiz slides have predefined answers with one or more marked as correct. The presenter starts the quiz, which then runs until its optional time limit expires or the presenter ends it. Counts and correct answers are only revealed once the quiz is finished; participants then see whether their answer was right. - migration: slide_options.is_correct, slides.voting_started_at/voting_ends_at - Slide::isVotingOpen() includes the quiz deadline, expired quizzes are closed lazily when the state is read - presenter countdown, quiz tiles and reveal with correct-answer summary - CSV export marks quiz answers as right/wrong Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
2.8 KiB
PHP
88 lines
2.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Test\TestCase;
|
|
|
|
use App\Model\Entity\Poll;
|
|
use App\Model\Entity\Slide;
|
|
use App\Model\Table\PollsTable;
|
|
use App\Model\Table\SlidesTable;
|
|
use Cake\ORM\TableRegistry;
|
|
|
|
/**
|
|
* Helpers to create test data. Use together with the fixtures
|
|
* app.Polls, app.Slides, app.SlideOptions, app.Responses.
|
|
*/
|
|
trait PlenarioTestTrait
|
|
{
|
|
/**
|
|
* @return array{0: \App\Model\Entity\Poll, 1: string} Poll and plain admin token
|
|
*/
|
|
protected function createPoll(string $title = 'Testumfrage', string $email = 'owner@example.org'): array
|
|
{
|
|
/** @var \App\Model\Table\PollsTable $polls */
|
|
$polls = TableRegistry::getTableLocator()->get('Polls');
|
|
[$poll, $token] = $polls->createPoll(['title' => $title, 'email' => $email]);
|
|
$this->assertNotNull($token, 'Poll could not be created: ' . json_encode($poll->getErrors()));
|
|
|
|
return [$poll, (string)$token];
|
|
}
|
|
|
|
/**
|
|
* @param \App\Model\Entity\Poll $poll Poll
|
|
* @param string $type Slide type
|
|
* @param array<string, mixed> $data Extra slide data
|
|
* @param list<string> $options Option labels (choice, quiz: the first one is correct)
|
|
* @return \App\Model\Entity\Slide Slide incl. slide_options
|
|
*/
|
|
protected function createSlide(Poll $poll, string $type = Slide::TYPE_CHOICE, array $data = [], array $options = ['Ja', 'Nein']): Slide
|
|
{
|
|
/** @var \App\Model\Table\SlidesTable $slides */
|
|
$slides = TableRegistry::getTableLocator()->get('Slides');
|
|
$slide = $slides->newEntity($data + [
|
|
'type' => $type,
|
|
'question' => 'Frage ' . $type,
|
|
'settings' => Slide::DEFAULT_SETTINGS[$type] ?? [],
|
|
]);
|
|
$slide->poll_id = $poll->id;
|
|
$slides->saveOrFail($slide);
|
|
if ($type === Slide::TYPE_CHOICE) {
|
|
$slides->syncOptions($slide, $options);
|
|
}
|
|
if ($type === Slide::TYPE_QUIZ) {
|
|
// First option is the correct one.
|
|
$slides->syncOptions($slide, $options, [$options[0]]);
|
|
}
|
|
|
|
return $slides->get($slide->id, contain: ['SlideOptions']);
|
|
}
|
|
|
|
/**
|
|
* Makes the slide the poll's current slide.
|
|
*/
|
|
protected function goLive(Poll $poll, Slide $slide): Poll
|
|
{
|
|
$polls = $this->pollsTable();
|
|
$poll->current_slide_id = $slide->id;
|
|
$polls->saveOrFail($poll);
|
|
|
|
return $polls->get($poll->id);
|
|
}
|
|
|
|
protected function pollsTable(): PollsTable
|
|
{
|
|
/** @var \App\Model\Table\PollsTable $table */
|
|
$table = TableRegistry::getTableLocator()->get('Polls');
|
|
|
|
return $table;
|
|
}
|
|
|
|
protected function slidesTable(): SlidesTable
|
|
{
|
|
/** @var \App\Model\Table\SlidesTable $table */
|
|
$table = TableRegistry::getTableLocator()->get('Slides');
|
|
|
|
return $table;
|
|
}
|
|
}
|