tests/ChillPersonBundle: use mutualized getClientAuthenticated()

This commit is contained in:
Christophe Siraut 2021-04-23 11:13:35 +02:00
parent 3445335b2d
commit 53813f8f29
2 changed files with 16 additions and 22 deletions

View File

@ -24,12 +24,14 @@ namespace Chill\PersonBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DomCrawler\Form; use Symfony\Component\DomCrawler\Form;
use Chill\MainBundle\Test\PrepareClientTrait;
/** /**
* Test creation and deletion for persons * Test creation and deletion for persons
*/ */
class PersonControllerCreateTest extends WebTestCase class PersonControllerCreateTest extends WebTestCase
{ {
use PrepareClientTrait;
const FIRSTNAME_INPUT = 'chill_personbundle_person_creation[firstName]'; const FIRSTNAME_INPUT = 'chill_personbundle_person_creation[firstName]';
const LASTNAME_INPUT = "chill_personbundle_person_creation[lastName]"; const LASTNAME_INPUT = "chill_personbundle_person_creation[lastName]";
@ -39,20 +41,12 @@ class PersonControllerCreateTest extends WebTestCase
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()
* return an authenticated client, useful for submitting form
*
* @return \Symfony\Component\BrowserKit\Client
*/
private function getAuthenticatedClient($username = 'center a_social')
{ {
return static::createClient(array(), array( $this->client = $this::getClientAuthenticated();
'PHP_AUTH_USER' => $username,
'PHP_AUTH_PW' => 'password',
));
} }
/** /**
* *
* @param Form $creationForm * @param Form $creationForm
@ -76,8 +70,8 @@ class PersonControllerCreateTest extends WebTestCase
*/ */
public function testAddAPersonPage() public function testAddAPersonPage()
{ {
$client = $this->getAuthenticatedClient();
$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(),
@ -122,7 +116,7 @@ class PersonControllerCreateTest extends WebTestCase
*/ */
public function testFirstnameTooLong(Form $form) public function testFirstnameTooLong(Form $form)
{ {
$client = $this->getAuthenticatedClient(); $client = $this-client;
$this->fillAValidCreationForm($form); $this->fillAValidCreationForm($form);
$form->get(self::FIRSTNAME_INPUT)->setValue(mb_substr(self::LONG_TEXT, 0, 256)); $form->get(self::FIRSTNAME_INPUT)->setValue(mb_substr(self::LONG_TEXT, 0, 256));
$crawler = $client->submit($form); $crawler = $client->submit($form);
@ -171,7 +165,7 @@ class PersonControllerCreateTest extends WebTestCase
public function testValidForm(Form $form) public function testValidForm(Form $form)
{ {
$this->fillAValidCreationForm($form); $this->fillAValidCreationForm($form);
$client = $this->getAuthenticatedClient(); $client = $this->client;
$client->submit($form); $client->submit($form);
$this->assertTrue($client->getResponse()->isRedirect(), $this->assertTrue($client->getResponse()->isRedirect(),
@ -198,7 +192,7 @@ class PersonControllerCreateTest extends WebTestCase
*/ */
public function testPersonViewAccessible($personId) public function testPersonViewAccessible($personId)
{ {
$client = $this->getAuthenticatedClient(); $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(),
@ -212,7 +206,7 @@ class PersonControllerCreateTest extends WebTestCase
*/ */
public function testValidFormWithMultiCenterUser() public function testValidFormWithMultiCenterUser()
{ {
$client = $this->getAuthenticatedClient('multi_center'); $client = $this->getClientAuthenticated('multi_center');
$crawler = $client->request('GET', '/fr/person/new'); $crawler = $client->request('GET', '/fr/person/new');
@ -242,7 +236,7 @@ class PersonControllerCreateTest extends WebTestCase
public function testReviewExistingDetectionInversedLastNameWithFirstName() public function testReviewExistingDetectionInversedLastNameWithFirstName()
{ {
$client = $this->getAuthenticatedClient(); $client = $this->client;
$crawler = $client->request('GET', '/fr/person/new'); $crawler = $client->request('GET', '/fr/person/new');

View File

@ -24,6 +24,7 @@ namespace Chill\PersonBundle\Tests\Controller;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Chill\MainBundle\Test\PrepareClientTrait;
/** /**
* Test the edition of persons * Test the edition of persons
@ -34,6 +35,8 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/ */
class PersonControllerUpdateTest extends WebTestCase class PersonControllerUpdateTest extends WebTestCase
{ {
use PrepareClientTrait;
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */ /** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
private $em; private $em;
@ -71,10 +74,7 @@ class PersonControllerUpdateTest extends WebTestCase
$this->editUrl = '/en/person/'.$this->person->getId().'/general/edit'; $this->editUrl = '/en/person/'.$this->person->getId().'/general/edit';
$this->viewUrl = '/en/person/'.$this->person->getId().'/general'; $this->viewUrl = '/en/person/'.$this->person->getId().'/general';
$this->client = static::createClient(array(), array( $this->client = $this->getClientAuthenticated();
'PHP_AUTH_USER' => 'center a_social',
'PHP_AUTH_PW' => 'password',
));
} }
/** /**