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']));
|
||||
}
|
||||
}
|
||||
@@ -267,7 +267,7 @@ class ScaleCommentsTest extends TestCase
|
||||
$this->assertResponseContains('Kommentar bearbeiten');
|
||||
$this->assertResponseContains('Sehr <gut>');
|
||||
|
||||
$this->post('/p/' . $poll->join_code . '/comment', ['slide_id' => $slide->id, 'comment' => ' Sehr gut! ', 'value' => '1']);
|
||||
$this->post('/p/' . $poll->join_code . '/edit', ['slide_id' => $slide->id, 'comment' => ' Sehr gut! ', 'value' => '1']);
|
||||
$this->assertRedirect('/p/' . $poll->join_code);
|
||||
$this->assertFlashMessage('Dein Kommentar wurde gespeichert.');
|
||||
|
||||
@@ -279,8 +279,8 @@ class ScaleCommentsTest extends TestCase
|
||||
$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->post('/p/' . $poll->join_code . '/edit', ['slide_id' => $slide->id, 'comment' => ' Sehr gut! ']);
|
||||
$this->post('/p/' . $poll->join_code . '/edit', ['slide_id' => $slide->id, 'comment' => '']);
|
||||
$this->assertFlashMessage('Dein Kommentar wurde entfernt.');
|
||||
$this->assertNull($this->slidesTable()->Responses->get($rows->first()->id)->text_value);
|
||||
}
|
||||
@@ -293,7 +293,7 @@ class ScaleCommentsTest extends TestCase
|
||||
$this->get('/p/' . $poll->join_code);
|
||||
$this->assertResponseContains('Kommentar hinzufügen');
|
||||
|
||||
$this->post('/p/' . $poll->join_code . '/comment', ['slide_id' => $slide->id, 'comment' => 'Nachgereicht']);
|
||||
$this->post('/p/' . $poll->join_code . '/edit', ['slide_id' => $slide->id, 'comment' => 'Nachgereicht']);
|
||||
$row = $this->slidesTable()->Responses->find()
|
||||
->where(['slide_id' => $slide->id, 'participant_hash' => $this->hash('b', $poll)])
|
||||
->firstOrFail();
|
||||
@@ -309,7 +309,7 @@ class ScaleCommentsTest extends TestCase
|
||||
$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->post('/p/' . $poll->join_code . '/edit', ['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)])
|
||||
@@ -322,7 +322,7 @@ class ScaleCommentsTest extends TestCase
|
||||
$votes = new VoteService();
|
||||
|
||||
try {
|
||||
$votes->editComment($poll, $slide, $this->hash('z', $poll), ['comment' => 'Ohne Bewertung']);
|
||||
$votes->editText($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());
|
||||
@@ -333,6 +333,6 @@ class ScaleCommentsTest extends TestCase
|
||||
$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']);
|
||||
$votes->editText($poll, $plain, $this->hash('a', $poll), ['comment' => 'Eingeschmuggelt']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user