Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Form/Type/Filter/DateRangeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
],
]);
}
}
6 changes: 4 additions & 2 deletions src/Form/Type/Filter/DateTimeRangeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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],
],
]);
}
}
2 changes: 1 addition & 1 deletion src/Form/Type/Filter/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
]);
}
}
40 changes: 40 additions & 0 deletions tests/Form/Type/Filter/BaseTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* 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;
}
47 changes: 47 additions & 0 deletions tests/Form/Type/Filter/ChoiceTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* 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)),
];
}
}
47 changes: 47 additions & 0 deletions tests/Form/Type/Filter/DateRangeTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* 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)),
];
}
}
34 changes: 30 additions & 4 deletions tests/Form/Type/Filter/DateTimeRangeTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)),
];
}
}
47 changes: 47 additions & 0 deletions tests/Form/Type/Filter/DateTimeTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* 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)),
];
}
}
47 changes: 47 additions & 0 deletions tests/Form/Type/Filter/DateTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* 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)),
];
}
}
34 changes: 34 additions & 0 deletions tests/Form/Type/Filter/DefaultTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* 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;
}
}
Loading