Let participants withdraw their own word cloud terms
CI / Deploy / test (push) Successful in 59s
CI / Deploy / deploy (push) Skipped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 12:07:44 +01:00
1 parent 3a8962976e
commit ad5223906c
7 files changed
+154 -6

No files matched your search

@@ -279,4 +279,49 @@ class VoteServiceTest extends TestCase
$this->assertEquals($slide->modified, $this->slidesTable()->get($slide->id)->modified);
$this->assertSame($slide->position, $this->slidesTable()->get($slide->id)->position);
}
public function testWordcloudOwnEntryCanBeRemoved(): void
{
[$poll] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_WORDCLOUD);
$poll = $this->goLive($poll, $slide);
$service = new VoteService();
$service->submit($poll, $slide, 'p1', ['word' => 'Kafee']);
$service->submit($poll, $slide, 'p1', ['word' => 'Tee']);
$service->submit($poll, $slide, 'p2', ['word' => 'tee']);
$service->submit($poll, $slide, 'p2', ['word' => 'Kafee', 'vote' => 'down']);
$state = (new PollStateService())->wordState($slide, 'p1');
$this->assertSame([['text' => 'Kafee', 'down' => false], ['text' => 'Tee', 'down' => false]], $state['own']);
// Only the own row goes: "Tee" stays with the other upvote, "Kafee" keeps p2's downvote.
$service->submit($poll, $slide, 'p1', ['word' => 'TEE', 'vote' => 'remove']);
$service->submit($poll, $slide, 'p1', ['word' => 'Kafee', 'vote' => 'remove']);
$results = (new ResultsService())->forSlide($slide);
$this->assertSame([['tee', 1, 0]], array_map(fn($w) => [$w['text'], $w['count'], $w['down']], $results['words']));
$this->assertSame([], (new PollStateService())->wordState($slide, 'p1')['own']);
$this->assertSame(2, $this->fetchTable('Responses')->find()->where(['slide_id' => $slide->id])->count());
// A downvote can be withdrawn too; afterwards the word can be named again.
$service->submit($poll, $slide, 'p2', ['word' => 'kafee', 'vote' => 'remove']);
$this->assertSame([['text' => 'tee', 'down' => false]], (new PollStateService())->wordState($slide, 'p2')['own']);
$service->submit($poll, $slide, 'p1', ['word' => 'Kaffee']);
$this->assertSame(['kaffee'], (new PollStateService())->wordState($slide, 'p1')['mine']);
// Removing again (or someone else's word) changes nothing.
foreach ([['p1', 'Tee'], ['p3', 'Kaffee'], ['p1', '']] as [$participant, $word]) {
try {
$service->submit($poll, $slide, $participant, ['word' => $word, 'vote' => 'remove']);
$this->fail('VoteException expected for ' . $participant . '/' . $word);
} catch (VoteException $e) {
$this->assertSame('Diesen Begriff hast du nicht genannt.', $e->getMessage());
}
}
$this->assertSame(2, $this->fetchTable('Responses')->find()->where(['slide_id' => $slide->id])->count());
$this->slidesTable()->updateAll(['is_voting_open' => false], ['id' => $slide->id]);
$slide = $this->slidesTable()->get($slide->id);
$this->expectException(VoteException::class);
$service->submit($poll, $slide, 'p1', ['word' => 'Kaffee', 'vote' => 'remove']);
}
}