Merge pull request 'Feature/hide slides' (#55) from feature/hide-slides into main
CI / Deploy / test (push) Successful in 1m1s
CI / Deploy / deploy (push) Successful in 8s

Reviewed-on: #55
This commit was merged in pull request #55.
This commit is contained in:
gnilebein committed 2026-11-11 17:00:21 +01:00
commit aefaaba086
16 files changed
+546 -39

No files matched your search

@@ -0,0 +1,129 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\Controller;
use App\Model\Entity\Slide;
use App\Service\VoteService;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* Duplicating a slide from the dashboard (slides:duplicate).
*/
class DuplicateSlideTest 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();
}
public function testCopyIsPlacedBehindOriginalWithoutResponses(): void
{
[$poll, $token] = $this->createPoll();
$first = $this->createSlide($poll, Slide::TYPE_CHOICE, [
'description' => '*Wichtig*',
'settings' => ['multiple' => true] + Slide::DEFAULT_SETTINGS[Slide::TYPE_CHOICE],
], ['Rot', 'Grün', 'Blau']);
$last = $this->createSlide($poll, Slide::TYPE_OPEN);
$poll = $this->goLive($poll, $first);
(new VoteService())->submit($poll, $first, VoteService::participantHash(str_repeat('a', 32), $poll->id), [
'option_id' => $first->slide_options[0]->id,
]);
$this->post("/admin/$token/slides/{$first->id}/duplicate");
$slides = $this->slidesTable()->listForPoll($poll->id);
$this->assertSame([$first->id, $last->id], [$slides[0]->id, $slides[2]->id]);
$copy = $slides[1];
$this->assertRedirect(['_name' => 'slides:edit', 'token' => $token, 'id' => $copy->id]);
$this->assertSame([1, 2, 3], array_map(fn($s) => $s->position, $slides));
$this->assertSame('Frage choice (Kopie)', $copy->question);
$this->assertSame('*Wichtig*', $copy->description);
$this->assertSame($first->getSettings(), $copy->getSettings());
$this->assertSame(['Rot', 'Grün', 'Blau'], array_map(fn($o) => $o->label, $copy->slide_options));
$this->assertNotContains($copy->slide_options[0]->id, array_map(fn($o) => $o->id, $first->slide_options));
$responses = TableRegistry::getTableLocator()->get('Responses');
$this->assertSame(0, $responses->find()->where(['slide_id' => $copy->id])->count());
$this->assertSame(1, $responses->find()->where(['slide_id' => $first->id])->count(), 'original keeps its votes');
$this->assertSame($first->id, $this->pollsTable()->get($poll->id)->current_slide_id, 'live slide stays');
}
public function testCopyStartsFresh(): void
{
[$poll, $token] = $this->createPoll();
$quiz = $this->createSlide($poll, Slide::TYPE_QUIZ, [], ['Richtig', 'Falsch', 'Auch falsch']);
$quiz->setVotingOpen(true);
$quiz->is_voting_open = false;
$qa = $this->createSlide($poll, Slide::TYPE_QA);
$qa->stage = Slide::QA_DISCUSS;
$qa->is_voting_open = false;
$closed = $this->createSlide($poll, Slide::TYPE_SCALE, ['is_voting_open' => false]);
$this->slidesTable()->saveManyOrFail([$quiz, $qa]);
foreach ([$quiz, $qa, $closed] as $slide) {
$this->post("/admin/$token/slides/{$slide->id}/duplicate");
$this->assertResponseCode(302);
}
$slides = $this->slidesTable()->listForPoll($poll->id);
$this->assertCount(6, $slides);
[, $quizCopy, , $qaCopy, , $scaleCopy] = $slides;
$this->assertSame(Slide::QUIZ_READY, $quizCopy->quizPhase());
$this->assertNull($quizCopy->voting_started_at);
$this->assertSame([true, false, false], array_map(fn($o) => $o->is_correct, $quizCopy->slide_options));
$this->assertSame(Slide::QA_COLLECT, $qaCopy->qaStage());
$this->assertTrue($qaCopy->is_voting_open);
$this->assertSame(Slide::TYPE_SCALE, $scaleCopy->type);
$this->assertTrue($scaleCopy->is_voting_open);
}
public function testOnlySlidesOfOwnPollAndOnlyPost(): void
{
[$poll, $token] = $this->createPoll();
[$other] = $this->createPoll('Andere');
$own = $this->createSlide($poll);
$foreign = $this->createSlide($other);
$this->post("/admin/$token/slides/{$foreign->id}/duplicate");
$this->assertResponseCode(404);
$this->assertSame(1, $this->slidesTable()->find()->where(['poll_id' => $other->id])->count());
$this->get("/admin/$token/slides/{$own->id}/duplicate");
$this->assertResponseCode(404);
$this->assertSame(1, $this->slidesTable()->find()->where(['poll_id' => $poll->id])->count());
}
public function testLongQuestionIsShortened(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_CONTENT, ['question' => str_repeat('x', 500)], []);
$this->post("/admin/$token/slides/{$slide->id}/duplicate");
$copy = $this->slidesTable()->listForPoll($poll->id)[1];
$this->assertSame(500, mb_strlen($copy->question));
}
public function testDashboardOffersDuplicate(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll);
$this->get("/admin/$token");
$this->assertResponseContains("/admin/$token/slides/{$slide->id}/duplicate");
$this->assertResponseContains('Duplizieren');
}
}
@@ -0,0 +1,172 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\Controller;
use App\Model\Entity\Slide;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* Hiding slides (slides:visibility): prepared, but skipped in the presentation.
*/
class HiddenSlideTest 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();
}
public function testHideAndShowAgainIsIdempotent(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll);
$this->assertFalse($slide->is_hidden, 'new slides are visible');
foreach ([1, 1] as $hidden) {
$this->post("/admin/$token/slides/{$slide->id}/visibility", ['hidden' => $hidden]);
$this->assertRedirect(['_name' => 'admin', 'token' => $token]);
$this->assertTrue($this->slidesTable()->get($slide->id)->is_hidden);
}
$this->get("/admin/$token");
$this->assertResponseContains('ausgeblendet');
$this->assertResponseContains('Einblenden');
foreach ([0, 0] as $hidden) {
$this->post("/admin/$token/slides/{$slide->id}/visibility", ['hidden' => $hidden]);
$this->assertFalse($this->slidesTable()->get($slide->id)->is_hidden);
}
}
public function testPresentationSkipsHiddenSlides(): void
{
[$poll, $token] = $this->createPoll();
$first = $this->hidden($this->createSlide($poll, Slide::TYPE_CHOICE));
$second = $this->createSlide($poll, Slide::TYPE_OPEN);
$third = $this->hidden($this->createSlide($poll, Slide::TYPE_WORDCLOUD));
$fourth = $this->createSlide($poll, Slide::TYPE_SCALE);
// Starting the presentation begins with the first visible slide.
$this->get("/admin/$token/present");
$this->assertSame($second->id, $this->pollsTable()->get($poll->id)->current_slide_id);
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
$this->post("/admin/$token/control", ['action' => 'next']);
$state = json_decode((string)$this->_response->getBody(), true);
$this->assertSame($fourth->id, $state['slide']['id']);
$this->assertSame(1, $state['index']);
$this->assertSame(2, $state['count']);
$this->assertSame(2, $state['hiddenCount']);
$this->assertSame([$second->id, $fourth->id], array_column($state['slides'], 'id'));
$this->post("/admin/$token/control", ['action' => 'prev']);
$this->assertSame($second->id, $this->pollsTable()->get($poll->id)->current_slide_id);
// A hidden slide can not go live.
$this->post("/admin/$token/control", ['action' => 'goto', 'slide_id' => $third->id]);
$this->assertResponseCode(400);
$this->assertSame($second->id, $this->pollsTable()->get($poll->id)->current_slide_id);
$this->assertNotSame($first->id, $this->pollsTable()->get($poll->id)->current_slide_id);
}
public function testHidingTheLiveSlidePausesWithTheNextVisibleSlide(): void
{
[$poll, $token] = $this->createPoll();
$live = $this->createSlide($poll, Slide::TYPE_CHOICE);
$this->hidden($this->createSlide($poll, Slide::TYPE_OPEN));
$next = $this->createSlide($poll, Slide::TYPE_SCALE);
$this->goLive($poll, $live);
$this->post("/admin/$token/slides/{$live->id}/visibility", ['hidden' => 1]);
$poll = $this->pollsTable()->get($poll->id);
$this->assertNull($poll->current_slide_id);
$this->assertSame($next->id, $poll->paused_slide_id, 'resumes with the next visible slide');
// Participants see the pause page.
$this->get('/p/' . $poll->join_code . '/state');
$state = json_decode((string)$this->_response->getBody(), true);
$this->assertNull($state['slide']);
}
public function testHidingTheLastVisibleSlideFallsBackToThePreviousOne(): void
{
[$poll, $token] = $this->createPoll();
$previous = $this->createSlide($poll, Slide::TYPE_CHOICE);
$paused = $this->createSlide($poll, Slide::TYPE_OPEN);
$poll = $this->goLive($poll, $paused);
$poll->pause();
$this->pollsTable()->saveOrFail($poll);
$this->post("/admin/$token/slides/{$paused->id}/visibility", ['hidden' => 1]);
$this->assertSame($previous->id, $this->pollsTable()->get($poll->id)->paused_slide_id);
}
public function testDeletingSkipsHiddenSlidesForResuming(): void
{
[$poll, $token] = $this->createPoll();
$live = $this->createSlide($poll, Slide::TYPE_CHOICE);
$this->hidden($this->createSlide($poll, Slide::TYPE_OPEN));
$this->goLive($poll, $live);
$this->post("/admin/$token/slides/{$live->id}/delete");
$poll = $this->pollsTable()->get($poll->id);
$this->assertNull($poll->current_slide_id);
$this->assertNull($poll->paused_slide_id, 'no visible slide left');
}
public function testEmbeddedHiddenSlideDoesNotGoLive(): void
{
[$poll] = $this->createPoll();
$slide = $this->hidden($this->createSlide($poll, Slide::TYPE_CHOICE));
$key = $this->pollsTable()->ensureEmbedKey($poll);
$this->post("/e/$key/{$slide->id}/activate");
$this->assertResponseOk();
$state = json_decode((string)$this->_response->getBody(), true);
$this->assertFalse($state['isLive']);
$this->assertTrue($state['isHidden']);
$this->assertNull($this->pollsTable()->get($poll->id)->current_slide_id);
}
public function testPdfExportLeavesHiddenSlidesOut(): void
{
[$poll, $token] = $this->createPoll();
$this->hidden($this->createSlide($poll, Slide::TYPE_CHOICE, ['question' => 'Versteckte Frage']));
$this->createSlide($poll, Slide::TYPE_OPEN, ['question' => 'Sichtbare Frage']);
$html = $this->exportHtml($token);
$this->assertStringNotContainsString('Versteckte Frage', $html);
$this->assertStringContainsString('Sichtbare Frage', $html);
$this->assertStringContainsString('Folie 1', $html);
}
protected function hidden(Slide $slide): Slide
{
$slide->is_hidden = true;
$this->slidesTable()->saveOrFail($slide);
return $slide;
}
public function testOnlySlidesOfOwnPoll(): void
{
[, $token] = $this->createPoll();
[$other] = $this->createPoll('Andere');
$foreign = $this->createSlide($other);
$this->post("/admin/$token/slides/{$foreign->id}/visibility", ['hidden' => 1]);
$this->assertResponseCode(404);
$this->assertFalse($this->slidesTable()->get($foreign->id)->is_hidden);
}
}