Merge branch 'fix-person-tests' into features/household

This commit is contained in:
2021-05-31 21:40:24 +02:00
51 changed files with 1410 additions and 589 deletions

View File

@@ -28,7 +28,7 @@ class AccompanyingCourseControllerTest extends WebTestCase
$this->assertResponseRedirects();
$location = $this->client->getResponse()->headers->get('Location');
$this->assertEquals(1, \preg_match("|^\/[^\/]+\/parcours/([\d]+)/show$|", $location));
$this->assertEquals(1, \preg_match("|^\/[^\/]+\/parcours/([\d]+)/edit$|", $location));
}
@@ -48,7 +48,7 @@ class AccompanyingCourseControllerTest extends WebTestCase
$location = $this->client->getResponse()->headers->get('Location');
$matches = [];
$this->assertEquals(1, \preg_match("|^\/[^\/]+\/parcours/([\d]+)/show$|", $location, $matches));
$this->assertEquals(1, \preg_match("|^\/[^\/]+\/parcours/([\d]+)/edit$|", $location, $matches));
$id = $matches[1];
$period = self::$container->get(EntityManagerInterface::class)

View File

@@ -148,7 +148,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
* 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
* and we fill the close form (at /fr/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
@@ -158,10 +158,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
*/
public function testClosingCurrentPeriod()
{
$crawler = $this->client->request('GET', '/en/person/'
$crawler = $this->client->request('GET', '/fr/person/'
.$this->person->getId().'/accompanying-period/close');
$form = $crawler->selectButton('Close accompanying period')->form();
$form = $crawler->selectButton('Clôre la période')->form();
$form->get(self::CLOSING_MOTIVE_INPUT)
->setValue($this->getLastValueOnClosingMotive($form));
@@ -171,7 +171,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
$cr = $this->client->submit($form);
$this->assertTrue($this->client->getResponse()->isRedirect(
'/en/person/'.$this->person->getId().'/accompanying-period'),
'/fr/person/'.$this->person->getId().'/accompanying-period'),
'the server redirects to /accompanying-period page');
$this->assertGreaterThan(0, $this->client->followRedirect()
->filter('.success')->count(),
@@ -182,7 +182,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
* 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
* and we fill the close form (at /fr/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
@@ -192,10 +192,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
*/
public function testClosingCurrentPeriodWithDateClosingBeforeOpeningFails()
{
$crawler = $this->client->request('GET', '/en/person/'
$crawler = $this->client->request('GET', '/fr/person/'
.$this->person->getId().'/accompanying-period/close');
$form = $crawler->selectButton('Close accompanying period')->form();
$form = $crawler->selectButton('Clôre la période')->form();
$form->get(self::CLOSING_MOTIVE_INPUT)
->setValue($this->getLastValueOnClosingMotive($form));
@@ -223,10 +223,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
*/
public function testAddNewPeriodBeforeActual()
{
$crawler = $this->client->request('GET', '/en/person/'
$crawler = $this->client->request('GET', '/fr/person/'
.$this->person->getId().'/accompanying-period/create');
$form = $crawler->selectButton('Create an accompanying period')->form();
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
$form->get(self::CLOSING_MOTIVE_INPUT)
->setValue($this->getLastValueOnClosingMotive($form));
$form->get(self::CLOSING_INPUT)
@@ -237,7 +237,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
$this->client->submit($form);
$this->assertTrue($this->client->getResponse()->isRedirect(
'/en/person/'.$this->person->getId().'/accompanying-period'),
'/fr/person/'.$this->person->getId().'/accompanying-period'),
'the server redirects to /accompanying-period page');
$this->assertGreaterThan(0, $this->client->followRedirect()
->filter('.success')->count(),
@@ -257,10 +257,13 @@ class AccompanyingPeriodControllerTest extends WebTestCase
*/
public function testCreatePeriodWithClosingAfterCurrentFails()
{
$crawler = $this->client->request('GET', '/en/person/'
$this->markTestSkipped("Multiple period may now cover. This test is kept ".
"in case of a configuration may add this feature again");
$crawler = $this->client->request('GET', '/fr/person/'
.$this->person->getId().'/accompanying-period/create');
$form = $crawler->selectButton('Create an accompanying period')->form();
$form = $crawler->selectButton("Créer une période d'accompagnement")->form();
$form->get(self::CLOSING_MOTIVE_INPUT)
->setValue($this->getLastValueOnClosingMotive($form));
$form->get(self::CLOSING_INPUT)
@@ -289,10 +292,13 @@ class AccompanyingPeriodControllerTest extends WebTestCase
*/
public function testCreatePeriodWithOpeningAndClosingAfterCurrentFails()
{
$crawler = $this->client->request('GET', '/en/person/'
$this->markTestSkipped("Multiple period may now cover. This test is kept ".
"in case of a configuration may add this feature again");
$crawler = $this->client->request('GET', '/fr/person/'
.$this->person->getId().'/accompanying-period/create');
$form = $crawler->selectButton('Create an accompanying period')->form();
$form = $crawler->selectButton("Créer une période d'accompagnement")->form();
$form->get(self::CLOSING_MOTIVE_INPUT)
->setValue($this->getLastValueOnClosingMotive($form));
$form->get(self::CLOSING_INPUT)
@@ -330,10 +336,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
]
));
$crawler = $this->client->request('GET', '/en/person/'
$crawler = $this->client->request('GET', '/fr/person/'
.$this->person->getId().'/accompanying-period/create');
$form = $crawler->selectButton('Create an accompanying period')->form();;
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();;
$form->get(self::CLOSING_MOTIVE_INPUT)
->setValue($this->getLastValueOnClosingMotive($form));
$form->get(self::CLOSING_INPUT)
@@ -361,10 +367,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
*/
public function testCreatePeriodWithClosingBeforeOpeningFails()
{
$crawler = $this->client->request('GET', '/en/person/'
$crawler = $this->client->request('GET', '/fr/person/'
.$this->person->getId().'/accompanying-period/create');
$form = $crawler->selectButton('Create an accompanying period')->form();
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
$form->get(self::CLOSING_MOTIVE_INPUT)
->setValue($this->getLastValueOnClosingMotive($form));
$form->get(self::CLOSING_INPUT)
@@ -403,10 +409,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
]
));
$crawler = $this->client->request('GET', '/en/person/'
$crawler = $this->client->request('GET', '/fr/person/'
.$this->person->getId().'/accompanying-period/create');
$form = $crawler->selectButton('Create an accompanying period')->form();
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
$form->get(self::CLOSING_MOTIVE_INPUT)
->setValue($this->getLastValueOnClosingMotive($form));
$form->get(self::CLOSING_INPUT)
@@ -444,10 +450,10 @@ class AccompanyingPeriodControllerTest extends WebTestCase
]
));
$crawler = $this->client->request('GET', '/en/person/'
$crawler = $this->client->request('GET', '/fr/person/'
.$this->person->getId().'/accompanying-period/create');
$form = $crawler->selectButton('Create an accompanying period')->form();
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
$form->get(self::CLOSING_MOTIVE_INPUT)
->setValue($this->getLastValueOnClosingMotive($form));
$form->get(self::CLOSING_INPUT)
@@ -498,7 +504,8 @@ class AccompanyingPeriodControllerTest extends WebTestCase
//$criteria->where(Criteria::expr()->eq('openingDate', \DateTime::createFromFormat()))
$firstPeriod = reset($periods);
$lastPeriod = end($periods);
$this->markTestSkipped("From here, the test should be rewritten");
// 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())
@@ -523,4 +530,4 @@ class AccompanyingPeriodControllerTest extends WebTestCase
"Test the response is a redirection => the period is re-opened");
}
}
}

View File

@@ -1,16 +0,0 @@
<?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');
}
}

View File

@@ -25,7 +25,7 @@ namespace Chill\PersonBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DomCrawler\Form;
use Chill\MainBundle\Test\PrepareClientTrait;
use \Symfony\Component\BrowserKit\Client;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
/**
* Test creation and deletion for persons
@@ -34,7 +34,7 @@ class PersonControllerCreateTest extends WebTestCase
{
use PrepareClientTrait;
private Client $client;
private KernelBrowser $client;
const FIRSTNAME_INPUT = 'chill_personbundle_person_creation[firstName]';
const LASTNAME_INPUT = "chill_personbundle_person_creation[lastName]";
@@ -59,8 +59,8 @@ class PersonControllerCreateTest extends WebTestCase
string $firstname = 'God',
string $lastname = 'Jesus'
) {
$creationForm->get(self::FIRSTNAME_INPUT)->setValue($firstname);
$creationForm->get(self::LASTNAME_INPUT)->setValue($lastname);
$creationForm->get(self::FIRSTNAME_INPUT)->setValue($firstname.'_'.uniqid());
$creationForm->get(self::LASTNAME_INPUT)->setValue($lastname.'_'.uniqid());
$creationForm->get(self::GENDER_INPUT)->select("man");
$date = new \DateTime('1947-02-01');
$creationForm->get(self::BIRTHDATE_INPUT)->setValue($date->format('d-m-Y'));
@@ -114,20 +114,6 @@ class PersonControllerCreateTest extends WebTestCase
return $form;
}
/**
*
* @param Form $form
* @depends testAddAPersonPage
*/
public function testForgedNullGender(Form $form)
{
$form->get(self::FIRSTNAME_INPUT)->setValue('john');
$form->get(self::LASTNAME_INPUT)->setValue('doe');
$date = new \DateTime('1947-02-01');
$form->get(self::BIRTHDATE_INPUT)->setValue($date->format('d-m-Y'));
$this->client->submit($form);
$this->assertResponseStatusCodeSame(500);
}
/**
* Test the creation of a valid person.
@@ -140,8 +126,8 @@ class PersonControllerCreateTest extends WebTestCase
{
$this->fillAValidCreationForm($form);
$client = $this->client;
$client->submit($form);
$crawler = $client->submit($form);
$this->assertTrue((bool)$client->getResponse()->isRedirect(),
"a valid form redirect to url /{_locale}/person/{personId}/general/edit");
$client->followRedirect();

View File

@@ -20,18 +20,16 @@
namespace Chill\PersonBundle\Tests\Controller;
//ini_set('memory_limit', '-1');
use Chill\PersonBundle\Entity\Person;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Chill\MainBundle\Test\PrepareClientTrait;
/**
* 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
{
@@ -71,8 +69,8 @@ class PersonControllerUpdateTest extends WebTestCase
$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->editUrl = '/fr/person/'.$this->person->getId().'/general/edit';
$this->viewUrl = '/fr/person/'.$this->person->getId().'/general';
$this->client = $this->getClientAuthenticated();
}
@@ -104,10 +102,10 @@ class PersonControllerUpdateTest extends WebTestCase
public function testHiddenFielsArePresent()
{
$crawler = $this->client->request('GET', $this->editUrl);
$configurables = array('placeOfBirth', 'phonenumber', 'email',
'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus');
$form = $crawler->selectButton('Submit')->form(); //;
$form = $crawler->selectButton('Enregistrer')->form(); //;
foreach($configurables as $key) {
$this->assertTrue($form->has('chill_personbundle_person['.$key.']'));
@@ -162,18 +160,18 @@ class PersonControllerUpdateTest extends WebTestCase
{
$crawler = $this->client->request('GET', $this->editUrl);
$form = $crawler->selectButton('Submit')
$form = $crawler->selectButton('Enregistrer')
->form();
//transform countries into value if needed
switch ($field) {
case 'nationality':
case 'countryOfBirth':
if ($value !== NULL) {
if (FALSE === empty($value)) {
$country = $this->em->getRepository('ChillMainBundle:Country')
->findOneByCountryCode($value);
$transformedValue = $country->getId();
} else {
$transformedValue = NULL;
$transformedValue = '';
}
break;
default:
@@ -208,7 +206,7 @@ class PersonControllerUpdateTest extends WebTestCase
$crawler = $this->client->request('GET', $this->editUrl);
$selectedLanguages = array('en', 'an', 'bbj');
$form = $crawler->selectButton('Submit')
$form = $crawler->selectButton('Enregistrer')
->form();
$form->get('chill_personbundle_person[spokenLanguages]')
->setValue($selectedLanguages);
@@ -238,7 +236,7 @@ class PersonControllerUpdateTest extends WebTestCase
{
$crawler = $this->client->request('GET', $this->editUrl);
$form = $crawler->selectButton('Submit')
$form = $crawler->selectButton('Enregistrer')
->form();
$form->get('chill_personbundle_person['.$field.']')
->setValue($value);
@@ -264,7 +262,7 @@ class PersonControllerUpdateTest extends WebTestCase
['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(); }],
['phonenumber', '+32123456789', 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(); }],
@@ -275,7 +273,6 @@ class PersonControllerUpdateTest extends WebTestCase
['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(); }]
);
}

View File

@@ -22,10 +22,6 @@ 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 */
@@ -66,6 +62,7 @@ class PersonControllerViewTestWithHiddenFields extends WebTestCase
*/
public function testViewPerson()
{
$this->markTestSkipped("This configuration does not allow multiple environnements");
$client = static::createClient(
array('environment' => 'test_with_hidden_fields'),
array(