mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 22:04:23 +00:00
111 lines
3.3 KiB
PHP
111 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace Chill\PersonBundle\Tests\Controller;
|
|
|
|
use Chill\MainBundle\Test\PrepareClientTrait;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
class PersonApiControllerTest extends WebTestCase
|
|
{
|
|
use PrepareClientTrait;
|
|
|
|
/**
|
|
* @dataProvider dataGetPersonFromCenterB
|
|
*/
|
|
public function testPersonGetUnauthorized($personId): void
|
|
{
|
|
$client = $this->getClientAuthenticated();
|
|
|
|
$client->request(Request::METHOD_GET, "/api/1.0/person/person/{$personId}.json");
|
|
$response = $client->getResponse();
|
|
|
|
$this->assertEquals(403, $response->getStatusCode());
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataGetPersonFromCenterA
|
|
*/
|
|
public function testPersonGet($personId): void
|
|
{
|
|
$client = $this->getClientAuthenticated();
|
|
|
|
$client->request(Request::METHOD_GET, "/api/1.0/person/person/{$personId}.json");
|
|
$response = $client->getResponse();
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
$data = \json_decode($client->getResponse()->getContent(), true);
|
|
|
|
$this->assertArrayHasKey('type', $data);
|
|
$this->assertArrayHasKey('id', $data);
|
|
$this->assertEquals('person', $data['type']);
|
|
$this->assertEquals($personId, $data['id']);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataGetPersonFromCenterA
|
|
*/
|
|
public function testPersonAddressSuggestion($personId): void
|
|
{
|
|
$client = $this->getClientAuthenticated();
|
|
|
|
$client->request(Request::METHOD_GET, "/api/1.0/person/address/suggest/by-person/{$personId}.json");
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataGetPersonFromCenterB
|
|
*/
|
|
public function testPersonAddressSuggestionUnauthorized($personId): void
|
|
{
|
|
$client = $this->getClientAuthenticated();
|
|
|
|
$client->request(Request::METHOD_GET, "/api/1.0/person/address/suggest/by-person/{$personId}.json");
|
|
$response = $client->getResponse();
|
|
|
|
$this->assertEquals(403, $response->getStatusCode());
|
|
}
|
|
|
|
public function dataGetPersonFromCenterA(): \Iterator
|
|
{
|
|
self::bootKernel();
|
|
$em = self::$container->get(EntityManagerInterface::class);
|
|
$personIds= $em->createQuery("SELECT p.id FROM ".Person::class." p ".
|
|
"JOIN p.center c ".
|
|
"WHERE c.name = :center")
|
|
->setParameter('center', 'Center A')
|
|
->setMaxResults(100)
|
|
->getScalarResult()
|
|
;
|
|
|
|
\shuffle($personIds);
|
|
|
|
yield \array_pop($personIds);
|
|
yield \array_pop($personIds);
|
|
yield \array_pop($personIds);
|
|
yield \array_pop($personIds);
|
|
}
|
|
|
|
public function dataGetPersonFromCenterB(): \Iterator
|
|
{
|
|
self::bootKernel();
|
|
$em = self::$container->get(EntityManagerInterface::class);
|
|
$personIds= $em->createQuery("SELECT p.id FROM ".Person::class." p ".
|
|
"JOIN p.center c ".
|
|
"WHERE c.name = :center")
|
|
->setParameter('center', 'Center B')
|
|
->setMaxResults(100)
|
|
->getScalarResult()
|
|
;
|
|
|
|
\shuffle($personIds);
|
|
|
|
yield \array_pop($personIds);
|
|
yield \array_pop($personIds);
|
|
}
|
|
}
|