Anonymous/internal feedback now only presets "hide results" on the stage: presenter and embed get the full results flagged private and can show them on demand. Participants still never get results of private slides, the public PDF export strips them via ResultsService::withoutContents(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
268 lines
10 KiB
PHP
268 lines
10 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Test\TestCase\Controller;
|
|
|
|
use App\Model\Entity\Poll;
|
|
use App\Model\Entity\Slide;
|
|
use App\Model\Table\SlidesTable;
|
|
use App\Service\VoteService;
|
|
use App\Test\TestCase\PlenarioTestTrait;
|
|
use Cake\TestSuite\IntegrationTestTrait;
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
/**
|
|
* Open questions and scales as anonymous/internal feedback: the stage starts with hidden results
|
|
* (flag `private`, contents included so the presenter can show them), participants never get results.
|
|
*/
|
|
class PrivateFeedbackTest 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();
|
|
}
|
|
|
|
/**
|
|
* @return array{0: \App\Model\Entity\Poll, 1: string, 2: \App\Model\Entity\Slide}
|
|
*/
|
|
protected function privateSlideWithAnswer(string $text = 'Geheimes <Feedback>'): array
|
|
{
|
|
[$poll, $token] = $this->createPoll();
|
|
$slide = $this->createSlide($poll, Slide::TYPE_OPEN, ['settings' => ['private' => true]]);
|
|
$poll = $this->goLive($poll, $slide);
|
|
(new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('a', 32), $poll->id), ['text' => $text]);
|
|
|
|
return [$poll, $token, $slide];
|
|
}
|
|
|
|
protected function participantState(Poll $poll): array
|
|
{
|
|
$this->get('/p/' . $poll->join_code . '/state');
|
|
|
|
return json_decode((string)$this->_response->getBody(), true);
|
|
}
|
|
|
|
public function testSettingIsSanitized(): void
|
|
{
|
|
$this->assertTrue(SlidesTable::sanitizeSettings(Slide::TYPE_OPEN, ['private' => '1'])['private']);
|
|
$this->assertFalse(SlidesTable::sanitizeSettings(Slide::TYPE_OPEN, ['private' => '0'])['private']);
|
|
$this->assertFalse(SlidesTable::sanitizeSettings(Slide::TYPE_OPEN, [])['private']);
|
|
}
|
|
|
|
public function testExistingOpenSlidesStayPublic(): void
|
|
{
|
|
[$poll] = $this->createPoll();
|
|
$slide = $this->createSlide($poll, Slide::TYPE_OPEN, ['settings' => []]);
|
|
|
|
$this->assertFalse($slide->isPrivate());
|
|
}
|
|
|
|
public function testFormSavesPrivateSetting(): void
|
|
{
|
|
[$poll, $token] = $this->createPoll();
|
|
$this->post("/admin/$token/slides/add?type=open", [
|
|
'type' => 'open',
|
|
'question' => 'Was können wir besser machen?',
|
|
'settings' => ['private' => '1'],
|
|
]);
|
|
|
|
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
|
|
$this->assertTrue($slide->isPrivate());
|
|
}
|
|
|
|
public function testPresenterGetsAnswersFlaggedPrivate(): void
|
|
{
|
|
[, $token] = $this->privateSlideWithAnswer();
|
|
|
|
$this->get("/admin/$token/state");
|
|
$state = json_decode((string)$this->_response->getBody(), true);
|
|
|
|
// Flag = the stage starts with hidden results; showing them is the presenter's choice.
|
|
$this->assertTrue($state['results']['private']);
|
|
$this->assertSame('Geheimes <Feedback>', $state['results']['answers'][0]['text']);
|
|
$this->assertSame(1, $state['results']['participants']);
|
|
}
|
|
|
|
public function testParticipantsNeverSeeAnswers(): void
|
|
{
|
|
[$poll] = $this->privateSlideWithAnswer();
|
|
$this->assertTrue($poll->show_results_to_participants);
|
|
|
|
$this->assertNull($this->participantState($poll)['results']);
|
|
$this->get('/p/' . $poll->join_code);
|
|
$this->assertResponseContains('Anonymes Feedback');
|
|
$this->assertResponseNotContains('Geheimes');
|
|
|
|
// Not even after answering themselves.
|
|
$this->post('/p/' . $poll->join_code . '/vote', ['slide_id' => $poll->current_slide_id, 'text' => 'Meins']);
|
|
$this->assertNull($this->participantState($poll)['results']);
|
|
$this->assertResponseNotContains('Geheimes');
|
|
}
|
|
|
|
public function testEmbedGetsAnswersFlaggedPrivate(): void
|
|
{
|
|
[$poll, , $slide] = $this->privateSlideWithAnswer();
|
|
$key = $this->pollsTable()->ensureEmbedKey($poll);
|
|
|
|
$this->get("/e/$key/{$slide->id}/state");
|
|
$state = json_decode((string)$this->_response->getBody(), true);
|
|
|
|
$this->assertResponseOk();
|
|
$this->assertTrue($state['results']['private']);
|
|
$this->assertCount(1, $state['results']['answers']);
|
|
}
|
|
|
|
public function testAdminReadsAnswers(): void
|
|
{
|
|
[, $token, $slide] = $this->privateSlideWithAnswer();
|
|
|
|
$this->get("/admin/$token");
|
|
$this->assertResponseContains("/slides/{$slide->id}/answers");
|
|
|
|
$this->get("/admin/$token/slides/{$slide->id}/answers");
|
|
$this->assertResponseOk();
|
|
$this->assertResponseContains('Geheimes <Feedback>');
|
|
$this->assertHeader('Referrer-Policy', 'no-referrer');
|
|
}
|
|
|
|
public function testAnswersPageOnlyForOwnOpenSlides(): void
|
|
{
|
|
[$poll, $token] = $this->createPoll();
|
|
$choice = $this->createSlide($poll);
|
|
[$other] = $this->createPoll('Andere');
|
|
$foreign = $this->createSlide($other, Slide::TYPE_OPEN);
|
|
|
|
$this->get("/admin/$token/slides/{$choice->id}/answers");
|
|
$this->assertResponseCode(404);
|
|
$this->get("/admin/$token/slides/{$foreign->id}/answers");
|
|
$this->assertResponseCode(404);
|
|
}
|
|
|
|
public function testPublicOpenQuestionStillShowsAnswers(): void
|
|
{
|
|
[$poll, $token] = $this->createPoll();
|
|
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
|
|
$poll = $this->goLive($poll, $slide);
|
|
(new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('b', 32), $poll->id), ['text' => 'Offen']);
|
|
|
|
$this->get("/admin/$token/state");
|
|
$state = json_decode((string)$this->_response->getBody(), true);
|
|
|
|
$this->assertFalse($state['results']['private']);
|
|
$this->assertSame('Offen', $state['results']['answers'][0]['text']);
|
|
}
|
|
|
|
/**
|
|
* @return array{0: \App\Model\Entity\Poll, 1: string, 2: \App\Model\Entity\Slide}
|
|
*/
|
|
protected function privateScaleWithRatings(): array
|
|
{
|
|
[$poll, $token] = $this->createPoll();
|
|
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['scale_min' => 1, 'scale_max' => 5, 'private' => true]]);
|
|
$poll = $this->goLive($poll, $slide);
|
|
$votes = new VoteService();
|
|
$votes->submit($poll, $slide, VoteService::participantHash(str_repeat('a', 32), $poll->id), ['value' => 2]);
|
|
$votes->submit($poll, $slide, VoteService::participantHash(str_repeat('b', 32), $poll->id), ['value' => 5]);
|
|
|
|
return [$poll, $token, $slide];
|
|
}
|
|
|
|
public function testScaleSettingIsSanitized(): void
|
|
{
|
|
$this->assertTrue(SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['private' => '1'])['private']);
|
|
$this->assertFalse(SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, [])['private']);
|
|
|
|
[$poll] = $this->createPoll();
|
|
$this->assertFalse($this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => []])->isPrivate());
|
|
}
|
|
|
|
public function testFormSavesPrivateScaleSetting(): void
|
|
{
|
|
[$poll, $token] = $this->createPoll();
|
|
$this->post("/admin/$token/slides/add?type=scale", [
|
|
'type' => 'scale',
|
|
'question' => 'Wie zufrieden bist du?',
|
|
'settings' => ['scale_min' => '1', 'scale_max' => '5', 'private' => '1'],
|
|
]);
|
|
|
|
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
|
|
$this->assertTrue($slide->isPrivate());
|
|
}
|
|
|
|
public function testPresenterGetsScaleResultsFlaggedPrivate(): void
|
|
{
|
|
[, $token] = $this->privateScaleWithRatings();
|
|
|
|
$this->get("/admin/$token/state");
|
|
$state = json_decode((string)$this->_response->getBody(), true);
|
|
|
|
$this->assertTrue($state['results']['private']);
|
|
$this->assertCount(5, $state['results']['buckets']);
|
|
$this->assertEqualsWithDelta(3.5, $state['results']['average'], 0.001);
|
|
$this->assertSame(2, $state['results']['participants']);
|
|
}
|
|
|
|
public function testParticipantsNeverSeeScaleResults(): void
|
|
{
|
|
[$poll] = $this->privateScaleWithRatings();
|
|
$this->assertTrue($poll->show_results_to_participants);
|
|
|
|
$this->assertNull($this->participantState($poll)['results']);
|
|
$this->get('/p/' . $poll->join_code);
|
|
$this->assertResponseContains('Internes Feedback');
|
|
|
|
$this->post('/p/' . $poll->join_code . '/vote', ['slide_id' => $poll->current_slide_id, 'value' => '3']);
|
|
$this->assertNull($this->participantState($poll)['results']);
|
|
}
|
|
|
|
public function testEmbedGetsScaleResultsFlaggedPrivate(): void
|
|
{
|
|
[$poll, , $slide] = $this->privateScaleWithRatings();
|
|
$key = $this->pollsTable()->ensureEmbedKey($poll);
|
|
|
|
$this->get("/e/$key/{$slide->id}/state");
|
|
$state = json_decode((string)$this->_response->getBody(), true);
|
|
|
|
$this->assertResponseOk();
|
|
$this->assertTrue($state['results']['private']);
|
|
$this->assertEqualsWithDelta(3.5, $state['results']['average'], 0.001);
|
|
}
|
|
|
|
public function testAdminReadsScaleResults(): void
|
|
{
|
|
[, $token, $slide] = $this->privateScaleWithRatings();
|
|
|
|
$this->get("/admin/$token");
|
|
$this->assertResponseContains("/slides/{$slide->id}/answers");
|
|
|
|
$this->get("/admin/$token/slides/{$slide->id}/answers");
|
|
$this->assertResponseOk();
|
|
$this->assertResponseContains('Internes Feedback');
|
|
$this->assertResponseContains('3,5');
|
|
$this->assertResponseContains('2 Bewertungen');
|
|
}
|
|
|
|
public function testPublicScaleStillShowsResults(): void
|
|
{
|
|
[$poll, $token] = $this->createPoll();
|
|
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['scale_min' => 1, 'scale_max' => 5]]);
|
|
$poll = $this->goLive($poll, $slide);
|
|
(new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('c', 32), $poll->id), ['value' => 4]);
|
|
|
|
$this->get("/admin/$token/state");
|
|
$state = json_decode((string)$this->_response->getBody(), true);
|
|
|
|
$this->assertFalse($state['results']['private']);
|
|
$this->assertEqualsWithDelta(4.0, $state['results']['average'], 0.001);
|
|
}
|
|
}
|