Let participants edit their scale comment while voting is open

Participants can fix typos in, add or remove their own comment until the
voting closes. The rating itself stays unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 11:40:24 +01:00
1 parent bd488e0b81
commit d518b7a37e
6 files changed
+244 -20

No files matched your search

@@ -257,4 +257,82 @@ class ScaleCommentsTest extends TestCase
$this->assertStringContainsString('Bewertung 4', $html);
}
public function testParticipantCanEditOwnCommentWhileOpen(): void
{
[$poll, , $slide] = $this->scaleWithComments();
$this->cookie('plenario_pid', str_repeat('a', 32));
$this->get('/p/' . $poll->join_code);
$this->assertResponseContains('Kommentar bearbeiten');
$this->assertResponseContains('Sehr &lt;gut&gt;');
$this->post('/p/' . $poll->join_code . '/comment', ['slide_id' => $slide->id, 'comment' => ' Sehr gut! ', 'value' => '1']);
$this->assertRedirect('/p/' . $poll->join_code);
$this->assertFlashMessage('Dein Kommentar wurde gespeichert.');
$rows = $this->slidesTable()->Responses->find()
->where(['slide_id' => $slide->id, 'participant_hash' => $this->hash('a', $poll)])
->all();
$this->assertCount(1, $rows);
$this->assertSame('Sehr gut!', $rows->first()->text_value);
$this->assertSame(4, $rows->first()->numeric_value, 'the rating stays unchanged');
// Repeating the request is harmless, an empty comment removes it.
$this->post('/p/' . $poll->join_code . '/comment', ['slide_id' => $slide->id, 'comment' => ' Sehr gut! ']);
$this->post('/p/' . $poll->join_code . '/comment', ['slide_id' => $slide->id, 'comment' => '']);
$this->assertFlashMessage('Dein Kommentar wurde entfernt.');
$this->assertNull($this->slidesTable()->Responses->get($rows->first()->id)->text_value);
}
public function testParticipantWithoutCommentCanAddOne(): void
{
[$poll, , $slide] = $this->scaleWithComments();
$this->cookie('plenario_pid', str_repeat('b', 32));
$this->get('/p/' . $poll->join_code);
$this->assertResponseContains('Kommentar hinzufügen');
$this->post('/p/' . $poll->join_code . '/comment', ['slide_id' => $slide->id, 'comment' => 'Nachgereicht']);
$row = $this->slidesTable()->Responses->find()
->where(['slide_id' => $slide->id, 'participant_hash' => $this->hash('b', $poll)])
->firstOrFail();
$this->assertSame('Nachgereicht', $row->text_value);
}
public function testCommentCannotBeEditedAfterVotingClosed(): void
{
[$poll, , $slide] = $this->scaleWithComments();
$this->slidesTable()->updateAll(['is_voting_open' => false], ['id' => $slide->id]);
$this->cookie('plenario_pid', str_repeat('a', 32));
$this->get('/p/' . $poll->join_code);
$this->assertResponseNotContains('Kommentar bearbeiten');
$this->post('/p/' . $poll->join_code . '/comment', ['slide_id' => $slide->id, 'comment' => 'Zu spät']);
$this->assertFlashMessage('Die Abstimmung zu dieser Frage ist geschlossen.');
$this->assertSame('Sehr <gut>', $this->slidesTable()->Responses->find()
->where(['slide_id' => $slide->id, 'participant_hash' => $this->hash('a', $poll)])
->firstOrFail()->text_value);
}
public function testCommentEditNeedsARatingAndACommentField(): void
{
[$poll, , $slide] = $this->scaleWithComments();
$votes = new VoteService();
try {
$votes->editComment($poll, $slide, $this->hash('z', $poll), ['comment' => 'Ohne Bewertung']);
$this->fail('Expected VoteException');
} catch (VoteException $e) {
$this->assertSame('Bitte gib zuerst deine Bewertung ab.', $e->getMessage());
}
$this->assertFalse($this->slidesTable()->Responses->exists(['text_value' => 'Ohne Bewertung']));
$plain = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['scale_min' => 1, 'scale_max' => 5]]);
$poll = $this->goLive($poll, $plain);
$votes->submit($poll, $plain, $this->hash('a', $poll), ['value' => 3]);
$this->expectException(VoteException::class);
$votes->editComment($poll, $plain, $this->hash('a', $poll), ['comment' => 'Eingeschmuggelt']);
}
}