Fix tests on person's controller

This commit is contained in:
Julien Fastré 2023-08-29 15:02:38 +02:00
parent 939a6753bd
commit 5314e7b501
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 11 additions and 60 deletions

View File

@ -134,25 +134,6 @@ final class PersonControllerCreateTest extends WebTestCase
return $form;
}
/**
* Test if, for a given person if its person view page (at the url
* fr/person/$personID/general) is accessible.
*
* @param int|string $personId The is of the person
* @depends testValidForm
*/
public function testPersonViewAccessible(int|string $personId)
{
$client = $this->client;
$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'
);
}
public function testReviewExistingDetectionInversedLastNameWithFirstName()
{
$client = $this->client;
@ -162,23 +143,23 @@ final class PersonControllerCreateTest extends WebTestCase
//test the page is loaded before continuing
$this->assertTrue($client->getResponse()->isSuccessful());
$form = $crawler->selectButton('Ajouter la personne')->form();
$form = $crawler->selectButton("Créer l'usager")->form();
$form = $this->fillAValidCreationForm($form, 'Charline', 'dd');
$client->submit($form);
$this->assertStringContainsString(
'DEPARDIEU',
'usager a un nom similaire',
$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 = $crawler->selectButton("Créer l'usager")->form();
$form = $this->fillAValidCreationForm($form, 'dd', 'Charline');
$client->submit($form);
$this->assertStringContainsString(
'DEPARDIEU',
'usager a un nom similaire',
$client->getCrawler()->text(),
'check that the page has detected the lastname of a person existing in database'
);
@ -194,32 +175,12 @@ final class PersonControllerCreateTest extends WebTestCase
$client = $this->client;
$crawler = $client->request('GET', '/fr/person/new');
$form = $crawler->selectButton('Ajouter la personne')->form();
$this->fillAValidCreationForm($form);
$form = $crawler->selectButton("Créer l'usager")->form();
$this->fillAValidCreationForm($form, uniqid(), uniqid());
$client = $this->client;
$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->assertMatchesRegularExpression(
'|/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];
self::assertResponseRedirects();
}
/**
@ -236,10 +197,10 @@ final class PersonControllerCreateTest extends WebTestCase
$client->getResponse()->isSuccessful(),
'The page is accessible at the URL /{_locale}/person/new'
);
$form = $crawler->selectButton('Ajouter la personne')->form();
$form = $crawler->selectButton("Créer l'usager")->form();
// create a very long name to avoid collision
$this->fillAValidCreationForm($form, 'Carmela Girdana Assuntamente Castalle', 'rabbit');
$this->fillAValidCreationForm($form, uniqid(), uniqid());
$this->assertTrue(
$form->has(self::CENTER_INPUT),
@ -254,16 +215,7 @@ final class PersonControllerCreateTest extends WebTestCase
$client->submit($form);
$this->assertTrue(
$client->getResponse()->isRedirect(),
'a valid form redirect to url /{_locale}/person/{personId}/general/edit'
);
$client->followRedirect();
$this->assertMatchesRegularExpression(
'|/fr/person/[1-9][0-9]*/general/edit$|',
$client->getHistory()->current()->getUri(),
'a valid form redirect to url /{_locale}/person/{personId}/general/edit'
);
self::assertResponseRedirects();
}
private function fillAValidCreationForm(

View File

@ -71,9 +71,8 @@ final class PersonControllerViewTest extends WebTestCase
]);
$crawler = $client->request('GET', $this->viewUrl);
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
self::assertResponseIsSuccessful();
$this->assertGreaterThan(0, $crawler->filter('html:contains("TESTED PERSON")')->count());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginald")')->count());