Files
Plenario/tests/TestCase/Controller/AdminFragmentTest.php
T
gnilebeinandClaude Sonnet 5.5 b643072c3c
CI / Deploy / test (push) Successful in 58s
CI / Deploy / deploy (push) Skipped
Update slide list and edit slide form without page reloads
Slide list actions (hide, delete, reset, duplicate, go live, pause) now run
via fetch and refresh only the changed regions, keeping scroll position and
focus. Add/edit slide forms open in a dialog. Admin pages answer with a
slim fragment layout when the X-Fragment header is sent.

Replace postLink confirms (inline onclick, blocked by the CSP) with
postButton and data-confirm handled in plenario.js.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-11 20:28:03 +01:00

106 lines
3.3 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;
/**
* Dashboard updates without reloading: fragments (header X-Fragment) and the slide form in a dialog.
*/
class AdminFragmentTest 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 testFragmentContainsRegionsButNoPageFrame(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->get("/admin/$token");
$this->assertResponseOk();
$this->assertResponseContains('data-refresh="slides"');
$this->assertResponseContains('data-refresh="head"');
$this->assertResponseContains('data-refresh="flash"');
$this->assertResponseNotContains('<html');
$this->assertResponseNotContains('site-header');
}
public function testFullPageKeepsFrameAndRegions(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$this->get("/admin/$token");
$this->assertResponseContains('<html');
$this->assertResponseContains('data-refresh="flash"');
$this->assertResponseContains('<dialog');
}
public function testActionsUseNoInlineHandlers(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$this->get("/admin/$token");
$this->assertResponseNotContains('onclick=');
$this->assertResponseContains('data-confirm=');
}
public function testSlideFormFragmentIsTheDialogContent(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->get("/admin/$token/slides/{$slide->id}/edit");
$this->assertResponseOk();
$this->assertResponseContains('data-modal-content');
$this->assertResponseNotContains('site-header');
}
public function testValidationErrorKeepsTheFormInTheFragment(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->post("/admin/$token/slides/{$slide->id}/edit", ['question' => '']);
$this->assertResponseOk();
$this->assertResponseContains('data-modal-content');
$this->assertResponseContains('Bitte prüfe deine Eingaben.');
}
public function testSuccessfulSaveRedirectsToTheDashboard(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->post("/admin/$token/slides/{$slide->id}/edit", ['question' => 'Neue Frage']);
$this->assertRedirect(['_name' => 'admin', 'token' => $token]);
}
}