add filtering on accompanying period + fix problems in gender filter

This commit is contained in:
2019-01-11 16:45:31 +01:00
parent 5591a9cfcc
commit f7ac607ff0
12 changed files with 485 additions and 10 deletions

View File

@@ -0,0 +1,95 @@
<?php
/*
* Copyright (C) 2017 Champs Libres Cooperative <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\PersonBundle\Tests\Export\Filter;
use Chill\MainBundle\Test\Export\AbstractFilterTest;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
/**
*
*
*/
class AccompanyingPeriodFilterTest extends AbstractFilterTest
{
/**
*
* @var \Chill\PersonBundle\Export\Filter\BirthdateFilter
*/
private $filter;
public function setUp()
{
static::bootKernel();
$container = static::$kernel->getContainer();
try {
$this->filter = $container->get('chill.person.export.filter_accompanying_period');
} catch (ServiceNotFoundException $e) {
$this->markTestSkipped("The current configuration does not use accompanying_periods");
}
}
public function getFilter()
{
return $this->filter;
}
public function getFormData()
{
return array(
array(
'date_from' => \DateTime::createFromFormat('Y-m-d', '2000-01-01'),
'date_to' => \DateTime::createFromFormat('Y-m-d', '2010-01-01')
)
);
}
public function getQueryBuilders()
{
if (static::$kernel === null) {
static::bootKernel();
}
$em = static::$kernel->getContainer()
->get('doctrine.orm.entity_manager');
return array(
$em->createQueryBuilder()
->select('person.firstName')
->from('ChillPersonBundle:Person', 'person'),
$em->createQueryBuilder()
->select('person.firstName')
->from('ChillPersonBundle:Person', 'person')
// add a dummy where clause
->where('person.firstname IS NOT NULL'),
$em->createQueryBuilder()
->select('count(IDENTITY(p))')
->from('ChillPersonBundle:Person', 'person')
// add a dummy where clause
->where('person.firstname IS NOT NULL'),
$em->createQueryBuilder()
->select('count(IDENTITY(p))')
->from('ChillPersonBundle:Person', 'person')
->join('person.accompanyingPeriods', 'accompanying_period')
// add a dummy where clause
->where('person.firstname IS NOT NULL')
);
}
}

View File

@@ -37,6 +37,12 @@ class GenderFilterTest extends AbstractFilterTest
{
static::bootKernel();
// add a fake request with a default locale (used in translatable string)
$prophet = new \Prophecy\Prophet;
$request = $prophet->prophesize();
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
$request->getLocale()->willReturn('fr');
$container = static::$kernel->getContainer();
$this->filter = $container->get('chill.person.export.filter_gender');
@@ -52,10 +58,13 @@ class GenderFilterTest extends AbstractFilterTest
{
return array(
array(
'accepted_genders' => Person::FEMALE_GENDER
'accepted_genders' => [ Person::FEMALE_GENDER ]
),
array(
'accepted_genders' => Person::MALE_GENDER
'accepted_genders' => [ Person::MALE_GENDER ]
),
array(
'accepted_genders' => [ Person::MALE_GENDER, Person::BOTH_GENDER ]
)
);
}