The average is now the headline of a scale result and the distribution a compact detail below it. Two new settings (show_average, show_distribution) hide either part in the presentation; evaluation and PDF stay complete. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
91 lines
3.3 KiB
PHP
91 lines
3.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Test\TestCase\Controller;
|
|
|
|
use App\Model\Entity\Slide;
|
|
use App\Model\Table\SlidesTable;
|
|
use App\Service\VoteService;
|
|
use App\Test\TestCase\PlenarioTestTrait;
|
|
use Cake\TestSuite\IntegrationTestTrait;
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
/**
|
|
* Scale slides can hide the average and/or the distribution in the presentation.
|
|
*/
|
|
class ScalePartsTest extends TestCase
|
|
{
|
|
use IntegrationTestTrait;
|
|
use PlenarioTestTrait;
|
|
|
|
/**
|
|
* @var list<string>
|
|
*/
|
|
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->enableCsrfToken();
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $settings Extra settings
|
|
* @return array<string, mixed> Presenter results
|
|
*/
|
|
protected function presenterResults(array $settings): array
|
|
{
|
|
[$poll, $token] = $this->createPoll();
|
|
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => $settings + ['scale_min' => 1, 'scale_max' => 5]]);
|
|
$poll = $this->goLive($poll, $slide);
|
|
(new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('a', 32), $poll->id), ['value' => 4]);
|
|
|
|
$this->get("/admin/$token/state");
|
|
|
|
return json_decode((string)$this->_response->getBody(), true)['results'];
|
|
}
|
|
|
|
public function testBothPartsAreShownByDefault(): void
|
|
{
|
|
$settings = SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, []);
|
|
$this->assertTrue($settings['show_average']);
|
|
$this->assertTrue($settings['show_distribution']);
|
|
|
|
$results = $this->presenterResults([]);
|
|
$this->assertTrue($results['showAverage']);
|
|
$this->assertTrue($results['showDistribution']);
|
|
}
|
|
|
|
public function testPartsCanBeHidden(): void
|
|
{
|
|
$settings = SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['show_average' => '0', 'show_distribution' => '0']);
|
|
$this->assertFalse($settings['show_average']);
|
|
$this->assertFalse($settings['show_distribution']);
|
|
|
|
$results = $this->presenterResults(['show_average' => false, 'show_distribution' => false]);
|
|
$this->assertFalse($results['showAverage']);
|
|
$this->assertFalse($results['showDistribution']);
|
|
// The data stays complete (evaluation, PDF), only the presentation hides it.
|
|
$this->assertEqualsWithDelta(4.0, $results['average'], 0.001);
|
|
$this->assertSame(1, $results['participants']);
|
|
}
|
|
|
|
public function testFormSavesParts(): void
|
|
{
|
|
[$poll, $token] = $this->createPoll();
|
|
$this->get("/admin/$token/slides/add?type=scale");
|
|
$this->assertResponseContains('name="settings[show_average]"');
|
|
$this->assertResponseContains('name="settings[show_distribution]"');
|
|
|
|
$this->post("/admin/$token/slides/add?type=scale", [
|
|
'type' => 'scale',
|
|
'question' => 'Wie fandest du den Abend?',
|
|
'settings' => ['scale_min' => '1', 'scale_max' => '5', 'show_average' => '1', 'show_distribution' => '0'],
|
|
]);
|
|
|
|
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
|
|
$this->assertTrue($slide->setting('show_average'));
|
|
$this->assertFalse($slide->setting('show_distribution'));
|
|
}
|
|
}
|