ParametersTest.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. namespace App\Tests\Application\Organization;
  3. use App\Enum\Core\TimeZoneEnum;
  4. use App\Enum\Education\AdvancedEducationNotationTypeEnum;
  5. use App\Enum\Education\PeriodicityEnum;
  6. use App\Enum\Organization\BulletinCriteriaSortEnum;
  7. use App\Enum\Organization\SendToBulletinEnum;
  8. use App\Tests\Application\OtWebTestCase;
  9. class ParametersTest extends OtWebTestCase
  10. {
  11. public function testGetParametersCollection(): void
  12. {
  13. $this->logger->info("\033[1;34mStarting test... Get parameters as an admin\033[0m");
  14. $this->loginAs($this->user);
  15. $this->get('/api/parameters/1');
  16. $this->assertResponseStatusCodeSame(200);
  17. $this->logger->info("\033[1;32mTest 'testGetParametersCollection' succeed\033[0m");
  18. $this->logger->info("\033[1;34mStarting test... Put parameters as an admin\033[0m");
  19. $this->loginAs($this->user);
  20. $this->put('/api/parameters/1', [
  21. 'bulletinCriteriaSort' => BulletinCriteriaSortEnum::ALPHANUM,
  22. 'advancedEducationNotationType' => AdvancedEducationNotationTypeEnum::BY_TEACHER,
  23. 'timezone' => TimeZoneEnum::INDIAN_REUNION,
  24. 'educationPeriodicity' => PeriodicityEnum::HALF,
  25. 'bulletinReceiver' => SendToBulletinEnum::STUDENTS_AND_THEIR_GUARDIANS,
  26. ]);
  27. $this->assertResponseStatusCodeSame(200);
  28. $this->logger->info("\033[1;32mTest 'Put parameters as an admin' succeed\033[0m");
  29. $this->logger->info("\033[1;34mStarting test... put bad bulletin critieria sort\033[0m");
  30. $this->loginAs($this->user);
  31. $this->put('/api/parameters/1', [
  32. 'bulletinCriteriaSort' => 'BAD_CRITERIA_SORT',
  33. ]);
  34. $this->assertResponseStatusCodeSame(400);
  35. $this->logger->info("\033[1;32mTest 'testBadPutBulletinCriteriasort' succeed\033[0m");
  36. $this->logger->info("\033[1;34mStarting test... put bad advances education notation type\033[0m");
  37. $this->loginAs($this->user);
  38. $this->put('/api/parameters/1', [
  39. 'bulletinCriteriaSort' => 'bad_advancedEducation',
  40. ]);
  41. $this->assertResponseStatusCodeSame(400);
  42. $this->logger->info("\033[1;32mTest 'put bad advances education notation type' succeed\033[0m");
  43. $this->logger->info("\033[1;34mStarting test... delete paramaters as admin\033[0m");
  44. $this->loginAs($this->user);
  45. $this->delete('/api/parameters/1');
  46. $this->assertResponseStatusCodeSame(405);
  47. $this->logger->info("\033[1;32mTest 'delete paramaters as admin' succeed\033[0m");
  48. $this->logger->info("\033[1;34mStarting test... put bad timezone\033[0m");
  49. $this->loginAs($this->user);
  50. $this->put('/api/parameters/1', [
  51. 'timezone' => 'bad_timezone',
  52. ]);
  53. $this->assertResponseStatusCodeSame(400);
  54. $this->logger->info("\033[1;32mTest 'put bad timezone' succeed\033[0m");
  55. $this->logger->info("\033[1;34mStarting test... put bad periodicity\033[0m");
  56. $this->loginAs($this->user);
  57. $this->put('/api/parameters/1', [
  58. 'educationPeriodicity' => 'bad_periodicity',
  59. ]);
  60. $this->assertResponseStatusCodeSame(400);
  61. $this->logger->info("\033[1;32mTest 'put bad periodicity' succeed\033[0m");
  62. $this->logger->info("\033[1;34mStarting test... get parameters as a non admin\033[0m");
  63. $this->loginAsStudent($this->user);
  64. $this->get('/api/parameters/1');
  65. $this->assertResponseStatusCodeSame(403);
  66. $this->logger->info("\033[1;32mTest 'get parameters as a non admin' succeed\033[0m");
  67. $this->logger->info("\033[1;34mStarting test... put parameters as a non admin\033[0m");
  68. $this->loginAsStudent($this->user);
  69. $this->put('/api/parameters/1', [
  70. 'bulletinCriteriaSort' => BulletinCriteriaSortEnum::ALPHANUM,
  71. 'advancedEducationNotationType' => AdvancedEducationNotationTypeEnum::BY_TEACHER,
  72. 'timezone' => TimeZoneEnum::INDIAN_REUNION,
  73. 'educationPeriodicity' => PeriodicityEnum::HALF,
  74. 'bulletinReceiver' => SendToBulletinEnum::STUDENTS_AND_THEIR_GUARDIANS,
  75. ]);
  76. $this->assertResponseStatusCodeSame(403);
  77. $this->logger->info("\033[1;32mTest 'put parameters as a non admin' succeed\033[0m");
  78. $this->logger->info("\033[1;34mStarting test... intru of organization try to acceed parameters info\033[0m");
  79. $this->loginAsintruOfRoot($this->user);
  80. $this->get('/api/parameters/1');
  81. $this->assertResponseStatusCodeSame(403);
  82. $this->assertJsonContains([
  83. 'hydra:description' => 'Access Denied.',
  84. ]);
  85. $this->logger->info("\033[1;32mTest 'intru try to acceed param infos' succeed\033[0m");
  86. }
  87. // public function testPutMethode(): void
  88. // {
  89. // $this->loginAs($this->user);
  90. // $this->put('/api/parameters/1', [
  91. // 'bulletinCriteriaSort' => BulletinCriteriaSortEnum::ALPHANUM,
  92. // 'advancedEducationNotationType' => AdvancedEducationNotationTypeEnum::BY_TEACHER,
  93. // 'timezone' => TimeZoneEnum::INDIAN_REUNION,
  94. // 'educationPeriodicity' => PeriodicityEnum::HALF,
  95. // 'bulletinReceiver' => SendToBulletinEnum::STUDENTS_AND_THEIR_GUARDIANS
  96. // ]);
  97. // $this->assertResponseStatusCodeSame(200);
  98. // }
  99. // public function testBadPutBulletinCriteriasort()
  100. // {
  101. // $this->loginAs($this->user);
  102. // $this->put('/api/parameters/1', [
  103. // 'bulletinCriteriaSort' => 'BAD_CRITERIA_SORT'
  104. // ]);
  105. // $this->assertResponseStatusCodeSame(400);
  106. // }
  107. // public function testBadadvancedEducationNotationType()
  108. // {
  109. // $this->loginAs($this->user);
  110. // $this->put('/api/parameters/1', [
  111. // 'bulletinCriteriaSort' => 'bad_advancedEducation'
  112. // ]);
  113. // $this->assertResponseStatusCodeSame(400);
  114. // }
  115. // public function testDeleteParameters()
  116. // {
  117. // $this->loginAs($this->user);
  118. // $this->delete('/api/parameters/1');
  119. // $this->assertResponseStatusCodeSame(405);
  120. // }
  121. // public function testBadTimeZone()
  122. // {
  123. // $this->loginAs($this->user);
  124. // $this->put('/api/parameters/1', [
  125. // 'timezone' => 'bad_timezone'
  126. // ]);
  127. // $this->assertResponseStatusCodeSame(400);
  128. // }
  129. // public function testBadPeridicity()
  130. // {
  131. // $this->loginAs($this->user);
  132. // $this->put('/api/parameters/1', [
  133. // 'educationPeriodicity' => 'bad_periodicity'
  134. // ]);
  135. // $this->assertResponseStatusCodeSame(400);
  136. // }
  137. // public function testGetParamatersWithBadRoles()
  138. // {
  139. // $this->loginAsStudent($this->user);
  140. // $this->get('/api/parameters/1');
  141. // $this->assertResponseStatusCodeSame(403);
  142. // }
  143. // public function testPutParametersWithBadRoles()
  144. // {
  145. // $this->loginAsStudent($this->user);
  146. // $this->put('/api/parameters/1', [
  147. // 'bulletinCriteriaSort' => BulletinCriteriaSortEnum::ALPHANUM,
  148. // 'advancedEducationNotationType' => AdvancedEducationNotationTypeEnum::BY_TEACHER,
  149. // 'timezone' => TimeZoneEnum::INDIAN_REUNION,
  150. // 'educationPeriodicity' => PeriodicityEnum::HALF,
  151. // 'bulletinReceiver' => SendToBulletinEnum::STUDENTS_AND_THEIR_GUARDIANS
  152. // ]);
  153. // $this->assertResponseStatusCodeSame(403);
  154. // }
  155. // public function testGetCollectionWithintruOfOrganization()
  156. // {
  157. // $this->loginAsintruOfRoot($this->user);
  158. // $this->get('/api/parameters/1');
  159. // $this->assertResponseStatusCodeSame(403);
  160. // $this->assertJsonContains([
  161. // "hydra:description" => "Access Denied."
  162. // ]);
  163. // }
  164. }