mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-28 21:16:13 +00:00
DX: use more precise service parameter and use dataprovider for test
This commit is contained in:
parent
836cc7199e
commit
333579de06
@ -11,7 +11,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
@ -20,57 +22,73 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
*/
|
||||
final class PersonDuplicateControllerViewTest extends WebTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
public function providePersonData(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->em = self::$container
|
||||
->get('doctrine.orm.entity_manager');
|
||||
/** @var EntityManagerInterface $em */
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
/** @var CenterRepositoryInterface $centerRepository */
|
||||
$centerRepository = self::$container->get(CenterRepositoryInterface::class);
|
||||
|
||||
$center = $this->em->getRepository(\Chill\MainBundle\Entity\Center::class)
|
||||
->findOneBy(['name' => 'Center A']);
|
||||
|
||||
$this->person = (new Person())
|
||||
$center = $centerRepository->findOneBy(['name' => 'Center A']);
|
||||
$person = (new Person())
|
||||
->setLastName('Tested Persan')
|
||||
->setFirstName('Réginal')
|
||||
->setCenter($center)
|
||||
->setGender(Person::MALE_GENDER);
|
||||
$this->em->persist($this->person);
|
||||
$em->persist($person);
|
||||
|
||||
$this->person2 = (new Person())
|
||||
foreach ($person->getCenterHistory() as $centerHistory) {
|
||||
$em->persist($centerHistory);
|
||||
}
|
||||
|
||||
$person2 = (new Person())
|
||||
->setLastName('Tested Person')
|
||||
->setFirstName('Réginald')
|
||||
->setCenter($center)
|
||||
->setGender(Person::MALE_GENDER);
|
||||
$this->em->persist($this->person2);
|
||||
$em->persist($person2);
|
||||
|
||||
$this->em->flush();
|
||||
foreach ($person2->getCenterHistory() as $centerHistory) {
|
||||
$em->persist($centerHistory);
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
|
||||
yield [$person->getId(), $person2->getId()];
|
||||
}
|
||||
|
||||
public function testViewDuplicatePerson()
|
||||
/**
|
||||
* @dataProvider providePersonData
|
||||
* @param int $personId
|
||||
* @param int $person2Id
|
||||
* @return void
|
||||
*/
|
||||
public function testViewDuplicatePerson(int $personId, int $person2Id): void
|
||||
{
|
||||
$client = self::createClient([], [
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
]);
|
||||
|
||||
$crawler = $client->request('GET', '/en/person/' . $this->person->getId() . '/duplicate/view');
|
||||
$crawler = $client->request('GET', '/en/person/' . $personId . '/duplicate/view');
|
||||
$response = $client->getResponse();
|
||||
var_dump(substr($crawler->html(), 0, 500));
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("Find duplicate")')->count());
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginal")')->count());
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginald")')->count());
|
||||
|
||||
$crawler = $client->request('GET', '/en/person/' . $this->person->getId() . '/duplicate/' . $this->person2->getId() . '/confirm');
|
||||
$crawler = $client->request('GET', '/en/person/' . $personId . '/duplicate/' . $person2Id . '/confirm');
|
||||
$response = $client->getResponse();
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("Old person")')->count());
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("New person")')->count());
|
||||
|
||||
$crawler = $client->request('POST', '/en/person/' . $this->person->getId() . '/duplicate/' . $this->person2->getId() . '/confirm', [
|
||||
$crawler = $client->request('POST', '/en/person/' . $personId . '/duplicate/' . $person2Id . '/confirm', [
|
||||
'chill_personbundle_person_confirm_duplicate[confirm]' => 1,
|
||||
]);
|
||||
$response = $client->getResponse();
|
||||
|
Loading…
x
Reference in New Issue
Block a user