PersonTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Tests\Application\Person;
  3. use AppBundle\Entity\Person\Person;
  4. use App\Tests\Application\OtWebTestCase;
  5. class PersonTest extends OtWebTestCase
  6. {
  7. public function testPersonGetCollection(): void
  8. {
  9. $this->loginAs($this->user);
  10. $this->get('/api/people/'.$this->user->getPerson()->getId());
  11. $this->validateCollectionSchema(Person::class);
  12. $this->assertJsonContains([
  13. '@context' => '/api/contexts/Person',
  14. '@id' => '/api/people/'.$this->user->getPerson()->getId(),
  15. '@type' => 'Person',
  16. 'username' => 'username',
  17. ]);
  18. }
  19. public function testPersonGetHasNoRole(): void
  20. {
  21. // User has not the required role
  22. $this->user->setRoles([]);
  23. $this->user->save();
  24. $this->loginAs($this->user);
  25. $this->get('/api/people/'.$this->user->getPerson()->getId());
  26. $this->validateCollectionSchema(Person::class, 403);
  27. $this->assertJsonContains([
  28. 'hydra:description' => 'Access Denied.',
  29. ]);
  30. }
  31. public function testPersonGetCollection(): void
  32. {
  33. $this->loginAs($this->user);
  34. $this->get('/api/peoples');
  35. $this->assertResponseStatusCodeSame(404);
  36. }
  37. public function testPersonPut(): void
  38. {
  39. $this->loginAs($this->user);
  40. $this->put('/api/people/'.$this->user->getPerson()->getId(), []);
  41. // Expects : 405 Method Not Allowed
  42. $this->assertResponseStatusCodeSame(405);
  43. }
  44. public function testPersonPost(): void
  45. {
  46. $this->loginAs($this->user);
  47. $this->post('/api/people/'.$this->user->getPerson()->getId(), []);
  48. // Expects : 405 Method Not Allowed
  49. $this->assertResponseStatusCodeSame(405);
  50. }
  51. public function testPersonDelete(): void
  52. {
  53. $this->loginAs($this->user);
  54. $this->delete('/api/people/'.$this->user->getPerson()->getId());
  55. // Expects : 405 Method Not Allowed
  56. $this->assertResponseStatusCodeSame(405);
  57. }
  58. public function testPersonGetHasNoRole(): void
  59. {
  60. $this->loginAsStudent($this->user);
  61. $this->get('/api/people/' . $this->user->getPerson()->getId());
  62. $this->validateCollectionSchema(Person::class, 404);
  63. $this->assertJsonContains([
  64. "hydra:description" => "This route does not aim to be called."
  65. ]);
  66. }
  67. }