Merge remote-tracking branch 'origin/main' into fix/atomic-votes
CI / Deploy / test (push) Successful in 56s
CI / Deploy / deploy (push) Skipped

This commit is contained in:
gnilebein committed 2026-11-08 22:35:38 +01:00
commit 9d65e85c55
21 files changed
+402 -128

No files matched your search

@@ -5,7 +5,9 @@ namespace App\Test\TestCase\Controller;
use App\Model\Entity\Slide;
use App\Model\Table\PollsTable;
use App\Service\VoteService;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\Database\Driver\Sqlite;
use Cake\TestSuite\EmailTrait;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
@@ -180,6 +182,44 @@ class AdminControllerTest extends TestCase
$this->assertSame(2, $this->slidesTable()->get($third->id)->position);
}
public function testDeletingTheLiveSlidePausesAndResumesWithTheNextOne(): void
{
[$poll, $token] = $this->createPoll();
$first = $this->createSlide($poll, Slide::TYPE_OPEN);
$second = $this->createSlide($poll, Slide::TYPE_SCALE);
$third = $this->createSlide($poll, Slide::TYPE_CHOICE);
$poll = $this->goLive($poll, $second);
$this->post("/admin/$token/slides/{$second->id}/delete");
$poll = $this->pollsTable()->get($poll->id);
$this->assertTrue($poll->isPaused(), 'Participants see the pause page.');
$this->assertSame($third->id, $poll->paused_slide_id);
// The paused slide is deleted as well: resume with the previous one (last slide).
$this->post("/admin/$token/slides/{$third->id}/delete");
$poll = $this->pollsTable()->get($poll->id);
$this->assertTrue($poll->isPaused());
$this->assertSame($first->id, $poll->paused_slide_id);
// No slides left: back to "not started".
$this->post("/admin/$token/slides/{$first->id}/delete");
$poll = $this->pollsTable()->get($poll->id);
$this->assertNull($poll->current_slide_id);
$this->assertNull($poll->paused_slide_id);
$this->assertFalse($poll->isPaused());
}
public function testDeletingAnotherSlideKeepsTheLiveOne(): void
{
[$poll, $token] = $this->createPoll();
$live = $this->createSlide($poll, Slide::TYPE_OPEN);
$other = $this->createSlide($poll, Slide::TYPE_SCALE);
$poll = $this->goLive($poll, $live);
$this->post("/admin/$token/slides/{$other->id}/delete");
$this->assertSame($live->id, $this->pollsTable()->get($poll->id)->current_slide_id);
}
public function testReorderSlidesByDragAndDrop(): void
{
[$poll, $token] = $this->createPoll();
@@ -284,6 +324,36 @@ class AdminControllerTest extends TestCase
$this->assertFalse($this->pollsTable()->exists(['id' => $poll->id]));
}
public function testDeletePollRemovesOptionsAndResponses(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_CHOICE);
$poll = $this->goLive($poll, $slide);
(new VoteService())->submit($poll, $slide, 'participant', ['option_id' => $slide->slide_options[0]->id]);
$options = $this->fetchTable('SlideOptions');
$responses = $this->fetchTable('Responses');
$this->assertTrue($responses->exists(['slide_id' => $slide->id]));
// A normal SQLite connection does not enforce foreign keys (the test suite turns them on),
// so deleting must not rely on ON DELETE CASCADE.
$connection = $responses->getConnection();
$sqlite = $connection->getDriver() instanceof Sqlite;
if ($sqlite) {
$connection->execute('PRAGMA foreign_keys = OFF');
}
try {
$this->post("/admin/$token/delete", ['confirm_code' => $poll->join_code]);
} finally {
if ($sqlite) {
$connection->execute('PRAGMA foreign_keys = ON');
}
}
$this->assertFalse($this->slidesTable()->exists(['id' => $slide->id]));
$this->assertFalse($options->exists(['slide_id' => $slide->id]), 'Options must not outlive their poll.');
$this->assertFalse($responses->exists(['slide_id' => $slide->id]), 'Responses must not outlive their poll.');
}
public function testQrAndExport(): void
{
[, $token] = $this->createPoll();
@@ -70,6 +70,17 @@ class HomeControllerTest extends TestCase
$this->assertResponseNotContains('/admin/', 'Admin link must not be shown when disabled');
}
public function testCreateAcceptsEmailWithSurroundingSpaces(): void
{
$this->session(['Captcha.math.create' => 7]);
$this->post('/create', ['title' => ' Retro ', 'email' => ' Owner@Example.org ', 'captcha_answer' => '7']);
$this->assertRedirect(['_name' => 'created']);
$poll = $this->pollsTable()->find()->firstOrFail();
$this->assertSame('Retro', $poll->title);
$this->assertSame('owner@example.org', $poll->email);
}
public function testIndexRendersHiddenHoneypot(): void
{
$this->get('/');