mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-24 08:33:49 +00:00
resolving conflict
This commit is contained in:
464
Tests/Controller/AccompanyingPeriodControllerTest.php
Normal file
464
Tests/Controller/AccompanyingPeriodControllerTest.php
Normal file
@@ -0,0 +1,464 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
* 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\PersonHistoryFile as AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
|
||||
/**
|
||||
* Test the creation or deletion of accompanying periods
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\BrowserKit\Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Person
|
||||
*/
|
||||
private $person;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Doctrine\ORM\EntityManagerInterface
|
||||
*/
|
||||
private static $em;
|
||||
|
||||
const OPENING_INPUT = 'cl_chill_personbundle_personhistoryfile[date_opening]';
|
||||
const CLOSING_INPUT = 'cl_chill_personbundle_personhistoryfile[date_closing]';
|
||||
const CLOSING_MOTIVE_INPUT = 'cl_chill_personbundle_personhistoryfile[closingMotive]';
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
static::$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
|
||||
$this->person = (new Person(new \DateTime('2015-01-05')))
|
||||
->setFirstName('Roland')
|
||||
->setLastName('Gallorime')
|
||||
->setGenre(Person::GENRE_MAN)
|
||||
;
|
||||
|
||||
static::$em->persist($this->person);
|
||||
static::$em->flush();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
static::$em->refresh($this->person);
|
||||
static::$em->remove($this->person);
|
||||
|
||||
static::$em->flush();
|
||||
}
|
||||
|
||||
private 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->setDateClosing(new \DateTime($periodDef['closingDate']))
|
||||
->setClosingMotive($periodDef['closingMotive']);
|
||||
}
|
||||
|
||||
$this->person->addHistoryFile($period);
|
||||
|
||||
static::$em->persist($period);
|
||||
|
||||
}
|
||||
|
||||
static::$em->flush();
|
||||
}
|
||||
|
||||
private function getLastValueOnClosingMotive(\Symfony\Component\DomCrawler\Form $form)
|
||||
{
|
||||
$values = $form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->availableOptionValues();
|
||||
return end($values);
|
||||
}
|
||||
|
||||
private 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]/history/close
|
||||
* with : dateClosing: 2015-02-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to history 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().'/history/close');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->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().'/history'),
|
||||
'the server redirects to /history 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]/history/close
|
||||
* with : dateClosing: 2014-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to history 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().'/history/close');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->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 history view
|
||||
*/
|
||||
public function testAddNewPeriodBeforeActual()
|
||||
{
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->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().'/history'),
|
||||
'the server redirects to /history 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
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
public function testCreatePeriodWithClosingAfterCurrentFails()
|
||||
{
|
||||
|
||||
$this->markTestSkipped('this feature is not yet implemented');
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->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
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
public function testCreatePeriodWithOpeningAndClosingAfterCurrentFails()
|
||||
{
|
||||
|
||||
$this->markTestSkipped('this feature is not yet implemented');
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->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().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->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 history view
|
||||
*/
|
||||
public function testCreatePeriodWithClosingBeforeOpeningFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->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().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->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().'/history/create');
|
||||
|
||||
$form = $crawler->selectButton('Submit')->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");
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
/**
|
||||
* Test creation and deletion for persons
|
||||
*/
|
||||
class PersonControllerTest extends WebTestCase
|
||||
class PersonControllerCreateTest extends WebTestCase
|
||||
{
|
||||
|
||||
const FIRSTNAME_INPUT = 'chill_personbundle_person_creation[firstName]';
|
235
Tests/Controller/PersonControllerUpdateTest.php
Normal file
235
Tests/Controller/PersonControllerUpdateTest.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?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;
|
||||
|
||||
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
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Person
|
||||
*/
|
||||
private $person;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $editUrl;
|
||||
|
||||
/**
|
||||
* prepare client and select a random person
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$this->person = (new Person())
|
||||
->setLastName("My Beloved")
|
||||
->setFirstName("Jesus")
|
||||
->setGenre(Person::GENRE_MAN);
|
||||
|
||||
$this->em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$this->em->persist($this->person);
|
||||
$this->em->flush();
|
||||
|
||||
$this->editUrl = '/en/person/'.$this->person->getId().'/general/edit';
|
||||
$this->seeUrl = '/en/person/'.$this->person->getId().'/general';
|
||||
|
||||
$this->client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the edit page exist and rendering is successful
|
||||
*/
|
||||
public function testEditPageIsSuccessful()
|
||||
{
|
||||
$this->client->request('GET', $this->editUrl);
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful(),
|
||||
"The person edit form is accessible");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->em->refresh($this->person);
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect($this->seeUrl),
|
||||
'the page is redirected to general view');
|
||||
$this->assertEquals($value, $callback($this->person),
|
||||
'the value '.$field.' is updated in db');
|
||||
}
|
||||
|
||||
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->em->refresh($this->person);
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect($this->seeUrl),
|
||||
'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');
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @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(); }],
|
||||
['dateOfBirth', '15-12-1980', function(Person $person) { return $person->getDateOfBirth()->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(); }],
|
||||
['dateOfBirth', '', function(Person $person) { return $person->getDateOfBirth(); }],
|
||||
['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(); }],
|
||||
['genre', Person::GENRE_WOMAN, function(Person $person) { return $person->getGenre(); }]
|
||||
);
|
||||
}
|
||||
|
||||
public function providesInvalidFieldsValues()
|
||||
{
|
||||
return array(
|
||||
['firstName', $this->getVeryLongText()],
|
||||
['lastName', $this->getVeryLongText()],
|
||||
['firstName', ''],
|
||||
['lastName', ''],
|
||||
['dateOfBirth', 'false date']
|
||||
);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
@@ -16,7 +16,8 @@ class AppKernel extends Kernel
|
||||
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
|
||||
new Chill\PersonBundle\ChillPersonBundle(),
|
||||
new Chill\MainBundle\ChillMainBundle(),
|
||||
new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle,
|
||||
new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
|
||||
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle()
|
||||
#add here all the required bundle (some bundle are not required)
|
||||
);
|
||||
}
|
||||
|
2
Tests/Fixtures/App/app/DoctrineMigrations/.gitignore
vendored
Normal file
2
Tests/Fixtures/App/app/DoctrineMigrations/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
@@ -35,6 +35,9 @@ doctrine:
|
||||
auto_generate_proxy_classes: "%kernel.debug%"
|
||||
auto_mapping: true
|
||||
|
||||
chill_main:
|
||||
available_languages: [ fr, nl, en ]
|
||||
|
||||
security:
|
||||
providers:
|
||||
users:
|
||||
|
Reference in New Issue
Block a user