| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace App\Tests\Application\Organization;
- use App\Tests\Application\OtWebTestCase;
- class SubdomainTest extends OtWebTestCase
- {
- public function testGetCollectionSubdomain(): void
- {
- $this->loginAs($this->user);
- $this->assertResponseIsSuccessful();
- $this->get('/api/subdomains');
- $this->assertResponseStatusCodeSame(200);
- $this->assertJsonContains([
- '@context' => '/api/contexts/Subdomain',
- '@id' => '/api/subdomains',
- '@type' => 'hydra:Collection',
- 'hydra:totalItems' => 1,
- 'hydra:member' => [
- ["subdomain" => "subdomain"]
- ],
- ]);
- }
- public function testPutSubdomainWhenIsActive(): void
- {
- $this->loginAs($this->user);
- $this->assertResponseIsSuccessful();
- $this->put('/api/subdomains/1', [
- 'subdomain' => 'toto',
- 'active' => false
- ]);
- // not supported
- $this->assertResponseStatusCodeSame(500);
- // hydra descriion : not supported
- $this->assertJsonContains([
- '@context' => '/api/contexts/Error',
- '@type' => 'hydra:Error',
- 'hydra:title' => 'An error occurred',
- 'hydra:description' => 'not supported',
- ]);
- }
- public function testSubdomainWhenIsActiveAndPutActive(): void
- {
- $this->loginAs($this->user);
- $this->assertResponseIsSuccessful();
- $this->put('/api/subdomains/1', [
- 'subdomain' => 'toto',
- 'active' => true
- ]);
- // not supported
- $this->assertResponseStatusCodeSame(500);
- $this->assertJsonContains([
- '@context' => '/api/contexts/Error',
- '@type' => 'hydra:Error',
- 'hydra:title' => 'An error occurred',
- 'hydra:description' => 'The subdomain is already active',
- ]);
- }
- public function testDeleteSubdomain(): void
- {
- $this->loginAs($this->user);
- $this->assertResponseIsSuccessful();
- $this->delete('/api/subdomains/1');
- $this->assertResponseStatusCodeSame(405);
- }
- // attention : vérifier que les !ROLE_ORGANIZATION peuvent accéder à la ressource
- public function testGetCollectionWithBadRoles()
- {
- $this->loginAsStudent($this->user);
- $this->get('/api/subdomains');
- $this->assertResponseStatusCodeSame(200);
- $this->assertJsonContains([
- '@context' => '/api/contexts/Subdomain',
- '@id' => '/api/subdomains',
- '@type' => 'hydra:Collection',
- 'hydra:totalItems' => 1,
- 'hydra:member' => [
- ["subdomain" => "subdomain"]
- ],
- ]);
- }
- public function testPutSubdomainWithBadRoles(): void
- {
-
- $this->loginAsStudent($this->user);
- $this->assertResponseIsSuccessful();
- $this->put('/api/subdomains/1', [
- 'subdomain' => 'toto',
- 'active' => false
- ]);
- // not supported
- $this->assertResponseStatusCodeSame(403);
- // hydra descriion : not supported
- $this->assertJsonContains([
- '@context' => '/api/contexts/Error',
- '@type' => 'hydra:Error',
- 'hydra:title' => 'An error occurred',
- ]);
- }
- public function testDeleteMethodWithBadRoles(): void
- {
- $this->loginAsStudent($this->user);
- $this->assertResponseIsSuccessful();
- $this->delete('/api/subdomains/1');
- $this->assertResponseStatusCodeSame(405);
- // error not found
- $this->assertJsonContains([
- '@context' => '/api/contexts/Error',
- '@type' => 'hydra:Error',
- 'hydra:title' => 'An error occurred',
- ]);
- }
- public function testPostMethodWithBadRoles(): void
- {
- $this->loginAsStudent($this->user);
- $this->assertResponseIsSuccessful();
- $this->post('/api/subdomains', [
- 'subdomain' => 'toto',
- 'active' => false
- ]);
- $this->assertResponseStatusCodeSame(403);
- }
- public function testGetCollectionFromIntruOfOrganization(): void
- {
- $this->loginAsintruOfRoot($this->user);
- $this->assertResponseIsSuccessful();
- $this->get('/api/subdomains/1');
- // pas le droit d'accéder à la ressource
- $this->assertResponseStatusCodeSame(404);
- // not found
- $this->assertJsonContains([
- '@context' => '/api/contexts/Error',
- '@type' => 'hydra:Error',
- 'hydra:title' => 'An error occurred',
- ]);
-
- }
- }
|