Hidden slides stay prepared in the dashboard but are skipped when presenting (start, next/prev, goto), can not go live via embed and are left out of the PDF export. Hiding the live or paused slide pauses the poll like deleting it and resumes with the next visible slide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
173 lines
6.8 KiB
PHP
173 lines
6.8 KiB
PHP
<?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);
|
|
}
|
|
}
|