Add ordering slide type
CI / Deploy / test (push) Successful in 50s
CI / Deploy / deploy (push) Skipped

Participants bring shuffled items into the correct order and submit it
once. The admin enters the items in the correct order and can reorder
them by drag & drop or arrow keys. Closing the voting reveals the
solution: how many got it completely right and how often each item was
placed correctly; participants see whether their order was right.

The drag & drop mechanics of the slide list are extracted into a
reusable makeSortable() helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-07 16:47:37 +01:00
1 parent 4eed568a64
commit 918e077734
17 files changed
+922 -95

No files matched your search

@@ -0,0 +1,93 @@
<?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;
/**
* Ordering slides through the HTTP layer: editor, participant page, voting, export.
*/
class OrderSlideTest 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 testAddAndEditKeepTheEnteredOrder(): void
{
[$poll, $token] = $this->createPoll();
$this->get("/admin/$token/slides/add?type=order");
$this->assertResponseOk();
$this->assertResponseContains('name="order_options[]"');
$this->assertResponseContains('data-order-options');
$data = ['type' => 'order', 'question' => 'Sortiere nach Größe', 'is_voting_open' => '1'];
$this->post("/admin/$token/slides/add?type=order", $data + ['order_options' => ['Maus', '', '']]);
$this->assertResponseOk();
$this->assertResponseContains('Bitte gib mindestens zwei Einträge an.');
$this->post("/admin/$token/slides/add?type=order", $data + ['order_options' => ['Maus', 'Maus', 'Hund']]);
$this->assertResponseContains('Jeder Eintrag darf nur einmal vorkommen');
$this->post("/admin/$token/slides/add?type=order", $data + ['order_options' => ['Maus', 'Katze', '', 'Elefant']]);
$this->assertRedirect(['_name' => 'admin', 'token' => $token]);
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->contain(['SlideOptions'])->firstOrFail();
$this->assertSame(['Maus', 'Katze', 'Elefant'], array_map(fn($o) => $o->label, $slide->slide_options));
$this->assertTrue($slide->is_voting_open);
$ids = array_map(fn($o) => $o->id, $slide->slide_options);
// Reordering in the editor keeps the options (ids), only the positions change.
$this->post("/admin/$token/slides/{$slide->id}/edit", $data + ['order_options' => ['Elefant', 'Katze', 'Maus']]);
$slide = $this->slidesTable()->get($slide->id, contain: ['SlideOptions']);
$this->assertSame(['Elefant', 'Katze', 'Maus'], array_map(fn($o) => $o->label, $slide->slide_options));
$this->assertSame(array_reverse($ids), array_map(fn($o) => $o->id, $slide->slide_options));
$this->get("/admin/$token");
$this->assertResponseContains('Elefant → Katze → Maus');
}
public function testParticipantSortsSubmitsAndSeesVerdict(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_ORDER, [], ['Eins', 'Zwei', 'Drei']);
$this->goLive($poll, $slide);
$ids = array_map(fn($o) => $o->id, $slide->slide_options);
$this->cookie('plenario_pid', str_repeat('b', 32));
$this->get('/p/' . $poll->join_code);
$this->assertResponseOk();
$this->assertResponseContains('data-order-form');
$this->assertResponseContains('Reihenfolge einreichen');
preg_match_all('/name="order\[\]" value="(\d+)"/', (string)$this->_response->getBody(), $matches);
$shown = array_map('intval', $matches[1]);
$this->assertNotSame($ids, $shown, 'items are shuffled');
$this->assertEqualsCanonicalizing($ids, $shown);
$this->post('/p/' . $poll->join_code . '/vote', ['slide_id' => $slide->id, 'order' => $ids]);
$this->assertRedirect(['_name' => 'participate', 'code' => $poll->join_code]);
$this->get('/p/' . $poll->join_code);
$this->assertResponseContains('Deine Reihenfolge ist angekommen.');
$this->post("/admin/$token/control", ['action' => 'toggle']);
$this->get('/p/' . $poll->join_code);
$this->assertResponseContains('Richtig – deine Reihenfolge stimmt!');
$this->get("/admin/$token/export.csv");
$this->assertResponseOk();
$this->assertResponseContains('Eins → Zwei → Drei (richtig)');
}
}