SubdomainTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace App\Tests\Application\Organization;
  3. use App\Tests\Application\OtWebTestCase;
  4. class SubdomainTest extends OtWebTestCase
  5. {
  6. public function testSubdomainResource(): void
  7. {
  8. $this->logger->info("\033[1;34mStarting test... Retrieve the list of subdomain as an admin user\033[0m");
  9. $this->loginAs($this->user);
  10. $this->assertResponseIsSuccessful();
  11. $this->get('/api/subdomains');
  12. $this->assertResponseStatusCodeSame(200);
  13. $this->assertJsonContains([
  14. '@context' => '/api/contexts/Subdomain',
  15. '@id' => '/api/subdomains',
  16. '@type' => 'hydra:Collection',
  17. 'hydra:totalItems' => 1,
  18. 'hydra:member' => [
  19. ['subdomain' => 'subdomain'],
  20. ],
  21. ]);
  22. $this->logger->info("\033[1;32mTest 'test get subdomain collection' succeed\033[0m");
  23. $this->logger->info("\033[1;34mStarting test... get all subdomains as a non-admin\033[0m");
  24. $this->loginAsStudent($this->user);
  25. $this->get('/api/subdomains');
  26. $this->assertResponseStatusCodeSame(403);
  27. $this->logger->info("\033[1;32mTest 'get all subdomains as a non-admin' succeed\033[0m");
  28. $this->logger->info("\033[1;34mStarting test... put subdomain as an admin\033[0m");
  29. $this->loginAs($this->user);
  30. $this->assertResponseIsSuccessful();
  31. $this->put('/api/subdomains/1', [
  32. 'subdomain' => 'toto',
  33. 'active' => false,
  34. ]);
  35. $this->assertResponseStatusCodeSame(500);
  36. $this->assertJsonContains([
  37. '@context' => '/api/contexts/Error',
  38. '@type' => 'hydra:Error',
  39. 'hydra:title' => 'An error occurred',
  40. 'hydra:description' => 'not supported',
  41. ]);
  42. $this->logger->info("\033[1;32mTest 'put subdomain as an admin' succeed\033[0m");
  43. $this->logger->info("\033[1;34mStarting test... put subdomain as an non-admin\033[0m");
  44. $this->loginAs($this->user);
  45. $this->assertResponseIsSuccessful();
  46. $this->put('/api/subdomains/1', [
  47. 'subdomain' => 'toto',
  48. 'active' => true,
  49. ]);
  50. $this->assertResponseStatusCodeSame(500);
  51. $this->assertJsonContains([
  52. '@context' => '/api/contexts/Error',
  53. '@type' => 'hydra:Error',
  54. 'hydra:title' => 'An error occurred',
  55. 'hydra:description' => 'The subdomain is already active',
  56. ]);
  57. $this->logger->info("\033[1;32mTest 'put subdomain as an non-admin' succeed\033[0m");
  58. $this->logger->info("\033[1;34mStarting test... get a subdomain as an admin\033[0m");
  59. $this->loginAs($this->user);
  60. $this->assertResponseIsSuccessful();
  61. $this->delete('/api/subdomains/1');
  62. $this->assertResponseStatusCodeSame(405);
  63. $this->logger->info("\033[1;32mTest 'get a subdomain as an admin' succeed\033[0m");
  64. $this->logger->info("\033[1;34mStarting test... put a subdomain as an non-admin\033[0m");
  65. $this->loginAsStudent($this->user);
  66. $this->assertResponseIsSuccessful();
  67. $this->put('/api/subdomains/1', [
  68. 'subdomain' => 'toto',
  69. 'active' => false,
  70. ]);
  71. $this->assertResponseStatusCodeSame(403);
  72. $this->assertJsonContains([
  73. '@context' => '/api/contexts/Error',
  74. '@type' => 'hydra:Error',
  75. 'hydra:title' => 'An error occurred',
  76. ]);
  77. $this->logger->info("\033[1;32mTest 'put a subdomains as an non-admin' succeed\033[0m");
  78. $this->logger->info("\033[1;34mStarting test... delete a subdomain as an admin\033[0m");
  79. $this->loginAs($this->user);
  80. $this->assertResponseIsSuccessful();
  81. $this->delete('/api/subdomains/1');
  82. $this->assertResponseStatusCodeSame(405);
  83. $this->assertJsonContains([
  84. '@context' => '/api/contexts/Error',
  85. '@type' => 'hydra:Error',
  86. 'hydra:title' => 'An error occurred',
  87. ]);
  88. $this->logger->info("\033[1;32mTest 'delete as an non-admin' succeed\033[0m");
  89. $this->logger->info("\033[1;34mStarting test... delete a subdomain as an non-admin\033[0m");
  90. $this->loginAsStudent($this->user);
  91. $this->assertResponseIsSuccessful();
  92. $this->delete('/api/subdomains/1');
  93. $this->assertResponseStatusCodeSame(405);
  94. $this->assertJsonContains([
  95. '@context' => '/api/contexts/Error',
  96. '@type' => 'hydra:Error',
  97. 'hydra:title' => 'An error occurred',
  98. ]);
  99. $this->logger->info("\033[1;32mTest 'delete as an non-admin' succeed\033[0m");
  100. }
  101. }