Fixtures/fix loading people

This commit is contained in:
2021-08-17 20:01:29 +00:00
parent 4cf676858e
commit c7cc2c7596
11 changed files with 453 additions and 434 deletions

View File

@@ -3,7 +3,7 @@
/*
* 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>
*
* 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 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.";
public function setUp(): void
@@ -51,7 +51,7 @@ class PersonControllerCreateTest extends WebTestCase
}
/**
*
*
* @param Form $creationForm
*/
private function fillAValidCreationForm(
@@ -64,26 +64,26 @@ class PersonControllerCreateTest extends WebTestCase
$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->client;
$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");
$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 ');
$this->assertTrue($form->has(self::FIRSTNAME_INPUT),
'The page contains a "firstname" input');
@@ -91,27 +91,27 @@ class PersonControllerCreateTest extends WebTestCase
'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),
$this->assertTrue($form->has(self::BIRTHDATE_INPUT),
'The page has a "date of birth" input');
$genderType = $form->get(self::GENDER_INPUT);
$this->assertEquals('radio', $genderType->getType(),
$this->assertEquals('radio', $genderType->getType(),
'The gender input has radio buttons');
$this->assertEquals(3, count($genderType->availableOptionValues()),
'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');
$this->assertTrue(in_array('woman', $genderType->availableOptionValues()),
$this->assertTrue(in_array('woman', $genderType->availableOptionValues()),
'gender has "femme" option');
$this->assertFalse($genderType->hasValue(), 'The gender input is not checked');
return $form;
}
/**
* Test the creation of a valid person.
*
*
* @param Form $form
* @return string The id of the created person
* @depends testAddAPersonPage
@@ -125,9 +125,9 @@ class PersonControllerCreateTest extends WebTestCase
$this->assertTrue((bool)$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$|',
$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");
@@ -149,11 +149,11 @@ class PersonControllerCreateTest extends WebTestCase
$client = $this->client;
$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"
. "/{_locale}/person/{personID}/general");
}
/**
* test adding a person with a user with multi center
* is valid
@@ -161,70 +161,71 @@ class PersonControllerCreateTest extends WebTestCase
public function testValidFormWithMultiCenterUser()
{
$client = $this->getClientAuthenticated('multi_center');
$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");
$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),
'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(),
$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(),
$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->client;
$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(),
$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(),
$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) {

View File

@@ -33,165 +33,165 @@ class PersonSearchTest extends WebTestCase
public function testExpected()
{
$client = $this->getAuthenticatedClient();
$crawler = $client->request('GET', '/fr/search', array(
'q' => '@person Depardieu'
));
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
}
public function testExpectedNamed()
{
$client = $this->getAuthenticatedClient();
$crawler = $client->request('GET', '/fr/search', array(
'q' => '@person Depardieu', 'name' => 'person_regular'
));
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
}
public function testSearchByLastName()
{
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu');
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
}
public function testSearchByFirstNameLower()
{
$crawler = $this->generateCrawlerForSearch('@person firstname:Gérard');
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
}
public function testSearchByFirstNamePartim()
{
$crawler = $this->generateCrawlerForSearch('@person firstname:Ger');
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
}
public function testLastNameAccentued()
{
$crawlerSpecial = $this->generateCrawlerForSearch('@person lastname:manço');
$this->assertRegExp('/Manço/', $crawlerSpecial->filter('.list-with-period')->text());
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person lastname:manco');
$this->assertRegExp('/Manço/', $crawlerNoSpecial->filter('.list-with-period')->text());
}
public function testSearchByFirstName()
{
$crawler = $this->generateCrawlerForSearch('@person firstname:Jean');
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
}
public function testSearchByFirstNameLower2()
{
$crawler = $this->generateCrawlerForSearch('@person firstname:jean');
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
}
public function testSearchByFirstNamePartim2()
{
$crawler = $this->generateCrawlerForSearch('@person firstname:ean');
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
}
public function testSearchByFirstNameAccented()
{
$crawlerSpecial = $this->generateCrawlerForSearch('@person firstname:Gérard');
$this->assertRegExp('/Gérard/', $crawlerSpecial->filter('.list-with-period')->text());
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person firstname:Gerard');
$this->assertRegExp('/Gérard/', $crawlerNoSpecial->filter('.list-with-period')->text());
}
public function testSearchCombineLastnameAndNationality()
{
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu nationality:RU');
$this->assertRegExp('/Gérard/', $crawler->filter('.list-with-period')->text());
//if this is a AND clause, Jean Depardieu should not appears
$this->assertNotRegExp('/Jean/', $crawler->filter('.list-with-period')->text(),
"assert clause firstname and nationality are AND");
}
public function testSearchCombineLastnameAndFirstName()
{
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu firstname:Jean');
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
//if this is a AND clause, Jean Depardieu should not appears
$this->assertNotRegExp('/Gérard/', $crawler->filter('.list-with-period')->text(),
"assert clause firstname and nationality are AND");
}
public function testSearchBirthdate()
{
$crawler = $this->generateCrawlerForSearch('@person birthdate:1948-12-27');
$this->assertRegExp('/Gérard/', $crawler->filter('.list-with-period')->text());
$this->assertRegExp('/Bart/', $crawler->filter('.list-with-period')->text());
}
public function testSearchCombineBirthdateAndLastName()
{
$crawler = $this->generateCrawlerForSearch('@person birthdate:1948-12-27 lastname:(Van Snick)');
$this->assertRegExp('/Bart/', $crawler->filter('.list-with-period')->text());
$this->assertNotRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
}
public function testSearchCombineGenderAndLastName()
{
$crawler = $this->generateCrawlerForSearch('@person gender:woman lastname:(Depardieu)');
$this->assertRegExp('/Charline/', $crawler->filter('.list-with-period')->text());
$this->assertNotRegExp('/Gérard/', $crawler->filter('.list-with-period')->text());
}
public function testSearchMultipleTrigramUseAndClauseInDefault()
{
$crawler = $this->generateCrawlerForSearch('@person cha dep');
$this->assertRegExp('/Charline/', $crawler->filter('.list-with-period')->text());
$this->assertNotRegExp('/Gérard/', $crawler->filter('.list-with-period')->text());
$this->assertNotRegExp('/Jean/', $crawler->filter('.list-with-period')->text());
}
public function testDefaultAccented()
{
$crawlerSpecial = $this->generateCrawlerForSearch('@person manço');
$this->assertRegExp('/Manço/', $crawlerSpecial->filter('.list-with-period')->text());
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person manco');
$this->assertRegExp('/Manço/', $crawlerNoSpecial->filter('.list-with-period')->text());
$crawlerSpecial = $this->generateCrawlerForSearch('@person Étienne');
$this->assertRegExp('/Étienne/', $crawlerSpecial->filter('.list-with-period')->text());
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person etienne');
$this->assertRegExp('/Étienne/', $crawlerNoSpecial->filter('.list-with-period')->text());
}
/**
* test that person which a user cannot see are not displayed in results
*/
@@ -199,30 +199,29 @@ class PersonSearchTest extends WebTestCase
{
$crawlerCanSee = $this->generateCrawlerForSearch('Gérard', 'center a_social');
$crawlerCannotSee = $this->generateCrawlerForSearch('Gérard', 'center b_social');
$this->assertRegExp('/Gérard/', $crawlerCanSee->text(),
'center a_social may see "Gérard" in center a');
$this->assertRegExp('/Aucune personne ne correspond aux termes de recherche/',
$crawlerCannotSee->text(),
'center b_social may not see any "Gérard" associated to center b');
$this->assertRegExp('/Depardieu/', $crawlerCanSee->text(),
'center a_social may see "Depardieu" in center a');
$this->assertNotRegExp('/Depardieu/', $crawlerCannotSee->text(),
'center b_social may see "Depardieu" in center b');
}
private function generateCrawlerForSearch($pattern, $username = 'center a_social')
{
$client = $this->getAuthenticatedClient($username);
$crawler = $client->request('GET', '/fr/search', array(
'q' => $pattern,
));
$this->assertTrue($client->getResponse()->isSuccessful());
return $crawler;
}
/**
*
*
* @return \Symfony\Component\BrowserKit\Client
*/
private function getAuthenticatedClient($username = 'center a_social')

View File

@@ -27,7 +27,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Chill\MainBundle\Test\PrepareClientTrait;
/**
* This class tests entries are shown for closing and opening
* This class tests entries are shown for closing and opening
* periods in timeline.
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
@@ -40,22 +40,19 @@ class TimelineAccompanyingPeriodTest extends WebTestCase
/**
* @dataProvider provideDataPersonWithAccompanyingPeriod
*/
public function testEntriesAreShown($personId)
public function testEntriesAreShown($personId)
{
$client = $this->getClientAuthenticated();
$crawler = $client->request('GET', "/en/person/{$personId}/timeline");
$this->assertTrue($client->getResponse()->isSuccessful(),
"the timeline page loads sucessfully");
$this->assertGreaterThan(0, $crawler->filter('.timeline div')->count(),
"the timeline page contains multiple div inside a .timeline element");
$this->assertContains(" Une période d'accompagnement est ouverte",
$this->assertContains("est ouvert",
$crawler->filter('.timeline')->text(),
"the text 'une période d'accompagnement a été ouverte' is present");
$this->assertContains("Une periode d'accompagnement se clôture",
$crawler->Filter('.timeline')->text(),
"the text 'Une période d'accompagnement a été fermée' is present");
"the text 'est ouvert' is present");
}
public function provideDataPersonWithAccompanyingPeriod()
@@ -71,8 +68,7 @@ class TimelineAccompanyingPeriodTest extends WebTestCase
->join('part.accompanyingPeriod', 'period')
->join('p.center', 'center')
->select('p.id')
->where($qb->expr()->isNotNull('period.closingDate'))
->andWhere($qb->expr()->eq('center.name', ':center'))
->where($qb->expr()->eq('center.name', ':center'))
->setParameter('center', 'Center A')
->setMaxResults(1000)
->getQuery()
@@ -86,5 +82,5 @@ class TimelineAccompanyingPeriodTest extends WebTestCase
yield [ \array_pop($personIds)['id'] ];
}
}