Skip to content

Commit efd45cb

Browse files
committed
improve test coverage
1 parent 8689753 commit efd45cb

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

tests/Form/Type/FormSpecificationTypeTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,19 @@ protected function getExtensions(): array
5555
/**
5656
* @covers \Zikula\Bundle\DynamicFormBundle\Entity\AbstractFormSpecification
5757
*/
58-
public function testNameFieldOnNew(): void
58+
public function testFormCreation(): void
5959
{
6060
$formData = new class() extends AbstractFormSpecification {
6161
};
6262
$form = $this->factory->create(FormSpecificationType::class, $formData);
6363

6464
$this->assertTrue($form->has('name'));
6565
$this->assertFalse($form->get('name')->isDisabled());
66+
67+
$this->assertInstanceOf(TextType::class, $form->get('labels')->getConfig()->getType()->getInnerType());
68+
$this->assertInstanceOf(TextType::class, $form->get('groups')->getConfig()->getType()->getInnerType());
69+
$this->assertCount(0, $form->get('labels'));
70+
$this->assertCount(0, $form->get('groups'));
6671
}
6772

6873
/**
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Zikula package.
7+
*
8+
* Copyright Zikula - https://ziku.la/
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Zikula\Bundle\DynamicFormBundle\Tests\Form\Type;
15+
16+
use Symfony\Component\EventDispatcher\EventDispatcher;
17+
use Symfony\Component\Form\FormExtensionInterface;
18+
use Symfony\Component\Form\PreloadedExtension;
19+
use Symfony\Component\Form\Test\TypeTestCase;
20+
use Symfony\Component\Translation\IdentityTranslator;
21+
use Zikula\Bundle\DynamicFormBundle\Entity\AbstractFormSpecification;
22+
use Zikula\Bundle\DynamicFormBundle\EventSubscriber\FormTypeChoiceEventSubscriber;
23+
use Zikula\Bundle\DynamicFormBundle\Form\Type\FormSpecificationType;
24+
use Zikula\Bundle\DynamicFormBundle\Form\Type\TranslationCollectionType;
25+
use Zikula\Bundle\DynamicFormBundle\Provider\LocaleProviderInterface;
26+
27+
class FormSpecificationTypeTranslatedTest extends TypeTestCase
28+
{
29+
/**
30+
* @return FormExtensionInterface[]
31+
*/
32+
protected function getExtensions(): array
33+
{
34+
$dispatcher = new EventDispatcher();
35+
$translator = new IdentityTranslator();
36+
$localeProvider = new class() implements LocaleProviderInterface {
37+
public function getSupportedLocales(): array
38+
{
39+
return ['en', 'de'];
40+
}
41+
42+
public function getSupportedLocaleNames(string $displayLocale = null): array
43+
{
44+
return ['English' => 'en', 'German' => 'de'];
45+
}
46+
};
47+
48+
$dispatcher->addSubscriber(new FormTypeChoiceEventSubscriber($translator));
49+
$formSpecificationType = new FormSpecificationType($dispatcher, true);
50+
$translationCollectionType = new TranslationCollectionType($localeProvider);
51+
52+
return [
53+
new PreloadedExtension([$formSpecificationType, $translationCollectionType], []),
54+
];
55+
}
56+
57+
/**
58+
* @covers \Zikula\Bundle\DynamicFormBundle\Entity\AbstractFormSpecification
59+
*/
60+
public function testFormCreation(): void
61+
{
62+
$formData = new class() extends AbstractFormSpecification {
63+
};
64+
$form = $this->factory->create(FormSpecificationType::class, $formData);
65+
$this->assertInstanceOf(TranslationCollectionType::class, $form->get('labels')->getConfig()->getType()->getInnerType());
66+
$this->assertInstanceOf(TranslationCollectionType::class, $form->get('groups')->getConfig()->getType()->getInnerType());
67+
$this->assertCount(2, $form->get('labels'));
68+
$this->assertCount(2, $form->get('groups'));
69+
$this->assertTrue($form->get('labels')->has('en'));
70+
$this->assertTrue($form->get('labels')->has('de'));
71+
$this->assertTrue($form->get('groups')->has('en'));
72+
$this->assertTrue($form->get('groups')->has('de'));
73+
}
74+
}

0 commit comments

Comments
 (0)