mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
fix folder name
This commit is contained in:
@@ -0,0 +1,526 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <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\Controller;
|
||||
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
|
||||
/**
|
||||
* Test the creation or deletion of accompanying periods
|
||||
*
|
||||
* The person on which the test is done has a (current) period opened (and not
|
||||
* closed) starting the 2015-01-05.
|
||||
*/
|
||||
class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
{
|
||||
/** @var \Symfony\Component\BrowserKit\Client */
|
||||
protected $client;
|
||||
|
||||
/** @var Person The person on which the form is applied*/
|
||||
protected $person;
|
||||
|
||||
/** @var \Doctrine\ORM\EntityManagerInterface */
|
||||
protected static $em;
|
||||
|
||||
const OPENING_INPUT = 'chill_personbundle_accompanyingperiod[openingDate]';
|
||||
const CLOSING_INPUT = 'chill_personbundle_accompanyingperiod[closingDate]';
|
||||
const CLOSING_MOTIVE_INPUT = 'chill_personbundle_accompanyingperiod[closingMotive]';
|
||||
|
||||
/**
|
||||
* Setup before the first test of this class (see phpunit doc)
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
static::bootKernel();
|
||||
static::$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup before each test method (see phpunit doc)
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
|
||||
$center = static::$em->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
|
||||
$this->person = (new Person(new \DateTime('2015-01-05')))
|
||||
->setFirstName('Roland')
|
||||
->setLastName('Gallorime')
|
||||
->setCenter($center)
|
||||
->setGender(Person::MALE_GENDER);
|
||||
|
||||
static::$em->persist($this->person);
|
||||
static::$em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* TearDown after each test method (see phpunit doc)
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
static::$em->refresh($this->person);
|
||||
static::$em->remove($this->person);
|
||||
|
||||
static::$em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array of periods (key openingDate, closingDate (optioal),
|
||||
* closingMotive) generate the periods in the db.
|
||||
*/
|
||||
protected function generatePeriods(array $periods)
|
||||
{
|
||||
foreach ($periods as $periodDef) {
|
||||
$period = new AccompanyingPeriod(new \DateTime($periodDef['openingDate']));
|
||||
|
||||
if (array_key_exists('closingDate', $periodDef)) {
|
||||
if (!array_key_exists('closingMotive', $periodDef)) {
|
||||
throw new \LogicalException('you must define a closing '
|
||||
. 'motive into your periods fixtures');
|
||||
}
|
||||
|
||||
$period->setClosingDate(new \DateTime($periodDef['closingDate']))
|
||||
->setClosingMotive($periodDef['closingMotive']);
|
||||
}
|
||||
|
||||
$this->person->addAccompanyingPeriod($period);
|
||||
static::$em->persist($period);
|
||||
}
|
||||
|
||||
static::$em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last value of a closing motive
|
||||
* @var \Symfony\Component\DomCrawler\Form The form
|
||||
* @return Chill\PersonBundle\Entity\AccompanyingPeriod The last value of closing
|
||||
* motive
|
||||
*/
|
||||
protected function getLastValueOnClosingMotive(\Symfony\Component\DomCrawler\Form $form)
|
||||
{
|
||||
$values = $form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->availableOptionValues();
|
||||
return end($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random closing motive
|
||||
* @return Chill\PersonBundle\Entity\AccompanyingPeriod The last closing motive
|
||||
*/
|
||||
protected function getRandomClosingMotive()
|
||||
{
|
||||
$motives = static::$em
|
||||
->getRepository('ChillPersonBundle:AccompanyingPeriod\ClosingMotive')
|
||||
->findAll();
|
||||
return end($motives);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the closing of a periods
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we fill the close form (at /en/person/[id]/accompanying-period/close
|
||||
* with : dateClosing: 2015-02-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to period view
|
||||
* And the next page should have a `.error` element present in page
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
public function testClosingCurrentPeriod()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/accompanying-period/close');
|
||||
|
||||
$form = $crawler->selectButton('Close accompanying period')->form();
|
||||
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue((new \DateTime('2015-02-01'))->format('d-m-Y'));
|
||||
|
||||
$cr = $this->client->submit($form);
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect(
|
||||
'/en/person/'.$this->person->getId().'/accompanying-period'),
|
||||
'the server redirects to /accompanying-period page');
|
||||
$this->assertGreaterThan(0, $this->client->followRedirect()
|
||||
->filter('.success')->count(),
|
||||
"a 'success' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the closing of a periods
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we fill the close form (at /en/person/[id]/accompanying-period/close
|
||||
* with : dateClosing: 2014-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to period view
|
||||
* And the next page should have a `.error` element present in page
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
public function testClosingCurrentPeriodWithDateClosingBeforeOpeningFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/accompanying-period/close');
|
||||
|
||||
$form = $crawler->selectButton('Close accompanying period')->form();
|
||||
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue((new \DateTime('2014-01-01'))->format('d-m-Y'));
|
||||
|
||||
$crawlerResponse = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stays on the /close page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse
|
||||
->filter('.error')->count(),
|
||||
"an '.error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the creation of a new period
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2014-12-31
|
||||
* with : dateOpening: 2014-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to period view
|
||||
*/
|
||||
public function testAddNewPeriodBeforeActual()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('31-12-2014');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-01-2014');
|
||||
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect(
|
||||
'/en/person/'.$this->person->getId().'/accompanying-period'),
|
||||
'the server redirects to /accompanying-period page');
|
||||
$this->assertGreaterThan(0, $this->client->followRedirect()
|
||||
->filter('.success')->count(),
|
||||
"a 'success' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a period with closing after current fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2015-02-01 (after 2015-01-05)
|
||||
* with : dateOpening: 2014-12-31
|
||||
* with : the last closing motive in list
|
||||
* Then the response should not redirect to any page
|
||||
* and an error element is shown
|
||||
*/
|
||||
public function testCreatePeriodWithClosingAfterCurrentFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('01-02-2015');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('31-12-2014');
|
||||
|
||||
$crawler = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a period after a current opened period fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2015-03-01
|
||||
* with : dateOpening: 2015-02-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should not redirect to any page
|
||||
* and an error element is shown
|
||||
*/
|
||||
public function testCreatePeriodWithOpeningAndClosingAfterCurrentFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('01-03-2015');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-02-2015');
|
||||
|
||||
$crawler = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* create a period with date end between another period must fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and that this person has another accompanying period between 2014-01-01 and 2014-12-31
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2014-16-01
|
||||
* with : dateOpening: 2013-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should not redirect
|
||||
* and a error element is shown on the response page
|
||||
*/
|
||||
public function testCreatePeriodWithDateEndBetweenAnotherPeriodFails()
|
||||
{
|
||||
$this->generatePeriods(array(
|
||||
[
|
||||
'openingDate' => '2014-01-01',
|
||||
'closingDate' => '2014-12-31',
|
||||
'closingMotive' => $this->getRandomClosingMotive()
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();;
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('31-12-2014');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-02-2015');
|
||||
|
||||
$crawlerResponse = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* create a period with date closing after opening fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2014-01-01 (before opening)
|
||||
* with : dateOpening: 2015-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to period view
|
||||
*/
|
||||
public function testCreatePeriodWithClosingBeforeOpeningFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('01-01-2014');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-01-2015');
|
||||
|
||||
$crawler = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* create a period with date closing and date opening inside another period
|
||||
* fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and that this person has another accompanying period between 2014-01-01 and 2014-12-31
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2014-02-01
|
||||
* with : dateOpening: 2014-03-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should not redirect
|
||||
* and a error element is shown on the response page
|
||||
*/
|
||||
public function testCreatePeriodAfterOpeningFails()
|
||||
{
|
||||
$this->generatePeriods(array(
|
||||
[
|
||||
'openingDate' => '2014-01-01',
|
||||
'closingDate' => '2014-12-31',
|
||||
'closingMotive' => $this->getRandomClosingMotive()
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('2014-02-01');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-03-2014');
|
||||
|
||||
$crawlerResponse = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a period with dateOpening between another period must fails
|
||||
*
|
||||
* Given that a person as an accompanying period opened since 2015-01-05
|
||||
* and that this person has another accompanying period between 2014-01-01 and 2014-12-31
|
||||
* and we create a new period
|
||||
* with : dateClosing: 2015-01-01
|
||||
* with : dateOpening: 2014-06-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should not redirect
|
||||
* and a error element is shown on the response page
|
||||
*/
|
||||
public function testCreatePeriodWithDateOpeningBetweenAnotherPeriodFails()
|
||||
{
|
||||
$this->generatePeriods(array(
|
||||
[
|
||||
'openingDate' => '2014-01-01',
|
||||
'closingDate' => '2014-12-31',
|
||||
'closingMotive' => $this->getRandomClosingMotive()
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Create an accompanying period')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue('2015-01-01');
|
||||
$form->get(self::OPENING_INPUT)
|
||||
->setValue('01-06-2014');
|
||||
|
||||
$crawlerResponse = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group reopening
|
||||
*/
|
||||
public function testReOpeningPeriod()
|
||||
{
|
||||
// test that re-opening a period which is opened does not work
|
||||
$this->client->request('GET',
|
||||
sprintf(
|
||||
'/fr/person/%d/accompanying-period/%d/re-open',
|
||||
$this->person->getId(),
|
||||
$this->person->getOpenedAccompanyingPeriod()->getId()
|
||||
)
|
||||
);
|
||||
$this->assertEquals(400, $this->client->getResponse()->getStatusCode(),
|
||||
"Test an error is returned on a period which cannot be reopened");
|
||||
|
||||
// close the current period
|
||||
$period = $this->person->getOpenedAccompanyingPeriod();
|
||||
$period->setClosingDate(new \DateTime('2015-02-05'));
|
||||
$this->person->close($period);
|
||||
|
||||
$this->generatePeriods(array(
|
||||
[
|
||||
'openingDate' => '2014-01-01',
|
||||
'closingDate' => '2014-12-31',
|
||||
'closingMotive' => $this->getRandomClosingMotive()
|
||||
]
|
||||
));
|
||||
|
||||
$periods = $this->person->getAccompanyingPeriodsOrdered();
|
||||
/* @var $criteria Criteria */
|
||||
$criteria = Criteria::create();
|
||||
//$criteria->where(Criteria::expr()->eq('openingDate', \DateTime::createFromFormat()))
|
||||
$firstPeriod = reset($periods);
|
||||
$lastPeriod = end($periods);
|
||||
|
||||
// test that it is not possible to open the first period in the list
|
||||
$this->client->request('GET',
|
||||
sprintf('/fr/person/%d/accompanying-period/%d/re-open', $this->person->getId(), reset($periods)->getId())
|
||||
);
|
||||
$this->assertEquals(400, $this->client->getResponse()->getStatusCode(),
|
||||
"Test an error is returned on the first period in the list");
|
||||
|
||||
// test that re-opening the last closed period works
|
||||
$crawler = $this->client->request('GET',
|
||||
sprintf('/fr/person/%d/accompanying-period/%d/re-open', $this->person->getId(), end($periods)->getId())
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
||||
|
||||
$links = $crawler->selectLink('Confirmer');
|
||||
|
||||
$this->assertEquals(1, $links->count(), "test the link 'confirmer' is present");
|
||||
|
||||
$this->client->click($links->link());
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect(),
|
||||
"Test the response is a redirection => the period is re-opened");
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class AdminControllerTest extends WebTestCase
|
||||
{
|
||||
public function testIndex()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/{_locale}/admin/person');
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 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\PersonBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PersonAddressControllerTest extends WebTestCase
|
||||
{
|
||||
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
|
||||
protected $em;
|
||||
|
||||
/** @var Person The person on which the test is executed */
|
||||
protected static $person;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Chill\MainBundle\Entity\PostalCode
|
||||
*/
|
||||
protected $postalCode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\BrowserKit\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$center = $em->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
|
||||
self::$person = (new Person())
|
||||
->setLastName("Tested person")
|
||||
->setFirstName("Test")
|
||||
->setCenter($center)
|
||||
->setGender(Person::MALE_GENDER);
|
||||
|
||||
$em->persist(self::$person);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare client and create a random person
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$this->em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$this->postalCode = $this->em->getRepository('ChillMainBundle:PostalCode')
|
||||
->findOneBy(array('code' => 1000));
|
||||
|
||||
$this->client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
}
|
||||
|
||||
public static function tearDownAfter()
|
||||
{
|
||||
$this->refreshPerson();
|
||||
$this->em->remove(self::$person);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the person from the db
|
||||
*/
|
||||
protected function refreshPerson()
|
||||
{
|
||||
self::$person = $this->em->getRepository('ChillPersonBundle:Person')
|
||||
->find(self::$person->getId());
|
||||
}
|
||||
|
||||
public function testEmptyList()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/person/'.
|
||||
self::$person->getId().'/address/list');
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful());
|
||||
|
||||
$this->assertEquals(1, $crawler->filter('td:contains("Pas d\'adresse renseignée")')
|
||||
->count(),
|
||||
"assert that a message say 'no address given'");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testEmptyList
|
||||
*/
|
||||
public function testCreateAddress()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/person/'.
|
||||
self::$person->getId().'/address/new');
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful());
|
||||
|
||||
// get the form and populate the most obvious fields (postcode will come later)
|
||||
$form = $crawler->filter('.bt-create')->form(array(
|
||||
'address[streetAddress1]' => 'Rue de la Paix, 50',
|
||||
'address[streetAddress2]' => $this->postalCode->getId(),
|
||||
'address[validFrom]' => '15-01-2016'
|
||||
));
|
||||
|
||||
// select a random postal code
|
||||
$values = $form['address[postCode]']->availableOptionValues();
|
||||
$form['address[postCode]']->setValue($values[array_rand($values)]);
|
||||
|
||||
$this->client->submit($form);
|
||||
|
||||
$crawler = $this->client->followRedirect();
|
||||
|
||||
$this->assertRegexp('|/fr/person/[0-9]{1,}/address/list|',
|
||||
$this->client->getHistory()->current()->getUri(),
|
||||
"assert that the current page is on |/fr/person/[0-9]{1,}/address/list|");
|
||||
$this->assertEquals(1, $crawler
|
||||
->filter('div.flash_message.success')
|
||||
->count(),
|
||||
"Asserting that the response page contains a success flash message");
|
||||
$this->assertEquals(1, $crawler
|
||||
->filter('td:contains("Rue de la Paix, 50")')
|
||||
->count(),
|
||||
"Asserting that the page contains the new address");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateAddress
|
||||
*/
|
||||
public function testUpdateAddress()
|
||||
{
|
||||
$this->refreshPerson();
|
||||
$address = self::$person->getLastAddress();
|
||||
|
||||
$crawler = $this->client->request('GET', '/fr/person/'.self::$person->getId()
|
||||
.'/address/'.$address->getId().'/edit');
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $crawler->filter('.bt-save')->form(array(
|
||||
'address[streetAddress1]' => 'Rue du Trou Normand, 15',
|
||||
'address[validFrom]' => '15-01-2015'
|
||||
));
|
||||
|
||||
$this->client->submit($form);
|
||||
|
||||
$crawler = $this->client->followRedirect();
|
||||
|
||||
$this->assertRegexp('|/fr/person/[0-9]{1,}/address/list|',
|
||||
$this->client->getHistory()->current()->getUri(),
|
||||
"assert that the current page is on |/fr/person/[0-9]{1,}/address/list|");
|
||||
$this->assertGreaterThan(0, $crawler
|
||||
->filter('div.flash_message.success')
|
||||
->count(),
|
||||
"Asserting that the response page contains a success flash message");
|
||||
$this->assertEquals(1, $crawler
|
||||
->filter('td:contains("Rue du Trou Normand")')
|
||||
->count(),
|
||||
"Asserting that the page contains the new address");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <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\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\DomCrawler\Form;
|
||||
|
||||
/**
|
||||
* Test creation and deletion for persons
|
||||
*/
|
||||
class PersonControllerCreateTest extends WebTestCase
|
||||
{
|
||||
|
||||
const FIRSTNAME_INPUT = 'chill_personbundle_person_creation[firstName]';
|
||||
const LASTNAME_INPUT = "chill_personbundle_person_creation[lastName]";
|
||||
const GENDER_INPUT = "chill_personbundle_person_creation[gender]";
|
||||
const BIRTHDATE_INPUT = "chill_personbundle_person_creation[birthdate]";
|
||||
const CREATEDATE_INPUT = "chill_personbundle_person_creation[creation_date]";
|
||||
const CENTER_INPUT = "chill_personbundle_person_creation[center]";
|
||||
|
||||
const LONG_TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosq. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta.Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosq.";
|
||||
|
||||
/**
|
||||
* return an authenticated client, useful for submitting form
|
||||
*
|
||||
* @return \Symfony\Component\BrowserKit\Client
|
||||
*/
|
||||
private function getAuthenticatedClient($username = 'center a_social')
|
||||
{
|
||||
return static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => $username,
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Form $creationForm
|
||||
*/
|
||||
private function fillAValidCreationForm(Form &$creationForm,
|
||||
$firstname = 'God', $lastname = 'Jesus')
|
||||
{
|
||||
$creationForm->get(self::FIRSTNAME_INPUT)->setValue($firstname);
|
||||
$creationForm->get(self::LASTNAME_INPUT)->setValue($lastname);
|
||||
$creationForm->get(self::GENDER_INPUT)->select("man");
|
||||
$date = new \DateTime('1947-02-01');
|
||||
$creationForm->get(self::BIRTHDATE_INPUT)->setValue($date->format('d-m-Y'));
|
||||
|
||||
return $creationForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the "add a person" page : test that required elements are present
|
||||
*
|
||||
* see https://redmine.champs-libres.coop/projects/chillperson/wiki/Test_plan_for_page_%22add_a_person%22
|
||||
*/
|
||||
public function testAddAPersonPage()
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
|
||||
$crawler = $client->request('GET', '/fr/person/new');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful(),
|
||||
"The page is accessible at the URL /{_locale}/person/new");
|
||||
$form = $crawler->selectButton("Ajouter la personne")->form();
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\DomCrawler\Form', $form,
|
||||
'The page contains a butto ');
|
||||
$this->assertTrue($form->has(self::FIRSTNAME_INPUT),
|
||||
'The page contains a "firstname" input');
|
||||
$this->assertTrue($form->has(self::LASTNAME_INPUT),
|
||||
'The page contains a "lastname" input');
|
||||
$this->assertTrue($form->has(self::GENDER_INPUT),
|
||||
'The page contains a "gender" input');
|
||||
$this->assertTrue($form->has(self::BIRTHDATE_INPUT),
|
||||
'The page has a "date of birth" input');
|
||||
$this->assertTrue($form->has(self::CREATEDATE_INPUT),
|
||||
'The page contains a "creation date" input');
|
||||
|
||||
$genderType = $form->get(self::GENDER_INPUT);
|
||||
$this->assertEquals('radio', $genderType->getType(),
|
||||
'The gender input has two radio button: man and women');
|
||||
$this->assertEquals(2, count($genderType->availableOptionValues()),
|
||||
'The gender input has two radio button: man and women');
|
||||
$this->assertTrue(in_array('man', $genderType->availableOptionValues()),
|
||||
'gender has "homme" option');
|
||||
$this->assertTrue(in_array('woman', $genderType->availableOptionValues()),
|
||||
'gender has "femme" option');
|
||||
$this->assertFalse($genderType->hasValue(), 'The gender input is not checked');
|
||||
|
||||
$today = new \DateTime();
|
||||
$this->assertEquals($today->format('d-m-Y'), $form->get(self::CREATEDATE_INPUT)
|
||||
->getValue(), 'The creation date input has the current date by default');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Form $form
|
||||
* @depends testAddAPersonPage
|
||||
*/
|
||||
public function testFirstnameTooLong(Form $form)
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
$this->fillAValidCreationForm($form);
|
||||
$form->get(self::FIRSTNAME_INPUT)->setValue(mb_substr(self::LONG_TEXT, 0, 256));
|
||||
$crawler = $client->submit($form);
|
||||
|
||||
$this->assertEquals(1, $crawler->filter('.error')->count(),
|
||||
"An error message is shown if we fill more than 255 characters in firstname");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Form $form
|
||||
* @depends testAddAPersonPage
|
||||
*/
|
||||
public function testLastnameTooLong(Form $form)
|
||||
{
|
||||
$this->fillAValidCreationForm($form);
|
||||
$form->get(self::LASTNAME_INPUT)->setValue(mb_substr(self::LONG_TEXT, 0, 256));
|
||||
$crawler = $this->getAuthenticatedClient()->submit($form);
|
||||
|
||||
$this->assertEquals(1, $crawler->filter('.error')->count(),
|
||||
"An error message is shown if we fill more than 255 characters in lastname");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Form $form
|
||||
* @depends testAddAPersonPage
|
||||
*/
|
||||
public function testGenderIsNull(Form $form)
|
||||
{
|
||||
$this->fillAValidCreationForm($form);
|
||||
$form->get(self::GENDER_INPUT)->disableValidation()->setValue(NULL);
|
||||
$crawler = $this->getAuthenticatedClient()->submit($form);
|
||||
|
||||
$this->assertEquals(1, $crawler->filter('.error')->count(),
|
||||
'A message is shown if gender is not set');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the creation of a valid person.
|
||||
*
|
||||
* @param Form $form
|
||||
* @return string The id of the created person
|
||||
* @depends testAddAPersonPage
|
||||
*/
|
||||
public function testValidForm(Form $form)
|
||||
{
|
||||
$this->fillAValidCreationForm($form);
|
||||
$client = $this->getAuthenticatedClient();
|
||||
$client->submit($form);
|
||||
|
||||
$this->assertTrue($client->getResponse()->isRedirect(),
|
||||
"a valid form redirect to url /{_locale}/person/{personId}/general/edit");
|
||||
$client->followRedirect();
|
||||
|
||||
// visualize regexp here : http://jex.im/regulex/#!embed=false&flags=&re=%2Ffr%2Fperson%2F[1-9][0-9]*%2Fgeneral%2Fedit%24
|
||||
$this->assertRegExp('|/fr/person/[1-9][0-9]*/general/edit$|',
|
||||
$client->getHistory()->current()->getUri(),
|
||||
"a valid form redirect to url /{_locale}/person/{personId}/general/edit");
|
||||
|
||||
$regexPersonId = null;
|
||||
preg_match("/person\/([1-9][0-9]*)\/general\/edit$/",
|
||||
$client->getHistory()->current()->getUri(), $regexPersonId);
|
||||
return $regexPersonId[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if, for a given person if its person view page (at the url
|
||||
* fr/person/$personID/general) is accessible
|
||||
*
|
||||
* @param string|int $personId The is of the person
|
||||
* @depends testValidForm
|
||||
*/
|
||||
public function testPersonViewAccessible($personId)
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
$client->request('GET', '/fr/person/'.$personId.'/general');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful(),
|
||||
"The person view page is accessible at the URL"
|
||||
. "/{_locale}/person/{personID}/general");
|
||||
}
|
||||
|
||||
/**
|
||||
* test adding a person with a user with multi center
|
||||
* is valid
|
||||
*/
|
||||
public function testValidFormWithMultiCenterUser()
|
||||
{
|
||||
$client = $this->getAuthenticatedClient('multi_center');
|
||||
|
||||
$crawler = $client->request('GET', '/fr/person/new');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful(),
|
||||
"The page is accessible at the URL /{_locale}/person/new");
|
||||
$form = $crawler->selectButton("Ajouter la personne")->form();
|
||||
|
||||
$this->fillAValidCreationForm($form, 'roger', 'rabbit');
|
||||
|
||||
$this->assertTrue($form->has(self::CENTER_INPUT),
|
||||
'The page contains a "center" input');
|
||||
$centerInput = $form->get(self::CENTER_INPUT);
|
||||
$availableValues = $centerInput->availableOptionValues();
|
||||
$lastCenterInputValue = end($availableValues);
|
||||
$centerInput->setValue($lastCenterInputValue);
|
||||
|
||||
$client->submit($form);
|
||||
|
||||
$this->assertTrue($client->getResponse()->isRedirect(),
|
||||
"a valid form redirect to url /{_locale}/person/{personId}/general/edit");
|
||||
$client->followRedirect();
|
||||
$this->assertRegExp('|/fr/person/[1-9][0-9]*/general/edit$|',
|
||||
$client->getHistory()->current()->getUri(),
|
||||
"a valid form redirect to url /{_locale}/person/{personId}/general/edit");
|
||||
|
||||
}
|
||||
|
||||
public function testReviewExistingDetectionInversedLastNameWithFirstName()
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
|
||||
$crawler = $client->request('GET', '/fr/person/new');
|
||||
|
||||
//test the page is loaded before continuing
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $crawler->selectButton("Ajouter la personne")->form();
|
||||
$form = $this->fillAValidCreationForm($form, 'Charline', 'dd');
|
||||
$client->submit($form);
|
||||
|
||||
$this->assertContains('Depardieu', $client->getCrawler()->text(),
|
||||
"check that the page has detected the lastname of a person existing in database");
|
||||
|
||||
//inversion
|
||||
$form = $crawler->selectButton("Ajouter la personne")->form();
|
||||
$form = $this->fillAValidCreationForm($form, 'dd', 'Charline');
|
||||
$client->submit($form);
|
||||
|
||||
$this->assertContains('Depardieu', $client->getCrawler()->text(),
|
||||
"check that the page has detected the lastname of a person existing in database");
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
static::bootKernel();
|
||||
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
//remove two people created during test
|
||||
$jesus = $em->getRepository('ChillPersonBundle:Person')
|
||||
->findOneBy(array('firstName' => 'God'));
|
||||
if ($jesus !== NULL) {
|
||||
$em->remove($jesus);
|
||||
}
|
||||
|
||||
$jesus2 = $em->getRepository('ChillPersonBundle:Person')
|
||||
->findOneBy(array('firstName' => 'roger'));
|
||||
if ($jesus2 !== NULL) {
|
||||
$em->remove($jesus2);
|
||||
}
|
||||
$em->flush();
|
||||
}
|
||||
}
|
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a suite of a modules, Chill is a software for social workers
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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\Controller;
|
||||
|
||||
//ini_set('memory_limit', '-1');
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* Test the edition of persons
|
||||
*
|
||||
* As I am logged in as "center a_social"
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PersonControllerUpdateTest extends WebTestCase
|
||||
{
|
||||
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
|
||||
private $em;
|
||||
|
||||
/** @var Person The person on which the test is executed */
|
||||
private $person;
|
||||
|
||||
/** @var string The url using for editing the person's information */
|
||||
private $editUrl;
|
||||
|
||||
/** @var string The url using for seeing the person's information */
|
||||
private $viewUrl;
|
||||
|
||||
/**
|
||||
* Prepare client and create a random person
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$this->em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$center = $this->em->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
|
||||
$this->person = (new Person())
|
||||
->setLastName("My Beloved")
|
||||
->setFirstName("Jesus")
|
||||
->setCenter($center)
|
||||
->setGender(Person::MALE_GENDER);
|
||||
|
||||
$this->em->persist($this->person);
|
||||
$this->em->flush();
|
||||
|
||||
$this->editUrl = '/en/person/'.$this->person->getId().'/general/edit';
|
||||
$this->viewUrl = '/en/person/'.$this->person->getId().'/general';
|
||||
|
||||
$this->client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the person from the db
|
||||
*/
|
||||
protected function refreshPerson()
|
||||
{
|
||||
$this->person = $this->em->getRepository('ChillPersonBundle:Person')
|
||||
->find($this->person->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the edit page are accessible
|
||||
*/
|
||||
public function testEditPageIsSuccessful()
|
||||
{
|
||||
$this->client->request('GET', $this->editUrl);
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful(),
|
||||
"The person edit form is accessible");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configurable fields are present
|
||||
*
|
||||
* @group configurable_fields
|
||||
*/
|
||||
public function testHiddenFielsArePresent()
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
|
||||
$configurables = array('placeOfBirth', 'phonenumber', 'email',
|
||||
'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus');
|
||||
$form = $crawler->selectButton('Submit')->form(); //;
|
||||
|
||||
foreach($configurables as $key) {
|
||||
$this->assertTrue($form->has('chill_personbundle_person['.$key.']'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the edit page of a given person is not accessible for a user
|
||||
* of another center of the person
|
||||
*/
|
||||
public function testEditPageDeniedForUnauthorized_OutsideCenter()
|
||||
{
|
||||
$client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center b_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
|
||||
$client->request('GET', $this->editUrl);
|
||||
$this->assertEquals(403, $client->getResponse()->getStatusCode(),
|
||||
"The edit page of a person of a center A must not be accessible for user of center B");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the edit page of a given person are not accessible for an
|
||||
* administrative user
|
||||
*/
|
||||
public function testEditPageDeniedForUnauthorized_InsideCenter()
|
||||
{
|
||||
$client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center a_administrative',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
|
||||
$client->request('GET', $this->editUrl);
|
||||
$this->assertEquals(403, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the edition of a field
|
||||
*
|
||||
* Given I fill the field with $value
|
||||
* And I submit the form
|
||||
* Then I am redirected to the 'general' page
|
||||
* And the person is updated in the db
|
||||
*
|
||||
* @dataProvider validTextFieldsProvider
|
||||
* @param string $field
|
||||
* @param string $value
|
||||
* @param \Closure $callback
|
||||
*/
|
||||
public function testEditTextField($field, $value, \Closure $callback)
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
|
||||
$form = $crawler->selectButton('Submit')
|
||||
->form();
|
||||
//transform countries into value if needed
|
||||
switch ($field) {
|
||||
case 'nationality':
|
||||
case 'countryOfBirth':
|
||||
if ($value !== NULL) {
|
||||
$country = $this->em->getRepository('ChillMainBundle:Country')
|
||||
->findOneByCountryCode($value);
|
||||
$transformedValue = $country->getId();
|
||||
} else {
|
||||
$transformedValue = NULL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$transformedValue = $value;
|
||||
}
|
||||
|
||||
$form->get('chill_personbundle_person['.$field. ']')
|
||||
->setValue($transformedValue);
|
||||
|
||||
$this->client->submit($form);
|
||||
$this->refreshPerson();
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect($this->viewUrl),
|
||||
'the page is redirected to general view');
|
||||
$this->assertEquals($value, $callback($this->person),
|
||||
'the value '.$field.' is updated in db');
|
||||
|
||||
$crawler = $this->client->followRedirect();
|
||||
$this->assertGreaterThan(0, $crawler->filter('.success')->count(),
|
||||
'a element .success is shown');
|
||||
|
||||
if($field == 'birthdate' or $field == 'memo' or $field == 'countryOfBirth' or $field == 'nationality'
|
||||
or $field == 'gender') {
|
||||
// we do not perform test on the web page contents.
|
||||
} else {
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("'.$value.'")')->count());
|
||||
}
|
||||
}
|
||||
|
||||
public function testEditLanguages()
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
$selectedLanguages = array('en', 'an', 'bbj');
|
||||
|
||||
$form = $crawler->selectButton('Submit')
|
||||
->form();
|
||||
$form->get('chill_personbundle_person[spokenLanguages]')
|
||||
->setValue($selectedLanguages);
|
||||
|
||||
$this->client->submit($form);
|
||||
$this->refreshPerson();
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect($this->viewUrl),
|
||||
'the page is redirected to /general view');
|
||||
//retrieve languages codes present in person
|
||||
foreach($this->person->getSpokenLanguages() as $lang){
|
||||
$languagesCodesPresents[] = $lang->getId();
|
||||
}
|
||||
$this->assertEquals(asort($selectedLanguages), asort($languagesCodesPresents),
|
||||
'the person speaks the expected languages');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test tbe detection of invalid data during the update procedure
|
||||
*
|
||||
* @dataProvider providesInvalidFieldsValues
|
||||
* @param string $field
|
||||
* @param string $value
|
||||
*/
|
||||
public function testInvalidFields($field, $value)
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
|
||||
$form = $crawler->selectButton('Submit')
|
||||
->form();
|
||||
$form->get('chill_personbundle_person['.$field.']')
|
||||
->setValue($value);
|
||||
|
||||
$crawler = $this->client->submit($form);
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the page is not redirected to /general');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
'a element .error is shown');
|
||||
}
|
||||
|
||||
/**
|
||||
* provide valid values to test, with field name and
|
||||
* a function to find the value back from person entity
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function validTextFieldsProvider()
|
||||
{
|
||||
return array(
|
||||
['firstName', 'random Value', function(Person $person) { return $person->getFirstName(); } ],
|
||||
['lastName' , 'random Value', function(Person $person) { return $person->getLastName(); } ],
|
||||
['placeOfBirth', 'none place', function(Person $person) { return $person->getPlaceOfBirth(); }],
|
||||
['birthdate', '15-12-1980', function(Person $person) { return $person->getBirthdate()->format('d-m-Y'); }],
|
||||
['phonenumber', '0123456789', function(Person $person) { return $person->getPhonenumber(); }],
|
||||
['memo', 'jfkdlmq jkfldmsq jkmfdsq', function(Person $person) { return $person->getMemo(); }],
|
||||
['countryOfBirth', 'BE', function(Person $person) { return $person->getCountryOfBirth()->getCountryCode(); }],
|
||||
['nationality', 'FR', function(Person $person) { return $person->getNationality()->getCountryCode(); }],
|
||||
['placeOfBirth', '', function(Person $person) { return $person->getPlaceOfBirth(); }],
|
||||
['birthdate', '', function(Person $person) { return $person->getBirthdate(); }],
|
||||
['phonenumber', '', function(Person $person) { return $person->getPhonenumber(); }],
|
||||
['memo', '', function(Person $person) { return $person->getMemo(); }],
|
||||
['countryOfBirth', NULL, function(Person $person) { return $person->getCountryOfBirth(); }],
|
||||
['nationality', NULL, function(Person $person) { return $person->getNationality(); }],
|
||||
['gender', Person::FEMALE_GENDER, function(Person $person) { return $person->getGender(); }],
|
||||
['maritalStatus', NULL, function(Person $person) {return $person->getMaritalStatus(); }]
|
||||
);
|
||||
}
|
||||
|
||||
public function providesInvalidFieldsValues()
|
||||
{
|
||||
return array(
|
||||
['firstName', $this->getVeryLongText()],
|
||||
['lastName', $this->getVeryLongText()],
|
||||
['firstName', ''],
|
||||
['lastName', ''],
|
||||
['birthdate', 'false date']
|
||||
);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->refreshPerson();
|
||||
$this->em->remove($this->person);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
private function getVeryLongText()
|
||||
{
|
||||
return <<<EOT
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse molestie at enim id auctor. Vivamus malesuada elit ipsum, ac mollis ex facilisis sit amet. Phasellus accumsan, quam ut aliquet accumsan, augue ligula consequat erat, condimentum iaculis orci magna egestas eros. In vel blandit sapien. Duis ut dui vitae tortor iaculis malesuada vitae vitae lorem. Morbi efficitur dolor orci, a rhoncus urna blandit quis. Aenean at placerat dui, ut tincidunt nulla. In ultricies tempus ligula ac rutrum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce urna nibh, placerat vel auctor sed, maximus quis magna. Vivamus quam ante, consectetur vel feugiat quis, aliquet id ante. Integer gravida erat dignissim ante commodo mollis. Donec imperdiet mauris elit, nec blandit dolor feugiat ut. Proin iaculis enim ut tortor pretium commodo. Etiam aliquet hendrerit dolor sed fringilla. Vestibulum facilisis nibh tincidunt dui egestas, vitae congue mi imperdiet. Duis vulputate ultricies lectus id cursus. Fusce bibendum sem dignissim, bibendum purus quis, mollis ex. Cras ac est justo. Duis congue mattis ipsum, vitae sagittis justo dictum sit amet. Duis aliquam pharetra sem, non laoreet ante laoreet ac. Mauris ornare mi tempus rutrum consequat.
|
||||
EOT;
|
||||
}
|
||||
}
|
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a suite of a modules, Chill is a software for social workers
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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\Controller;
|
||||
|
||||
//ini_set('memory_limit', '-1');
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* Test the edition of persons
|
||||
*
|
||||
* As I am logged in as "center a_social"
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
|
||||
{
|
||||
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
|
||||
private $em;
|
||||
|
||||
/** @var Person The person on which the test is executed */
|
||||
private $person;
|
||||
|
||||
/** @var string The url using for editing the person's information */
|
||||
private $editUrl;
|
||||
|
||||
/** @var string The url using for seeing the person's information */
|
||||
private $viewUrl;
|
||||
|
||||
/**
|
||||
* Prepare client and create a random person
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel(array('environment' => 'test_with_hidden_fields'));
|
||||
|
||||
$this->em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$center = $this->em->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
|
||||
$this->person = (new Person())
|
||||
->setLastName("My Beloved")
|
||||
->setFirstName("Jesus")
|
||||
->setCenter($center)
|
||||
->setGender(Person::MALE_GENDER);
|
||||
|
||||
$this->em->persist($this->person);
|
||||
$this->em->flush();
|
||||
|
||||
$this->editUrl = '/en/person/'.$this->person->getId().'/general/edit';
|
||||
$this->viewUrl = '/en/person/'.$this->person->getId().'/general';
|
||||
|
||||
$this->client = static::createClient(
|
||||
array(
|
||||
'environment' => 'test_with_hidden_fields'
|
||||
),
|
||||
array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the person from the db
|
||||
*/
|
||||
protected function refreshPerson()
|
||||
{
|
||||
$this->person = $this->em->getRepository('ChillPersonBundle:Person')
|
||||
->find($this->person->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the edit page are accessible
|
||||
*/
|
||||
public function testEditPageIsSuccessful()
|
||||
{
|
||||
$this->client->request('GET', $this->editUrl);
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful(),
|
||||
"The person edit form is accessible");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configurable fields are absent
|
||||
*
|
||||
* @group configurable_fields
|
||||
*/
|
||||
public function testHiddenFielsAreAbsent()
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
|
||||
$configurables = array('placeOfBirth', 'phonenumber', 'email',
|
||||
'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus');
|
||||
$form = $crawler->selectButton('Submit')->form(); //;
|
||||
|
||||
foreach($configurables as $key) {
|
||||
$this->assertFalse($form->has('chill_personbundle_person['.$key.']'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the edition of a field
|
||||
*
|
||||
* Given I fill the field with $value
|
||||
* And I submit the form
|
||||
* Then I am redirected to the 'general' page
|
||||
* And the person is updated in the db
|
||||
*
|
||||
* @dataProvider validTextFieldsProvider
|
||||
* @param string $field
|
||||
* @param string $value
|
||||
* @param \Closure $callback
|
||||
*/
|
||||
public function testEditTextField($field, $value, \Closure $callback)
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
|
||||
$form = $crawler->selectButton('Submit')
|
||||
->form();
|
||||
//transform countries into value if needed
|
||||
switch ($field) {
|
||||
case 'nationality':
|
||||
case 'countryOfBirth':
|
||||
if ($value !== NULL) {
|
||||
$country = $this->em->getRepository('ChillMainBundle:Country')
|
||||
->findOneByCountryCode($value);
|
||||
$transformedValue = $country->getId();
|
||||
} else {
|
||||
$transformedValue = NULL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$transformedValue = $value;
|
||||
}
|
||||
|
||||
$form->get('chill_personbundle_person['.$field. ']')
|
||||
->setValue($transformedValue);
|
||||
|
||||
$this->client->submit($form);
|
||||
$this->refreshPerson();
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect($this->viewUrl),
|
||||
'the page is redirected to general view');
|
||||
$this->assertEquals($value, $callback($this->person),
|
||||
'the value '.$field.' is updated in db');
|
||||
|
||||
$crawler = $this->client->followRedirect();
|
||||
$this->assertGreaterThan(0, $crawler->filter('.success')->count(),
|
||||
'a element .success is shown');
|
||||
|
||||
if($field == 'birthdate' or $field == 'memo' or $field == 'countryOfBirth' or $field == 'nationality'
|
||||
or $field == 'gender') {
|
||||
// we do not perform test on the web page contents.
|
||||
} else {
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("'.$value.'")')->count());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* provide valid values to test, with field name and
|
||||
* a function to find the value back from person entity
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function validTextFieldsProvider()
|
||||
{
|
||||
return array(
|
||||
['firstName', 'random Value', function(Person $person) { return $person->getFirstName(); } ],
|
||||
['lastName' , 'random Value', function(Person $person) { return $person->getLastName(); } ],
|
||||
['birthdate', '15-12-1980', function(Person $person) { return $person->getBirthdate()->format('d-m-Y'); }],
|
||||
['memo', 'jfkdlmq jkfldmsq jkmfdsq', function(Person $person) { return $person->getMemo(); }],
|
||||
['birthdate', '', function(Person $person) { return $person->getBirthdate(); }],
|
||||
['gender', Person::FEMALE_GENDER, function(Person $person) { return $person->getGender(); }],
|
||||
);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->refreshPerson();
|
||||
$this->em->remove($this->person);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
private function getVeryLongText()
|
||||
{
|
||||
return <<<EOT
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse molestie at enim id auctor. Vivamus malesuada elit ipsum, ac mollis ex facilisis sit amet. Phasellus accumsan, quam ut aliquet accumsan, augue ligula consequat erat, condimentum iaculis orci magna egestas eros. In vel blandit sapien. Duis ut dui vitae tortor iaculis malesuada vitae vitae lorem. Morbi efficitur dolor orci, a rhoncus urna blandit quis. Aenean at placerat dui, ut tincidunt nulla. In ultricies tempus ligula ac rutrum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce urna nibh, placerat vel auctor sed, maximus quis magna. Vivamus quam ante, consectetur vel feugiat quis, aliquet id ante. Integer gravida erat dignissim ante commodo mollis. Donec imperdiet mauris elit, nec blandit dolor feugiat ut. Proin iaculis enim ut tortor pretium commodo. Etiam aliquet hendrerit dolor sed fringilla. Vestibulum facilisis nibh tincidunt dui egestas, vitae congue mi imperdiet. Duis vulputate ultricies lectus id cursus. Fusce bibendum sem dignissim, bibendum purus quis, mollis ex. Cras ac est justo. Duis congue mattis ipsum, vitae sagittis justo dictum sit amet. Duis aliquam pharetra sem, non laoreet ante laoreet ac. Mauris ornare mi tempus rutrum consequat.
|
||||
EOT;
|
||||
}
|
||||
}
|
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@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\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
/**
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Marc Ducobu <marc.ducobu@champs-libres.coop>
|
||||
*/
|
||||
class PersonControllerViewTest extends WebTestCase
|
||||
{
|
||||
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
|
||||
private $em;
|
||||
|
||||
/** @var Person A person used on which to run the test */
|
||||
private $person;
|
||||
|
||||
/** @var String The url to view the person details */
|
||||
private $viewUrl;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$this->em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$center = $this->em->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
|
||||
$this->person = (new Person())
|
||||
->setLastName("Tested Person")
|
||||
->setFirstName("Réginald")
|
||||
->setCenter($center)
|
||||
->setGender(Person::MALE_GENDER);
|
||||
|
||||
$this->em->persist($this->person);
|
||||
$this->em->flush();
|
||||
|
||||
$this->viewUrl = '/en/person/'.$this->person->getId().'/general';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the view page is accessible
|
||||
*
|
||||
* @group configurable_fields
|
||||
*/
|
||||
public function testViewPerson()
|
||||
{
|
||||
$client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
|
||||
$crawler = $client->request('GET', $this->viewUrl);
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("Tested Person")')->count());
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginald")')->count());
|
||||
$this->assertContains('Email addresses', $crawler->text());
|
||||
$this->assertContains('Phonenumber', $crawler->text());
|
||||
$this->assertContains('Langues parlées', $crawler->text());
|
||||
$this->assertContains(/* Etat */ 'civil', $crawler->text());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the view page of a given person is not accessible for a user
|
||||
* of another center of the person
|
||||
*/
|
||||
public function testViewPersonAccessDeniedForUnauthorized()
|
||||
{
|
||||
$client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center b_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
|
||||
$client->request('GET', $this->viewUrl);
|
||||
$this->assertEquals(403, $client->getResponse()->getStatusCode(),
|
||||
"The view page of a person of a center A must not be accessible for user of center B");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the person from the db
|
||||
*/
|
||||
protected function refreshPerson()
|
||||
{
|
||||
$this->person = $this->em->getRepository('ChillPersonBundle:Person')
|
||||
->find($this->person->getId());
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->refreshPerson();
|
||||
$this->em->remove($this->person);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@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\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
/**
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Marc Ducobu <marc.ducobu@champs-libres.coop>
|
||||
*/
|
||||
class PersonControllerViewTestWithHiddenFields extends WebTestCase
|
||||
{
|
||||
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
|
||||
private $em;
|
||||
|
||||
/** @var Person A person used on which to run the test */
|
||||
private $person;
|
||||
|
||||
/** @var String The url to view the person details */
|
||||
private $viewUrl;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel(array('environment' => 'test_with_hidden_fields'));
|
||||
|
||||
$this->em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$center = $this->em->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
|
||||
$this->person = (new Person())
|
||||
->setLastName("Tested Person")
|
||||
->setFirstName("Réginald")
|
||||
->setCenter($center)
|
||||
->setGender(Person::MALE_GENDER);
|
||||
|
||||
$this->em->persist($this->person);
|
||||
$this->em->flush();
|
||||
|
||||
$this->viewUrl = '/en/person/'.$this->person->getId().'/general';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the view page is accessible
|
||||
*
|
||||
* @group configurable_fields
|
||||
*/
|
||||
public function testViewPerson()
|
||||
{
|
||||
$client = static::createClient(
|
||||
array('environment' => 'test_with_hidden_fields'),
|
||||
array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
'HTTP_ACCEPT_LANGUAGE' => 'fr'
|
||||
)
|
||||
);
|
||||
|
||||
$crawler = $client->request('GET', $this->viewUrl);
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("Tested Person")')->count());
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginald")')->count());
|
||||
$this->assertNotContains('Email addresses', $crawler->text());
|
||||
$this->assertNotContains('Phonenumber', $crawler->text());
|
||||
$this->assertNotContains('Langues parlées', $crawler->text());
|
||||
$this->assertNotContains(/* Etat */ 'civil', $crawler->text());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the person from the db
|
||||
*/
|
||||
protected function refreshPerson()
|
||||
{
|
||||
$this->person = $this->em->getRepository('ChillPersonBundle:Person')
|
||||
->find($this->person->getId());
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->refreshPerson();
|
||||
$this->em->remove($this->person);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.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\Entity;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
public function testClosingIsAfterOpeningConsistency()
|
||||
{
|
||||
$datetime1 = new \DateTime('now');
|
||||
$datetime2 = new \DateTime('tomorrow');
|
||||
|
||||
$period = new AccompanyingPeriod($datetime1);
|
||||
$period->setClosingDate($datetime2);
|
||||
|
||||
$r = $period->isClosingAfterOpening();
|
||||
|
||||
$this->assertTrue($r);
|
||||
}
|
||||
|
||||
public function testClosingIsBeforeOpeningConsistency()
|
||||
{
|
||||
$datetime1 = new \DateTime('tomorrow');
|
||||
$datetime2 = new \DateTime('now');
|
||||
|
||||
$period = new AccompanyingPeriod($datetime1);
|
||||
$period->setClosingDate($datetime2);
|
||||
|
||||
$this->assertFalse($period->isClosingAfterOpening());
|
||||
}
|
||||
|
||||
public function testClosingEqualOpening()
|
||||
{
|
||||
$datetime = new \DateTime('now');
|
||||
|
||||
$period = new AccompanyingPeriod($datetime);
|
||||
$period->setClosingDate($datetime);
|
||||
|
||||
$this->assertTrue($period->isClosingAfterOpening());
|
||||
}
|
||||
|
||||
public function testIsOpen()
|
||||
{
|
||||
$period = new AccompanyingPeriod(new \DateTime());
|
||||
|
||||
$this->assertTrue($period->isOpen());
|
||||
}
|
||||
|
||||
public function testIsClosed()
|
||||
{
|
||||
$period = new AccompanyingPeriod(new \DateTime());
|
||||
$period->setClosingDate(new \DateTime('tomorrow'));
|
||||
|
||||
$this->assertFalse($period->isOpen());
|
||||
}
|
||||
|
||||
public function testCanBeReOpened()
|
||||
{
|
||||
$person = new Person(\DateTime::createFromFormat('Y-m-d', '2010-01-01'));
|
||||
$person->close($person->getAccompanyingPeriods()[0]
|
||||
->setClosingDate(\DateTime::createFromFormat('Y-m-d', '2010-12-31')));
|
||||
|
||||
$firstAccompanygingPeriod = $person->getAccompanyingPeriodsOrdered()[0];
|
||||
|
||||
$this->assertTrue($firstAccompanygingPeriod->canBeReOpened());
|
||||
|
||||
$lastAccompanyingPeriod = (new AccompanyingPeriod(\DateTime::createFromFormat('Y-m-d', '2011-01-01')))
|
||||
->setClosingDate(\DateTime::createFromFormat('Y-m-d', '2011-12-31'))
|
||||
;
|
||||
$person->addAccompanyingPeriod($lastAccompanyingPeriod);
|
||||
|
||||
$this->assertFalse($firstAccompanygingPeriod->canBeReOpened());
|
||||
}
|
||||
|
||||
}
|
154
src/Bundle/ChillPersonBundle/Tests/Entity/PersonTest.php
Normal file
154
src/Bundle/ChillPersonBundle/Tests/Entity/PersonTest.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <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\Entity;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
|
||||
/**
|
||||
* Unit tests for the person Entity
|
||||
*/
|
||||
class PersonTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test the creation of an accompanying, its closure and the access to
|
||||
* the current accompaniying period via the getCurrentAccompanyingPeriod
|
||||
* function.
|
||||
*/
|
||||
public function testGetCurrentAccompanyingPeriod()
|
||||
{
|
||||
$d = new \DateTime('yesterday');
|
||||
$p = new Person($d);
|
||||
|
||||
$period = $p->getCurrentAccompanyingPeriod();
|
||||
|
||||
$this->assertInstanceOf('Chill\PersonBundle\Entity\AccompanyingPeriod', $period);
|
||||
$this->assertTrue($period->isOpen());
|
||||
$this->assertEquals($d, $period->getOpeningDate());
|
||||
|
||||
//close and test
|
||||
$period->setClosingDate(new \DateTime('tomorrow'));
|
||||
|
||||
$shouldBeNull = $p->getCurrentAccompanyingPeriod();
|
||||
$this->assertNull($shouldBeNull);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the getAccompanyingPeriodsOrdered function return a list of
|
||||
* periods ordered ascendency.
|
||||
*/
|
||||
public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod()
|
||||
{
|
||||
$d = new \DateTime("2013/2/1");
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime("2013/3/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
|
||||
$p->close($period);
|
||||
|
||||
$f = new \DateTime("2013/1/1");
|
||||
$p->open(new AccompanyingPeriod($f));
|
||||
|
||||
$g = new \DateTime("2013/4/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
|
||||
$p->close($period);
|
||||
|
||||
$r = $p->getAccompanyingPeriodsOrdered();
|
||||
|
||||
$date = $r[0]->getOpeningDate()->format('Y-m-d');
|
||||
|
||||
$this->assertEquals($date, '2013-01-01');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the getAccompanyingPeriodsOrdered function, for periods
|
||||
* starting at the same time order regarding to the closing date.
|
||||
*/
|
||||
public function testAccompanyingPeriodOrderSameDateOpening() {
|
||||
$d = new \DateTime("2013/2/1");
|
||||
$p = new Person($d);
|
||||
|
||||
$g = new \DateTime("2013/4/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
|
||||
$p->close($period);
|
||||
|
||||
$f = new \DateTime("2013/2/1");
|
||||
$p->open(new AccompanyingPeriod($f));
|
||||
|
||||
$e = new \DateTime("2013/3/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
|
||||
$p->close($period);
|
||||
|
||||
$r = $p->getAccompanyingPeriodsOrdered();
|
||||
|
||||
$date = $r[0]->getClosingDate()->format('Y-m-d');
|
||||
|
||||
$this->assertEquals($date, '2013-03-01');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the function checkAccompanyingPeriodIsNotCovering returns
|
||||
* the good constant when two periods are collapsing : a period
|
||||
* is covering another one : start_1 < start_2 & end_2 < end_1
|
||||
*/
|
||||
public function testDateCoveringWithCoveringAccompanyingPeriod() {
|
||||
$d = new \DateTime("2013/2/1");
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime("2013/3/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
|
||||
$p->close($period);
|
||||
|
||||
$f = new \DateTime("2013/1/1");
|
||||
$p->open(new AccompanyingPeriod($f));
|
||||
|
||||
$g = new \DateTime("2013/4/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
|
||||
$p->close($period);
|
||||
|
||||
$r = $p->checkAccompanyingPeriodsAreNotCollapsing();
|
||||
|
||||
$this->assertEquals($r['result'], Person::ERROR_PERIODS_ARE_COLLAPSING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the function checkAccompanyingPeriodIsNotCovering returns
|
||||
* the good constant when two periods are collapsing : a period is open
|
||||
* before an existing period
|
||||
*/
|
||||
public function testNotOpenAFileReOpenedLater() {
|
||||
$d = new \DateTime("2013/2/1");
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime("2013/3/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
|
||||
$p->close($period);
|
||||
|
||||
$f = new \DateTime("2013/1/1");
|
||||
$p->open(new AccompanyingPeriod($f));
|
||||
|
||||
$r = $p->checkAccompanyingPeriodsAreNotCollapsing();
|
||||
|
||||
$this->assertEquals($r['result'], Person::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD);
|
||||
}
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
<?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\PersonBundle\Tests\Export\Aggregator;
|
||||
|
||||
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class AgeAggregatorTest extends AbstractAggregatorTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\PersonBundle\Export\Aggregator\AgeAggregator
|
||||
*/
|
||||
private $aggregator;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->aggregator = $container->get('chill.person.export.aggregator_age');
|
||||
}
|
||||
|
||||
public function getAggregator()
|
||||
{
|
||||
return $this->aggregator;
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'date_age_calculation' => \DateTime::createFromFormat('Y-m-d','2016-06-16')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
$em->createQueryBuilder()
|
||||
->select('count(person.id)')
|
||||
->from('ChillPersonBundle:Person', 'person')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
<?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\Aggregator;
|
||||
|
||||
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class GenderAggregatorTest extends AbstractAggregatorTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\PersonBundle\Export\Aggregator\GenderAggregator
|
||||
*/
|
||||
private $aggregator;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->aggregator = $container->get('chill.person.export.aggregator_gender');
|
||||
}
|
||||
|
||||
public function getAggregator()
|
||||
{
|
||||
return $this->aggregator;
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
$em->createQueryBuilder()
|
||||
->select('count(person.id)')
|
||||
->from('ChillPersonBundle:Person', 'person')
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?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\Aggregator;
|
||||
|
||||
require_once '/home/julien/dev/chill-dev/vendor/chill-project/main/Test/Export/AbstractAggregatorTest.php';
|
||||
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class NationalityAggregator extends AbstractAggregatorTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\PersonBundle\Export\Aggregator\NationalityAggregator
|
||||
*/
|
||||
private $aggregator;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->aggregator = $container->get('chill.person.export.aggregator_nationality');
|
||||
}
|
||||
|
||||
public function getAggregator()
|
||||
{
|
||||
return $this->aggregator;
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array('group_by_level' => 'country'),
|
||||
array('group_by_level' => 'continent')
|
||||
);
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
$em->createQueryBuilder()
|
||||
->select('count(person.id)')
|
||||
->from('ChillPersonBundle:Person', 'person')
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2016 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\Export;
|
||||
|
||||
use Chill\MainBundle\Test\Export\AbstractExportTest;
|
||||
|
||||
/**
|
||||
* Test CountPerson export
|
||||
*
|
||||
* @author julien.fastre@champs-libres.coop
|
||||
*/
|
||||
class CountPersonTest 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.person.export.export_count_person');
|
||||
}
|
||||
|
||||
|
||||
public function getExport()
|
||||
{
|
||||
return $this->export;
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
public function getModifiersCombination()
|
||||
{
|
||||
return array( [ 'person' ] );
|
||||
}
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2016 Julien Fastré <julien.fastre@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\Export;
|
||||
|
||||
use Chill\MainBundle\Test\Export\AbstractExportTest;
|
||||
use Chill\PersonBundle\Export\Export\ListPerson;
|
||||
|
||||
|
||||
/**
|
||||
* Test the export "ListPerson"
|
||||
*
|
||||
* @author julien.fastre@champs-libres.coop
|
||||
*/
|
||||
class ListPersonTest extends AbstractExportTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ListPerson
|
||||
*/
|
||||
private $export;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
/* @var $container \Symfony\Component\DependencyInjection\ContainerInterface */
|
||||
$container = self::$kernel->getContainer();
|
||||
|
||||
$this->export = $container->get('chill.person.export.list_person');
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getExport()
|
||||
{
|
||||
return $this->export;
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array('fields' => ['id', 'firstName', 'lastName']),
|
||||
array('fields' => ['id', 'birthdate', 'gender', 'memo', 'email', 'phonenumber']),
|
||||
array('fields' => ['firstName', 'lastName', 'phonenumber']),
|
||||
array('fields' => ['id', 'nationality']),
|
||||
array('fields' => ['id', 'countryOfBirth']),
|
||||
array('fields' => ['id', 'address_street_address_1',
|
||||
'address_street_address_2', 'address_valid_from',
|
||||
'address_postcode_label', 'address_postcode_code',
|
||||
'address_country_name', 'address_country_code'],
|
||||
'address_date' => \DateTime::createFromFormat('Y-m-d', '2016-06-12'))
|
||||
);
|
||||
}
|
||||
|
||||
public function getModifiersCombination()
|
||||
{
|
||||
return array(
|
||||
array('person')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
<?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'),
|
||||
$em->createQueryBuilder()
|
||||
->select('activity.date AS date')
|
||||
->select('activity.attendee as attendee')
|
||||
->from("ChillActivityBundle:Activity", 'activity')
|
||||
->join('activity.person', 'person')
|
||||
->join('person.center', 'center')
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class BirthdayFilterTest extends AbstractFilterTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\PersonBundle\Export\Filter\BirthdateFilter
|
||||
*/
|
||||
private $filter;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->filter = $container->get('chill.person.export.filter_birthdate');
|
||||
}
|
||||
|
||||
|
||||
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('p.firstName')
|
||||
->from('ChillPersonBundle:Person', 'p'),
|
||||
$em->createQueryBuilder()
|
||||
->select('p.firstName')
|
||||
->from('ChillPersonBundle:Person', 'p')
|
||||
// add a dummy where clause
|
||||
->where('p.firstname IS NOT NULL'),
|
||||
$em->createQueryBuilder()
|
||||
->select('count(IDENTITY(p))')
|
||||
->from('ChillPersonBundle:Person', 'p')
|
||||
// add a dummy where clause
|
||||
->where('p.firstname IS NOT NULL')
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2016 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 Chill\PersonBundle\Entity\Person;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class GenderFilterTest extends AbstractFilterTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\PersonBundle\Export\Filter\GenderFilter
|
||||
*/
|
||||
private $filter;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
public function getFilter()
|
||||
{
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'accepted_genders' => [ Person::FEMALE_GENDER ]
|
||||
),
|
||||
array(
|
||||
'accepted_genders' => [ Person::MALE_GENDER ]
|
||||
),
|
||||
array(
|
||||
'accepted_genders' => [ Person::MALE_GENDER, Person::BOTH_GENDER ]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
{
|
||||
if (static::$kernel === null) {
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
$em->createQueryBuilder()
|
||||
->select('p.firstName')
|
||||
->from('ChillPersonBundle:Person', 'p')
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 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\PersonBundle\Tests\Form\Type;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Chill\PersonBundle\Form\Type\PickPersonType;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PickPersonTypeTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Chill\MainBundle\Entity\User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\Form\FormFactoryInterface
|
||||
*/
|
||||
protected $formFactory;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->container = self::$kernel->getContainer();
|
||||
|
||||
$this->user = $this->container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(array('username' => 'multi_center'));
|
||||
|
||||
$this->formFactory = $this->container->get('form.factory');
|
||||
|
||||
$token = (new UsernamePasswordToken($this->user, 'password', 'firewall'));
|
||||
$this->container->get('security.token_storage')
|
||||
->setToken($token);
|
||||
}
|
||||
|
||||
public function testWithoutOption()
|
||||
{
|
||||
$form = $this->formFactory
|
||||
->createBuilder(PickPersonType::class, null, array())
|
||||
->getForm();
|
||||
|
||||
$this->assertInstanceOf(\Symfony\Component\Form\FormInterface::class,
|
||||
$form);
|
||||
|
||||
// transform into a view to have data-center attr
|
||||
$view = $form->createView();
|
||||
|
||||
$centerIds = array();
|
||||
|
||||
/* @var $centerIds \Symfony\Component\Form\ChoiceList\View\ChoiceView */
|
||||
foreach($view->vars['choices'] as $choice) {
|
||||
$centerIds[] = $choice->attr['data-center'];
|
||||
}
|
||||
|
||||
$this->assertEquals(2, count(array_unique($centerIds)),
|
||||
"test that the form contains people from 2 centers");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the form with an option 'centers' with an unique center
|
||||
* entity (not in an array)
|
||||
*/
|
||||
public function testWithOptionCenter()
|
||||
{
|
||||
$center = $this->container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:Center')
|
||||
->findOneBy(array('name' => 'Center A'))
|
||||
;
|
||||
|
||||
$form = $this->formFactory
|
||||
->createBuilder(PickPersonType::class, null, array(
|
||||
'centers' => $center
|
||||
))
|
||||
->getForm();
|
||||
|
||||
// transform into a view to have data-center attr
|
||||
$view = $form->createView();
|
||||
|
||||
/* @var $centerIds \Symfony\Component\Form\ChoiceList\View\ChoiceView */
|
||||
foreach($view->vars['choices'] as $choice) {
|
||||
$centerIds[] = $choice->attr['data-center'];
|
||||
}
|
||||
|
||||
$this->assertEquals(1, count(array_unique($centerIds)),
|
||||
"test that the form contains people from only one centers");
|
||||
|
||||
$this->assertEquals($center->getId(), array_unique($centerIds)[0]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the form with multiple centers
|
||||
*/
|
||||
public function testWithOptionCenters()
|
||||
{
|
||||
$centers = $this->container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:Center')
|
||||
->findAll()
|
||||
;
|
||||
|
||||
$form = $this->formFactory
|
||||
->createBuilder(PickPersonType::class, null, array(
|
||||
'centers' => $centers
|
||||
))
|
||||
->getForm();
|
||||
|
||||
// transform into a view to have data-center attr
|
||||
$view = $form->createView();
|
||||
|
||||
/* @var $centerIds \Symfony\Component\Form\ChoiceList\View\ChoiceView */
|
||||
foreach($view->vars['choices'] as $choice) {
|
||||
$centerIds[] = $choice->attr['data-center'];
|
||||
}
|
||||
|
||||
$this->assertEquals(2, count(array_unique($centerIds)),
|
||||
"test that the form contains people from only one centers");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test with an invalid center type in the option 'centers' (in an array)
|
||||
*
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testWithInvalidOptionCenters()
|
||||
{
|
||||
|
||||
$form = $this->formFactory
|
||||
->createBuilder(PickPersonType::class, null, array(
|
||||
'centers' => array('string')
|
||||
))
|
||||
->getForm();
|
||||
}
|
||||
|
||||
public function testWithOptionRoleInvalid()
|
||||
{
|
||||
$form = $this->formFactory
|
||||
->createBuilder(PickPersonType::class, null, array(
|
||||
'role' => new \Symfony\Component\Security\Core\Role\Role('INVALID')
|
||||
))
|
||||
->getForm();
|
||||
|
||||
// transform into a view to have data-center attr
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertEquals(0, count($view->vars['choices']));
|
||||
}
|
||||
|
||||
}
|
237
src/Bundle/ChillPersonBundle/Tests/Search/PersonSearchTest.php
Normal file
237
src/Bundle/ChillPersonBundle/Tests/Search/PersonSearchTest.php
Normal file
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2015 Champs-Libres Coopérative <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\Search;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
|
||||
/**
|
||||
* Test Person search
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PersonSearchTest extends WebTestCase
|
||||
{
|
||||
public function testExpected()
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
|
||||
$crawler = $client->request('GET', '/fr/search', array(
|
||||
'q' => '@person Depardieu'
|
||||
));
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testExpectedNamed()
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
|
||||
$crawler = $client->request('GET', '/fr/search', array(
|
||||
'q' => '@person Depardieu', 'name' => 'person_regular'
|
||||
));
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Depardieu');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNameLower()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:depardieu');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNamePartim()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Dep');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testFirstNameAccentued()
|
||||
{
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person firstname:manço');
|
||||
|
||||
$this->assertRegExp('/Manço/', $crawlerSpecial->text());
|
||||
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person firstname:manco');
|
||||
|
||||
$this->assertRegExp('/Manço/', $crawlerNoSpecial->text());
|
||||
}
|
||||
|
||||
public function testSearchByLastName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Jean');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByLastNameLower()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:jean');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByLastNamePartim()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:ean');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchByLastNameAccented()
|
||||
{
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person lastname:Gérard');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawlerSpecial->text());
|
||||
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person lastname:Gerard');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawlerNoSpecial->text());
|
||||
}
|
||||
|
||||
public function testSearchCombineFirstnameAndNationality()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Depardieu nationality:RU');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawler->text());
|
||||
//if this is a AND clause, Jean Depardieu should not appears
|
||||
$this->assertNotRegExp('/Jean/', $crawler->text(),
|
||||
"assert clause firstname and nationality are AND");
|
||||
}
|
||||
|
||||
public function testSearchCombineLastnameAndFirstName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Depardieu lastname:Jean');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->text());
|
||||
//if this is a AND clause, Jean Depardieu should not appears
|
||||
$this->assertNotRegExp('/Gérard/', $crawler->text(),
|
||||
"assert clause firstname and nationality are AND");
|
||||
}
|
||||
|
||||
public function testSearchBirthdate()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person birthdate:1948-12-27');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawler->text());
|
||||
$this->assertRegExp('/Bart/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchCombineBirthdateAndFirstName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person birthdate:1948-12-27 firstname:(Van Snick)');
|
||||
|
||||
$this->assertRegExp('/Bart/', $crawler->text());
|
||||
$this->assertNotRegExp('/Depardieu/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchCombineGenderAndFirstName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person gender:woman firstname:(Depardieu)');
|
||||
|
||||
$this->assertRegExp('/Charline/', $crawler->text());
|
||||
$this->assertNotRegExp('/Gérard/', $crawler->text());
|
||||
}
|
||||
|
||||
public function testSearchMultipleTrigramUseAndClauseInDefault()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person cha dep');
|
||||
|
||||
$this->assertRegExp('/Charline/', $crawler->text());
|
||||
$this->assertNotRegExp('/Gérard/', $crawler->text());
|
||||
$this->assertNotRegExp('/Jean/', $crawler->text());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testDefaultAccented()
|
||||
{
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person manço');
|
||||
|
||||
$this->assertRegExp('/Manço/', $crawlerSpecial->text());
|
||||
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person manco');
|
||||
|
||||
$this->assertRegExp('/Manço/', $crawlerNoSpecial->text());
|
||||
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person Étienne');
|
||||
|
||||
$this->assertRegExp('/Étienne/', $crawlerSpecial->text());
|
||||
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person etienne');
|
||||
|
||||
$this->assertRegExp('/Étienne/', $crawlerNoSpecial->text());
|
||||
}
|
||||
|
||||
/**
|
||||
* test that person which a user cannot see are not displayed in results
|
||||
*/
|
||||
public function testSearchWithAuthorization()
|
||||
{
|
||||
$crawlerCanSee = $this->generateCrawlerForSearch('Gérard', 'center a_social');
|
||||
$crawlerCannotSee = $this->generateCrawlerForSearch('Gérard', 'center b_social');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawlerCanSee->text(),
|
||||
'center a_social may see "Gérard" in center a');
|
||||
$this->assertRegExp('/Aucune personne ne correspond aux termes de recherche/',
|
||||
$crawlerCannotSee->text(),
|
||||
'center b_social may not see any "Gérard" associated to center b');
|
||||
|
||||
}
|
||||
|
||||
private function generateCrawlerForSearch($pattern, $username = 'center a_social')
|
||||
{
|
||||
$client = $this->getAuthenticatedClient($username);
|
||||
|
||||
$crawler = $client->request('GET', '/fr/search', array(
|
||||
'q' => $pattern
|
||||
));
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
return $crawler;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Symfony\Component\BrowserKit\Client
|
||||
*/
|
||||
private function getAuthenticatedClient($username = 'center a_social')
|
||||
{
|
||||
return static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => $username,
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
}
|
||||
}
|
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2015 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\PersonBundle\Tests\Security\Authorization;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\PermissionsGroup;
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\MainBundle\Entity\RoleScope;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Test\PrepareUserTrait;
|
||||
use Chill\MainBundle\Test\PrepareCenterTrait;
|
||||
use Chill\MainBundle\Test\PrepareScopeTrait;
|
||||
use Chill\MainBundle\Test\ProphecyTrait;
|
||||
|
||||
/**
|
||||
* Test PersonVoter
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
*/
|
||||
class PersonVoterTest extends KernelTestCase
|
||||
{
|
||||
|
||||
use PrepareUserTrait, PrepareCenterTrait, PrepareScopeTrait;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Chill\PersonBundle\Security\Authorization\PersonVoter
|
||||
*/
|
||||
protected $voter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Prophecy\Prophet
|
||||
*/
|
||||
protected $prophet;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
$this->voter = static::$kernel->getContainer()
|
||||
->get('chill.person.security.authorization.person');
|
||||
$this->prophet = new \Prophecy\Prophet();
|
||||
}
|
||||
|
||||
public function testNullUser()
|
||||
{
|
||||
$token = $this->prepareToken();
|
||||
$center = $this->prepareCenter(1, 'center');
|
||||
$person = $this->preparePerson($center);
|
||||
|
||||
$this->assertEquals(
|
||||
VoterInterface::ACCESS_DENIED,
|
||||
$this->voter->vote($token, $person, array('CHILL_PERSON_SEE')),
|
||||
"assert that a null user is not allowed to see"
|
||||
);
|
||||
}
|
||||
|
||||
public function testUserCanNotReachCenter()
|
||||
{
|
||||
$centerA = $this->prepareCenter(1, 'centera');
|
||||
$centerB = $this->prepareCenter(2, 'centerb');
|
||||
$scope = $this->prepareScope(1, 'default');
|
||||
$token = $this->prepareToken(array(
|
||||
array(
|
||||
'center' => $centerA, 'permissionsGroup' => array(
|
||||
['scope' => $scope, 'role' => 'CHILL_PERSON_UPDATE']
|
||||
)
|
||||
)
|
||||
));
|
||||
$person = $this->preparePerson($centerB);
|
||||
|
||||
$this->assertEquals(
|
||||
VoterInterface::ACCESS_DENIED,
|
||||
$this->voter->vote($token, $person, array('CHILL_PERSON_UPDATE')),
|
||||
'assert that a user with right not in the good center has access denied'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test a user with sufficient right may see the person
|
||||
*/
|
||||
public function testUserAllowed()
|
||||
{
|
||||
$center = $this->prepareCenter(1, 'center');
|
||||
$scope = $this->prepareScope(1, 'default');
|
||||
$token = $this->prepareToken(array(
|
||||
array(
|
||||
'center' => $center, 'permissionsGroup' => array(
|
||||
['scope' => $scope, 'role' => 'CHILL_PERSON_SEE']
|
||||
)
|
||||
)
|
||||
));
|
||||
$person = $this->preparePerson($center);
|
||||
|
||||
$this->assertEquals(
|
||||
VoterInterface::ACCESS_GRANTED,
|
||||
$this->voter->vote($token, $person, array('CHILL_PERSON_SEE')),
|
||||
'assert that a user with correct rights may is granted access'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test a user with sufficient right may see the person.
|
||||
* hierarchy between role is required
|
||||
*/
|
||||
public function testUserAllowedWithInheritance()
|
||||
{
|
||||
$center = $this->prepareCenter(1, 'center');
|
||||
$scope = $this->prepareScope(1, 'default');
|
||||
$token = $this->prepareToken(array(
|
||||
array(
|
||||
'center' => $center, 'permissionsGroup' => array(
|
||||
['scope' => $scope, 'role' => 'CHILL_PERSON_UPDATE']
|
||||
)
|
||||
)
|
||||
));
|
||||
$person = $this->preparePerson($center);
|
||||
$this->assertEquals(
|
||||
VoterInterface::ACCESS_GRANTED,
|
||||
$this->voter->vote($token, $person, array('CHILL_PERSON_SEE')),
|
||||
'assert that a user with correct role is granted on inherited roles'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare a person
|
||||
*
|
||||
* The only properties set is the center, others properties are ignored.
|
||||
*
|
||||
* @param Center $center
|
||||
* @return Person
|
||||
*/
|
||||
protected function preparePerson(Center $center)
|
||||
{
|
||||
return (new Person())
|
||||
->setCenter($center)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare a token interface with correct rights
|
||||
*
|
||||
* if $permissions = null, user will be null (no user associated with token
|
||||
*
|
||||
* @param array $permissions an array of permissions, with key 'center' for the center and 'permissions' for an array of permissions
|
||||
* @return \Symfony\Component\Security\Core\Authentication\Token\TokenInterface
|
||||
*/
|
||||
protected function prepareToken(array $permissions = null)
|
||||
{
|
||||
$token = $this->prophet->prophesize();
|
||||
$token
|
||||
->willImplement('\Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
|
||||
if ($permissions === NULL) {
|
||||
$token->getUser()->willReturn(null);
|
||||
} else {
|
||||
$token->getUser()->willReturn($this->prepareUser($permissions));
|
||||
}
|
||||
|
||||
return $token->reveal();
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2015 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\PersonBundle\Tests\Timeline;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\Tests\Functional\WebTestCase;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
|
||||
/**
|
||||
* This class tests entries are shown for closing and opening
|
||||
* periods in timeline.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
*/
|
||||
class TimelineAccompanyingPeriodTest extends \Chill\PersonBundle\Tests\Controller\AccompanyingPeriodControllerTest
|
||||
{
|
||||
public function testEntriesAreShown()
|
||||
{
|
||||
$this->generatePeriods(array(
|
||||
[
|
||||
'openingDate' => '2014-01-01',
|
||||
'closingDate' => '2014-12-31',
|
||||
'closingMotive' => $this->getRandomClosingMotive()
|
||||
]
|
||||
));
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/timeline');
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful(),
|
||||
"the timeline page loads sucessfully");
|
||||
$this->assertGreaterThan(0, $crawler->filter('.timeline div')->count(),
|
||||
"the timeline page contains multiple div inside a .timeline element");
|
||||
$this->assertContains("Ouverture d'une période d'accompagnement",
|
||||
$crawler->filter('.timeline')->text(),
|
||||
"the text 'une période d'accompagnement a été ouverte' is present");
|
||||
$this->assertContains("Fermeture de la période d'accompagnement",
|
||||
$crawler->Filter('.timeline')->text(),
|
||||
"the text 'Une période d'accompagnement a été fermée' is present");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@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\Validator;
|
||||
|
||||
use Chill\PersonBundle\Validator\Constraints\BirthdateValidator;
|
||||
use Chill\PersonBundle\Validator\Constraints\Birthdate;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophet;
|
||||
|
||||
/**
|
||||
* Test the behaviour of BirthdayValidator
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class BirthdateValidatorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* A prophecy for \Symfony\Component\Validator\Context\ExecutionContextInterface
|
||||
*
|
||||
* Will reveal \Symfony\Component\Validator\Context\ExecutionContextInterface
|
||||
*/
|
||||
private $context;
|
||||
|
||||
private $prophet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Birthdate
|
||||
*/
|
||||
private $constraint;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->prophet = new Prophet;
|
||||
|
||||
$constraintViolationBuilder = $this->prophet->prophesize();
|
||||
$constraintViolationBuilder->willImplement('Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface');
|
||||
|
||||
$constraintViolationBuilder->setParameter(Argument::any(), Argument::any())
|
||||
->willReturn($constraintViolationBuilder->reveal());
|
||||
$constraintViolationBuilder->addViolation()
|
||||
->willReturn($constraintViolationBuilder->reveal());
|
||||
|
||||
$this->context = $this->prophet->prophesize();
|
||||
$this->context->willImplement('Symfony\Component\Validator\Context\ExecutionContextInterface');
|
||||
$this->context->buildViolation(Argument::type('string'))
|
||||
->willReturn($constraintViolationBuilder->reveal());
|
||||
|
||||
$this->constraint = new Birthdate();
|
||||
}
|
||||
|
||||
public function testValidBirthDate()
|
||||
{
|
||||
|
||||
$date = new \DateTime('2015-01-01');
|
||||
|
||||
$birthdateValidator = new BirthdateValidator();
|
||||
$birthdateValidator->initialize($this->context->reveal());
|
||||
|
||||
$birthdateValidator->validate($date, $this->constraint);
|
||||
|
||||
$this->context->buildViolation(Argument::any())->shouldNotHaveBeenCalled();
|
||||
}
|
||||
|
||||
public function testInvalidBirthDate()
|
||||
{
|
||||
$date = new \DateTime('tomorrow');
|
||||
|
||||
$birthdateValidator = new BirthdateValidator();
|
||||
$birthdateValidator->initialize($this->context->reveal());
|
||||
|
||||
$birthdateValidator->validate($date, $this->constraint);
|
||||
|
||||
$this->context->buildViolation(Argument::type('string'))->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
public function testInvalidBirthDateWithParameter()
|
||||
{
|
||||
$date = (new \DateTime('today'))->sub(new \DateInterval('P1M'));
|
||||
|
||||
$birthdateValidator = new BirthdateValidator('P1Y');
|
||||
$birthdateValidator->initialize($this->context->reveal());
|
||||
|
||||
$birthdateValidator->validate($date, $this->constraint);
|
||||
|
||||
$this->context->buildViolation(Argument::type('string'))->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->prophet->checkPredictions();
|
||||
}
|
||||
|
||||
|
||||
}
|
8
src/Bundle/ChillPersonBundle/Tests/bootstrap.php
Normal file
8
src/Bundle/ChillPersonBundle/Tests/bootstrap.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
if (!is_file($autoloadFile = __DIR__.'/../vendor/autoload.php')) {
|
||||
throw new \LogicException('Could not find autoload.php in vendor/. Did you run "composer install --dev"?');
|
||||
}
|
||||
|
||||
require $autoloadFile;
|
||||
|
Reference in New Issue
Block a user