| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace App\Tests\Application\Person;
- use App\Entity\Person\Person;
- use App\Entity\Access\Access;
- use App\Entity\Organization\Organization;
- use App\Entity\Organization\Settings;
- use App\Entity\Public\PublicEvent;
- use App\Enum\Organization\PrincipalTypeEnum;
- use App\Enum\Organization\SettingsProductEnum;
- use App\Tests\Application\OtWebTestCase;
- use App\Tests\Fixture\Factory\Access\AccessFactory;
- use App\Tests\Fixture\Factory\Organization\OrganizationFactory;
- use App\Tests\Fixture\Factory\Organization\SettingsFactory;
- use App\Tests\Fixture\Factory\Person\PersonFactory;
- use App\Tests\Fixture\PersonFixtures;
- use Zenstruck\Foundry\Factory;
- use Zenstruck\Foundry\Proxy;
- use App\Enum\Organization\LegalEnum;
- class PersonTest extends OtWebTestCase
- {
- private Proxy | Person $person;
- private Proxy | Access $access;
- protected function setFixtures(): void
- {
- $this->person = PersonFactory::createOne(
- [
- 'username' => 'username',
- 'password' => 'password'
- ]
- );
- $organization = OrganizationFactory::createOne([
- 'legalStatus' => LegalEnum::ASSOCIATION_LAW_1901()->getValue(),
- 'principalType' => PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY()->getValue(),
- 'name' => 'My Organization'
- ]);
- SettingsFactory::createOne([
- 'product' => SettingsProductEnum::ARTIST(),
- 'organization' => $organization
- ]);
- $this->access = AccessFactory::createOne([
- 'person' => $this->person,
- 'organization' => $organization,
- 'roles' => ['ROLE_USERS_VIEW']
- ]);
- }
- public function testPersonGet(): void
- {
- $this->loginAs($this->access);
- $this->get('/api/people/' . $this->person->getId());
- $this->validateCollectionSchema(Person::class);
- $this->assertJsonContains([
- '@context' => '/api/contexts/Person',
- '@id' => '/api/people/' . $this->person->getId(),
- '@type' => 'Person',
- 'username' => 'username'
- ]);
- }
- public function testPersonGetHasNoRole(): void {
- $this->access->setRoles([]);
- $this->access->save();
- $this->loginAs($this->access);
- $this->get('/api/people/' . $this->person->getId());
- $this->validateCollectionSchema(Person::class, 403);
- $this->assertJsonContains([
- "hydra:description" => "Access Denied."
- ]);
- }
- public function testPersonGetCollection(): void {
- $this->loginAs($this->access);
- $this->get('/api/peoples');
- $this->assertResponseStatusCodeSame(404);
- }
- public function testPersonPut(): void {
- $this->loginAs($this->access);
- $this->put('/api/people/' . $this->person->getId(), []);
- // Expects : 405 Method Not Allowed
- $this->assertResponseStatusCodeSame(405);
- }
- public function testPersonPost(): void {
- $this->loginAs($this->access);
- $this->post('/api/people/' . $this->person->getId(), []);
- // Expects : 405 Method Not Allowed
- $this->assertResponseStatusCodeSame(405);
- }
- public function testPersonDelete(): void {
- $this->loginAs($this->access);
- $this->delete('/api/people/' . $this->person->getId());
- // Expects : 405 Method Not Allowed
- $this->assertResponseStatusCodeSame(405);
- }
- }
|