update export & aggregator & filter to new api + add tests

This commit is contained in:
2017-01-12 15:25:21 +01:00
parent a7dfc5e1bd
commit 2997614a04
10 changed files with 459 additions and 26 deletions

View File

@@ -0,0 +1,93 @@
<?php
/*
* Copyright (C) 2017 Champs-Libres <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\ActivityBundle\Tests\Aggregator;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ReasonAggregatorTest extends AbstractAggregatorTest
{
/**
*
* @var \Chill\ActivityBundle\Export\Aggregator\ReasonAggregator
*/
private $aggregator;
public function setUp()
{
static::bootKernel();
$container = static::$kernel->getContainer();
$this->aggregator = $container->get('chill.activity.export.reason_aggregator');
// 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->get('request_stack')
->push($request->reveal());
}
public function getAggregator()
{
return $this->aggregator;
}
public function getFormData()
{
return array(
array('level' => 'reasons'),
array('level' => 'categories')
);
}
public function getQueryBuilders()
{
if (static::$kernel === null) {
static::bootKernel();
}
$em = static::$kernel->getContainer()
->get('doctrine.orm.entity_manager');
return array(
$em->createQueryBuilder()
->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity'),
$em->createQueryBuilder()
->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity')
->join('activity.reasons', 'reasons'),
$em->createQueryBuilder()
->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity')
->join('activity.reasons', 'reasons')
->join('reasons.category', 'category')
);
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Chill\ActivityBundle\Tests\Export\Export;
use Chill\MainBundle\Test\Export\AbstractExportTest;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CountActivityTest extends AbstractExportTest
{
/**
*
* @var
*/
private $export;
public function setUp()
{
static::bootKernel();
/* @var $container \Symfony\Component\DependencyInjection\ContainerInterface */
$container = self::$kernel->getContainer();
$this->export = $container->get('chill.activity.export.count_activity');
}
public function getExport()
{
return $this->export;
}
public function getFormData()
{
return array(
array()
);
}
public function getModifiersCombination()
{
return array(
array('activity'),
array('activity', 'person')
);
}
}

View File

@@ -0,0 +1,109 @@
<?php
/*
* Copyright (C) 2017 Champs-Libres <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\ActivityBundle\Tests\Filter;
use Chill\MainBundle\Test\Export\AbstractFilterTest;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ActivityReasonFilterTest extends AbstractFilterTest
{
/**
*
* @var \Chill\PersonBundle\Export\Filter\GenderFilter
*/
private $filter;
public function setUp()
{
static::bootKernel();
$container = static::$kernel->getContainer();
$this->filter = $container->get('chill.activity.export.reason_filter');
// 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->get('request_stack')
->push($request->reveal());
}
public function getFilter()
{
return $this->filter;
}
public function getFormData()
{
if (static::$kernel === null) {
static::bootKernel();
}
$em = static::$kernel->getContainer()
->get('doctrine.orm.entity_manager')
;
$reasons = $em->createQuery("SELECT reason "
. "FROM ChillActivityBundle:ActivityReason reason")
->getResult();
// generate an array of 5 different combination of results
for ($i=0; $i < 5; $i++) {
$r[] = array('reasons' => new ArrayCollection(array_splice($reasons, ($i + 1) * -1)));
}
return $r;
}
public function getQueryBuilders()
{
if (static::$kernel === null) {
static::bootKernel();
}
$em = static::$kernel->getContainer()
->get('doctrine.orm.entity_manager');
return array(
$em->createQueryBuilder()
->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity'),
$em->createQueryBuilder()
->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity')
->join('activity.reasons', 'reasons'),
$em->createQueryBuilder()
->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity')
->join('activity.reasons', 'reasons')
->join('reasons.category', 'category')
);
}
}