Merge pull request 'Delete options and responses together with their poll' (#30) from fix/poll-delete-cascade into main
CI / Deploy / test (push) Successful in 1m0s
CI / Deploy / deploy (push) Successful in 5s

Reviewed-on: #30
This commit was merged in pull request #30.
This commit is contained in:
gnilebein committed 2026-11-08 22:31:14 +01:00
commit f536ea89fc
4 files changed
+71 -1

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;
@@ -284,6 +286,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();