diff --git a/src/Form/Type/Filter/DateRangeType.php b/src/Form/Type/Filter/DateRangeType.php index 9c3140dd58..f3653c2c8d 100644 --- a/src/Form/Type/Filter/DateRangeType.php +++ b/src/Form/Type/Filter/DateRangeType.php @@ -84,7 +84,11 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'field_type' => FormDateRangeType::class, - 'field_options' => ['format' => DateType::HTML5_FORMAT], + 'field_options' => [ + 'field_options' => [ + 'format' => DateType::HTML5_FORMAT, + ], + ], ]); } } diff --git a/src/Form/Type/Filter/DateTimeRangeType.php b/src/Form/Type/Filter/DateTimeRangeType.php index 8396a10af6..b663124d11 100644 --- a/src/Form/Type/Filter/DateTimeRangeType.php +++ b/src/Form/Type/Filter/DateTimeRangeType.php @@ -16,7 +16,7 @@ use Sonata\AdminBundle\Form\Type\Operator\DateRangeOperatorType; use Sonata\Form\Type\DateTimeRangeType as FormDateTimeRangeType; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\Extension\Core\Type\DateType; +use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Translation\TranslatorInterface; @@ -84,7 +84,9 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'field_type' => FormDateTimeRangeType::class, - 'field_options' => ['date_format' => DateType::HTML5_FORMAT], + 'field_options' => [ + 'field_options' => ['date_format' => DateTimeType::HTML5_FORMAT], + ], ]); } } diff --git a/src/Form/Type/Filter/DateType.php b/src/Form/Type/Filter/DateType.php index 3e6026acf6..ddc5680934 100644 --- a/src/Form/Type/Filter/DateType.php +++ b/src/Form/Type/Filter/DateType.php @@ -108,7 +108,7 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'field_type' => FormDateType::class, - 'field_options' => ['date_format' => FormDateType::HTML5_FORMAT], + 'field_options' => ['format' => FormDateType::HTML5_FORMAT], ]); } } diff --git a/tests/Form/Type/Filter/BaseTypeTest.php b/tests/Form/Type/Filter/BaseTypeTest.php new file mode 100644 index 0000000000..df3f0287dd --- /dev/null +++ b/tests/Form/Type/Filter/BaseTypeTest.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Tests\Form\Type\Filter; + +use Symfony\Component\Form\Test\TypeTestCase; + +abstract class BaseTypeTest extends TypeTestCase +{ + public function testHasTypeAndValue(): void + { + $form = $this->factory->create($this->getTestedType()); + + $this->assertTrue($form->has('type')); + $this->assertTrue($form->has('value')); + } + + public function testHasFieldTypeAndOptions(): void + { + $form = $this->factory->create($this->getTestedType()); + + $this->assertTrue($form->getConfig()->hasOption('field_type')); + $this->assertTrue($form->getConfig()->hasOption('field_options')); + } + + /** + * @phpstan-return class-string + */ + abstract protected function getTestedType(): string; +} diff --git a/tests/Form/Type/Filter/ChoiceTypeTest.php b/tests/Form/Type/Filter/ChoiceTypeTest.php new file mode 100644 index 0000000000..88489122f8 --- /dev/null +++ b/tests/Form/Type/Filter/ChoiceTypeTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Tests\Form\Type\Filter; + +use Sonata\AdminBundle\Form\Type\Filter\ChoiceType; +use Symfony\Component\Translation\TranslatorInterface; + +final class ChoiceTypeTest extends BaseTypeTest +{ + public function testDefaultOptions(): void + { + $form = $this->factory->create($this->getTestedType()); + + $view = $form->createView(); + + $this->assertFalse($view->children['type']->vars['required']); + $this->assertFalse($view->children['value']->vars['required']); + } + + protected function getTestedType(): string + { + return ChoiceType::class; + } + + /** + * NEXT_MAJOR: Remove this method. + * + * @return ChoiceType[] + */ + protected function getTypes(): array + { + return [ + new ChoiceType($this->createStub(TranslatorInterface::class)), + ]; + } +} diff --git a/tests/Form/Type/Filter/DateRangeTypeTest.php b/tests/Form/Type/Filter/DateRangeTypeTest.php new file mode 100644 index 0000000000..140915cd64 --- /dev/null +++ b/tests/Form/Type/Filter/DateRangeTypeTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Tests\Form\Type\Filter; + +use Sonata\AdminBundle\Form\Type\Filter\DateRangeType; +use Symfony\Component\Translation\TranslatorInterface; + +final class DateRangeTypeTest extends BaseTypeTest +{ + public function testDefaultOptions(): void + { + $form = $this->factory->create($this->getTestedType()); + + $view = $form->createView(); + + $this->assertFalse($view->children['type']->vars['required']); + $this->assertTrue($view->children['value']->vars['required']); + } + + protected function getTestedType(): string + { + return DateRangeType::class; + } + + /** + * NEXT_MAJOR: Remove this method. + * + * @return DateRangeType[] + */ + protected function getTypes(): array + { + return [ + new DateRangeType($this->createStub(TranslatorInterface::class)), + ]; + } +} diff --git a/tests/Form/Type/Filter/DateTimeRangeTypeTest.php b/tests/Form/Type/Filter/DateTimeRangeTypeTest.php index 93afa43263..3f5ee9d378 100644 --- a/tests/Form/Type/Filter/DateTimeRangeTypeTest.php +++ b/tests/Form/Type/Filter/DateTimeRangeTypeTest.php @@ -15,13 +15,22 @@ use Sonata\AdminBundle\Form\Type\Filter\DateTimeRangeType; use Sonata\Form\Type\DateTimeRangeType as FormDateTimeRangeType; -use Symfony\Component\Form\Extension\Core\Type\DateType; -use Symfony\Component\Form\Test\TypeTestCase; +use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Translation\TranslatorInterface; -final class DateTimeRangeTypeTest extends TypeTestCase +final class DateTimeRangeTypeTest extends BaseTypeTest { + public function testDefaultOptions(): void + { + $form = $this->factory->create($this->getTestedType()); + + $view = $form->createView(); + + $this->assertFalse($view->children['type']->vars['required']); + $this->assertTrue($view->children['value']->vars['required']); + } + public function testGetDefaultOptions(): void { $translator = $this->createStub(TranslatorInterface::class); @@ -36,8 +45,25 @@ public function testGetDefaultOptions(): void $expected = [ 'field_type' => FormDateTimeRangeType::class, - 'field_options' => ['date_format' => DateType::HTML5_FORMAT], + 'field_options' => ['field_options' => ['date_format' => DateTimeType::HTML5_FORMAT]], ]; $this->assertSame($expected, $options); } + + protected function getTestedType(): string + { + return DateTimeRangeType::class; + } + + /** + * NEXT_MAJOR: Remove this method. + * + * @return DateTimeRangeType[] + */ + protected function getTypes(): array + { + return [ + new DateTimeRangeType($this->createStub(TranslatorInterface::class)), + ]; + } } diff --git a/tests/Form/Type/Filter/DateTimeTypeTest.php b/tests/Form/Type/Filter/DateTimeTypeTest.php new file mode 100644 index 0000000000..a5916affee --- /dev/null +++ b/tests/Form/Type/Filter/DateTimeTypeTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Tests\Form\Type\Filter; + +use Sonata\AdminBundle\Form\Type\Filter\DateTimeType; +use Symfony\Component\Translation\TranslatorInterface; + +final class DateTimeTypeTest extends BaseTypeTest +{ + public function testDefaultOptions(): void + { + $form = $this->factory->create($this->getTestedType()); + + $view = $form->createView(); + + $this->assertFalse($view->children['type']->vars['required']); + $this->assertFalse($view->children['value']->vars['required']); + } + + protected function getTestedType(): string + { + return DateTimeType::class; + } + + /** + * NEXT_MAJOR: Remove this method. + * + * @return DateTimeType[] + */ + protected function getTypes(): array + { + return [ + new DateTimeType($this->createStub(TranslatorInterface::class)), + ]; + } +} diff --git a/tests/Form/Type/Filter/DateTypeTest.php b/tests/Form/Type/Filter/DateTypeTest.php new file mode 100644 index 0000000000..fc77800261 --- /dev/null +++ b/tests/Form/Type/Filter/DateTypeTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Tests\Form\Type\Filter; + +use Sonata\AdminBundle\Form\Type\Filter\DateType; +use Symfony\Component\Translation\TranslatorInterface; + +final class DateTypeTest extends BaseTypeTest +{ + public function testDefaultOptions(): void + { + $form = $this->factory->create($this->getTestedType()); + + $view = $form->createView(); + + $this->assertFalse($view->children['type']->vars['required']); + $this->assertFalse($view->children['value']->vars['required']); + } + + protected function getTestedType(): string + { + return DateType::class; + } + + /** + * NEXT_MAJOR: Remove this method. + * + * @return DateType[] + */ + protected function getTypes(): array + { + return [ + new DateType($this->createStub(TranslatorInterface::class)), + ]; + } +} diff --git a/tests/Form/Type/Filter/DefaultTypeTest.php b/tests/Form/Type/Filter/DefaultTypeTest.php new file mode 100644 index 0000000000..a89b521ee5 --- /dev/null +++ b/tests/Form/Type/Filter/DefaultTypeTest.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Tests\Form\Type\Filter; + +use Sonata\AdminBundle\Form\Type\Filter\DefaultType; + +final class DefaultTypeTest extends BaseTypeTest +{ + public function testDefaultOptions(): void + { + $form = $this->factory->create($this->getTestedType()); + + $view = $form->createView(); + + $this->assertFalse($view->children['type']->vars['required']); + $this->assertFalse($view->children['value']->vars['required']); + } + + protected function getTestedType(): string + { + return DefaultType::class; + } +} diff --git a/tests/Form/Type/Filter/NumberTypeTest.php b/tests/Form/Type/Filter/NumberTypeTest.php new file mode 100644 index 0000000000..f387ae426d --- /dev/null +++ b/tests/Form/Type/Filter/NumberTypeTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Tests\Form\Type\Filter; + +use Sonata\AdminBundle\Form\Type\Filter\NumberType; +use Symfony\Component\Translation\TranslatorInterface; + +final class NumberTypeTest extends BaseTypeTest +{ + public function testDefaultOptions(): void + { + $form = $this->factory->create($this->getTestedType()); + + $view = $form->createView(); + + $this->assertFalse($view->children['type']->vars['required']); + $this->assertFalse($view->children['value']->vars['required']); + } + + protected function getTestedType(): string + { + return NumberType::class; + } + + /** + * NEXT_MAJOR: Remove this method. + * + * @return NumberType[] + */ + protected function getTypes(): array + { + return [ + new NumberType($this->createStub(TranslatorInterface::class)), + ]; + } +}