Let participants edit their open answer while voting is open
Generalises the comment edit to /p/{code}/edit: open answers can be
corrected (not emptied), scale comments as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e6f52a0449
commit
51d1be8695
7 files changed
+135
-48
No files matched your search
@@ -180,4 +180,62 @@ class ParticipateControllerTest extends TestCase
|
||||
$this->assertArrayHasKey('state', $body);
|
||||
$this->assertSame(2, TableRegistry::getTableLocator()->get('Responses')->find()->where(['slide_id' => $slide->id])->count());
|
||||
}
|
||||
|
||||
public function testOpenAnswerCanBeEditedWhileVotingIsOpen(): void
|
||||
{
|
||||
[$poll] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
|
||||
$this->goLive($poll, $slide);
|
||||
$responses = TableRegistry::getTableLocator()->get('Responses');
|
||||
|
||||
$this->cookie('plenario_pid', self::PID);
|
||||
$this->post("/p/{$poll->join_code}/vote", ['slide_id' => $slide->id, 'text' => 'Tipfehler']);
|
||||
$this->cookie('plenario_pid', self::PID);
|
||||
$this->get('/p/' . $poll->join_code);
|
||||
$this->assertResponseContains('Antwort bearbeiten');
|
||||
$this->assertResponseContains('Tipfehler');
|
||||
|
||||
$this->cookie('plenario_pid', self::PID);
|
||||
$this->post("/p/{$poll->join_code}/edit", ['slide_id' => $slide->id, 'text' => ' Tippfehler ']);
|
||||
$this->assertRedirect(['_name' => 'participate', 'code' => $poll->join_code]);
|
||||
$this->assertFlashMessage('Deine Antwort wurde geändert.');
|
||||
$this->assertSame(1, $responses->find()->count());
|
||||
$this->assertSame('Tippfehler', $responses->find()->firstOrFail()->text_value);
|
||||
|
||||
// An open answer cannot be emptied.
|
||||
$this->cookie('plenario_pid', self::PID);
|
||||
$this->post("/p/{$poll->join_code}/edit", ['slide_id' => $slide->id, 'text' => ' ']);
|
||||
$this->assertFlashMessage('Bitte gib eine Antwort ein.');
|
||||
$this->assertSame('Tippfehler', $responses->find()->firstOrFail()->text_value);
|
||||
|
||||
// Without an own answer there is nothing to edit (and nothing is created).
|
||||
$this->cookie('plenario_pid', str_repeat('f', 32));
|
||||
$this->post("/p/{$poll->join_code}/edit", ['slide_id' => $slide->id, 'text' => 'Neu']);
|
||||
$this->assertFlashMessage('Du hast hier noch nicht geantwortet.');
|
||||
$this->assertSame(1, $responses->find()->count());
|
||||
|
||||
// Closed: no form, no change.
|
||||
TableRegistry::getTableLocator()->get('Slides')->updateAll(['is_voting_open' => false], ['id' => $slide->id]);
|
||||
$this->cookie('plenario_pid', self::PID);
|
||||
$this->get('/p/' . $poll->join_code);
|
||||
$this->assertResponseNotContains('Antwort bearbeiten');
|
||||
$this->cookie('plenario_pid', self::PID);
|
||||
$this->post("/p/{$poll->join_code}/edit", ['slide_id' => $slide->id, 'text' => 'Zu spät']);
|
||||
$this->assertFlashMessage('Die Abstimmung zu dieser Frage ist geschlossen.');
|
||||
$this->assertSame('Tippfehler', $responses->find()->firstOrFail()->text_value);
|
||||
}
|
||||
|
||||
public function testChoiceAnswersCannotBeEdited(): void
|
||||
{
|
||||
[$poll] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_CHOICE);
|
||||
$this->goLive($poll, $slide);
|
||||
|
||||
$this->cookie('plenario_pid', self::PID);
|
||||
$this->post("/p/{$poll->join_code}/vote", ['slide_id' => $slide->id, 'option_id' => $slide->slide_options[0]->id]);
|
||||
$this->cookie('plenario_pid', self::PID);
|
||||
$this->post("/p/{$poll->join_code}/edit", ['slide_id' => $slide->id, 'text' => 'Hack']);
|
||||
$this->assertFlashMessage('Diese Antwort kann nicht mehr geändert werden.');
|
||||
$this->assertFalse(TableRegistry::getTableLocator()->get('Responses')->exists(['text_value' => 'Hack']));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user