Step through quizzes with next on a clicker

Next on a quiz starts it, then ends it, and only then moves to the next
slide. Prev always goes to the previous slide and never touches the quiz.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-13 10:18:43 +01:00
1 parent 3c66597696
commit e4622b439e
3 files changed
+109 -1

No files matched your search

@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\Controller;
use App\Model\Entity\Poll;
use App\Model\Entity\Slide;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* Stepping through a presentation with a clicker (only next/prev): a quiz is started and ended before moving on.
*/
class QuizClickerTest extends TestCase
{
use IntegrationTestTrait;
use PlenarioTestTrait;
/**
* @var list<string>
*/
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
protected function setUp(): void
{
parent::setUp();
$this->enableCsrfToken();
}
/**
* @return array<string, mixed>
*/
protected function control(string $token, string $action): array
{
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
$this->post("/admin/$token/control", ['action' => $action]);
$this->assertResponseOk();
return json_decode((string)$this->_response->getBody(), true);
}
protected function createQuiz(Poll $poll, array $data = []): Slide
{
$quiz = $this->createSlide($poll, Slide::TYPE_QUIZ, $data);
$quiz->startFresh();
return $this->slidesTable()->saveOrFail($quiz);
}
public function testNextStartsAndEndsQuizBeforeMovingOn(): void
{
[$poll, $token] = $this->createPoll();
$intro = $this->createSlide($poll, Slide::TYPE_CONTENT);
$quiz = $this->createQuiz($poll, ['settings' => ['time_limit' => 0] + Slide::DEFAULT_SETTINGS[Slide::TYPE_QUIZ]]);
$outro = $this->createSlide($poll, Slide::TYPE_CONTENT);
$this->goLive($poll, $intro);
// Arriving at the quiz does not start it.
$state = $this->control($token, 'next');
$this->assertSame($quiz->id, $state['slide']['id']);
$this->assertSame(Slide::QUIZ_READY, $this->slidesTable()->get($quiz->id)->quizPhase());
// Next: start. Next: end. Next: next slide.
$state = $this->control($token, 'next');
$this->assertSame($quiz->id, $state['slide']['id']);
$this->assertSame(Slide::QUIZ_RUNNING, $this->slidesTable()->get($quiz->id)->quizPhase());
$state = $this->control($token, 'next');
$this->assertSame($quiz->id, $state['slide']['id']);
$this->assertSame(Slide::QUIZ_FINISHED, $this->slidesTable()->get($quiz->id)->quizPhase());
$state = $this->control($token, 'next');
$this->assertSame($outro->id, $state['slide']['id']);
// Back never restarts the quiz: it is passed through and stays finished.
$state = $this->control($token, 'prev');
$this->assertSame($quiz->id, $state['slide']['id']);
$this->assertSame(Slide::QUIZ_FINISHED, $this->slidesTable()->get($quiz->id)->quizPhase());
$state = $this->control($token, 'prev');
$this->assertSame($intro->id, $state['slide']['id']);
}
public function testPrevOnUnstartedQuizJustGoesBack(): void
{
[$poll, $token] = $this->createPoll();
$intro = $this->createSlide($poll, Slide::TYPE_CONTENT);
$quiz = $this->createQuiz($poll);
$this->goLive($poll, $quiz);
$state = $this->control($token, 'prev');
$this->assertSame($intro->id, $state['slide']['id']);
$this->assertSame(Slide::QUIZ_READY, $this->slidesTable()->get($quiz->id)->quizPhase());
}
}