use a more randomly name for tests

This commit is contained in:
Julien Fastré 2021-08-17 17:43:53 +02:00
parent 1a37910fb1
commit afb2a92997

View File

@ -3,7 +3,7 @@
/* /*
* Chill is a software for social workers * Chill is a software for social workers
* *
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop> * <http://www.champs-libres.coop>, <info@champs-libres.coop>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -42,7 +42,7 @@ class PersonControllerCreateTest extends WebTestCase
const BIRTHDATE_INPUT = "chill_personbundle_person_creation[birthdate]"; const BIRTHDATE_INPUT = "chill_personbundle_person_creation[birthdate]";
const CREATEDATE_INPUT = "chill_personbundle_person_creation[creation_date]"; const CREATEDATE_INPUT = "chill_personbundle_person_creation[creation_date]";
const CENTER_INPUT = "chill_personbundle_person_creation[center]"; 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."; 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.";
public function setUp(): void public function setUp(): void
@ -51,7 +51,7 @@ class PersonControllerCreateTest extends WebTestCase
} }
/** /**
* *
* @param Form $creationForm * @param Form $creationForm
*/ */
private function fillAValidCreationForm( private function fillAValidCreationForm(
@ -64,26 +64,26 @@ class PersonControllerCreateTest extends WebTestCase
$creationForm->get(self::GENDER_INPUT)->select("man"); $creationForm->get(self::GENDER_INPUT)->select("man");
$date = new \DateTime('1947-02-01'); $date = new \DateTime('1947-02-01');
$creationForm->get(self::BIRTHDATE_INPUT)->setValue($date->format('d-m-Y')); $creationForm->get(self::BIRTHDATE_INPUT)->setValue($date->format('d-m-Y'));
return $creationForm; return $creationForm;
} }
/** /**
* Test the "add a person" page : test that required elements are present * 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 * see https://redmine.champs-libres.coop/projects/chillperson/wiki/Test_plan_for_page_%22add_a_person%22
*/ */
public function testAddAPersonPage() public function testAddAPersonPage()
{ {
$client = $this->client; $client = $this->client;
$crawler = $client->request('GET', '/fr/person/new'); $crawler = $client->request('GET', '/fr/person/new');
$this->assertTrue($client->getResponse()->isSuccessful(), $this->assertTrue($client->getResponse()->isSuccessful(),
"The page is accessible at the URL /{_locale}/person/new"); "The page is accessible at the URL /{_locale}/person/new");
$form = $crawler->selectButton("Ajouter la personne")->form(); $form = $crawler->selectButton("Ajouter la personne")->form();
$this->assertInstanceOf('Symfony\Component\DomCrawler\Form', $form, $this->assertInstanceOf('Symfony\Component\DomCrawler\Form', $form,
'The page contains a butto '); 'The page contains a butto ');
$this->assertTrue($form->has(self::FIRSTNAME_INPUT), $this->assertTrue($form->has(self::FIRSTNAME_INPUT),
'The page contains a "firstname" input'); 'The page contains a "firstname" input');
@ -91,27 +91,27 @@ class PersonControllerCreateTest extends WebTestCase
'The page contains a "lastname" input'); 'The page contains a "lastname" input');
$this->assertTrue($form->has(self::GENDER_INPUT), $this->assertTrue($form->has(self::GENDER_INPUT),
'The page contains a "gender" input'); 'The page contains a "gender" input');
$this->assertTrue($form->has(self::BIRTHDATE_INPUT), $this->assertTrue($form->has(self::BIRTHDATE_INPUT),
'The page has a "date of birth" input'); 'The page has a "date of birth" input');
$genderType = $form->get(self::GENDER_INPUT); $genderType = $form->get(self::GENDER_INPUT);
$this->assertEquals('radio', $genderType->getType(), $this->assertEquals('radio', $genderType->getType(),
'The gender input has radio buttons'); 'The gender input has radio buttons');
$this->assertEquals(3, count($genderType->availableOptionValues()), $this->assertEquals(3, count($genderType->availableOptionValues()),
'The gender input has three options: man, women and undefined'); 'The gender input has three options: man, women and undefined');
$this->assertTrue(in_array('man', $genderType->availableOptionValues()), $this->assertTrue(in_array('man', $genderType->availableOptionValues()),
'gender has "homme" option'); 'gender has "homme" option');
$this->assertTrue(in_array('woman', $genderType->availableOptionValues()), $this->assertTrue(in_array('woman', $genderType->availableOptionValues()),
'gender has "femme" option'); 'gender has "femme" option');
$this->assertFalse($genderType->hasValue(), 'The gender input is not checked'); $this->assertFalse($genderType->hasValue(), 'The gender input is not checked');
return $form; return $form;
} }
/** /**
* Test the creation of a valid person. * Test the creation of a valid person.
* *
* @param Form $form * @param Form $form
* @return string The id of the created person * @return string The id of the created person
* @depends testAddAPersonPage * @depends testAddAPersonPage
@ -125,9 +125,9 @@ class PersonControllerCreateTest extends WebTestCase
$this->assertTrue((bool)$client->getResponse()->isRedirect(), $this->assertTrue((bool)$client->getResponse()->isRedirect(),
"a valid form redirect to url /{_locale}/person/{personId}/general/edit"); "a valid form redirect to url /{_locale}/person/{personId}/general/edit");
$client->followRedirect(); $client->followRedirect();
// visualize regexp here : http://jex.im/regulex/#!embed=false&flags=&re=%2Ffr%2Fperson%2F[1-9][0-9]*%2Fgeneral%2Fedit%24 // 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$|', $this->assertRegExp('|/fr/person/[1-9][0-9]*/general/edit$|',
$client->getHistory()->current()->getUri(), $client->getHistory()->current()->getUri(),
"a valid form redirect to url /{_locale}/person/{personId}/general/edit"); "a valid form redirect to url /{_locale}/person/{personId}/general/edit");
@ -149,11 +149,11 @@ class PersonControllerCreateTest extends WebTestCase
$client = $this->client; $client = $this->client;
$client->request('GET', '/fr/person/'.$personId.'/general'); $client->request('GET', '/fr/person/'.$personId.'/general');
$this->assertTrue($client->getResponse()->isSuccessful(), $this->assertTrue($client->getResponse()->isSuccessful(),
"The person view page is accessible at the URL" "The person view page is accessible at the URL"
. "/{_locale}/person/{personID}/general"); . "/{_locale}/person/{personID}/general");
} }
/** /**
* test adding a person with a user with multi center * test adding a person with a user with multi center
* is valid * is valid
@ -161,70 +161,71 @@ class PersonControllerCreateTest extends WebTestCase
public function testValidFormWithMultiCenterUser() public function testValidFormWithMultiCenterUser()
{ {
$client = $this->getClientAuthenticated('multi_center'); $client = $this->getClientAuthenticated('multi_center');
$crawler = $client->request('GET', '/fr/person/new'); $crawler = $client->request('GET', '/fr/person/new');
$this->assertTrue($client->getResponse()->isSuccessful(), $this->assertTrue($client->getResponse()->isSuccessful(),
"The page is accessible at the URL /{_locale}/person/new"); "The page is accessible at the URL /{_locale}/person/new");
$form = $crawler->selectButton("Ajouter la personne")->form(); $form = $crawler->selectButton("Ajouter la personne")->form();
$this->fillAValidCreationForm($form, 'roger', 'rabbit'); // create a very long name to avoid collision
$this->fillAValidCreationForm($form, 'Carmela Girdana Assuntamente Castalle', 'rabbit');
$this->assertTrue($form->has(self::CENTER_INPUT), $this->assertTrue($form->has(self::CENTER_INPUT),
'The page contains a "center" input'); 'The page contains a "center" input');
$centerInput = $form->get(self::CENTER_INPUT); $centerInput = $form->get(self::CENTER_INPUT);
$availableValues = $centerInput->availableOptionValues(); $availableValues = $centerInput->availableOptionValues();
$lastCenterInputValue = end($availableValues); $lastCenterInputValue = end($availableValues);
$centerInput->setValue($lastCenterInputValue); $centerInput->setValue($lastCenterInputValue);
$client->submit($form); $client->submit($form);
$this->assertTrue($client->getResponse()->isRedirect(), $this->assertTrue($client->getResponse()->isRedirect(),
"a valid form redirect to url /{_locale}/person/{personId}/general/edit"); "a valid form redirect to url /{_locale}/person/{personId}/general/edit");
$client->followRedirect(); $client->followRedirect();
$this->assertRegExp('|/fr/person/[1-9][0-9]*/general/edit$|', $this->assertRegExp('|/fr/person/[1-9][0-9]*/general/edit$|',
$client->getHistory()->current()->getUri(), $client->getHistory()->current()->getUri(),
"a valid form redirect to url /{_locale}/person/{personId}/general/edit"); "a valid form redirect to url /{_locale}/person/{personId}/general/edit");
} }
public function testReviewExistingDetectionInversedLastNameWithFirstName() public function testReviewExistingDetectionInversedLastNameWithFirstName()
{ {
$client = $this->client; $client = $this->client;
$crawler = $client->request('GET', '/fr/person/new'); $crawler = $client->request('GET', '/fr/person/new');
//test the page is loaded before continuing //test the page is loaded before continuing
$this->assertTrue($client->getResponse()->isSuccessful()); $this->assertTrue($client->getResponse()->isSuccessful());
$form = $crawler->selectButton("Ajouter la personne")->form(); $form = $crawler->selectButton("Ajouter la personne")->form();
$form = $this->fillAValidCreationForm($form, 'Charline', 'dd'); $form = $this->fillAValidCreationForm($form, 'Charline', 'dd');
$client->submit($form); $client->submit($form);
$this->assertContains('Depardieu', $client->getCrawler()->text(), $this->assertContains('Depardieu', $client->getCrawler()->text(),
"check that the page has detected the lastname of a person existing in database"); "check that the page has detected the lastname of a person existing in database");
//inversion //inversion
$form = $crawler->selectButton("Ajouter la personne")->form(); $form = $crawler->selectButton("Ajouter la personne")->form();
$form = $this->fillAValidCreationForm($form, 'dd', 'Charline'); $form = $this->fillAValidCreationForm($form, 'dd', 'Charline');
$client->submit($form); $client->submit($form);
$this->assertContains('Depardieu', $client->getCrawler()->text(), $this->assertContains('Depardieu', $client->getCrawler()->text(),
"check that the page has detected the lastname of a person existing in database"); "check that the page has detected the lastname of a person existing in database");
} }
public static function tearDownAfterClass() public static function tearDownAfterClass()
{ {
static::bootKernel(); static::bootKernel();
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager'); $em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
//remove two people created during test //remove two people created during test
$jesus = $em->getRepository('ChillPersonBundle:Person') $jesus = $em->getRepository('ChillPersonBundle:Person')
->findOneBy(array('firstName' => 'God')); ->findOneBy(array('firstName' => 'God'));
if ($jesus !== NULL) { if ($jesus !== NULL) {
$em->remove($jesus); $em->remove($jesus);
} }
$jesus2 = $em->getRepository('ChillPersonBundle:Person') $jesus2 = $em->getRepository('ChillPersonBundle:Person')
->findOneBy(array('firstName' => 'roger')); ->findOneBy(array('firstName' => 'roger'));
if ($jesus2 !== NULL) { if ($jesus2 !== NULL) {