Feature/load test #107
No files matched your search
@@ -34,7 +34,7 @@ E-Mail anlegen, kein Login, Verwaltung über einen geheimen Admin-Link, Teilnahm
|
||||
| Coding Standard | `vendor/bin/phpcs` / Autofix `vendor/bin/phpcbf` |
|
||||
| Neue Migration | `bin/cake bake migration NameDerMigration` |
|
||||
| Verwaiste Folienbilder löschen | `bin/cake images_cleanup [--dry-run]` |
|
||||
| Umfragen verwalten (Admin-CLI) | `bin/cake polls list\|show\|delete\|remind\|cleanup` (siehe [docs/operations.md](docs/operations.md)) |
|
||||
| Umfragen verwalten (Admin-CLI) | `bin/cake polls list\|show\|delete\|remind\|cleanup\|seed` (siehe [docs/operations.md](docs/operations.md)) |
|
||||
|
||||
**Vor jedem Commit:** `vendor/bin/phpunit` und `vendor/bin/phpcs` müssen grün sein
|
||||
(Warnungen zur Zeilenlänge bei langen deutschen Texten sind ok).
|
||||
@@ -70,7 +70,7 @@ src/
|
||||
QaService, SlideControlService, ResetService, ReportService
|
||||
Model/ Polls → Slides → SlideOptions, Slides → Responses
|
||||
Middleware/ HostHeader, SecurityHeaders (CSP mit Nonce, Framing, Referrer-Policy)
|
||||
Command/ images_cleanup, polls list|show|delete|remind|cleanup
|
||||
Command/ images_cleanup, polls list|show|delete|remind|cleanup|seed
|
||||
Mailer/ PollMailer
|
||||
templates/ Deutsche UI; Layouts: default, present, error, email, fragment, pdf
|
||||
webroot/ css/plenario.css (eigenes CSS, Tokens), js/plenario.js (Vanilla JS)
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Model\Entity\Slide;
|
||||
use Cake\Console\Arguments;
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\Console\ConsoleOptionParser;
|
||||
use Cake\Routing\Router;
|
||||
|
||||
/**
|
||||
* Creates a fresh demo poll with one slide of every interactive type, e.g. as target of the JMeter load test
|
||||
* (tests/load/plenario.jmx). Every run creates a NEW poll (new id and join code); the first slide, a choice
|
||||
* question, is live and open for voting. Remove them again with `bin/cake polls delete`.
|
||||
*
|
||||
* Usage: bin/cake polls seed [--title "..."] [--email "..."] [--json]
|
||||
*/
|
||||
class PollsSeedCommand extends PollsCommand
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function defaultName(): string
|
||||
{
|
||||
return 'polls seed';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Cake\Console\ConsoleOptionParser $parser Parser
|
||||
* @return \Cake\Console\ConsoleOptionParser
|
||||
*/
|
||||
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
|
||||
{
|
||||
return $parser
|
||||
->setDescription(__('Legt eine neue Demo-Umfrage mit Beispielfolien an (z. B. für den Lasttest). Jeder Aufruf erzeugt eine neue Umfrage.'))
|
||||
->addOption('title', [
|
||||
'help' => __('Titel der Umfrage.'),
|
||||
'default' => 'Lasttest',
|
||||
])
|
||||
->addOption('email', [
|
||||
'help' => __('E-Mail-Adresse des Besitzers (es wird nichts verschickt).'),
|
||||
'default' => 'lasttest@example.org',
|
||||
])
|
||||
->addOption('json', [
|
||||
'help' => __('Ausgabe als JSON statt als Text (für Skripte), inkl. Admin-Link.'),
|
||||
'boolean' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Cake\Console\Arguments $args Arguments
|
||||
* @param \Cake\Console\ConsoleIo $io Console
|
||||
* @return int
|
||||
*/
|
||||
public function execute(Arguments $args, ConsoleIo $io): int
|
||||
{
|
||||
$polls = $this->polls();
|
||||
$slides = $this->fetchTable('Slides');
|
||||
|
||||
$result = $polls->getConnection()->transactional(function () use ($polls, $slides, $args): array {
|
||||
[$poll, $token] = $polls->createPoll([
|
||||
'title' => (string)$args->getOption('title'),
|
||||
'email' => (string)$args->getOption('email'),
|
||||
]);
|
||||
if ($token === null) {
|
||||
return [$poll, null, 0];
|
||||
}
|
||||
|
||||
$first = null;
|
||||
$count = 0;
|
||||
foreach ($this->definitions() as [$type, $question, $options, $correct]) {
|
||||
$slide = $slides->newEntity([
|
||||
'type' => $type,
|
||||
'question' => $question,
|
||||
'settings' => Slide::DEFAULT_SETTINGS[$type] ?? [],
|
||||
]);
|
||||
$slide->poll_id = $poll->id;
|
||||
$slides->saveOrFail($slide);
|
||||
if ($options !== []) {
|
||||
$slides->syncOptions($slide, $options, $correct);
|
||||
}
|
||||
$first ??= $slide;
|
||||
$count++;
|
||||
}
|
||||
|
||||
$poll->showSlide($first->id);
|
||||
$polls->saveOrFail($poll);
|
||||
|
||||
return [$poll, $token, $count];
|
||||
});
|
||||
|
||||
[$poll, $token, $count] = $result;
|
||||
if ($token === null) {
|
||||
$io->err(__('Umfrage konnte nicht angelegt werden: {0}', (string)json_encode($poll->getErrors())));
|
||||
|
||||
return static::CODE_ERROR;
|
||||
}
|
||||
|
||||
$adminUrl = Router::url(['_name' => 'admin', 'token' => $token], true);
|
||||
if ($args->getOption('json')) {
|
||||
$this->printJson($io, $this->pollData($poll) + ['slides' => $count, 'adminUrl' => $adminUrl]);
|
||||
|
||||
return static::CODE_SUCCESS;
|
||||
}
|
||||
|
||||
$io->out([
|
||||
__('Umfrage #{0} angelegt mit {1} Folien (erste Folie live, Abstimmung offen).', $poll->id, $count),
|
||||
__('Beitrittscode: {0}', $poll->join_code),
|
||||
__('Teilnahme-Link: {0}', $this->joinLink($poll)),
|
||||
__('Admin-Link: {0}', $adminUrl),
|
||||
__('Lasttest: jmeter -n -t tests/load/plenario.jmx -Jcode={0} …', $poll->join_code),
|
||||
]);
|
||||
|
||||
return static::CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{0: string, 1: string, 2: list<string>, 3: list<string>}> Type, question, options, correct options
|
||||
*/
|
||||
protected function definitions(): array
|
||||
{
|
||||
return [
|
||||
[Slide::TYPE_CHOICE, 'Wie gefällt dir PlenarIO?', ['Super', 'Gut', 'Geht so', 'Gar nicht'], []],
|
||||
[Slide::TYPE_WORDCLOUD, 'Was fällt dir zu Live-Umfragen ein?', [], []],
|
||||
[Slide::TYPE_OPEN, 'Was wünschst du dir für heute?', [], []],
|
||||
[Slide::TYPE_SCALE, 'Wie zufrieden bist du?', [], []],
|
||||
[Slide::TYPE_QUIZ, 'Wie viele Kontinente gibt es?', ['7', '5', '6', '8'], ['7']],
|
||||
[Slide::TYPE_QA, 'Stell deine Frage', [], []],
|
||||
[Slide::TYPE_ORDER, 'Bringe die Planeten in die richtige Reihenfolge', ['Merkur', 'Venus', 'Erde', 'Mars'], []],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,24 @@ class PollsCommandsTest extends TestCase
|
||||
$this->assertTrue($this->pollsTable()->get($poll->id)->isExpired());
|
||||
}
|
||||
|
||||
public function testSeedCreatesNewPollWithLiveFirstSlideEveryTime(): void
|
||||
{
|
||||
$this->exec('polls seed --json');
|
||||
$this->assertExitSuccess();
|
||||
$first = json_decode(implode('', $this->_out->messages()), true);
|
||||
$this->exec('polls seed --json');
|
||||
$second = json_decode(implode('', $this->_out->messages()), true);
|
||||
|
||||
$this->assertNotSame($first['id'], $second['id']);
|
||||
$this->assertNotSame($first['joinCode'], $second['joinCode']);
|
||||
$this->assertSame(7, $second['slides']);
|
||||
|
||||
$poll = $this->pollsTable()->get($second['id']);
|
||||
$slide = $this->slidesTable()->get($poll->current_slide_id);
|
||||
$this->assertSame('choice', $slide->type);
|
||||
$this->assertTrue($slide->isVotingOpen());
|
||||
}
|
||||
|
||||
public function testSettingsAreRespected(): void
|
||||
{
|
||||
[$poll] = $this->createPoll();
|
||||
|
||||
Reference in new issue
Block a user