mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
Merge branch 'master' into _31_interface_creation_parcours
This commit is contained in:
commit
6939b4a313
@ -41,21 +41,14 @@ use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
|||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
/**
|
final class PersonController extends AbstractController
|
||||||
* Class PersonController
|
|
||||||
*
|
|
||||||
* @package Chill\PersonBundle\Controller
|
|
||||||
*/
|
|
||||||
class PersonController extends AbstractController
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var SimilarPersonMatcher
|
* @var SimilarPersonMatcher
|
||||||
*/
|
*/
|
||||||
protected $similarPersonMatcher;
|
protected $similarPersonMatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var TranslatorInterface
|
* @var TranslatorInterface
|
||||||
*/
|
*/
|
||||||
protected $translator;
|
protected $translator;
|
||||||
@ -66,34 +59,31 @@ class PersonController extends AbstractController
|
|||||||
protected $eventDispatcher;
|
protected $eventDispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var PersonRepository;
|
* @var PersonRepository;
|
||||||
*/
|
*/
|
||||||
protected $personRepository;
|
protected $personRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var ConfigPersonAltNamesHelper
|
* @var ConfigPersonAltNamesHelper
|
||||||
*/
|
*/
|
||||||
protected $configPersonAltNameHelper;
|
protected $configPersonAltNameHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var EntityManagerInterface
|
* @var EntityManagerInterface
|
||||||
*/
|
*/
|
||||||
protected $em;
|
private $em;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Psr\Log\LoggerInterface
|
* @var \Psr\Log\LoggerInterface
|
||||||
*/
|
*/
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ValidatorInterface
|
* @var ValidatorInterface
|
||||||
*/
|
*/
|
||||||
private $validator;
|
private $validator;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
SimilarPersonMatcher $similarPersonMatcher,
|
SimilarPersonMatcher $similarPersonMatcher,
|
||||||
TranslatorInterface $translator,
|
TranslatorInterface $translator,
|
||||||
EventDispatcherInterface $eventDispatcher,
|
EventDispatcherInterface $eventDispatcher,
|
||||||
@ -117,8 +107,7 @@ class PersonController extends AbstractController
|
|||||||
{
|
{
|
||||||
$cFGroup = null;
|
$cFGroup = null;
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
$cFDefaultGroup = $this->em->getRepository("ChillCustomFieldsBundle:CustomFieldsDefaultGroup")
|
||||||
$cFDefaultGroup = $em->getRepository("ChillCustomFieldsBundle:CustomFieldsDefaultGroup")
|
|
||||||
->findOneByEntity("Chill\PersonBundle\Entity\Person");
|
->findOneByEntity("Chill\PersonBundle\Entity\Person");
|
||||||
|
|
||||||
if($cFDefaultGroup) {
|
if($cFDefaultGroup) {
|
||||||
@ -207,8 +196,7 @@ class PersonController extends AbstractController
|
|||||||
->trans('The person data has been updated')
|
->trans('The person data has been updated')
|
||||||
);
|
);
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
$this->em->flush();
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
$url = $this->generateUrl('chill_person_view', array(
|
$url = $this->generateUrl('chill_person_view', array(
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
@ -402,11 +390,9 @@ class PersonController extends AbstractController
|
|||||||
'You are not allowed to create this person');
|
'You are not allowed to create this person');
|
||||||
|
|
||||||
if ($errors->count() === 0) {
|
if ($errors->count() === 0) {
|
||||||
$em = $this->getDoctrine()->getManager();
|
$this->em->persist($person);
|
||||||
|
|
||||||
$em->persist($person);
|
$this->em->flush();
|
||||||
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
return $this->redirect($this->generateUrl('chill_person_general_edit',
|
return $this->redirect($this->generateUrl('chill_person_general_edit',
|
||||||
array('person_id' => $person->getId())));
|
array('person_id' => $person->getId())));
|
||||||
|
@ -38,5 +38,4 @@ class AccompanyingPeriodRepository extends ServiceEntityRepository
|
|||||||
{
|
{
|
||||||
parent::__construct($registry, AccompanyingPeriod::class);
|
parent::__construct($registry, AccompanyingPeriod::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,174 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||||
|
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Tests\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Entity\Center;
|
||||||
|
use Doctrine\Common\Collections\Criteria;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test api for AccompanyingCourseControllerTest
|
||||||
|
*/
|
||||||
|
class AccompanyingCourseControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
protected static EntityManagerInterface $em;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup before the first test of this class (see phpunit doc)
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
static::bootKernel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup before each test method (see phpunit doc)
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->client = static::createClient(array(), array(
|
||||||
|
'PHP_AUTH_USER' => 'center a_social',
|
||||||
|
'PHP_AUTH_PW' => 'password',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @dataProvider dataGenerateRandomAccompanyingCourse
|
||||||
|
*/
|
||||||
|
public function testAccompanyingCourseShow(int $personId, AccompanyingPeriod $period)
|
||||||
|
{
|
||||||
|
$this->client->request(Request::METHOD_GET, sprintf('/fr/person/api/1.0/accompanying-course/%d/show.json', $period->getId()));
|
||||||
|
$response = $this->client->getResponse();
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode(), "Test that the response of rest api has a status code ok (200)");
|
||||||
|
|
||||||
|
$data = \json_decode($response->getContent());
|
||||||
|
$this->assertEquals($data->id, $period->getId(),
|
||||||
|
"test that the response's data contains the id of the period"
|
||||||
|
);
|
||||||
|
$this->assertGreaterThan(0, $data->participations);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @dataProvider dataGenerateRandomAccompanyingCourse
|
||||||
|
*/
|
||||||
|
public function testAccompanyingCourseAddParticipation(int $personId, AccompanyingPeriod $period)
|
||||||
|
{
|
||||||
|
$this->client->request(
|
||||||
|
Request::METHOD_POST,
|
||||||
|
sprintf('/fr/person/api/1.0/accompanying-course/%d/participation.json', $period->getId()),
|
||||||
|
[], // parameters
|
||||||
|
[], // files
|
||||||
|
[], // server parameters
|
||||||
|
\json_encode([ 'id' => $personId ])
|
||||||
|
);
|
||||||
|
$response = $this->client->getResponse();
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode(), "Test that the response of rest api has a status code ok (200)");
|
||||||
|
$this->client->request(Request::METHOD_GET, sprintf('/fr/person/api/1.0/accompanying-course/%d/show.json', $period->getId()));
|
||||||
|
|
||||||
|
$response = $this->client->getResponse();
|
||||||
|
$data = \json_decode($response->getContent());
|
||||||
|
|
||||||
|
$participationsPersonsIds = \array_map(
|
||||||
|
function($participation) { return $participation->person->id; },
|
||||||
|
$data->participations);
|
||||||
|
|
||||||
|
$this->assertContains($personId, $participationsPersonsIds);
|
||||||
|
|
||||||
|
$this->personId = $personId;
|
||||||
|
$this->period = $period;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
// remove participation created during test 'testAccompanyingCourseAddParticipation'
|
||||||
|
|
||||||
|
$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])
|
||||||
|
;
|
||||||
|
|
||||||
|
$em->remove($participation);
|
||||||
|
$em->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dataGenerateRandomAccompanyingCourse()
|
||||||
|
{
|
||||||
|
// 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
|
||||||
|
$maxGenerated = 1;
|
||||||
|
$maxResults = 15 * 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);
|
||||||
|
|
||||||
|
$nbGenerated = 0;
|
||||||
|
while ($nbGenerated < $maxGenerated) {
|
||||||
|
$id = \array_pop($personIds)["id"];
|
||||||
|
|
||||||
|
$person = $em->getRepository(Person::class)
|
||||||
|
->find($id);
|
||||||
|
$periods = $person->getAccompanyingPeriods();
|
||||||
|
|
||||||
|
yield [\array_pop($personIds)["id"], $periods[\array_rand($periods)] ];
|
||||||
|
|
||||||
|
$nbGenerated++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,3 +18,8 @@ services:
|
|||||||
tags: [ doctrine.repository_service ]
|
tags: [ doctrine.repository_service ]
|
||||||
arguments:
|
arguments:
|
||||||
- '@Doctrine\Persistence\ManagerRegistry'
|
- '@Doctrine\Persistence\ManagerRegistry'
|
||||||
|
|
||||||
|
Chill\PersonBundle\Repository\AccompanyingPeriodParticipationRepository:
|
||||||
|
arguments:
|
||||||
|
- '@Doctrine\Persistence\ManagerRegistry'
|
||||||
|
tags: [ doctrine.repository_service ]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user