From efd45cb882f1dbb937d60ff03e8a8b029a2b68d5 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Sun, 19 Jun 2022 15:05:27 -0400 Subject: [PATCH] improve test coverage --- tests/Form/Type/FormSpecificationTypeTest.php | 7 +- .../FormSpecificationTypeTranslatedTest.php | 74 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/Form/Type/FormSpecificationTypeTranslatedTest.php diff --git a/tests/Form/Type/FormSpecificationTypeTest.php b/tests/Form/Type/FormSpecificationTypeTest.php index d64f6bb..3cff5c2 100644 --- a/tests/Form/Type/FormSpecificationTypeTest.php +++ b/tests/Form/Type/FormSpecificationTypeTest.php @@ -55,7 +55,7 @@ protected function getExtensions(): array /** * @covers \Zikula\Bundle\DynamicFormBundle\Entity\AbstractFormSpecification */ - public function testNameFieldOnNew(): void + public function testFormCreation(): void { $formData = new class() extends AbstractFormSpecification { }; @@ -63,6 +63,11 @@ public function testNameFieldOnNew(): void $this->assertTrue($form->has('name')); $this->assertFalse($form->get('name')->isDisabled()); + + $this->assertInstanceOf(TextType::class, $form->get('labels')->getConfig()->getType()->getInnerType()); + $this->assertInstanceOf(TextType::class, $form->get('groups')->getConfig()->getType()->getInnerType()); + $this->assertCount(0, $form->get('labels')); + $this->assertCount(0, $form->get('groups')); } /** diff --git a/tests/Form/Type/FormSpecificationTypeTranslatedTest.php b/tests/Form/Type/FormSpecificationTypeTranslatedTest.php new file mode 100644 index 0000000..8af6154 --- /dev/null +++ b/tests/Form/Type/FormSpecificationTypeTranslatedTest.php @@ -0,0 +1,74 @@ + 'en', 'German' => 'de']; + } + }; + + $dispatcher->addSubscriber(new FormTypeChoiceEventSubscriber($translator)); + $formSpecificationType = new FormSpecificationType($dispatcher, true); + $translationCollectionType = new TranslationCollectionType($localeProvider); + + return [ + new PreloadedExtension([$formSpecificationType, $translationCollectionType], []), + ]; + } + + /** + * @covers \Zikula\Bundle\DynamicFormBundle\Entity\AbstractFormSpecification + */ + public function testFormCreation(): void + { + $formData = new class() extends AbstractFormSpecification { + }; + $form = $this->factory->create(FormSpecificationType::class, $formData); + $this->assertInstanceOf(TranslationCollectionType::class, $form->get('labels')->getConfig()->getType()->getInnerType()); + $this->assertInstanceOf(TranslationCollectionType::class, $form->get('groups')->getConfig()->getType()->getInnerType()); + $this->assertCount(2, $form->get('labels')); + $this->assertCount(2, $form->get('groups')); + $this->assertTrue($form->get('labels')->has('en')); + $this->assertTrue($form->get('labels')->has('de')); + $this->assertTrue($form->get('groups')->has('en')); + $this->assertTrue($form->get('groups')->has('de')); + } +}