mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +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\GroupSequenceProvider
|
||||||
* @Assert\Expression(
|
* @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."
|
* message="If the accompanying course is confirmed and confidential, a referrer must remain assigned."
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
|
@ -9,125 +9,45 @@
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Tests\AccompanyingPeriod;
|
namespace Chill\PersonBundle\Tests\AccompanyingPeriod;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Center;
|
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
class AccompanyingPeriodConfidentialTest extends KernelTestCase
|
||||||
* @coversNothing
|
|
||||||
*/
|
|
||||||
class AccompanyingPeriodConfidentialTest extends WebTestCase
|
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Setup before the first test of this class (see phpunit doc).
|
protected static $validator;
|
||||||
*/
|
|
||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
static::bootKernel();
|
self::bootKernel();
|
||||||
|
|
||||||
|
self::$validator = self::$container->get(ValidatorInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testConfidentialValid()
|
||||||
* Setup before each test method (see phpunit doc).
|
|
||||||
*/
|
|
||||||
public function setUp()
|
|
||||||
{
|
{
|
||||||
$this->client = static::createClient([], [
|
$period = new AccompanyingPeriod;
|
||||||
'PHP_AUTH_USER' => 'multi_center',
|
$period->setConfidential(true);
|
||||||
'PHP_AUTH_PW' => 'password',
|
$period->setStep('CONFIRMED');
|
||||||
]);
|
$period->setUser(new User());
|
||||||
|
|
||||||
|
|
||||||
|
$violations = self::$validator->validate($period, []);
|
||||||
|
|
||||||
|
$this->assertCount(0, $violations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataGenerateRandomAccompanyingCourse()
|
public function testConfidentialInvalid()
|
||||||
{
|
{
|
||||||
// $maxGenerated = 3;
|
$period = new AccompanyingPeriod;
|
||||||
// $maxResults = $maxGenerated * 8;
|
$period->setConfidential(true);
|
||||||
|
$period->setStep('CONFIRMED');
|
||||||
|
|
||||||
// static::bootKernel();
|
$violations = self::$validator->validate($period, []);
|
||||||
// $em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
|
|
||||||
// $center = $em->getRepository(Center::class)
|
|
||||||
// ->findOneBy(['name' => 'Center A']);
|
|
||||||
|
|
||||||
// $qb = $em->createQueryBuilder();
|
$this->assertCount(1, $violations);
|
||||||
// $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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user