Replace CSV export with PDF export
CI / Deploy / test (push) Successful in 53s
CI / Deploy / deploy (push) Skipped

The results export is now a PDF (Dompdf) with all interactive slides.
By default private slides (anonymous/internal feedback) only show their
number of participants; ?internal=1 creates the complete version incl.
their answers, marked as confidential on every page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-08 19:21:10 +01:00
1 parent 5cd1be1cf8
commit d1facd32a6
21 files changed
+1102 -110

No files matched your search

@@ -291,8 +291,9 @@ class AdminControllerTest extends TestCase
$this->assertResponseOk();
$this->assertContentType('image/svg+xml');
$this->get("/admin/$token/export.csv");
$this->get("/admin/$token/export.pdf");
$this->assertResponseOk();
$this->assertContentType('application/pdf');
$this->assertHeaderContains('Content-Disposition', 'attachment');
}
}
+3 -3
View File
@@ -86,8 +86,8 @@ class OrderSlideTest extends TestCase
$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)');
$html = $this->exportHtml($token);
$this->assertStringContainsString('1 von 1', $html);
$this->assertStringContainsString('komplett richtig sortiert', $html);
}
}
+169
View File
@@ -0,0 +1,169 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\Controller;
use App\Model\Entity\Poll;
use App\Model\Entity\Slide;
use App\Service\VoteService;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* PDF export of the results: public version without internal content, complete version on request.
*/
class PdfExportTest 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();
}
protected function hash(string $char, Poll $poll): string
{
return VoteService::participantHash(str_repeat($char, 32), $poll->id);
}
/**
* Poll with a public choice, a public open question, anonymous feedback and an internal scale with comments.
*
* @return array{0: \App\Model\Entity\Poll, 1: string}
*/
protected function pollWithPrivateSlides(): array
{
[$poll, $token] = $this->createPoll('Teamrunde');
$votes = new VoteService();
$choice = $this->createSlide($poll, Slide::TYPE_CHOICE, ['question' => 'Pizza oder Pasta?'], ['Pizza', 'Pasta']);
$open = $this->createSlide($poll, Slide::TYPE_OPEN, ['question' => 'Wünsche?']);
$anonymous = $this->createSlide($poll, Slide::TYPE_OPEN, [
'question' => 'Was läuft schief?',
'settings' => ['private' => true],
]);
$scale = $this->createSlide($poll, Slide::TYPE_SCALE, [
'question' => 'Wie zufrieden bist du?',
'settings' => ['scale_min' => 1, 'scale_max' => 5, 'private' => true, 'comments' => true],
]);
$poll = $this->goLive($poll, $choice);
$votes->submit($poll, $choice, $this->hash('a', $poll), ['option_id' => $choice->slide_options[0]->id]);
$poll = $this->goLive($poll, $open);
$votes->submit($poll, $open, $this->hash('a', $poll), ['text' => 'Mehr <Pausen>']);
$poll = $this->goLive($poll, $anonymous);
$votes->submit($poll, $anonymous, $this->hash('a', $poll), ['text' => 'Geheime Kritik']);
$poll = $this->goLive($poll, $scale);
$votes->submit($poll, $scale, $this->hash('a', $poll), ['value' => 2, 'comment' => 'Interner Kommentar']);
$votes->submit($poll, $scale, $this->hash('b', $poll), ['value' => 5]);
return [$poll, $token];
}
public function testDownloadsPdf(): void
{
[$poll, $token] = $this->pollWithPrivateSlides();
$this->exportHtml($token);
$this->assertHeaderContains('Content-Disposition', 'attachment');
$this->assertHeaderContains('Content-Disposition', 'plenario-' . $poll->join_code . '-' . date('Ymd') . '.pdf');
$this->assertHeader('Cache-Control', 'no-store, private');
$this->assertHeader('Referrer-Policy', 'no-referrer');
}
public function testPublicVersionLeavesOutInternalContent(): void
{
[, $token] = $this->pollWithPrivateSlides();
$html = $this->exportHtml($token);
$this->assertStringContainsString('Pizza oder Pasta?', $html);
$this->assertStringContainsString('Mehr &lt;Pausen&gt;', $html);
$this->assertStringContainsString('Fassung ohne interne Inhalte', $html);
// Private slides are listed with their number of participants only.
$this->assertStringContainsString('Was läuft schief?', $html);
$this->assertStringContainsString('Wie zufrieden bist du?', $html);
$this->assertStringContainsString('2 Personen haben teilgenommen', $html);
$this->assertStringNotContainsString('Geheime Kritik', $html);
$this->assertStringNotContainsString('Interner Kommentar', $html);
$this->assertStringNotContainsString('Bewertung 2', $html);
$this->assertStringNotContainsString('3,5', $html);
$this->assertStringNotContainsString('Vertraulich', $html);
}
public function testCompleteVersionContainsInternalContent(): void
{
[, $token] = $this->pollWithPrivateSlides();
$html = $this->exportHtml($token, true);
$this->assertHeaderContains('Content-Disposition', '-intern.pdf');
$this->assertStringContainsString('Vertraulich', $html);
$this->assertStringContainsString('Geheime Kritik', $html);
$this->assertStringContainsString('Interner Kommentar', $html);
$this->assertStringContainsString('Bewertung 2', $html);
$this->assertStringContainsString('3,5', $html, 'average of 2 and 5');
$this->assertStringContainsString('Mehr &lt;Pausen&gt;', $html);
}
public function testInternalFlagWithoutPrivateSlidesIsIgnored(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$html = $this->exportHtml($token, true);
$this->assertHeaderContains('Content-Disposition', 'plenario-' . $poll->join_code . '-' . date('Ymd') . '.pdf');
$this->assertStringNotContainsString('Vertraulich', $html);
$this->assertStringNotContainsString('Fassung', $html);
}
public function testUnfinishedQuizRevealsNothing(): void
{
[$poll, $token] = $this->createPoll();
$quiz = $this->createSlide($poll, Slide::TYPE_QUIZ, ['question' => 'Hauptstadt?', 'is_voting_open' => false], ['Berlin', 'Bonn']);
$poll = $this->goLive($poll, $quiz);
$this->post("/admin/$token/control", ['action' => 'open']);
$quiz = $this->slidesTable()->get($quiz->id, contain: ['SlideOptions']);
$this->assertSame(Slide::QUIZ_RUNNING, $quiz->quizPhase());
(new VoteService())->submit($poll, $quiz, $this->hash('a', $poll), ['option_id' => $quiz->slide_options[0]->id]);
$html = $this->exportHtml($token, true);
$this->assertStringContainsString('Hauptstadt?', $html);
$this->assertStringContainsString('nicht beendet', $html);
$this->assertStringNotContainsString('✓', $html);
$this->assertStringNotContainsString('richtig beantwortet', $html);
// Once finished, the solution and counts are part of the report.
$this->post("/admin/$token/control", ['action' => 'close']);
$html = $this->exportHtml($token);
$this->assertStringContainsString('✓ Berlin', $html);
$this->assertStringContainsString('1 von 1', $html);
}
public function testDashboardOffersVersionsOnlyWithPrivateSlides(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$this->get("/admin/$token");
$this->assertResponseContains('PDF herunterladen');
$this->assertResponseContains("/admin/$token/export.pdf");
$this->assertResponseNotContains('name="internal"');
$this->assertResponseNotContains('CSV');
$this->createSlide($poll, Slide::TYPE_OPEN, ['settings' => ['private' => true]]);
$this->get("/admin/$token");
$this->assertResponseContains('name="internal" value="1"');
$this->assertResponseContains('Ohne interne Inhalte');
}
}
+2 -4
View File
@@ -134,10 +134,8 @@ class QaSlideTest extends TestCase
$state = $this->control($token, ['action' => 'next']);
$this->assertSame($next->id, $state['slide']['id']);
$this->get("/admin/$token/export.csv");
$this->assertResponseOk();
$this->assertResponseContains('Upvote: Andere Frage');
$this->assertResponseContains('Meine Frage');
$html = $this->exportHtml($token);
$this->assertMatchesRegularExpression('/Andere Frage.*Meine Frage/s', $html, 'ranked by upvotes');
}
public function testResetStartsOver(): void
@@ -216,9 +216,9 @@ class ScaleCommentsTest extends TestCase
{
[, $token] = $this->scaleWithComments();
$this->get("/admin/$token/export.csv");
$html = $this->exportHtml($token);
$this->assertResponseContains('4 (Kommentar: Sehr <gut>)');
$this->assertResponseContains(';2;');
$this->assertStringContainsString('2 Kommentare', $html);
$this->assertStringContainsString('Sehr &lt;gut&gt;', $html);
}
}
+23
View File
@@ -7,6 +7,7 @@ use App\Model\Entity\Poll;
use App\Model\Entity\Slide;
use App\Model\Table\PollsTable;
use App\Model\Table\SlidesTable;
use App\View\PdfView;
use Cake\ORM\TableRegistry;
/**
@@ -85,4 +86,26 @@ trait PlenarioTestTrait
return $table;
}
/**
* Requests the PDF export (needs IntegrationTestTrait) and returns the HTML it was rendered from,
* since the PDF itself is compressed and not searchable.
*
* @param string $token Admin token
* @param bool $internal Complete version incl. internal content
* @return string
*/
protected function exportHtml(string $token, bool $internal = false): string
{
$this->get("/admin/$token/export.pdf" . ($internal ? '?internal=1' : ''));
$this->assertResponseOk();
$this->assertContentType('application/pdf');
$this->assertStringStartsWith('%PDF-', (string)$this->_response->getBody());
$view = new PdfView();
$view->set($this->_controller->viewBuilder()->getVars());
$view->setTemplatePath('Admin');
return $view->renderHtml('export');
}
}