mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Merge remote-tracking branch 'origin/master' into bootstrap-api
This commit is contained in:
@@ -24,12 +24,14 @@ namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\DomCrawler\Form;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
|
||||
/**
|
||||
* Test creation and deletion for persons
|
||||
*/
|
||||
class PersonControllerCreateTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
const FIRSTNAME_INPUT = 'chill_personbundle_person_creation[firstName]';
|
||||
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 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.";
|
||||
|
||||
/**
|
||||
* return an authenticated client, useful for submitting form
|
||||
*
|
||||
* @return \Symfony\Component\BrowserKit\Client
|
||||
*/
|
||||
private function getAuthenticatedClient($username = 'center a_social')
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
return static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => $username,
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
$this->client = $this::getClientAuthenticated();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Form $creationForm
|
||||
@@ -76,8 +70,8 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
*/
|
||||
public function testAddAPersonPage()
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
|
||||
$client = $this->client;
|
||||
$crawler = $client->request('GET', '/fr/person/new');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful(),
|
||||
@@ -99,9 +93,9 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
|
||||
$genderType = $form->get(self::GENDER_INPUT);
|
||||
$this->assertEquals('radio', $genderType->getType(),
|
||||
'The gender input has two radio button: man and women');
|
||||
$this->assertEquals(2, count($genderType->availableOptionValues()),
|
||||
'The gender input has two radio button: man and women');
|
||||
'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()),
|
||||
'gender has "homme" option');
|
||||
$this->assertTrue(in_array('woman', $genderType->availableOptionValues()),
|
||||
@@ -120,45 +114,14 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
* @param Form $form
|
||||
* @depends testAddAPersonPage
|
||||
*/
|
||||
public function testFirstnameTooLong(Form $form)
|
||||
public function testForgedNullGender(Form $form)
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
$this->fillAValidCreationForm($form);
|
||||
$form->get(self::FIRSTNAME_INPUT)->setValue(mb_substr(self::LONG_TEXT, 0, 256));
|
||||
$crawler = $client->submit($form);
|
||||
|
||||
$this->assertEquals(1, $crawler->filter('.error')->count(),
|
||||
"An error message is shown if we fill more than 255 characters in firstname");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Form $form
|
||||
* @depends testAddAPersonPage
|
||||
*/
|
||||
public function testLastnameTooLong(Form $form)
|
||||
{
|
||||
$this->fillAValidCreationForm($form);
|
||||
$form->get(self::LASTNAME_INPUT)->setValue(mb_substr(self::LONG_TEXT, 0, 256));
|
||||
$crawler = $this->getAuthenticatedClient()->submit($form);
|
||||
|
||||
$this->assertEquals(1, $crawler->filter('.error')->count(),
|
||||
"An error message is shown if we fill more than 255 characters in lastname");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Form $form
|
||||
* @depends testAddAPersonPage
|
||||
*/
|
||||
public function testGenderIsNull(Form $form)
|
||||
{
|
||||
$this->fillAValidCreationForm($form);
|
||||
$form->get(self::GENDER_INPUT)->disableValidation()->setValue(NULL);
|
||||
$crawler = $this->getAuthenticatedClient()->submit($form);
|
||||
|
||||
$this->assertEquals(1, $crawler->filter('.error')->count(),
|
||||
'A message is shown if gender is not set');
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,10 +134,10 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
public function testValidForm(Form $form)
|
||||
{
|
||||
$this->fillAValidCreationForm($form);
|
||||
$client = $this->getAuthenticatedClient();
|
||||
$client = $this->client;
|
||||
$client->submit($form);
|
||||
|
||||
$this->assertTrue($client->getResponse()->isRedirect(),
|
||||
$this->assertTrue((bool)$client->getResponse()->isRedirect(),
|
||||
"a valid form redirect to url /{_locale}/person/{personId}/general/edit");
|
||||
$client->followRedirect();
|
||||
|
||||
@@ -198,7 +161,7 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
*/
|
||||
public function testPersonViewAccessible($personId)
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
$client = $this->client;
|
||||
$client->request('GET', '/fr/person/'.$personId.'/general');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful(),
|
||||
@@ -212,7 +175,7 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
*/
|
||||
public function testValidFormWithMultiCenterUser()
|
||||
{
|
||||
$client = $this->getAuthenticatedClient('multi_center');
|
||||
$client = $this->getClientAuthenticated('multi_center');
|
||||
|
||||
$crawler = $client->request('GET', '/fr/person/new');
|
||||
|
||||
@@ -242,7 +205,7 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
|
||||
public function testReviewExistingDetectionInversedLastNameWithFirstName()
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
$client = $this->client;
|
||||
|
||||
$crawler = $client->request('GET', '/fr/person/new');
|
||||
|
||||
|
@@ -24,6 +24,7 @@ namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
|
||||
/**
|
||||
* Test the edition of persons
|
||||
@@ -34,6 +35,8 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
*/
|
||||
class PersonControllerUpdateTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
|
||||
private $em;
|
||||
|
||||
@@ -71,10 +74,7 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
$this->editUrl = '/en/person/'.$this->person->getId().'/general/edit';
|
||||
$this->viewUrl = '/en/person/'.$this->person->getId().'/general';
|
||||
|
||||
$this->client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
$this->client = $this->getClientAuthenticated();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -24,6 +24,10 @@ namespace Chill\PersonBundle\Tests\Entity;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use Generator;
|
||||
|
||||
/**
|
||||
* Unit tests for the person Entity
|
||||
@@ -151,4 +155,54 @@ class PersonTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->assertEquals($r['result'], Person::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD);
|
||||
}
|
||||
|
||||
public function dateProvider(): Generator
|
||||
{
|
||||
yield [(DateTime::createFromFormat('Y-m-d', '2021-01-05'))->settime(0, 0)];
|
||||
yield [(DateTime::createFromFormat('Y-m-d', '2021-02-05'))->settime(0, 0)];
|
||||
yield [(DateTime::createFromFormat('Y-m-d', '2021-03-05'))->settime(0, 0)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dateProvider
|
||||
*/
|
||||
public function testGetLastAddress(DateTime $date)
|
||||
{
|
||||
$p = new Person($date);
|
||||
|
||||
// Make sure that there is no last address.
|
||||
$this::assertNull($p->getLastAddress());
|
||||
|
||||
// Take an arbitrary date before the $date in parameter.
|
||||
$addressDate = clone $date;
|
||||
|
||||
// 1. Smoke test: Test that the first address added is the last one.
|
||||
$address1 = (new Address())->setValidFrom($addressDate->sub(new DateInterval('PT180M')));
|
||||
$p->addAddress($address1);
|
||||
|
||||
$this::assertCount(1, $p->getAddresses());
|
||||
$this::assertSame($address1, $p->getLastAddress());
|
||||
|
||||
// 2. Add an older address, which should not be the last address.
|
||||
$addressDate2 = clone $addressDate;
|
||||
$address2 = (new Address())->setValidFrom($addressDate2->sub(new DateInterval('PT30M')));
|
||||
$p->addAddress($address2);
|
||||
|
||||
$this::assertCount(2, $p->getAddresses());
|
||||
$this::assertSame($address1, $p->getLastAddress());
|
||||
|
||||
// 3. Add a newer address, which should be the last address.
|
||||
$addressDate3 = clone $addressDate;
|
||||
$address3 = (new Address())->setValidFrom($addressDate3->add(new DateInterval('PT30M')));
|
||||
$p->addAddress($address3);
|
||||
|
||||
$this::assertCount(3, $p->getAddresses());
|
||||
$this::assertSame($address3, $p->getLastAddress());
|
||||
|
||||
// 4. Get the last address from a specific date.
|
||||
$this::assertEquals($address1, $p->getLastAddress($addressDate));
|
||||
$this::assertEquals($address2, $p->getLastAddress($addressDate2));
|
||||
$this::assertEquals($address3, $p->getLastAddress($addressDate3));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -36,12 +36,6 @@ class PickPersonTypeTest extends KernelTestCase
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\Form\FormFactoryInterface
|
||||
@@ -52,16 +46,14 @@ class PickPersonTypeTest extends KernelTestCase
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->container = self::$kernel->getContainer();
|
||||
|
||||
$this->user = $this->container->get('doctrine.orm.entity_manager')
|
||||
$this->user = self::$container->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(array('username' => 'multi_center'));
|
||||
|
||||
$this->formFactory = $this->container->get('form.factory');
|
||||
$this->formFactory = self::$container->get('form.factory');
|
||||
|
||||
$token = (new UsernamePasswordToken($this->user, 'password', 'firewall'));
|
||||
$this->container->get('security.token_storage')
|
||||
self::$container->get('security.token_storage')
|
||||
->setToken($token);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user