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', ]); } }