PersonTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Tests\Application\Person;
  3. use App\Entity\Person\Person;
  4. use App\Tests\Application\OtWebTestCase;
  5. class PersonTest extends OtWebTestCase
  6. {
  7. public function testPersonGet(): 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. }