feat: keep questionnaires until submitted, remind teamers daily and take bus feedback per leg
This commit is contained in:
1 parent
abf9c1be0b
commit
e72616fdbf
37 files changed
+1119
-238
No files matched your search
@@ -46,6 +46,19 @@ class QuestionnaireCatalogTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An escort may ride the outbound bus, the return bus or both, so the bus feedback is answered
|
||||
* per leg and no longer asks for the direction.
|
||||
*/
|
||||
public function testOnlyTheBusFeedbackIsAnsweredPerLeg(): void
|
||||
{
|
||||
$catalog = new QuestionnaireCatalog(self::SHIPPED_DIR);
|
||||
|
||||
$this->assertTrue($catalog->get(QuestionnaireCatalog::BUS_FEEDBACK)->perBusLeg);
|
||||
$this->assertNull($catalog->get(QuestionnaireCatalog::BUS_FEEDBACK)->getQuestion('direction'));
|
||||
$this->assertFalse($catalog->get(QuestionnaireCatalog::TEAMER_FEEDBACK)->perBusLeg);
|
||||
}
|
||||
|
||||
public function testTheTwoQuestionnairesAreTheCurrentKeys(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
@@ -112,16 +125,16 @@ class QuestionnaireCatalogTest extends TestCase
|
||||
$this->assertSame('Alte Frage', $catalog->get('sample', 1)->getQuestion('answer')->label);
|
||||
}
|
||||
|
||||
public function testTheWindowStartsTheGivenDaysBeforeToday(): void
|
||||
public function testTheGoLiveDateIsADay(): void
|
||||
{
|
||||
$this->assertEquals(new \DateTimeImmutable('today -2 days'), QuestionnaireCatalog::windowStart(2));
|
||||
$this->assertEquals(new \DateTimeImmutable('2026-11-10 00:00'), QuestionnaireCatalog::parseGoLive('2026-11-10'));
|
||||
}
|
||||
|
||||
public function testANegativeWindowFailsLoudly(): void
|
||||
public function testAMalformedGoLiveDateFailsLoudly(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
QuestionnaireCatalog::windowStart(-1);
|
||||
QuestionnaireCatalog::parseGoLive('10.11.2026');
|
||||
}
|
||||
|
||||
public function testUnknownQuestionnaireIsRejected(): void
|
||||
@@ -151,6 +164,10 @@ class QuestionnaireCatalogTest extends TestCase
|
||||
static fn (array $d): array => self::withQuestion($d, 1, ['requried' => true]),
|
||||
'unknown field(s) requried',
|
||||
];
|
||||
yield 'per_bus_leg not a boolean' => [
|
||||
static fn (array $d): array => ['per_bus_leg' => 'yes'] + $d,
|
||||
'per_bus_leg must be true or false',
|
||||
];
|
||||
yield 'unknown type' => [
|
||||
static fn (array $d): array => self::withQuestion($d, 1, ['type' => 'slider']),
|
||||
'unknown type "slider"',
|
||||
|
||||
@@ -19,7 +19,8 @@ use PHPUnit\Framework\TestCase;
|
||||
*
|
||||
* The lists below are the Google forms' questions in their order, with what each became:
|
||||
* "question:<key>" is asked, "context:<field>" is taken from the disposition and snapshotted into
|
||||
* the response (DispositionContext::build()). Google's "Bitte ankreuzen:" checkbox list was split
|
||||
* the response (DispositionContext::build()), "legs" is the per-bus-leg choice of rides the
|
||||
* teamer escorted (App\Form\QuestionnaireType), which became a response per leg. Google's "Bitte ankreuzen:" checkbox list was split
|
||||
* into five single-choice questions, so it maps to five.
|
||||
*/
|
||||
class QuestionnaireCompletenessTest extends TestCase
|
||||
@@ -48,7 +49,7 @@ class QuestionnaireCompletenessTest extends TestCase
|
||||
|
||||
private const array BUS_FEEDBACK = [
|
||||
'(Datum, ohne Titel)' => ['context:escortPickupDate', 'context:dateTo'],
|
||||
'Hin- oder Rückfahrt' => ['question:direction'],
|
||||
'Hin- oder Rückfahrt' => ['legs'],
|
||||
'Reiseziel:' => ['context:destinationProduct'],
|
||||
'Bus-Unternehmen:' => ['question:bus_company'],
|
||||
'Name des Busunternehmens:' => ['question:bus_company_other'],
|
||||
@@ -120,9 +121,11 @@ class QuestionnaireCompletenessTest extends TestCase
|
||||
|
||||
foreach ($googleQuestions as $label => $targets) {
|
||||
foreach ($targets as $target) {
|
||||
[$kind, $key] = explode(':', $target);
|
||||
[$kind, $key] = explode(':', $target) + [1 => null];
|
||||
|
||||
if ('question' === $kind) {
|
||||
if ('legs' === $kind) {
|
||||
$this->assertTrue($definition->perBusLeg, sprintf('"%s" is not asked as the legs escorted', $label));
|
||||
} elseif ('question' === $kind) {
|
||||
$this->assertNotNull($definition->getQuestion($key), sprintf('"%s" is not asked as "%s"', $label, $key));
|
||||
$mapped[] = $key;
|
||||
} else {
|
||||
|
||||
@@ -133,7 +133,7 @@ class TestControllerTest extends WebTestCase
|
||||
$crawler = $this->client->request('GET', sprintf('/administrative/questionnaire/test/%s?bus_escort=1', $this->assignment->getUuid()));
|
||||
|
||||
$this->assertStringContainsString('Mit dem Bus-Feedback', $crawler->text());
|
||||
$this->assertCount(1, $crawler->filter('[data-question-key="bus_feedback.bus_company"]'));
|
||||
$this->assertCount(1, $crawler->filter('[data-question-key="bus_feedback.outbound.bus_company"]'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ use Symfony\Component\DomCrawler\Form;
|
||||
|
||||
/**
|
||||
* The teamer's page: one form, and as many responses as questionnaires apply - the teamer feedback
|
||||
* for every placement, the bus feedback as well after a bus escort.
|
||||
* for every placement, the bus feedback as well after a bus escort, once per ride escorted.
|
||||
*
|
||||
* Runs in a transaction that is rolled back; the client keeps its kernel so every request shares
|
||||
* that connection. The profile checks that would otherwise send the teamer elsewhere first are
|
||||
@@ -79,7 +79,9 @@ class EditControllerTest extends WebTestCase
|
||||
$this->assertStringContainsString('Reiseleitung', $crawler->filter('h1 + p')->text());
|
||||
$this->assertStringContainsString('Busbegleitung ab Stuttgart', $crawler->filter('h1 + p')->text());
|
||||
$this->assertCount(1, $crawler->filter('[data-question-key="teamer_feedback.office_briefing_rating"]'));
|
||||
$this->assertCount(1, $crawler->filter('[data-question-key="bus_feedback.bus_company"]'));
|
||||
$this->assertCount(1, $crawler->filter('[data-question-key="bus_feedback.legs"]'));
|
||||
$this->assertCount(1, $crawler->filter('[data-question-key="bus_feedback.outbound.bus_company"]'));
|
||||
$this->assertCount(1, $crawler->filter('[data-question-key="bus_feedback.return.bus_company"]'));
|
||||
}
|
||||
|
||||
public function testAPlacementWithoutEscortGetsTheTeamerFeedbackOnly(): void
|
||||
@@ -95,18 +97,61 @@ class EditControllerTest extends WebTestCase
|
||||
{
|
||||
$disposition = $this->placement(busEscort: true);
|
||||
$form = $this->open($disposition)->selectButton('Entwurf speichern')->form();
|
||||
$form['questionnaire[bus_feedback][bus_team][driver_names]'] = 'Hans';
|
||||
$form['questionnaire[bus_feedback][legs]'] = 'outbound';
|
||||
$form['questionnaire[bus_feedback][outbound][bus_team][driver_names]'] = 'Hans';
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/teamer/questionnaire/%s', $disposition->getUuid()));
|
||||
$this->assertSame([
|
||||
QuestionnaireCatalog::BUS_FEEDBACK => QuestionnaireResponseStatus::DRAFT,
|
||||
'bus_feedback.outbound' => QuestionnaireResponseStatus::DRAFT,
|
||||
QuestionnaireCatalog::TEAMER_FEEDBACK => QuestionnaireResponseStatus::DRAFT,
|
||||
], $this->statuses($disposition));
|
||||
|
||||
// reopened, the draft is back in the form
|
||||
// reopened, the draft is back in the form, the leg chosen included
|
||||
$crawler = $this->open($disposition);
|
||||
$this->assertSame('Hans', $crawler->filter('input[name="questionnaire[bus_feedback][bus_team][driver_names]"]')->attr('value'));
|
||||
$this->assertSame('Hans', $crawler->filter('input[name="questionnaire[bus_feedback][outbound][bus_team][driver_names]"]')->attr('value'));
|
||||
$this->assertSame('outbound', $crawler->filter('input[name="questionnaire[bus_feedback][legs]"][checked]')->attr('value'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Choosing one ride after having saved both drops the other ride's draft: it would otherwise
|
||||
* come back as chosen.
|
||||
*/
|
||||
public function testALegNoLongerChosenLosesItsDraft(): void
|
||||
{
|
||||
$disposition = $this->placement(busEscort: true);
|
||||
$form = $this->open($disposition)->selectButton('Entwurf speichern')->form();
|
||||
$form['questionnaire[bus_feedback][legs]'] = 'both';
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertSame(['bus_feedback.outbound', 'bus_feedback.return', QuestionnaireCatalog::TEAMER_FEEDBACK], array_keys($this->statuses($disposition)));
|
||||
|
||||
$form = $this->open($disposition)->selectButton('Entwurf speichern')->form();
|
||||
$form['questionnaire[bus_feedback][legs]'] = 'return';
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertSame(['bus_feedback.return', QuestionnaireCatalog::TEAMER_FEEDBACK], array_keys($this->statuses($disposition)));
|
||||
}
|
||||
|
||||
/**
|
||||
* An escort who rode both buses gives the bus feedback twice, each ride a response of its own.
|
||||
*/
|
||||
public function testBothRidesAreSubmittedAsTwoBusResponses(): void
|
||||
{
|
||||
$disposition = $this->placement(busEscort: true);
|
||||
$form = $this->open($disposition)->selectButton('Absenden')->form();
|
||||
$this->answerAll($form, [QuestionnaireCatalog::TEAMER_FEEDBACK, QuestionnaireCatalog::BUS_FEEDBACK], legs: 'both');
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertSame([
|
||||
'bus_feedback.outbound' => QuestionnaireResponseStatus::SUBMITTED,
|
||||
'bus_feedback.return' => QuestionnaireResponseStatus::SUBMITTED,
|
||||
QuestionnaireCatalog::TEAMER_FEEDBACK => QuestionnaireResponseStatus::SUBMITTED,
|
||||
], $this->statuses($disposition));
|
||||
|
||||
$crawler = $this->client->followRedirect();
|
||||
$this->assertStringContainsString('Bus-Feedback: Hinfahrt', $crawler->text());
|
||||
$this->assertStringContainsString('Bus-Feedback: Rückfahrt', $crawler->text());
|
||||
}
|
||||
|
||||
public function testOneSubmitSubmitsBoth(): void
|
||||
@@ -118,7 +163,7 @@ class EditControllerTest extends WebTestCase
|
||||
|
||||
$this->assertResponseRedirects(sprintf('/teamer/questionnaire/%s/detail', $disposition->getUuid()));
|
||||
$this->assertSame([
|
||||
QuestionnaireCatalog::BUS_FEEDBACK => QuestionnaireResponseStatus::SUBMITTED,
|
||||
'bus_feedback.outbound' => QuestionnaireResponseStatus::SUBMITTED,
|
||||
QuestionnaireCatalog::TEAMER_FEEDBACK => QuestionnaireResponseStatus::SUBMITTED,
|
||||
], $this->statuses($disposition));
|
||||
|
||||
@@ -131,7 +176,7 @@ class EditControllerTest extends WebTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Nothing is half-submitted: a bus question left open keeps both questionnaires unsubmitted.
|
||||
* Nothing is half-submitted: the rides left unsaid keep both questionnaires unsubmitted.
|
||||
*/
|
||||
public function testAnIncompleteBusFeedbackSubmitsNeither(): void
|
||||
{
|
||||
@@ -161,32 +206,43 @@ class EditControllerTest extends WebTestCase
|
||||
|
||||
/**
|
||||
* Answers every required question that is shown without a follow-up: first option, rating 5.
|
||||
* The bus feedback for the given rides.
|
||||
*
|
||||
* @param list<string> $questionnaires
|
||||
*/
|
||||
private function answerAll(Form $form, array $questionnaires): void
|
||||
private function answerAll(Form $form, array $questionnaires, string $legs = 'outbound'): void
|
||||
{
|
||||
$catalog = self::getContainer()->get(QuestionnaireCatalog::class);
|
||||
|
||||
foreach ($questionnaires as $key) {
|
||||
foreach ($catalog->get($key)->sections as $section) {
|
||||
foreach ($section->questions as $question) {
|
||||
if (!$question->required || null !== $question->showIf) {
|
||||
continue;
|
||||
}
|
||||
$definition = $catalog->get($key);
|
||||
$prefixes = [$key];
|
||||
|
||||
$form[sprintf('questionnaire[%s][%s][%s]', $key, $section->key, $question->key)] = match ($question->type) {
|
||||
QuestionType::CHOICE => $question->options[0]->key,
|
||||
QuestionType::RATING => '5',
|
||||
default => 'Antwort',
|
||||
};
|
||||
if ($definition->perBusLeg) {
|
||||
$form[sprintf('questionnaire[%s][legs]', $key)] = $legs;
|
||||
$prefixes = array_map(static fn (string $leg): string => $key.']['.$leg, 'both' === $legs ? ['outbound', 'return'] : [$legs]);
|
||||
}
|
||||
|
||||
foreach ($prefixes as $prefix) {
|
||||
foreach ($definition->sections as $section) {
|
||||
foreach ($section->questions as $question) {
|
||||
if (!$question->required || null !== $question->showIf) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$form[sprintf('questionnaire[%s][%s][%s]', $prefix, $section->key, $question->key)] = match ($question->type) {
|
||||
QuestionType::CHOICE => $question->options[0]->key,
|
||||
QuestionType::RATING => '5',
|
||||
default => 'Antwort',
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, QuestionnaireResponseStatus> keyed by questionnaire, sorted
|
||||
* @return array<string, QuestionnaireResponseStatus> keyed by questionnaire (and leg), sorted
|
||||
*/
|
||||
private function statuses(Disposition $disposition): array
|
||||
{
|
||||
@@ -194,7 +250,7 @@ class EditControllerTest extends WebTestCase
|
||||
$statuses = [];
|
||||
|
||||
foreach ($this->entityManager->getRepository(QuestionnaireResponse::class)->findBy(['disposition' => $disposition->getId()]) as $response) {
|
||||
$statuses[$response->getQuestionnaire()] = $response->getStatus();
|
||||
$statuses[$response->getQuestionnaire().(null === $response->getLeg() ? '' : '.'.$response->getLeg()->value)] = $response->getStatus();
|
||||
}
|
||||
|
||||
ksort($statuses);
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Entity\Assignment;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\Teamer;
|
||||
use App\Enum\BusLeg;
|
||||
use App\Enum\ConditionOperator;
|
||||
use App\Enum\QuestionnaireResponseStatus;
|
||||
use App\Enum\QuestionType;
|
||||
@@ -81,6 +82,28 @@ class QuestionnaireResponseTest extends TestCase
|
||||
$this->response()->submit($this->definition(key: 'other'), [], [], new \DateTimeImmutable());
|
||||
}
|
||||
|
||||
/**
|
||||
* The bus feedback is one response per escorted leg; any other questionnaire one per
|
||||
* placement - a leg there would slip past the unique key.
|
||||
*/
|
||||
public function testALegIsRequiredExactlyForAPerBusLegQuestionnaire(): void
|
||||
{
|
||||
$disposition = new Disposition(new Application(new Assignment(), new Teamer()));
|
||||
$perLeg = new Definition('bus_feedback', 1, 'Bus-Feedback', null, [], perBusLeg: true);
|
||||
|
||||
$this->assertSame(BusLeg::RETURN, QuestionnaireResponse::forDisposition($perLeg, $disposition, BusLeg::RETURN)->getLeg());
|
||||
$this->assertNull(QuestionnaireResponse::forDisposition($this->definition(), $disposition)->getLeg());
|
||||
|
||||
foreach ([[$perLeg, null], [$this->definition(), BusLeg::OUTBOUND]] as [$definition, $leg]) {
|
||||
try {
|
||||
QuestionnaireResponse::forDisposition($definition, $disposition, $leg);
|
||||
$this->fail(sprintf('"%s" accepted leg %s', $definition->key, $leg?->value ?? 'none'));
|
||||
} catch (\LogicException) {
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function response(): QuestionnaireResponse
|
||||
{
|
||||
$disposition = new Disposition(new Application(new Assignment(), new Teamer()));
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Tests\Form;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Enum\BusLeg;
|
||||
use App\Enum\QuestionType;
|
||||
use App\Form\QuestionnaireType;
|
||||
use App\Model\Questionnaire\Definition;
|
||||
@@ -14,6 +15,7 @@ use App\Model\Questionnaire\Section;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
|
||||
/**
|
||||
* Runs against the shipped definitions - teamer feedback alone, and with the bus feedback on the
|
||||
@@ -60,21 +62,109 @@ class QuestionnaireTypeTest extends KernelTestCase
|
||||
$this->assertSame([QuestionnaireCatalog::TEAMER_FEEDBACK, QuestionnaireCatalog::BUS_FEEDBACK], array_keys($data));
|
||||
// keyed by question within each questionnaire, not by section, and a rating is an int
|
||||
$this->assertSame(5, $data[QuestionnaireCatalog::TEAMER_FEEDBACK]['office_briefing_rating']);
|
||||
$this->assertSame('outbound', $data[QuestionnaireCatalog::BUS_FEEDBACK]['direction']);
|
||||
$this->assertSame(BusLeg::OUTBOUND->value, $data[QuestionnaireCatalog::BUS_FEEDBACK][QuestionnaireType::LEGS]);
|
||||
$this->assertSame('boonk', $data[QuestionnaireCatalog::BUS_FEEDBACK][BusLeg::OUTBOUND->value]['bus_company']);
|
||||
$this->assertArrayNotHasKey('organisation', $data[QuestionnaireCatalog::TEAMER_FEEDBACK]);
|
||||
|
||||
$sets = QuestionnaireType::answerSets($data, $definitions);
|
||||
$this->assertSame(
|
||||
[[QuestionnaireCatalog::TEAMER_FEEDBACK, null], [QuestionnaireCatalog::BUS_FEEDBACK, BusLeg::OUTBOUND]],
|
||||
array_map(static fn (array $set): array => [$set['definition']->key, $set['leg']], $sets),
|
||||
);
|
||||
$this->assertSame('boonk', $sets[1]['answers']['bus_company']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every required question of either questionnaire is demanded, as far as it is shown.
|
||||
* An escort who rode both buses answers the bus feedback twice, and each ride is demanded in
|
||||
* full.
|
||||
*/
|
||||
public function testEmptySubmitDemandsTheVisibleRequiredQuestionsOfBoth(): void
|
||||
public function testBothLegsAreEachAnsweredAndDemanded(): void
|
||||
{
|
||||
$definitions = $this->both();
|
||||
$data = $this->complete($definitions, QuestionnaireType::BOTH_LEGS);
|
||||
unset($data[QuestionnaireCatalog::BUS_FEEDBACK][BusLeg::RETURN->value]['bus_trip']['bus_company']);
|
||||
|
||||
$form = $this->createForm($definitions);
|
||||
$form->submit($data + [QuestionnaireType::SUBMIT => '']);
|
||||
|
||||
$this->assertCount(1, $form->getErrors(true));
|
||||
$this->assertCount(1, $form->get(QuestionnaireCatalog::BUS_FEEDBACK)->get(BusLeg::RETURN->value)->get('bus_trip')->get('bus_company')->getErrors());
|
||||
|
||||
$form = $this->createForm($definitions);
|
||||
$form->submit($this->complete($definitions, QuestionnaireType::BOTH_LEGS) + [QuestionnaireType::SUBMIT => '']);
|
||||
|
||||
$this->assertTrue($form->isValid(), (string) $form->getErrors(true));
|
||||
$this->assertSame(
|
||||
[null, BusLeg::OUTBOUND, BusLeg::RETURN],
|
||||
array_column(QuestionnaireType::answerSets($form->getData(), $definitions), 'leg'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Switching from both rides to one leaves the other leg's fields filled in the browser; they
|
||||
* must not become a response.
|
||||
*/
|
||||
public function testALegNotChosenIsNeitherDemandedNorStored(): void
|
||||
{
|
||||
$definitions = $this->both();
|
||||
$data = $this->complete($definitions, QuestionnaireType::BOTH_LEGS);
|
||||
$data[QuestionnaireCatalog::BUS_FEEDBACK][QuestionnaireType::LEGS] = BusLeg::RETURN->value;
|
||||
$data[QuestionnaireCatalog::BUS_FEEDBACK][BusLeg::OUTBOUND->value] = [];
|
||||
|
||||
$form = $this->createForm($definitions);
|
||||
$form->submit($data + [QuestionnaireType::SUBMIT => '']);
|
||||
|
||||
$this->assertTrue($form->isValid(), (string) $form->getErrors(true));
|
||||
$this->assertSame([null, BusLeg::RETURN], array_column(QuestionnaireType::answerSets($form->getData(), $definitions), 'leg'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{array<string, array<string, mixed>>, string|null}>
|
||||
*/
|
||||
public static function storedLegs(): iterable
|
||||
{
|
||||
yield 'nothing saved yet' => [[], null];
|
||||
yield 'one leg' => [['return' => ['bus_company' => 'boonk']], 'return'];
|
||||
yield 'both legs' => [['outbound' => [], 'return' => []], QuestionnaireType::BOTH_LEGS];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, array<string, mixed>> $answersByLeg
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('storedLegs')]
|
||||
public function testTheChosenLegsAreReadBackFromTheStoredOnes(array $answersByLeg, ?string $legs): void
|
||||
{
|
||||
$this->assertSame([QuestionnaireType::LEGS => $legs] + $answersByLeg, QuestionnaireType::legData($answersByLeg));
|
||||
}
|
||||
|
||||
public function testALegIsShownOnlyWhileChosen(): void
|
||||
{
|
||||
$row = $this->createForm($this->both())->createView()->children[QuestionnaireCatalog::BUS_FEEDBACK]->children[BusLeg::RETURN->value];
|
||||
|
||||
$this->assertSame('bus_feedback.return', $row->vars['row_attr']['data-question-key']);
|
||||
$this->assertSame(
|
||||
['question' => 'bus_feedback.legs', 'operator' => 'in', 'value' => ['return', 'both']],
|
||||
json_decode($row->vars['row_attr']['data-show-if'], true),
|
||||
);
|
||||
$this->assertSame(
|
||||
'bus_feedback.return.bus_company',
|
||||
$row->children['bus_trip']->children['bus_company']->vars['row_attr']['data-question-key'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every required question of the teamer feedback is demanded, as far as it is shown, and of the
|
||||
* bus feedback first which rides were escorted - no leg is shown before that.
|
||||
*/
|
||||
public function testEmptySubmitDemandsTheVisibleRequiredQuestionsAndTheLegs(): void
|
||||
{
|
||||
$form = $this->createForm($this->both());
|
||||
$form->submit([QuestionnaireType::SUBMIT => '']);
|
||||
|
||||
$this->assertFalse($form->isValid());
|
||||
$this->assertCount(1, $form->get(QuestionnaireCatalog::BUS_FEEDBACK)->get(QuestionnaireType::LEGS)->getErrors());
|
||||
|
||||
foreach ($this->both() as $definition) {
|
||||
foreach ([$this->teamerFeedback()] as $definition) {
|
||||
foreach ($definition->sections as $section) {
|
||||
foreach ($section->questions as $question) {
|
||||
$this->assertCount(
|
||||
@@ -120,12 +210,12 @@ class QuestionnaireTypeTest extends KernelTestCase
|
||||
{
|
||||
$definitions = $this->both();
|
||||
$data = $this->complete($definitions);
|
||||
$data[QuestionnaireCatalog::BUS_FEEDBACK]['bus_trip']['bus_company'] = 'other';
|
||||
$data[QuestionnaireCatalog::BUS_FEEDBACK][BusLeg::OUTBOUND->value]['bus_trip']['bus_company'] = 'other';
|
||||
|
||||
$form = $this->createForm($definitions);
|
||||
$form->submit($data + [QuestionnaireType::SUBMIT => '']);
|
||||
|
||||
$this->assertCount(1, $form->get(QuestionnaireCatalog::BUS_FEEDBACK)->get('bus_trip')->get('bus_company_other')->getErrors());
|
||||
$this->assertCount(1, $form->get(QuestionnaireCatalog::BUS_FEEDBACK)->get(BusLeg::OUTBOUND->value)->get('bus_trip')->get('bus_company_other')->getErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,15 +224,15 @@ class QuestionnaireTypeTest extends KernelTestCase
|
||||
*/
|
||||
public function testNoFieldIsHtmlRequired(): void
|
||||
{
|
||||
$view = $this->createForm($this->both())->createView();
|
||||
|
||||
foreach ($view as $questionnaire) {
|
||||
foreach ($questionnaire as $section) {
|
||||
foreach ($section as $field) {
|
||||
$this->assertFalse($field->vars['required'], $field->vars['full_name']);
|
||||
}
|
||||
$assertNotRequired = function (FormView $view) use (&$assertNotRequired): void {
|
||||
foreach ($view as $child) {
|
||||
// buttons have no required at all
|
||||
$this->assertFalse($child->vars['required'] ?? false, $child->vars['full_name']);
|
||||
$assertNotRequired($child);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$assertNotRequired($this->createForm($this->both())->createView());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,33 +305,56 @@ class QuestionnaireTypeTest extends KernelTestCase
|
||||
|
||||
/**
|
||||
* A submission answering every question that is shown when each choice takes its first option
|
||||
* and each rating is 5.
|
||||
* and each rating is 5; a per-bus-leg questionnaire for the given legs.
|
||||
*
|
||||
* @param list<Definition> $definitions
|
||||
*
|
||||
* @return array<string, array<string, array<string, mixed>>>
|
||||
* @return array<string, array<string, mixed>>
|
||||
*/
|
||||
private function complete(array $definitions): array
|
||||
private function complete(array $definitions, string $legs = 'outbound'): array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
foreach ($definitions as $definition) {
|
||||
$answers = [];
|
||||
$sections = $this->completeSections($definition);
|
||||
|
||||
foreach ($definition->sections as $section) {
|
||||
foreach ($section->questions as $question) {
|
||||
$answer = match ($question->type) {
|
||||
QuestionType::CHOICE => $question->options[0]->key,
|
||||
QuestionType::MULTI => [$question->options[0]->key],
|
||||
QuestionType::RATING => 5,
|
||||
QuestionType::DATE => '01.01.2026',
|
||||
QuestionType::TEXT, QuestionType::TEXTAREA => 'Antwort',
|
||||
};
|
||||
$answers[$question->key] = $answer;
|
||||
if (!$definition->perBusLeg) {
|
||||
$data[$definition->key] = $sections;
|
||||
|
||||
if ($definition->isVisible($question, $answers)) {
|
||||
$data[$definition->key][$section->key][$question->key] = is_int($answer) ? (string) $answer : $answer;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[$definition->key] = [QuestionnaireType::LEGS => $legs];
|
||||
|
||||
foreach (QuestionnaireType::BOTH_LEGS === $legs ? BusLeg::cases() : [BusLeg::from($legs)] as $leg) {
|
||||
$data[$definition->key][$leg->value] = $sections;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, mixed>> keyed by section, then question
|
||||
*/
|
||||
private function completeSections(Definition $definition): array
|
||||
{
|
||||
$data = [];
|
||||
$answers = [];
|
||||
|
||||
foreach ($definition->sections as $section) {
|
||||
foreach ($section->questions as $question) {
|
||||
$answer = match ($question->type) {
|
||||
QuestionType::CHOICE => $question->options[0]->key,
|
||||
QuestionType::MULTI => [$question->options[0]->key],
|
||||
QuestionType::RATING => 5,
|
||||
QuestionType::DATE => '01.01.2026',
|
||||
QuestionType::TEXT, QuestionType::TEXTAREA => 'Antwort',
|
||||
};
|
||||
$answers[$question->key] = $answer;
|
||||
|
||||
if ($definition->isVisible($question, $answers)) {
|
||||
$data[$section->key][$question->key] = is_int($answer) ? (string) $answer : $answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,16 @@ use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\Teamer;
|
||||
use App\Enum\BusLeg;
|
||||
use App\Repository\DispositionRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* Which questionnaires the dashboard reminds a teamer of. Run against db_test with real rows,
|
||||
* because the question is which rows come back: the response is joined as an arbitrary entity,
|
||||
* and a wrong JOIN condition would quietly let a draft, or a response to another questionnaire,
|
||||
* decide the outcome.
|
||||
* Which questionnaires the dashboard and the daily reminder mail remind a teamer of. Run against
|
||||
* db_test with real rows, because the question is which rows come back: the responses are looked up
|
||||
* in EXISTS subqueries, and a wrong condition there would quietly let a draft, a response to
|
||||
* another questionnaire, or a second bus leg decide the outcome.
|
||||
*
|
||||
* Every test runs inside a transaction that is rolled back, so db_test - shared between
|
||||
* branches - keeps nothing.
|
||||
@@ -25,6 +26,8 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
{
|
||||
use QuestionnaireFixturesTrait;
|
||||
|
||||
private const string GO_LIVE = '2026-01-01';
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private DispositionRepository $repository;
|
||||
@@ -93,8 +96,8 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Each questionnaire key belongs in its JOIN condition: in the WHERE clause, the response to
|
||||
* one questionnaire would stand in for the other's.
|
||||
* Each questionnaire key belongs in its own EXISTS: the response to one questionnaire must not
|
||||
* stand in for the other's.
|
||||
*/
|
||||
public function testTheBusFeedbackDoesNotStandInForTheTeamerFeedback(): void
|
||||
{
|
||||
@@ -121,13 +124,42 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
$this->assertSame([['disposition' => $disposition, 'draft' => false]], $this->pending());
|
||||
}
|
||||
|
||||
public function testAnAssignmentEndingOnTheWindowsFirstDayIsPending(): void
|
||||
/**
|
||||
* Only submitting ends it, however long ago the trip ended.
|
||||
*/
|
||||
public function testAnUnfinishedQuestionnaireStaysPendingLongAfterTheTrip(): void
|
||||
{
|
||||
$this->escort(dateTo: 'today -30 days');
|
||||
$this->escort(dateTo: self::GO_LIVE);
|
||||
|
||||
$this->assertCount(1, $this->pending());
|
||||
}
|
||||
|
||||
/**
|
||||
* Two leg drafts are one placement on the dashboard, not two rows.
|
||||
*/
|
||||
public function testBothLegDraftsListThePlacementOnce(): void
|
||||
{
|
||||
$disposition = $this->escort();
|
||||
$this->respond($disposition, submit: true);
|
||||
$this->respond($disposition, submit: false, questionnaire: QuestionnaireCatalog::BUS_FEEDBACK, leg: BusLeg::OUTBOUND);
|
||||
$this->respond($disposition, submit: false, questionnaire: QuestionnaireCatalog::BUS_FEEDBACK, leg: BusLeg::RETURN);
|
||||
|
||||
$this->assertSame([['disposition' => $disposition, 'draft' => true]], $this->pending());
|
||||
}
|
||||
|
||||
/**
|
||||
* An escort who rode only the return bus has a single leg response; it settles the bus
|
||||
* feedback.
|
||||
*/
|
||||
public function testASubmittedReturnLegSettlesTheBusFeedback(): void
|
||||
{
|
||||
$disposition = $this->escort();
|
||||
$this->respond($disposition, submit: true);
|
||||
$this->respond($disposition, submit: true, questionnaire: QuestionnaireCatalog::BUS_FEEDBACK, leg: BusLeg::RETURN);
|
||||
|
||||
$this->assertSame([], $this->pending());
|
||||
}
|
||||
|
||||
public function testAnAssignmentEndingTodayIsPending(): void
|
||||
{
|
||||
$this->escort(dateTo: 'today');
|
||||
@@ -154,7 +186,7 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
{
|
||||
return [
|
||||
'not over yet' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('tomorrow'))],
|
||||
'ended before the window' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('today -31 days'))],
|
||||
'ended before go-live' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('2025-12-31'))],
|
||||
'skip formalities' => [static fn (Disposition $d) => $d->getAssignment()->setSkipFormalities(true)],
|
||||
'called off' => [static fn (Disposition $d) => $d->setStatus(Disposition::STATUS_CALLED_OFF)],
|
||||
'assignment called off' => [static fn (Disposition $d) => $d->getAssignment()->setStatus(Assignment::STATUS_CALLED_OFF)],
|
||||
@@ -170,6 +202,66 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
$this->assertSame([], $this->pending());
|
||||
}
|
||||
|
||||
/**
|
||||
* The mail starts the day after the trip: on its last day the teamer is only just back.
|
||||
*/
|
||||
public function testTheReminderStartsTheDayAfterTheTrip(): void
|
||||
{
|
||||
$this->withUser($this->teamer);
|
||||
$yesterday = $this->escort(dateTo: 'yesterday');
|
||||
$this->escort(dateTo: 'today');
|
||||
|
||||
$this->assertSame([$yesterday], $this->reminded());
|
||||
}
|
||||
|
||||
public function testTheReminderCoversEveryTeamerAndKeepsGoingUntilSubmitted(): void
|
||||
{
|
||||
$this->withUser($this->teamer);
|
||||
$other = (new Teamer())->setFirstName('Alex')->setLastName('Beispiel')->setGender('d');
|
||||
$this->entityManager->persist($other);
|
||||
$this->withUser($other);
|
||||
|
||||
$old = $this->escort(dateTo: self::GO_LIVE);
|
||||
$draft = $this->escort(teamer: $other);
|
||||
$this->respond($draft, submit: false);
|
||||
$done = $this->escort();
|
||||
$this->respond($done, submit: true);
|
||||
$this->respond($done, submit: true, questionnaire: QuestionnaireCatalog::BUS_FEEDBACK);
|
||||
|
||||
$reminded = $this->reminded();
|
||||
|
||||
$this->assertContains($old, $reminded);
|
||||
$this->assertContains($draft, $reminded);
|
||||
$this->assertNotContains($done, $reminded);
|
||||
}
|
||||
|
||||
/**
|
||||
* A teamer who cannot log in cannot submit, and would be mailed every day forever.
|
||||
*
|
||||
* @param \Closure(Teamer, ?\App\Entity\User): mixed $change
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('notReminded')]
|
||||
public function testTeamersWhoCannotLogInAreNotReminded(bool $withUser, \Closure $change): void
|
||||
{
|
||||
$user = $withUser ? $this->withUser($this->teamer) : null;
|
||||
$change($this->teamer, $user);
|
||||
$this->escort();
|
||||
|
||||
$this->assertSame([], $this->reminded());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{bool, \Closure(Teamer, ?\App\Entity\User): mixed}>
|
||||
*/
|
||||
public static function notReminded(): array
|
||||
{
|
||||
return [
|
||||
'no user account' => [false, static fn () => null],
|
||||
'user blocked' => [true, static fn (Teamer $t, $user) => $user->setDisabledAt(new \DateTimeImmutable('yesterday'))],
|
||||
'teamer deleted' => [true, static fn (Teamer $t) => $t->setDeleted()],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{disposition: Disposition, draft: bool}>
|
||||
*/
|
||||
@@ -177,6 +269,16 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
{
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->repository->findPendingQuestionnaireByTeamer($this->teamer, QuestionnaireCatalog::windowStart(30));
|
||||
return $this->repository->findPendingQuestionnaireByTeamer($this->teamer, new \DateTimeImmutable(self::GO_LIVE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<Disposition>
|
||||
*/
|
||||
private function reminded(): array
|
||||
{
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->repository->findQuestionnaireReminders(new \DateTimeImmutable(self::GO_LIVE), new \DateTimeImmutable('today'));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\User;
|
||||
use App\Enum\BusLeg;
|
||||
use App\Model\Questionnaire\Definition;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
@@ -50,10 +52,14 @@ trait QuestionnaireFixturesTrait
|
||||
return $disposition;
|
||||
}
|
||||
|
||||
private function respond(Disposition $disposition, bool $submit, string $questionnaire = QuestionnaireCatalog::TEAMER_FEEDBACK): QuestionnaireResponse
|
||||
/**
|
||||
* A bus feedback is given per leg, the outbound one unless another is named.
|
||||
*/
|
||||
private function respond(Disposition $disposition, bool $submit, string $questionnaire = QuestionnaireCatalog::TEAMER_FEEDBACK, ?BusLeg $leg = null): QuestionnaireResponse
|
||||
{
|
||||
$definition = new Definition($questionnaire, 1, 'Beispiel', null, []);
|
||||
$response = QuestionnaireResponse::forDisposition($definition, $disposition);
|
||||
$perBusLeg = QuestionnaireCatalog::BUS_FEEDBACK === $questionnaire;
|
||||
$definition = new Definition($questionnaire, 1, 'Beispiel', null, [], $perBusLeg);
|
||||
$response = QuestionnaireResponse::forDisposition($definition, $disposition, $perBusLeg ? $leg ?? BusLeg::OUTBOUND : null);
|
||||
|
||||
if ($submit) {
|
||||
$response->submit($definition, [], [], new \DateTimeImmutable());
|
||||
@@ -65,4 +71,23 @@ trait QuestionnaireFixturesTrait
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* The login a teamer needs to be reminded at all.
|
||||
*/
|
||||
private function withUser(Teamer $teamer): User
|
||||
{
|
||||
$user = (new User())
|
||||
->setFirstName($teamer->getFirstName())
|
||||
->setLastName($teamer->getLastName())
|
||||
->setEmail(uniqid('questionnaire.', true).'@example.com')
|
||||
->setRoles(['ROLE_TEAMER'])
|
||||
->setBusProAddressId(1)
|
||||
->setBusProPersonId(1)
|
||||
->setTeamer($teamer)
|
||||
;
|
||||
$this->entityManager->persist($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
$this->assertSame(
|
||||
$expected ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,
|
||||
(new DispositionVoter($this->security, 30))->vote($token, $disposition, [DispositionVoter::MANAGE_RECEIPTS]),
|
||||
(new DispositionVoter($this->security, '2026-01-01'))->vote($token, $disposition, [DispositionVoter::MANAGE_RECEIPTS]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -217,20 +217,19 @@ class DispositionVoterTest extends TestCase
|
||||
{
|
||||
return [
|
||||
'assignment not over yet' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('tomorrow'))],
|
||||
'ended before the window' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('today -31 days'))],
|
||||
'ended before go-live' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('2025-12-31'))],
|
||||
'skip formalities' => [static fn (Disposition $d) => $d->getAssignment()->setSkipFormalities(true)],
|
||||
'called off' => [static fn (Disposition $d) => $d->setStatus(Disposition::STATUS_CALLED_OFF)],
|
||||
];
|
||||
}
|
||||
|
||||
public function testTheQuestionnaireIsStillOfferedOnTheWindowsLastDay(): void
|
||||
/**
|
||||
* An unfinished questionnaire stays open however long ago the trip ended - only go-live and
|
||||
* submitting end it.
|
||||
*/
|
||||
public function testTheQuestionnaireStaysOpenLongAfterTheTrip(): void
|
||||
{
|
||||
$this->assertQuestionnaire(true, $this->escortDisposition(dateTo: 'today -30 days'));
|
||||
}
|
||||
|
||||
public function testTheWindowIsConfigurable(): void
|
||||
{
|
||||
$this->assertQuestionnaire(false, $this->escortDisposition(dateTo: 'today -8 days'), windowDays: 7);
|
||||
$this->assertQuestionnaire(true, $this->escortDisposition(dateTo: '2026-01-01'));
|
||||
}
|
||||
|
||||
public function testAnotherTeamerMayNotFillInTheQuestionnaire(): void
|
||||
@@ -252,11 +251,18 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
$this->assertSame(
|
||||
VoterInterface::ACCESS_DENIED,
|
||||
$this->questionnaireVote($disposition, (new User())->setTeamer($disposition->getTeamer()), 30),
|
||||
$this->questionnaireVote($disposition, (new User())->setTeamer($disposition->getTeamer()), '2026-01-01'),
|
||||
);
|
||||
}
|
||||
|
||||
private function assertQuestionnaire(bool $expected, Disposition $disposition, int $windowDays = 30, ?User $user = null): void
|
||||
public function testAMalformedGoLiveDateFailsLoudly(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
new DispositionVoter($this->security, '01.01.2026');
|
||||
}
|
||||
|
||||
private function assertQuestionnaire(bool $expected, Disposition $disposition, string $goLive = '2026-01-01', ?User $user = null): void
|
||||
{
|
||||
$this->security
|
||||
->method('isGranted')
|
||||
@@ -265,20 +271,20 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
$this->assertSame(
|
||||
$expected ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,
|
||||
$this->questionnaireVote($disposition, $user ?? (new User())->setTeamer($disposition->getTeamer()), $windowDays),
|
||||
$this->questionnaireVote($disposition, $user ?? (new User())->setTeamer($disposition->getTeamer()), $goLive),
|
||||
);
|
||||
}
|
||||
|
||||
private function questionnaireVote(Disposition $disposition, User $user, int $windowDays): int
|
||||
private function questionnaireVote(Disposition $disposition, User $user, string $goLive): int
|
||||
{
|
||||
$token = $this->createStub(TokenInterface::class);
|
||||
$token->method('getUser')->willReturn($user);
|
||||
|
||||
return (new DispositionVoter($this->security, $windowDays))->vote($token, $disposition, [DispositionVoter::QUESTIONNAIRE]);
|
||||
return (new DispositionVoter($this->security, $goLive))->vote($token, $disposition, [DispositionVoter::QUESTIONNAIRE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A bus escort that ended yesterday, well within the 30-day window the tests use.
|
||||
* A bus escort that ended yesterday, after the go-live date the tests use.
|
||||
*/
|
||||
private function escortDisposition(string $dateTo = 'yesterday'): Disposition
|
||||
{
|
||||
@@ -294,7 +300,7 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
private function vote(string $attribute, Disposition $disposition): int
|
||||
{
|
||||
return (new DispositionVoter($this->security, 30))->vote(
|
||||
return (new DispositionVoter($this->security, '2026-01-01'))->vote(
|
||||
$this->createStub(TokenInterface::class),
|
||||
$disposition,
|
||||
[$attribute],
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service\Cron;
|
||||
|
||||
use App\Config\EmailTextKey;
|
||||
use App\Email\Mailer;
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\Embeddable\Communication;
|
||||
use App\Entity\Teamer;
|
||||
use App\Repository\DispositionRepository;
|
||||
use App\Service\Cron\QuestionnaireReminderService;
|
||||
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
/**
|
||||
* One mail per teamer, however many placements they owe a questionnaire for. Which placements
|
||||
* those are is the repository's rule, pinned in DispositionRepositoryQuestionnaireTest.
|
||||
*/
|
||||
#[AllowMockObjectsWithoutExpectations]
|
||||
class QuestionnaireReminderServiceTest extends TestCase
|
||||
{
|
||||
private DispositionRepository&MockObject $repository;
|
||||
private Mailer&MockObject $mailer;
|
||||
private QuestionnaireReminderService $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->repository = $this->createMock(DispositionRepository::class);
|
||||
$this->mailer = $this->createMock(Mailer::class);
|
||||
|
||||
$this->service = new QuestionnaireReminderService($this->repository, $this->mailer, new NullLogger(), '2026-11-10');
|
||||
}
|
||||
|
||||
public function testItAsksForTheGoLiveDateAndToday(): void
|
||||
{
|
||||
$this->repository
|
||||
->expects($this->once())
|
||||
->method('findQuestionnaireReminders')
|
||||
->with(new \DateTimeImmutable('2026-11-10'), new \DateTimeImmutable('2026-11-20'))
|
||||
->willReturn([])
|
||||
;
|
||||
|
||||
$this->assertSame('Sent 0 questionnaire reminders to teamers', $this->service->sendReminders(new \DateTimeImmutable('2026-11-20 01:00')));
|
||||
}
|
||||
|
||||
public function testOneMailPerTeamerListsEveryPlacement(): void
|
||||
{
|
||||
$kim = $this->teamer('[email protected]');
|
||||
$alex = $this->teamer('[email protected]');
|
||||
|
||||
$this->repository->method('findQuestionnaireReminders')->willReturn([
|
||||
$this->placement($kim, '2026-11-14'),
|
||||
$this->placement($kim, '2026-11-07'),
|
||||
$this->placement($alex, '2026-11-14'),
|
||||
]);
|
||||
|
||||
$sent = [];
|
||||
$this->mailer
|
||||
->expects($this->exactly(2))
|
||||
->method('createAndSendText')
|
||||
->willReturnCallback(function (EmailTextKey $key, array $placeholders, array $options) use (&$sent): void {
|
||||
$this->assertSame(EmailTextKey::REMINDER_QUESTIONNAIRE, $key);
|
||||
$sent[$options['to']] = $placeholders['destinations'];
|
||||
})
|
||||
;
|
||||
|
||||
$this->assertSame('Sent 2 questionnaire reminders to teamers', $this->service->sendReminders(new \DateTimeImmutable('2026-11-20')));
|
||||
$this->assertSame(['[email protected]', '[email protected]'], array_keys($sent));
|
||||
// labelled as everywhere in the reminders, by Destination::__toString()
|
||||
$this->assertSame('07.11.26 - 14.11.26 Skireise, 31.10.26 - 07.11.26 Skireise', $sent['[email protected]']);
|
||||
$this->assertSame('07.11.26 - 14.11.26 Skireise', $sent['[email protected]']);
|
||||
}
|
||||
|
||||
public function testATeamerWithoutAnAddressIsSkipped(): void
|
||||
{
|
||||
$this->repository->method('findQuestionnaireReminders')->willReturn([$this->placement(new Teamer(), '2026-11-14')]);
|
||||
$this->mailer->expects($this->never())->method('createAndSendText');
|
||||
|
||||
$this->assertSame('Sent 0 questionnaire reminders to teamers', $this->service->sendReminders(new \DateTimeImmutable('2026-11-20')));
|
||||
}
|
||||
|
||||
public function testAMalformedGoLiveDateFailsLoudly(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
new QuestionnaireReminderService($this->repository, $this->mailer, new NullLogger(), '10.11.2026');
|
||||
}
|
||||
|
||||
private function teamer(string $email): Teamer
|
||||
{
|
||||
return (new Teamer())->setCommunication((new Communication())->setEmail($email));
|
||||
}
|
||||
|
||||
private function placement(Teamer $teamer, string $dateTo): Disposition
|
||||
{
|
||||
$destination = (new Destination())
|
||||
->setProduct('Skireise')
|
||||
->setDateFrom(new \DateTimeImmutable($dateTo.' -7 days'))
|
||||
->setDateTo(new \DateTimeImmutable($dateTo))
|
||||
;
|
||||
|
||||
return new Disposition(new Application((new Assignment())->setDestination($destination), $teamer));
|
||||
}
|
||||
}
|
||||
@@ -24,18 +24,27 @@ use Twig\Environment;
|
||||
*/
|
||||
class QuestionnaireTemplateTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* The bus questions come once per leg, plus the choice of legs and the two leg blocks, which
|
||||
* the controller shows and hides like conditional questions.
|
||||
*/
|
||||
public function testEveryQuestionRowCarriesItsKeyAndConditionalOnesTheirCondition(): void
|
||||
{
|
||||
$crawler = $this->renderForm();
|
||||
|
||||
$this->assertCount(
|
||||
count($this->definition()->getQuestions()) + count($this->busDefinition()->getQuestions()),
|
||||
count($this->definition()->getQuestions()) + 2 * count($this->busDefinition()->getQuestions()) + 3,
|
||||
$crawler->filter('[data-question-key]'),
|
||||
);
|
||||
$this->assertSame(
|
||||
'{"question":"bus_feedback.bus_company","operator":"equals","value":"other"}',
|
||||
$crawler->filter('[data-question-key="bus_feedback.bus_company_other"]')->attr('data-show-if'),
|
||||
'{"question":"bus_feedback.return.bus_company","operator":"equals","value":"other"}',
|
||||
$crawler->filter('[data-question-key="bus_feedback.return.bus_company_other"]')->attr('data-show-if'),
|
||||
);
|
||||
$this->assertSame(
|
||||
'{"question":"bus_feedback.legs","operator":"in","value":["outbound","both"]}',
|
||||
$crawler->filter('[data-question-key="bus_feedback.outbound"]')->attr('data-show-if'),
|
||||
);
|
||||
$this->assertSame('Hinfahrt', trim($crawler->filter('[data-question-key="bus_feedback.outbound"] > h3')->text()));
|
||||
}
|
||||
|
||||
public function testSectionsAreFieldsetsWithTheirTitle(): void
|
||||
@@ -44,7 +53,7 @@ class QuestionnaireTemplateTest extends KernelTestCase
|
||||
|
||||
$this->assertSame('Organisation & Ablauf', trim($crawler->filter('fieldset legend')->first()->text()));
|
||||
$this->assertCount(
|
||||
count($this->definition()->sections) + count($this->busDefinition()->sections),
|
||||
count($this->definition()->sections) + 2 * count($this->busDefinition()->sections),
|
||||
$crawler->filter('fieldset'),
|
||||
);
|
||||
}
|
||||
@@ -69,7 +78,7 @@ class QuestionnaireTemplateTest extends KernelTestCase
|
||||
$seminar = $crawler->filter('[data-question-key="teamer_feedback.team_week_seminar"] select');
|
||||
$this->assertCount(1, $seminar);
|
||||
$this->assertSame('', $seminar->filter('option')->first()->attr('value'));
|
||||
$this->assertCount(1, $crawler->filter('[data-question-key="bus_feedback.wc"] select'));
|
||||
$this->assertCount(1, $crawler->filter('[data-question-key="bus_feedback.outbound.wc"] select'));
|
||||
|
||||
// the labels wrapping a radio: the whole row is the click target
|
||||
$rows = $crawler
|
||||
|
||||
Reference in new issue
Block a user