SubdomainTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace App\Tests\Application\Organization;
  3. use App\Tests\Application\OtWebTestCase;
  4. class SubdomainTest extends OtWebTestCase
  5. {
  6. public function testGetCollectionSubdomain(): void
  7. {
  8. $this->loginAs($this->user);
  9. $this->assertResponseIsSuccessful();
  10. $this->get('/api/subdomains');
  11. $this->assertResponseStatusCodeSame(200);
  12. $this->assertJsonContains([
  13. '@context' => '/api/contexts/Subdomain',
  14. '@id' => '/api/subdomains',
  15. '@type' => 'hydra:Collection',
  16. 'hydra:totalItems' => 1,
  17. 'hydra:member' => [
  18. ["subdomain" => "subdomain"]
  19. ],
  20. ]);
  21. }
  22. public function testPutSubdomainWhenIsActive(): void
  23. {
  24. $this->loginAs($this->user);
  25. $this->assertResponseIsSuccessful();
  26. $this->put('/api/subdomains/1', [
  27. 'subdomain' => 'toto',
  28. 'active' => false
  29. ]);
  30. // not supported
  31. $this->assertResponseStatusCodeSame(500);
  32. // hydra descriion : not supported
  33. $this->assertJsonContains([
  34. '@context' => '/api/contexts/Error',
  35. '@type' => 'hydra:Error',
  36. 'hydra:title' => 'An error occurred',
  37. 'hydra:description' => 'not supported',
  38. ]);
  39. }
  40. public function testSubdomainWhenIsActiveAndPutActive(): void
  41. {
  42. $this->loginAs($this->user);
  43. $this->assertResponseIsSuccessful();
  44. $this->put('/api/subdomains/1', [
  45. 'subdomain' => 'toto',
  46. 'active' => true
  47. ]);
  48. // not supported
  49. $this->assertResponseStatusCodeSame(500);
  50. $this->assertJsonContains([
  51. '@context' => '/api/contexts/Error',
  52. '@type' => 'hydra:Error',
  53. 'hydra:title' => 'An error occurred',
  54. 'hydra:description' => 'The subdomain is already active',
  55. ]);
  56. }
  57. public function testDeleteSubdomain(): void
  58. {
  59. $this->loginAs($this->user);
  60. $this->assertResponseIsSuccessful();
  61. $this->delete('/api/subdomains/1');
  62. $this->assertResponseStatusCodeSame(405);
  63. }
  64. // attention : vérifier que les !ROLE_ORGANIZATION peuvent accéder à la ressource
  65. public function testGetCollectionWithBadRoles()
  66. {
  67. $this->loginAsStudent($this->user);
  68. $this->get('/api/subdomains');
  69. $this->assertResponseStatusCodeSame(200);
  70. $this->assertJsonContains([
  71. '@context' => '/api/contexts/Subdomain',
  72. '@id' => '/api/subdomains',
  73. '@type' => 'hydra:Collection',
  74. 'hydra:totalItems' => 1,
  75. 'hydra:member' => [
  76. ["subdomain" => "subdomain"]
  77. ],
  78. ]);
  79. }
  80. public function testPutSubdomainWithBadRoles(): void
  81. {
  82. $this->loginAsStudent($this->user);
  83. $this->assertResponseIsSuccessful();
  84. $this->put('/api/subdomains/1', [
  85. 'subdomain' => 'toto',
  86. 'active' => false
  87. ]);
  88. // not supported
  89. $this->assertResponseStatusCodeSame(403);
  90. // hydra descriion : not supported
  91. $this->assertJsonContains([
  92. '@context' => '/api/contexts/Error',
  93. '@type' => 'hydra:Error',
  94. 'hydra:title' => 'An error occurred',
  95. ]);
  96. }
  97. public function testDeleteMethodWithBadRoles(): void
  98. {
  99. $this->loginAsStudent($this->user);
  100. $this->assertResponseIsSuccessful();
  101. $this->delete('/api/subdomains/1');
  102. $this->assertResponseStatusCodeSame(405);
  103. // error not found
  104. $this->assertJsonContains([
  105. '@context' => '/api/contexts/Error',
  106. '@type' => 'hydra:Error',
  107. 'hydra:title' => 'An error occurred',
  108. ]);
  109. }
  110. public function testPostMethodWithBadRoles(): void
  111. {
  112. $this->loginAsStudent($this->user);
  113. $this->assertResponseIsSuccessful();
  114. $this->post('/api/subdomains', [
  115. 'subdomain' => 'toto',
  116. 'active' => false
  117. ]);
  118. $this->assertResponseStatusCodeSame(403);
  119. }
  120. public function testGetCollectionFromIntruOfOrganization(): void
  121. {
  122. $this->loginAsintruOfRoot($this->user);
  123. $this->assertResponseIsSuccessful();
  124. $this->get('/api/subdomains/1');
  125. // pas le droit d'accéder à la ressource
  126. $this->assertResponseStatusCodeSame(404);
  127. // not found
  128. $this->assertJsonContains([
  129. '@context' => '/api/contexts/Error',
  130. '@type' => 'hydra:Error',
  131. 'hydra:title' => 'An error occurred',
  132. ]);
  133. }
  134. }