mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43: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();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user