Allow Q&A rounds without upvotes and limit upvotes per question
CI / Deploy / test (push) Successful in 57s
CI / Deploy / deploy (push) Skipped

- max_upvotes = 0 disables upvoting: the voting stage is skipped
  (collect -> discuss), questions are discussed in submission order
- new setting max_upvotes_per_question caps a participant's upvotes
  on a single question (0 = no limit besides max_upvotes)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-09 08:36:02 +01:00
1 parent 3e44ded107
commit bc86ec2db6
16 files changed
+235 -38

No files matched your search

+67 -1
View File
@@ -12,6 +12,7 @@ use App\Service\VoteException;
use App\Service\VoteService;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\TestSuite\TestCase;
use InvalidArgumentException;
/**
* Q&A slides: collect questions, upvote, discuss one by one.
@@ -76,8 +77,73 @@ class QaTest extends TestCase
$this->assertSame(Slide::QA_COLLECT, $slide->qaStage());
$table = $this->slidesTable();
$this->assertSame(1, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '0']])->setting('max_upvotes'));
$this->assertSame(0, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '0']])->setting('max_upvotes'));
$this->assertSame(0, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '-3']])->setting('max_upvotes'));
$this->assertSame(10, $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '99']])->setting('max_upvotes'));
$this->assertSame(0, $slide->setting('max_upvotes_per_question'));
$patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '5', 'max_upvotes_per_question' => '2']]);
$this->assertSame([2, 2], [$patched->setting('max_upvotes_per_question'), $patched->qaUpvotesPerQuestion()]);
$patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '3', 'max_upvotes_per_question' => '99']]);
// Never more per question than in total.
$this->assertSame([10, 3], [$patched->setting('max_upvotes_per_question'), $patched->qaUpvotesPerQuestion()]);
$patched = $table->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => '4', 'max_upvotes_per_question' => '0']]);
$this->assertSame(4, $patched->qaUpvotesPerQuestion(), '0 = no limit per question');
}
public function testWithoutUpvotesThereIsNoVotingStage(): void
{
[$poll, $slide] = $this->createQa(0);
$this->assertFalse($slide->hasQaUpvotes());
$this->assertSame([Slide::QA_COLLECT, Slide::QA_DISCUSS], $slide->qaStages());
$first = $this->ask($poll, $slide, 'p1', 'Frage A');
$this->ask($poll, $slide, 'p2', 'Frage B');
$this->assertVoteFails('Bei dieser Fragerunde wird nicht abgestimmt.', fn() => $this->vote($poll, $slide, 'p2', $first));
$qa = new QaService();
try {
$qa->setStage($slide, Slide::QA_VOTE);
$this->fail('No voting stage expected');
} catch (InvalidArgumentException) {
}
// collect → discuss, in submission order.
$this->assertTrue($qa->advance($slide));
$slide = $this->slidesTable()->get($slide->id);
$this->assertSame([Slide::QA_DISCUSS, $first, false], [$slide->qaStage(), $slide->focus_response_id, $slide->is_voting_open]);
$this->assertFalse($qa->advance($slide));
$results = (new ResultsService())->forSlide($slide);
$this->assertSame([['collect', 'discuss'], 0], [$results['stages'], $results['maxUpvotes']]);
$this->assertSame(['Frage A', 'Frage B'], array_column($results['questions'], 'text'));
$this->assertSame(0, (new PollStateService())->forParticipant($poll, 'p1')['qa']['maxUpvotes']);
}
public function testUpvotesPerQuestionAreLimited(): void
{
[$poll] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_QA, ['settings' => ['max_upvotes' => 3, 'max_upvotes_per_question' => 1]]);
$poll = $this->goLive($poll, $slide);
$a = $this->ask($poll, $slide, 'p1', 'Frage A');
$b = $this->ask($poll, $slide, 'p1', 'Frage B');
$slide = $this->stage($slide, Slide::QA_VOTE);
$this->vote($poll, $slide, 'p2', $a);
$this->assertVoteFails('Du kannst jeder Frage nur eine Stimme geben.', fn() => $this->vote($poll, $slide, 'p2', $a));
$this->vote($poll, $slide, 'p2', $b);
// Withdrawing frees the question again.
$this->vote($poll, $slide, 'p2', $a, 'remove');
$this->vote($poll, $slide, 'p2', $a);
$state = (new PollStateService())->forParticipant($poll, 'p2')['qa'];
$this->assertEquals([1, 1, [$a => 1, $b => 1]], [$state['maxPerQuestion'], $state['votesLeft'], $state['upvoted']]);
$this->slidesTable()->patchEntity($slide, ['type' => 'qa', 'settings' => ['max_upvotes' => 3, 'max_upvotes_per_question' => 2]]);
$this->slidesTable()->saveOrFail($slide);
$this->vote($poll, $slide, 'p2', $a);
$this->vote($poll, $slide, 'p3', $b);
$this->vote($poll, $slide, 'p3', $b);
$this->assertVoteFails('Du kannst jeder Frage höchstens 2 Stimmen geben.', fn() => $this->vote($poll, $slide, 'p3', $b));
}
public function testCollectQuestionsSeveralPerParticipantWithoutDuplicates(): void