PersonTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Tests\Application\Person;
  3. use App\Entity\Person\Person;
  4. use App\Entity\Access\Access;
  5. use App\Entity\Organization\Organization;
  6. use App\Entity\Organization\Settings;
  7. use App\Entity\Public\PublicEvent;
  8. use App\Enum\Organization\PrincipalTypeEnum;
  9. use App\Enum\Organization\SettingsProductEnum;
  10. use App\Tests\Application\OtWebTestCase;
  11. use App\Tests\Fixture\Factory\Access\AccessFactory;
  12. use App\Tests\Fixture\Factory\Organization\OrganizationFactory;
  13. use App\Tests\Fixture\Factory\Organization\SettingsFactory;
  14. use App\Tests\Fixture\Factory\Person\PersonFactory;
  15. use App\Tests\Fixture\PersonFixtures;
  16. use Zenstruck\Foundry\Factory;
  17. use Zenstruck\Foundry\Proxy;
  18. use App\Enum\Organization\LegalEnum;
  19. class PersonTest extends OtWebTestCase
  20. {
  21. private Proxy | Person $person;
  22. private Proxy | Access $access;
  23. protected function setFixtures(): void
  24. {
  25. $this->person = PersonFactory::createOne(
  26. [
  27. 'username' => 'username',
  28. 'password' => 'password'
  29. ]
  30. );
  31. $organization = OrganizationFactory::createOne([
  32. 'legalStatus' => LegalEnum::ASSOCIATION_LAW_1901()->getValue(),
  33. 'principalType' => PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY()->getValue(),
  34. 'name' => 'My Organization'
  35. ]);
  36. SettingsFactory::createOne([
  37. 'product' => SettingsProductEnum::ARTIST(),
  38. 'organization' => $organization
  39. ]);
  40. $this->access = AccessFactory::createOne([
  41. 'person' => $this->person,
  42. 'organization' => $organization,
  43. 'roles' => ['ROLE_USERS_VIEW']
  44. ]);
  45. }
  46. public function testPersonGet(): void
  47. {
  48. $this->loginAs($this->access);
  49. $this->get('/api/people/' . $this->person->getId());
  50. $this->validateCollectionSchema(Person::class);
  51. $this->assertJsonContains([
  52. '@context' => '/api/contexts/Person',
  53. '@id' => '/api/people/' . $this->person->getId(),
  54. '@type' => 'Person',
  55. 'username' => 'username'
  56. ]);
  57. }
  58. public function testPersonGetHasNoRole(): void {
  59. $this->access->setRoles([]);
  60. $this->access->save();
  61. $this->loginAs($this->access);
  62. $this->get('/api/people/' . $this->person->getId());
  63. $this->validateCollectionSchema(Person::class, 403);
  64. $this->assertJsonContains([
  65. "hydra:description" => "Access Denied."
  66. ]);
  67. }
  68. public function testPersonGetCollection(): void {
  69. $this->loginAs($this->access);
  70. $this->get('/api/peoples');
  71. $this->assertResponseStatusCodeSame(404);
  72. }
  73. public function testPersonPut(): void {
  74. $this->loginAs($this->access);
  75. $this->put('/api/people/' . $this->person->getId(), []);
  76. // Expects : 405 Method Not Allowed
  77. $this->assertResponseStatusCodeSame(405);
  78. }
  79. public function testPersonPost(): void {
  80. $this->loginAs($this->access);
  81. $this->post('/api/people/' . $this->person->getId(), []);
  82. // Expects : 405 Method Not Allowed
  83. $this->assertResponseStatusCodeSame(405);
  84. }
  85. public function testPersonDelete(): void {
  86. $this->loginAs($this->access);
  87. $this->delete('/api/people/' . $this->person->getId());
  88. // Expects : 405 Method Not Allowed
  89. $this->assertResponseStatusCodeSame(405);
  90. }
  91. }