mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
test written, but the validation expression is not yet correct
This commit is contained in:
parent
9aba4ea8f6
commit
f971dc05eb
@ -50,7 +50,7 @@ use UnexpectedValueException;
|
||||
* })
|
||||
* @Assert\GroupSequenceProvider
|
||||
* @Assert\Expression(
|
||||
* "this.isConfidential and this.getUser === NULL",
|
||||
* "this.isConfidential && this.getUser && this.getStep === 'CONFIRMED'",
|
||||
* message="If the accompanying course is confirmed and confidential, a referrer must remain assigned."
|
||||
* )
|
||||
*/
|
||||
|
@ -9,125 +9,45 @@
|
||||
|
||||
namespace Chill\PersonBundle\Tests\AccompanyingPeriod;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class AccompanyingPeriodConfidentialTest extends WebTestCase
|
||||
|
||||
class AccompanyingPeriodConfidentialTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* Setup before the first test of this class (see phpunit doc).
|
||||
*/
|
||||
|
||||
protected static $validator;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
static::bootKernel();
|
||||
self::bootKernel();
|
||||
|
||||
self::$validator = self::$container->get(ValidatorInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup before each test method (see phpunit doc).
|
||||
*/
|
||||
public function setUp()
|
||||
public function testConfidentialValid()
|
||||
{
|
||||
$this->client = static::createClient([], [
|
||||
'PHP_AUTH_USER' => 'multi_center',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
]);
|
||||
$period = new AccompanyingPeriod;
|
||||
$period->setConfidential(true);
|
||||
$period->setStep('CONFIRMED');
|
||||
$period->setUser(new User());
|
||||
|
||||
|
||||
$violations = self::$validator->validate($period, []);
|
||||
|
||||
$this->assertCount(0, $violations);
|
||||
}
|
||||
|
||||
public function dataGenerateRandomAccompanyingCourse()
|
||||
public function testConfidentialInvalid()
|
||||
{
|
||||
// $maxGenerated = 3;
|
||||
// $maxResults = $maxGenerated * 8;
|
||||
$period = new AccompanyingPeriod;
|
||||
$period->setConfidential(true);
|
||||
$period->setStep('CONFIRMED');
|
||||
|
||||
// static::bootKernel();
|
||||
// $em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
|
||||
// $center = $em->getRepository(Center::class)
|
||||
// ->findOneBy(['name' => 'Center A']);
|
||||
$violations = self::$validator->validate($period, []);
|
||||
|
||||
// $qb = $em->createQueryBuilder();
|
||||
// $personIds = $qb
|
||||
// ->select('p.id')
|
||||
// ->distinct(true)
|
||||
// ->from(Person::class, 'p')
|
||||
// ->join('p.accompanyingPeriodParticipations', 'participation')
|
||||
// ->join('participation.accompanyingPeriod', 'ap')
|
||||
// ->andWhere(
|
||||
// $qb->expr()->eq('ap.step', ':step')
|
||||
// )
|
||||
// ->andWhere(
|
||||
// $qb->expr()->eq('ap.confidential', ':confidential')
|
||||
// )
|
||||
// ->setParameter('step', AccompanyingPeriod::STEP_CONFIRMED)
|
||||
// ->setParameter('confidential', true)
|
||||
// ->setMaxResults($maxResults)
|
||||
// ->getQuery()
|
||||
// ->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)]->getId()];
|
||||
|
||||
// ++$nbGenerated;
|
||||
// }
|
||||
|
||||
yield [3744];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGenerateRandomAccompanyingCourse
|
||||
*/
|
||||
public function testRemoveUserWhenConfidential(int $periodId)
|
||||
{
|
||||
static::bootKernel();
|
||||
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$period = $em->getRepository(AccompanyingPeriod::class)
|
||||
->find($periodId);
|
||||
|
||||
$isConfidential = $period->isConfidential();
|
||||
$step = $period->getStep();
|
||||
|
||||
$initialUser = $period->getUser();
|
||||
|
||||
$user = new \stdClass();
|
||||
$user->id = "NULL";
|
||||
$user->type = 'user';
|
||||
|
||||
$this->client->request(
|
||||
Request::METHOD_PATCH,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d.json', $periodId),
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
json_encode(['type' => 'accompanying_period', 'user' => $user])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertEquals(422, $response->getStatusCode());
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$period = $em->getRepository(AccompanyingPeriod::class)
|
||||
->find($periodId);
|
||||
$this->assertEquals($user, $period->getUser());
|
||||
|
||||
// assign initial user again
|
||||
$period->setUser($initialUser);
|
||||
$em->flush();
|
||||
$this->assertCount(1, $violations);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user