renderForm(); $this->assertCount(count($this->definition()->getQuestions()), $crawler->filter('[data-question-key]')); $this->assertSame( '{"question":"bus_company","operator":"equals","value":"other"}', $crawler->filter('[data-question-key="bus_company_other"]')->attr('data-show-if'), ); } public function testSectionsAreFieldsetsWithTheirTitle(): void { $crawler = $this->renderForm(); $this->assertSame('Organisation & Ablauf', trim($crawler->filter('fieldset legend')->first()->text())); $this->assertCount(count($this->definition()->sections), $crawler->filter('fieldset')); } public function testRatingIsFiveRadiosInARadioGroup(): void { $group = $this->renderForm()->filter('[data-question-key="office_briefing_rating"] [role="radiogroup"]'); $this->assertCount(5, $group->filter('input[type="radio"]')); } public function testAnswersShowLabelsNotKeysAndSkipHiddenQuestions(): void { $definition = $this->definition(); $response = QuestionnaireResponse::forDisposition($definition, new Disposition(new Application(new Assignment(), new Teamer()))) ->submit($definition, [ 'office_briefing_rating' => 2, 'office_briefing_low_reason' => 'Briefing kam zu spät', 'bus_company' => 'heess', 'had_organisational_problems' => 'no', ], [], new \DateTimeImmutable()) ; $html = self::getContainer()->get(Environment::class)->render('questionnaire/_answers.html.twig', [ 'definition' => $definition, 'answers' => $response->getAnswers(), ]); $this->assertStringContainsString('2 von 5', $html); $this->assertStringContainsString('Briefing kam zu spät', $html); $this->assertStringContainsString('Heeß', $html); $this->assertStringContainsString('Nein', $html); $this->assertStringNotContainsString('heess', $html); // nothing was answered there, so the section is left out $this->assertStringNotContainsString('Bewertung Bus & Fahrer', $html); } private function renderForm(): Crawler { self::bootKernel(); $container = self::getContainer(); $form = $container->get(FormFactoryInterface::class)->create(QuestionnaireType::class, [], [ 'definition' => $this->definition(), 'csrf_protection' => false, ]); $html = $container->get(Environment::class) ->createTemplate('{{ form(form) }}') ->render(['form' => $form->createView()]) ; return new Crawler($html); } private function definition(): Definition { return new QuestionnaireCatalog(__DIR__.'/../../config/questionnaires')->get(QuestionnaireCatalog::TEAMER_ASSIGNMENT); } }