This commit is contained in:
Julien Fastré 2022-10-10 20:53:49 +02:00
parent cbd7acebd5
commit 2f77deaa60
5 changed files with 79 additions and 79 deletions

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Form\Type; namespace Chill\MainBundle\Form\Type;
use Chill\MainBundle\Entity\LocationType; use Chill\MainBundle\Entity\LocationType;
@ -40,8 +49,7 @@ class Select2LocationTypeType extends AbstractType
->setDefault('label', 'Location type') ->setDefault('label', 'Location type')
->setDefault('label_attr', []) ->setDefault('label_attr', [])
->setDefault('multiple', false) ->setDefault('multiple', false)
->setAllowedTypes('multiple', ['bool']) ->setAllowedTypes('multiple', ['bool']);
;
} }
public function getBlockPrefix(): string public function getBlockPrefix(): string

View File

@ -57,8 +57,7 @@ class Select2UserLocationType extends AbstractType
->setDefault('label', 'Current location') ->setDefault('label', 'Current location')
->setDefault('label_attr', []) ->setDefault('label_attr', [])
->setDefault('multiple', false) ->setDefault('multiple', false)
->setAllowedTypes('multiple', ['bool']) ->setAllowedTypes('multiple', ['bool']);
;
} }
public function getBlockPrefix(): string public function getBlockPrefix(): string

View File

@ -29,6 +29,18 @@ use function is_string;
*/ */
abstract class AbstractAggregatorTest extends KernelTestCase abstract class AbstractAggregatorTest extends KernelTestCase
{ {
/**
* provide data for `testAliasDidNotDisappears`.
*/
public function dataProviderAliasDidNotDisappears()
{
foreach ($this->getQueryBuilders() as $qb) {
foreach ($this->getFormData() as $data) {
yield [clone $qb, $data];
}
}
}
/** /**
* provide data for `testAlterQuery`. * provide data for `testAlterQuery`.
*/ */
@ -63,18 +75,6 @@ abstract class AbstractAggregatorTest extends KernelTestCase
} }
} }
/**
* provide data for `testAliasDidNotDisappears`.
*/
public function dataProviderAliasDidNotDisappears()
{
foreach ($this->getQueryBuilders() as $qb) {
foreach ($this->getFormData() as $data) {
yield [clone $qb, $data];
}
}
}
/** /**
* Create an aggregator instance which will be used in tests. * Create an aggregator instance which will be used in tests.
* *
@ -107,6 +107,28 @@ abstract class AbstractAggregatorTest extends KernelTestCase
*/ */
abstract public function getQueryBuilders(); abstract public function getQueryBuilders();
/**
* Compare aliases array before and after that aggregator alter query.
*
* @dataProvider dataProviderAliasDidNotDisappears
*
* @return void
*/
public function testAliasDidNotDisappears(QueryBuilder $qb, array $data)
{
$aliases = $qb->getAllAliases();
$this->getAggregator()->alterQuery($qb, $data);
$alteredQuery = $qb->getAllAliases();
$this->assertGreaterThanOrEqual(count($aliases), count($alteredQuery));
foreach ($aliases as $alias) {
$this->assertContains($alias, $alteredQuery);
}
}
/** /**
* test the alteration of query by the filter. * test the alteration of query by the filter.
* *
@ -269,29 +291,4 @@ abstract class AbstractAggregatorTest extends KernelTestCase
'test that the title is not empty' 'test that the title is not empty'
); );
} }
/**
* Compare aliases array before and after that aggregator alter query
*
* @dataProvider dataProviderAliasDidNotDisappears
*
* @param QueryBuilder $qb
* @param array $data
* @return void
*/
public function testAliasDidNotDisappears(QueryBuilder $qb, array $data)
{
$aliases = $qb->getAllAliases();
$this->getAggregator()->alterQuery($qb, $data);
$alteredQuery = $qb->getAllAliases();
$this->assertGreaterThanOrEqual(count($aliases), count($alteredQuery));
foreach ($aliases as $alias) {
$this->assertContains($alias, $alteredQuery);
}
}
} }

View File

@ -40,6 +40,18 @@ abstract class AbstractFilterTest extends KernelTestCase
$this->prophet = $this->getProphet(); $this->prophet = $this->getProphet();
} }
/**
* provide data for `testAliasDidNotDisappears`.
*/
public function dataProviderAliasDidNotDisappears()
{
foreach ($this->getQueryBuilders() as $qb) {
foreach ($this->getFormData() as $data) {
yield [clone $qb, $data];
}
}
}
public function dataProviderAlterQuery() public function dataProviderAlterQuery()
{ {
foreach ($this->getQueryBuilders() as $qb) { foreach ($this->getQueryBuilders() as $qb) {
@ -56,18 +68,6 @@ abstract class AbstractFilterTest extends KernelTestCase
} }
} }
/**
* provide data for `testAliasDidNotDisappears`.
*/
public function dataProviderAliasDidNotDisappears()
{
foreach ($this->getQueryBuilders() as $qb) {
foreach ($this->getFormData() as $data) {
yield [clone $qb, $data];
}
}
}
/** /**
* Create a filter which will be used in tests. * Create a filter which will be used in tests.
* *
@ -99,6 +99,28 @@ abstract class AbstractFilterTest extends KernelTestCase
*/ */
abstract public function getQueryBuilders(); abstract public function getQueryBuilders();
/**
* Compare aliases array before and after that filter alter query.
*
* @dataProvider dataProviderAliasDidNotDisappears
*
* @return void
*/
public function testAliasDidNotDisappears(QueryBuilder $qb, array $data)
{
$aliases = $qb->getAllAliases();
$this->getFilter()->alterQuery($qb, $data);
$alteredQuery = $qb->getAllAliases();
$this->assertGreaterThanOrEqual(count($aliases), count($alteredQuery));
foreach ($aliases as $alias) {
$this->assertContains($alias, $alteredQuery);
}
}
/** /**
* test the alteration of query by the filter. * test the alteration of query by the filter.
* *
@ -211,28 +233,4 @@ abstract class AbstractFilterTest extends KernelTestCase
'test that the title is not empty' 'test that the title is not empty'
); );
} }
/**
* Compare aliases array before and after that filter alter query
*
* @dataProvider dataProviderAliasDidNotDisappears
*
* @param QueryBuilder $qb
* @param array $data
* @return void
*/
public function testAliasDidNotDisappears(QueryBuilder $qb, array $data)
{
$aliases = $qb->getAllAliases();
$this->getFilter()->alterQuery($qb, $data);
$alteredQuery = $qb->getAllAliases();
$this->assertGreaterThanOrEqual(count($aliases), count($alteredQuery));
foreach ($aliases as $alias) {
$this->assertContains($alias, $alteredQuery);
}
}
} }

View File

@ -20,7 +20,6 @@ use Symfony\Component\Form\FormBuilderInterface;
class AdministrativeLocationFilter implements FilterInterface class AdministrativeLocationFilter implements FilterInterface
{ {
private TranslatableStringHelper $translatableStringHelper; private TranslatableStringHelper $translatableStringHelper;
public function __construct( public function __construct(
@ -49,7 +48,6 @@ class AdministrativeLocationFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder->add('accepted_locations', Select2UserLocationType::class, [ $builder->add('accepted_locations', Select2UserLocationType::class, [
'label' => 'Accepted locations', 'label' => 'Accepted locations',
'label_attr' => [ 'label_attr' => [