mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Merge branch 'master' into 'fix-accompanying-period-opening'
# Conflicts: # src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php
This commit is contained in:
@@ -27,11 +27,14 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
|
||||
|
||||
/**
|
||||
* Test api for AccompanyingCourseControllerTest
|
||||
@@ -40,6 +43,10 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
{
|
||||
protected static EntityManagerInterface $em;
|
||||
|
||||
protected ?int $personId = NULL;
|
||||
|
||||
protected ?AccompanyingPeriod $period = NULL;
|
||||
|
||||
/**
|
||||
* Setup before the first test of this class (see phpunit doc)
|
||||
*/
|
||||
@@ -85,6 +92,310 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
$this->assertEquals(404, $response->getStatusCode(), "Test that the response of rest api has a status code 'not found' (404)");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider dataGenerateRandomAccompanyingCourseWithSocialIssue
|
||||
*/
|
||||
public function testAccompanyingCourseAddRemoveSocialIssue(AccompanyingPeriod $period, SocialIssue $si)
|
||||
{
|
||||
$this->client->request(
|
||||
Request::METHOD_POST,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/socialissue.json', $period->getId()),
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
\json_encode([ 'type' => 'social_issue', 'id' => $si->getId() ])
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
||||
|
||||
$data = \json_decode($this->client->getResponse()->getContent(), true);
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertArrayHasKey('type', $data);
|
||||
$this->assertEquals('social_issue', $data['type']);
|
||||
|
||||
|
||||
$this->client->request(
|
||||
Request::METHOD_DELETE,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/socialissue.json', $period->getId()),
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
\json_encode([ 'type' => 'social_issue', 'id' => $si->getId() ])
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGenerateRandomRequestorValidData
|
||||
*/
|
||||
public function testCommentWithValidData(AccompanyingPeriod $period, $personId, $thirdPartyId)
|
||||
{
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$this->client->request(
|
||||
Request::METHOD_POST,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/comment.json', $period->getId()),
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'type' => 'accompanying_period_comment', 'content' => "this is a text"])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
|
||||
$this->client->request(
|
||||
Request::METHOD_DELETE,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/comment.json', $period->getId()),
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'type' => 'accompanying_period_comment', 'id' => $data['id']])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGenerateRandomRequestorValidData
|
||||
*/
|
||||
public function testResourceWithValidData(AccompanyingPeriod $period, $personId, $thirdPartyId)
|
||||
{
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
// post a person
|
||||
$this->client->request(
|
||||
Request::METHOD_POST,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/resource.json', $period->getId()),
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'type' => 'accompanying_period_resource', 'resource' => [ 'type' => 'person', 'id' => $personId ]])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertEquals($personId, $data['resource']['id']);
|
||||
|
||||
// check into database
|
||||
$resource = $em->getRepository(Resource::class)
|
||||
->find($data['id']);
|
||||
$this->assertInstanceOf(Resource::class, $resource);
|
||||
$this->assertInstanceOf(Person::class, $resource->getResource());
|
||||
$this->assertEquals($personId, $resource->getResource()->getId());
|
||||
|
||||
// remove the resource
|
||||
$this->client->request(
|
||||
Request::METHOD_DELETE,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/requestor.json', $period->getId()),
|
||||
[],
|
||||
[],
|
||||
[], //server
|
||||
\json_encode([ 'type' => 'accompanying_period_resource', 'id' => $resource->getId()])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
|
||||
// post a third party
|
||||
$this->client->request(
|
||||
Request::METHOD_POST,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/resource.json', $period->getId()),
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'type' => 'accompanying_period_resource', 'resource' => [ 'type' => 'thirdparty', 'id' => $thirdPartyId ]])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertEquals($thirdPartyId, $data['resource']['id']);
|
||||
|
||||
// check into database
|
||||
$resource = $em->getRepository(Resource::class)
|
||||
->find($data['id']);
|
||||
$this->assertInstanceOf(Resource::class, $resource);
|
||||
$this->assertInstanceOf(ThirdParty::class, $resource->getResource());
|
||||
$this->assertEquals($thirdPartyId, $resource->getResource()->getId());
|
||||
|
||||
// remove the resource
|
||||
$this->client->request(
|
||||
Request::METHOD_DELETE,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/requestor.json', $period->getId()),
|
||||
[],
|
||||
[],
|
||||
[], //server
|
||||
\json_encode([ 'type' => 'accompanying_period_resource', 'id' => $resource->getId()])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGenerateRandomRequestorValidData
|
||||
*/
|
||||
public function testRequestorWithValidData(AccompanyingPeriod $period, $personId, $thirdPartyId)
|
||||
{
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
// post a person
|
||||
$this->client->request(
|
||||
Request::METHOD_POST,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/requestor.json', $period->getId()),
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'type' => 'person', 'id' => $personId ])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertEquals($personId, $data['id']);
|
||||
|
||||
// check into database
|
||||
$period = $em->getRepository(AccompanyingPeriod::class)
|
||||
->find($period->getId());
|
||||
$this->assertInstanceOf(Person::class, $period->getRequestor());
|
||||
$this->assertEquals($personId, $period->getRequestor()->getId());
|
||||
|
||||
// post a third party
|
||||
$this->client->request(
|
||||
Request::METHOD_POST,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/requestor.json', $period->getId()),
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'type' => 'thirdparty', 'id' => $thirdPartyId ])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertEquals($thirdPartyId, $data['id']);
|
||||
|
||||
// check into database
|
||||
$period = $em->getRepository(AccompanyingPeriod::class)
|
||||
->find($period->getId());
|
||||
$this->assertInstanceOf(ThirdParty::class, $period->getRequestor());
|
||||
$this->assertEquals($thirdPartyId, $period->getRequestor()->getId());
|
||||
|
||||
// remove the requestor
|
||||
$this->client->request(
|
||||
Request::METHOD_DELETE,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/requestor.json', $period->getId())
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
|
||||
// check into database
|
||||
$period = $em->getRepository(AccompanyingPeriod::class)
|
||||
->find($period->getId());
|
||||
$em->refresh($period);
|
||||
$this->assertNull($period->getRequestor());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGenerateNewAccompanyingCourse
|
||||
*/
|
||||
public function testConfirm(AccompanyingPeriod $period)
|
||||
{
|
||||
$this->client->request(
|
||||
Request::METHOD_POST,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/confirm.json', $period->getId())
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
||||
|
||||
// add period to remove it in tear down
|
||||
$this->period = $period;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider dataGenerateRandomAccompanyingCourse
|
||||
*/
|
||||
public function testAccompanyingPeriodPatch(int $personId, AccompanyingPeriod $period)
|
||||
{
|
||||
$initialValueEmergency = $period->isEmergency();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$this->client->request(
|
||||
Request::METHOD_PATCH,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d.json', $period->getId()),
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'type' => 'accompanying_period', 'emergency' => !$initialValueEmergency ])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$period = $em->getRepository(AccompanyingPeriod::class)
|
||||
->find($period->getId());
|
||||
$em->refresh($period);
|
||||
$this->assertEquals(!$initialValueEmergency, $period->isEmergency());
|
||||
|
||||
// restore the initial valud
|
||||
$period->setEmergency($initialValueEmergency);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
public function dataGenerateRandomRequestorValidData(): \Iterator
|
||||
{
|
||||
$dataLength = 2;
|
||||
$maxResults = 100;
|
||||
|
||||
static::bootKernel();
|
||||
$em = static::$container->get(EntityManagerInterface::class);
|
||||
$center = $em->getRepository(Center::class)
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
|
||||
$personIds = $em->createQuery("SELECT p.id FROM ".
|
||||
Person::class." p ".
|
||||
" WHERE p.center = :center")
|
||||
->setParameter('center', $center)
|
||||
->setMaxResults($maxResults)
|
||||
->getScalarResult();
|
||||
|
||||
// create a random order
|
||||
shuffle($personIds);
|
||||
|
||||
$thirdPartyIds = $em->createQuery("SELECT t.id FROM ".
|
||||
ThirdParty::class." t ")
|
||||
->setMaxResults($maxResults)
|
||||
->getScalarResult();
|
||||
|
||||
// create a random order
|
||||
shuffle($thirdPartyIds);
|
||||
|
||||
$i = 0;
|
||||
while ($i <= $dataLength) {
|
||||
$person = $em->getRepository(Person::class)
|
||||
->find(\array_pop($personIds)['id']);
|
||||
|
||||
if (count($person->getAccompanyingPeriods()) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$period = $person->getAccompanyingPeriods()[0];
|
||||
|
||||
yield [$period, \array_pop($personIds)['id'], \array_pop($thirdPartyIds)['id'] ];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider dataGenerateRandomAccompanyingCourse
|
||||
@@ -97,7 +408,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'id' => $personId ])
|
||||
\json_encode([ 'type' => 'person', 'id' => $personId ])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
@@ -128,7 +439,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'id' => $personId ])
|
||||
\json_encode([ 'type' => 'person', 'id' => $personId ])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
@@ -148,25 +459,79 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// remove participation created during test 'testAccompanyingCourseAddParticipation'
|
||||
// and if the test could not remove it
|
||||
|
||||
$testAddParticipationName = 'testAccompanyingCourseAddParticipation';
|
||||
|
||||
if ($testAddParticipationName !== \substr($this->getName(), 0, \strlen($testAddParticipationName))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$em = static::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$participation = $em
|
||||
->getRepository(AccompanyingPeriodParticipation::class)
|
||||
->findOneBy(['person' => $this->personId, 'accompanyingPeriod' => $this->period])
|
||||
;
|
||||
// remove participation if set
|
||||
if ($this->personId && $this->period) {
|
||||
$participation = $em
|
||||
->getRepository(AccompanyingPeriodParticipation::class)
|
||||
->findOneBy(['person' => $this->personId, 'accompanyingPeriod' => $this->period])
|
||||
;
|
||||
|
||||
if (NULL !== $participation) {
|
||||
$em->remove($participation);
|
||||
$em->flush();
|
||||
if (NULL !== $participation) {
|
||||
$em->remove($participation);
|
||||
$em->flush();
|
||||
}
|
||||
$this->personId = NULL;
|
||||
$this->period = NULL;
|
||||
} elseif ($this->period) {
|
||||
$period = $em
|
||||
->getRepository(AccompanyingPeriod::class)
|
||||
->find($this->period->getId()) ;
|
||||
|
||||
if ($period !== NULL) {
|
||||
$em->remove($period);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
$this->period = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function dataGenerateRandomAccompanyingCourseWithSocialIssue()
|
||||
{
|
||||
// note about max result for person query, and maxGenerated:
|
||||
//
|
||||
// in the final loop, an id is popped out of the personIds array twice:
|
||||
//
|
||||
// * one for getting the person, which will in turn provide his accompanying period;
|
||||
// * one for getting the personId to populate to the data manager
|
||||
//
|
||||
// Ensure to keep always $maxGenerated to the double of $maxResults. x8 is a good compromize :)
|
||||
$maxGenerated = 3;
|
||||
$maxResults = $maxGenerated * 8;
|
||||
|
||||
static::bootKernel();
|
||||
$em = static::$container->get(EntityManagerInterface::class);
|
||||
$center = $em->getRepository(Center::class)
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
|
||||
$personIds = $em->createQuery("SELECT p.id FROM ".
|
||||
Person::class." p ".
|
||||
" WHERE p.center = :center")
|
||||
->setParameter('center', $center)
|
||||
->setMaxResults($maxResults)
|
||||
->getScalarResult();
|
||||
|
||||
// create a random order
|
||||
shuffle($personIds);
|
||||
|
||||
$socialIssues = $em->createQuery("SELECT s FROM ".
|
||||
SocialIssue::class." s ")
|
||||
->setMaxResults(10)
|
||||
->getResult();
|
||||
|
||||
$nbGenerated = 0;
|
||||
while ($nbGenerated < $maxGenerated) {
|
||||
$id = \array_pop($personIds)["id"];
|
||||
|
||||
$person = $em->getRepository(Person::class)
|
||||
->find($id);
|
||||
$periods = $person->getAccompanyingPeriods();
|
||||
|
||||
yield [$periods[\array_rand($periods)], $socialIssues[\array_rand($socialIssues)] ];
|
||||
|
||||
$nbGenerated++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,4 +576,39 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
$nbGenerated++;
|
||||
}
|
||||
}
|
||||
|
||||
public function dataGenerateNewAccompanyingCourse()
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$period = new AccompanyingPeriod(new \DateTime('1 week ago'));
|
||||
$user = $em->getRepository(User::class)
|
||||
->findOneByUsernameCanonical('center a_social');
|
||||
$period->setCreatedBy($user);
|
||||
//$period->setCreatedAt(new \DateTime('yesterday'));
|
||||
|
||||
$center = $em->getRepository(Center::class)
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
|
||||
$personIds = $em->createQuery("SELECT p.id FROM ".
|
||||
Person::class." p ".
|
||||
" WHERE p.center = :center")
|
||||
->setParameter('center', $center)
|
||||
->setMaxResults(100)
|
||||
->getScalarResult();
|
||||
|
||||
// create a random order
|
||||
shuffle($personIds);
|
||||
|
||||
for ($i = 0; $i<2; $i++) {
|
||||
$person = $em->getRepository(Person::class)->find(\array_pop($personIds));
|
||||
$period->addPerson($person);
|
||||
}
|
||||
|
||||
$em->persist($period);
|
||||
$em->flush();
|
||||
|
||||
yield [ $period ];
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class AccompanyingCourseControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
self::bootKernel();
|
||||
$this->client = $this->getClientAuthenticated();
|
||||
}
|
||||
|
||||
public function testNewWithoutUsers()
|
||||
{
|
||||
$this->client->request('GET', '/fr/person/parcours/new');
|
||||
|
||||
$this->assertResponseRedirects();
|
||||
$location = $this->client->getResponse()->headers->get('Location');
|
||||
|
||||
$this->assertEquals(1, \preg_match("|^\/[^\/]+\/parcours/([\d]+)/show$|", $location));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGenerateRandomUsers
|
||||
*/
|
||||
public function testWithNewUsers($personId0, $personId1)
|
||||
{
|
||||
$this->client->request('GET', '/fr/person/parcours/new', [
|
||||
'person_id' => [
|
||||
$personId0,
|
||||
$personId1
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertResponseRedirects();
|
||||
$location = $this->client->getResponse()->headers->get('Location');
|
||||
$matches = [];
|
||||
|
||||
$this->assertEquals(1, \preg_match("|^\/[^\/]+\/parcours/([\d]+)/show$|", $location, $matches));
|
||||
$id = $matches[1];
|
||||
|
||||
$period = self::$container->get(EntityManagerInterface::class)
|
||||
->getRepository(AccompanyingPeriod::class)
|
||||
->find($id);
|
||||
|
||||
$this->assertNotNull($period);
|
||||
|
||||
$this->assertEquals(2, count($period->getParticipations()));
|
||||
}
|
||||
|
||||
public function dataGenerateRandomUsers(): \Iterator
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$period = new AccompanyingPeriod(new \DateTime('1 week ago'));
|
||||
$user = $em->getRepository(User::class)
|
||||
->findOneByUsernameCanonical('center a_social');
|
||||
$period->setCreatedBy($user);
|
||||
//$period->setCreatedAt(new \DateTime('yesterday'));
|
||||
|
||||
$center = $em->getRepository(Center::class)
|
||||
->findOneBy(array('name' => 'Center A'));
|
||||
|
||||
$personIds = $em->createQuery("SELECT p.id FROM ".
|
||||
Person::class." p ".
|
||||
" WHERE p.center = :center")
|
||||
->setParameter('center', $center)
|
||||
->setMaxResults(100)
|
||||
->getScalarResult();
|
||||
|
||||
yield [ \array_pop($personIds), \array_pop($personIds) ];
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
<?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']);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@@ -25,6 +25,7 @@ namespace Chill\PersonBundle\Tests\Controller;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\DomCrawler\Form;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use \Symfony\Component\BrowserKit\Client;
|
||||
|
||||
/**
|
||||
* Test creation and deletion for persons
|
||||
@@ -32,7 +33,9 @@ use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
class PersonControllerCreateTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
|
||||
private Client $client;
|
||||
|
||||
const FIRSTNAME_INPUT = 'chill_personbundle_person_creation[firstName]';
|
||||
const LASTNAME_INPUT = "chill_personbundle_person_creation[lastName]";
|
||||
const GENDER_INPUT = "chill_personbundle_person_creation[gender]";
|
||||
@@ -42,18 +45,20 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
|
||||
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()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->client = $this::getClientAuthenticated();
|
||||
$this->client = $this->getClientAuthenticated();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Form $creationForm
|
||||
*/
|
||||
private function fillAValidCreationForm(Form &$creationForm,
|
||||
$firstname = 'God', $lastname = 'Jesus')
|
||||
{
|
||||
private function fillAValidCreationForm(
|
||||
Form &$creationForm,
|
||||
string $firstname = 'God',
|
||||
string $lastname = 'Jesus'
|
||||
) {
|
||||
$creationForm->get(self::FIRSTNAME_INPUT)->setValue($firstname);
|
||||
$creationForm->get(self::LASTNAME_INPUT)->setValue($lastname);
|
||||
$creationForm->get(self::GENDER_INPUT)->select("man");
|
||||
|
@@ -11,7 +11,7 @@ class PersonDuplicateControllerViewTest extends WebTestCase
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$this->em = static::$kernel->getContainer()
|
||||
$this->em = static::$container
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$center = $this->em->getRepository('ChillMainBundle:Center')
|
||||
|
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
|
||||
class SocialIssueApiControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
self::bootKernel();
|
||||
}
|
||||
|
||||
public function testList(): array
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
$client->request(Request::METHOD_GET, '/api/1.0/person/social-work/social-issue.json');
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$data = \json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, $data['count']);
|
||||
$this->assertGreaterThan(0, count($data['results']));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testList
|
||||
*/
|
||||
public function testItem(array $data): void
|
||||
{
|
||||
$socialIssues = $data['results'];
|
||||
shuffle($socialIssues);
|
||||
$socialIssue = \array_pop($socialIssues);
|
||||
|
||||
|
||||
$client = $this->getClientAuthenticated();
|
||||
$client->request(Request::METHOD_GET, sprintf('/api/1.0/person/social-work/social-issue/%d.json', $socialIssue['id']));
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$data = \json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertArrayHasKey('type', $data);
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Entity\AccompanyingPeriod;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
|
||||
class ResourceTest extends TestCase
|
||||
{
|
||||
public function testSetResource()
|
||||
{
|
||||
$person = new Person();
|
||||
$thirdParty = new ThirdParty();
|
||||
|
||||
$resource = new Resource();
|
||||
|
||||
$resource->setResource($person);
|
||||
|
||||
$this->assertSame($person, $resource->getResource());
|
||||
$this->assertNull($resource->getThirdParty());
|
||||
|
||||
$resource->setResource($thirdParty);
|
||||
|
||||
$this->assertSame($thirdParty, $resource->getResource());
|
||||
$this->assertNull($resource->getPerson());
|
||||
|
||||
// we repeat adding a person, to ensure that third party is
|
||||
// well reset
|
||||
$resource->setResource($person);
|
||||
$this->assertSame($person, $resource->getResource());
|
||||
$this->assertNull($resource->getThirdParty());
|
||||
|
||||
$resource->setResource(null);
|
||||
$this->assertNull($resource->getThirdParty());
|
||||
$this->assertNull($resource->getPerson());
|
||||
$this->assertNull($resource->getResource());
|
||||
}
|
||||
}
|
@@ -25,6 +25,8 @@ namespace Chill\PersonBundle\Tests\Entity;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
|
||||
|
||||
class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
@@ -120,4 +122,56 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertNull($period->getOpenParticipationContainsPerson($person4));
|
||||
$this->assertEquals(1, $period->getParticipationsContainsPerson($person4)->count());
|
||||
}
|
||||
|
||||
public function testRequestor()
|
||||
{
|
||||
$period = new AccompanyingPeriod(new \DateTime());
|
||||
$person = new Person();
|
||||
$thirdParty = new ThirdParty();
|
||||
|
||||
$this->assertNull($period->getRequestorThirdParty());
|
||||
$this->assertNull($period->getRequestorPerson());
|
||||
$this->assertNull($period->getRequestor());
|
||||
|
||||
$period->setRequestor($person);
|
||||
$this->assertNull($period->getRequestorThirdParty());
|
||||
$this->assertSame($person, $period->getRequestorPerson());
|
||||
$this->assertSame($person, $period->getRequestor());
|
||||
|
||||
$period->setRequestor($thirdParty);
|
||||
$this->assertNull($period->getRequestorPerson());
|
||||
$this->assertSame($thirdParty, $period->getRequestorThirdParty());
|
||||
$this->assertSame($thirdParty, $period->getRequestor());
|
||||
|
||||
$period->setRequestor(NULL);
|
||||
$this->assertNull($period->getRequestorThirdParty());
|
||||
$this->assertNull($period->getRequestorPerson());
|
||||
$this->assertNull($period->getRequestor());
|
||||
}
|
||||
|
||||
public function testInitialComment()
|
||||
{
|
||||
$period = new AccompanyingPeriod(new \DateTime());
|
||||
$comment = new Comment();
|
||||
$replacingComment = new Comment();
|
||||
|
||||
$period->setInitialComment(NULL);
|
||||
$this->assertNull($period->getInitialComment());
|
||||
|
||||
$period->setInitialComment($comment);
|
||||
$this->assertSame($period->getInitialComment(), $comment);
|
||||
$this->assertSame($period, $comment->getAccompanyingPeriod());
|
||||
$this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments");
|
||||
|
||||
$period->setInitialComment($replacingComment);
|
||||
$this->assertSame($period->getInitialComment(), $replacingComment);
|
||||
$this->assertSame($period, $replacingComment->getAccompanyingPeriod());
|
||||
$this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments");
|
||||
$this->assertNull($comment->getAccompanyingPeriod());
|
||||
|
||||
$period->setInitialComment(NULL);
|
||||
$this->assertNull($period->getInitialComment());
|
||||
$this->assertNull($replacingComment->getAccompanyingPeriod());
|
||||
$this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments");
|
||||
}
|
||||
}
|
||||
|
@@ -38,9 +38,7 @@ class AgeAggregatorTest extends AbstractAggregatorTest
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->aggregator = $container->get('chill.person.export.aggregator_age');
|
||||
$this->aggregator = static::$container->get('chill.person.export.aggregator_age');
|
||||
}
|
||||
|
||||
public function getAggregator()
|
||||
@@ -63,7 +61,7 @@ class AgeAggregatorTest extends AbstractAggregatorTest
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
$em = static::$container
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
|
@@ -37,9 +37,7 @@ class GenderAggregatorTest extends AbstractAggregatorTest
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->aggregator = $container->get('chill.person.export.aggregator_gender');
|
||||
$this->aggregator = static::$container->get('chill.person.export.aggregator_gender');
|
||||
}
|
||||
|
||||
public function getAggregator()
|
||||
@@ -60,7 +58,7 @@ class GenderAggregatorTest extends AbstractAggregatorTest
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
$em = static::$container
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
|
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
namespace Chill\PersonBundle\Tests\Export\Aggregator;
|
||||
|
||||
require_once '/home/julien/dev/chill-dev/vendor/chill-project/main/Test/Export/AbstractAggregatorTest.php';
|
||||
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||
|
||||
/**
|
||||
@@ -25,7 +24,7 @@ use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class NationalityAggregator extends AbstractAggregatorTest
|
||||
class NationalityAggregatorTest extends AbstractAggregatorTest
|
||||
{
|
||||
/**
|
||||
*
|
||||
@@ -37,9 +36,7 @@ class NationalityAggregator extends AbstractAggregatorTest
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->aggregator = $container->get('chill.person.export.aggregator_nationality');
|
||||
$this->aggregator = static::$container->get('chill.person.export.aggregator_nationality');
|
||||
}
|
||||
|
||||
public function getAggregator()
|
||||
@@ -61,7 +58,7 @@ class NationalityAggregator extends AbstractAggregatorTest
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
$em = static::$container
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
@@ -36,10 +36,7 @@ class CountPersonTest extends AbstractExportTest
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
/* @var $container \Symfony\Component\DependencyInjection\ContainerInterface */
|
||||
$container = self::$kernel->getContainer();
|
||||
|
||||
$this->export = $container->get('chill.person.export.export_count_person');
|
||||
$this->export = static::$container->get('chill.person.export.export_count_person');
|
||||
}
|
||||
|
||||
|
||||
|
@@ -40,10 +40,7 @@ class ListPersonTest extends AbstractExportTest
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
/* @var $container \Symfony\Component\DependencyInjection\ContainerInterface */
|
||||
$container = self::$kernel->getContainer();
|
||||
|
||||
$this->export = $container->get('chill.person.export.list_person');
|
||||
$this->export = static::$container->get('chill.person.export.list_person');
|
||||
|
||||
// add a fake request with a default locale (used in translatable string)
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
@@ -51,7 +48,7 @@ class ListPersonTest extends AbstractExportTest
|
||||
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
|
||||
$request->getLocale()->willReturn('fr');
|
||||
|
||||
$container->get('request_stack')
|
||||
static::$container->get('request_stack')
|
||||
->push($request->reveal());
|
||||
}
|
||||
|
||||
|
@@ -36,10 +36,8 @@ class AccompanyingPeriodFilterTest extends AbstractFilterTest
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
try {
|
||||
$this->filter = $container->get('chill.person.export.filter_accompanying_period');
|
||||
$this->filter = static::$container->get('chill.person.export.filter_accompanying_period');
|
||||
} catch (ServiceNotFoundException $e) {
|
||||
$this->markTestSkipped("The current configuration does not use accompanying_periods");
|
||||
}
|
||||
@@ -67,7 +65,7 @@ class AccompanyingPeriodFilterTest extends AbstractFilterTest
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
$em = static::$container
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
|
@@ -36,9 +36,7 @@ class BirthdayFilterTest extends AbstractFilterTest
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->filter = $container->get('chill.person.export.filter_birthdate');
|
||||
$this->filter = static::$container->get('chill.person.export.filter_birthdate');
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +61,7 @@ class BirthdayFilterTest extends AbstractFilterTest
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
$em = static::$container
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
|
@@ -43,9 +43,7 @@ class GenderFilterTest extends AbstractFilterTest
|
||||
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
|
||||
$request->getLocale()->willReturn('fr');
|
||||
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$this->filter = $container->get('chill.person.export.filter_gender');
|
||||
$this->filter = static::$container->get('chill.person.export.filter_gender');
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +73,7 @@ class GenderFilterTest extends AbstractFilterTest
|
||||
static::bootKernel();
|
||||
}
|
||||
|
||||
$em = static::$kernel->getContainer()
|
||||
$em = static::$container
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
return array(
|
||||
|
@@ -60,7 +60,7 @@ class PersonVoterTest extends KernelTestCase
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
$this->voter = static::$kernel->getContainer()
|
||||
$this->voter = static::$container
|
||||
->get('chill.person.security.authorization.person');
|
||||
$this->prophet = new \Prophecy\Prophet();
|
||||
}
|
||||
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Workflows;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
|
||||
class AccompanyingPeriodLifecycle extends KernelTestCase
|
||||
{
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
}
|
||||
|
||||
public function testConfirm()
|
||||
{
|
||||
$registry = self::$container->get(Registry::class);
|
||||
$period = new AccompanyingPeriod(new \DateTime('now'));
|
||||
$workflow = $registry->get($period);
|
||||
|
||||
$this->assertArrayHasKey('DRAFT', $workflow->getMarking($period)->getPlaces());
|
||||
$this->assertTrue($workflow->can($period, 'confirm'));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user