mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 13:54:59 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,52 +1,76 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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 Iterator;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use function array_pop;
|
||||
use function json_decode;
|
||||
use function shuffle;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class PersonApiControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
/**
|
||||
* @dataProvider dataGetPersonFromCenterB
|
||||
*/
|
||||
public function testPersonGetUnauthorized($personId): void
|
||||
public function dataGetPersonFromCenterA(): Iterator
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
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();
|
||||
|
||||
$client->request(Request::METHOD_GET, "/api/1.0/person/person/{$personId}.json");
|
||||
$response = $client->getResponse();
|
||||
shuffle($personIds);
|
||||
|
||||
$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']);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGetPersonFromCenterA
|
||||
*
|
||||
* @param mixed $personId
|
||||
*/
|
||||
public function testPersonAddressSuggestion($personId): void
|
||||
{
|
||||
@@ -59,6 +83,8 @@ class PersonApiControllerTest extends WebTestCase
|
||||
|
||||
/**
|
||||
* @dataProvider dataGetPersonFromCenterB
|
||||
*
|
||||
* @param mixed $personId
|
||||
*/
|
||||
public function testPersonAddressSuggestionUnauthorized($personId): void
|
||||
{
|
||||
@@ -70,41 +96,40 @@ class PersonApiControllerTest extends WebTestCase
|
||||
$this->assertEquals(403, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function dataGetPersonFromCenterA(): \Iterator
|
||||
/**
|
||||
* @dataProvider dataGetPersonFromCenterA
|
||||
*
|
||||
* @param mixed $personId
|
||||
*/
|
||||
public function testPersonGet($personId): void
|
||||
{
|
||||
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()
|
||||
;
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
\shuffle($personIds);
|
||||
$client->request(Request::METHOD_GET, "/api/1.0/person/person/{$personId}.json");
|
||||
$response = $client->getResponse();
|
||||
|
||||
yield \array_pop($personIds);
|
||||
yield \array_pop($personIds);
|
||||
yield \array_pop($personIds);
|
||||
yield \array_pop($personIds);
|
||||
}
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
public function dataGetPersonFromCenterB(): \Iterator
|
||||
$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 dataGetPersonFromCenterB
|
||||
*
|
||||
* @param mixed $personId
|
||||
*/
|
||||
public function testPersonGetUnauthorized($personId): void
|
||||
{
|
||||
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()
|
||||
;
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
\shuffle($personIds);
|
||||
$client->request(Request::METHOD_GET, "/api/1.0/person/person/{$personId}.json");
|
||||
$response = $client->getResponse();
|
||||
|
||||
yield \array_pop($personIds);
|
||||
yield \array_pop($personIds);
|
||||
}
|
||||
$this->assertEquals(403, $response->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user