Merge pull request 'Add quiz slide type' (#6) from feature/quiz-slide into main
Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
commit
50010484be
18 files changed
+999
-43
No files matched your search
@@ -88,6 +88,67 @@ class AdminControllerTest extends TestCase
|
||||
$this->assertSame(1, $slide->position);
|
||||
}
|
||||
|
||||
public function testAddQuizSlide(): void
|
||||
{
|
||||
[, $token] = $this->createPoll();
|
||||
$data = [
|
||||
'type' => 'quiz',
|
||||
'question' => 'Hauptstadt von Frankreich?',
|
||||
'settings' => ['time_limit' => '20'],
|
||||
'is_voting_open' => '1',
|
||||
'quiz_options' => [
|
||||
['label' => 'Lyon', 'correct' => '0'],
|
||||
['label' => 'Paris', 'correct' => '1'],
|
||||
['label' => ''],
|
||||
],
|
||||
];
|
||||
|
||||
$this->get("/admin/$token/slides/add?type=quiz");
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains('name="quiz_options[0][label]"');
|
||||
$this->assertResponseNotContains('name="is_voting_open"');
|
||||
|
||||
$this->post("/admin/$token/slides/add?type=quiz", ['quiz_options' => [['label' => 'A'], ['label' => 'B']]] + $data);
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains('Bitte markiere mindestens eine Antwort als richtig.');
|
||||
|
||||
$this->post("/admin/$token/slides/add?type=quiz", $data);
|
||||
$this->assertRedirect(['_name' => 'admin', 'token' => $token]);
|
||||
$slide = $this->slidesTable()->find()->contain(['SlideOptions'])->firstOrFail();
|
||||
$this->assertSame(['Lyon', 'Paris'], array_map(fn($o) => $o->label, $slide->slide_options));
|
||||
$this->assertSame([false, true], array_map(fn($o) => $o->is_correct, $slide->slide_options));
|
||||
$this->assertSame(['time_limit' => 20], $slide->settings);
|
||||
$this->assertFalse($slide->is_voting_open, 'quiz starts closed until the presenter starts it');
|
||||
}
|
||||
|
||||
public function testPresenterStartsAndEndsQuiz(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_QUIZ, ['is_voting_open' => false], ['Richtig', 'Falsch']);
|
||||
$this->goLive($poll, $slide);
|
||||
$control = function (string $action) use ($token): array {
|
||||
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
|
||||
$this->post("/admin/$token/control", ['action' => $action]);
|
||||
$this->assertResponseOk();
|
||||
|
||||
return json_decode((string)$this->_response->getBody(), true);
|
||||
};
|
||||
|
||||
$state = $control('toggle');
|
||||
$this->assertSame('running', $state['results']['phase']);
|
||||
$this->assertGreaterThan(25, $state['results']['remaining']);
|
||||
$this->assertStringNotContainsString('correct', (string)$this->_response->getBody());
|
||||
$this->assertNotNull($this->slidesTable()->get($slide->id)->voting_ends_at);
|
||||
|
||||
$state = $control('toggle');
|
||||
$this->assertSame('finished', $state['results']['phase']);
|
||||
$this->assertTrue($state['results']['options'][0]['correct']);
|
||||
|
||||
$this->post("/admin/$token/slides/{$slide->id}/reset");
|
||||
$slide = $this->slidesTable()->get($slide->id);
|
||||
$this->assertSame(Slide::QUIZ_READY, $slide->quizPhase());
|
||||
}
|
||||
|
||||
public function testEditKeepsVotesOfUnchangedOptions(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
|
||||
Reference in new issue
Block a user