PersonTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Tests\Application\Person;
  3. use App\Tests\Application\OtWebTestCase;
  4. use AppBundle\Entity\Person\Person;
  5. use Monolog\Logger;
  6. class PersonTest extends OtWebTestCase
  7. {
  8. public function testPersonGetCollection(): void
  9. {
  10. $this->logger->info("\033[1;34mStarting test... Retrieve the list of all accesses for an admin user\033[0m");
  11. $this->loginAs($this->user);
  12. $this->get('/api/accesses');
  13. $this->assertResponseStatusCodeSame(200);
  14. $this->logger->info("\033[1;32mTest 'testPersonGetCollection' succeed\033[0m");
  15. // $this->logger->info("\033[1;34mStarting test: Retrieve the access of an admin user\033[0m");
  16. // $this->loginAs($this->user);
  17. // $this->get('/api/admin-access/' . $this->user->getId());
  18. // $this->assertResponseStatusCodeSame(200);
  19. // $this->logger->info("\033[1;32mTest 'tesGetAdminAccess' succeed\033[0m");
  20. $this->logger->info("\033[1;34mStarting test: admin can change the access infos of a user\033[0m");
  21. $this->loginAs($this->user);
  22. $this->put('/api/accesses/2', [
  23. 'username' => 'nouveau username',
  24. ]);
  25. $this->assertResponseStatusCodeSame(200);
  26. $this->logger->info("\033[1;32mTest 'testPersonPut' succeed\033[0m");
  27. $this->logger->info("\033[1;34mStarting test: a student can't access the list of all accesses\033[0m");
  28. $this->loginAsStudent($this->user);
  29. $this->get('/api/accesses');
  30. $this->assertResponseStatusCodeSame(200);
  31. $this->logger->info("\033[1;32mTest 'testStudentUnableToAcceedAllAccesses' succeed\033[0m");
  32. $this->logger->info("\033[1;34mStarting test: a non admin role can't access the info of an admin user\033[0m");
  33. $this->loginAsStudent($this->user);
  34. $this->get('/api/admin-access/1');
  35. $this->validateCollectionSchema(Person::class, 404);
  36. $this->assertJsonContains([
  37. 'hydra:description' => 'Not Found',
  38. ]);
  39. $this->logger->info("\033[1;32mTest 'testPersonUnableToAcceddAdminInfo' succeed\033[0m");
  40. // il faudra relancer les fixtures après ce test
  41. $this->logger->info("\033[1;34mStarting test: delete an user as an admin\033[0m");
  42. $this->loginAs($this->user);
  43. $this->delete('/api/accesses/2');
  44. $this->assertResponseStatusCodeSame(204);
  45. $this->logger->info("\033[1;32mTest 'delete an user as an admin' succeed\033[0m");
  46. }
  47. }