EducationTimingTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Tests\Application\Education;
  3. use App\Tests\Application\OtWebTestCase;
  4. class EducationTimingTest extends OtWebTestCase
  5. {
  6. /**
  7. * TODO : revenir sur ces tests qui ne sont pas à jour
  8. * dû à des conflits de roles.
  9. */
  10. public function testEducationTimingResource()
  11. {
  12. $this->logger->info("\033[1;34mStarting test... get education Timings collection as an admin\033[0m");
  13. $this->loginAs($this->user);
  14. $this->get('/api/education_timings');
  15. $this->assertResponseStatusCodeSame(200);
  16. $this->assertJsonContains([
  17. 'hydra:member' => [
  18. [
  19. 'organization' => '/api/organizations/1',
  20. 'timing' => 45,
  21. ],
  22. ],
  23. ]);
  24. $this->logger->info("\033[1;32mTest 'get education Timings collection as an admin' succeed\033[0m");
  25. $this->logger->info("\033[1;34mStarting test... create an education timings as an admin\033[0m");
  26. $this->loginAs($this->user);
  27. $this->post('/api/education_timings', [
  28. 'timing' => 60,
  29. ]);
  30. $this->assertResponseStatusCodeSame(201);
  31. $this->assertJsonContains([
  32. '@context' => '/api/contexts/EducationTiming',
  33. '@id' => '/api/education_timings/3',
  34. '@type' => 'EducationTiming',
  35. 'id' => 3,
  36. 'timing' => 60,
  37. 'organization' => '/api/organizations/1',
  38. 'educationStudents' => [],
  39. 'educationCurriculums' => [],
  40. ]);
  41. $this->logger->info("\033[1;32mTest 'get education Timings collection as an admin' succeed\033[0m");
  42. $this->logger->info("\033[1;34mStarting test... change an education timing as an admin\033[0m");
  43. $this->loginAs($this->user);
  44. $this->put('/api/education_timings/1', [
  45. 'timing' => 60,
  46. ]);
  47. $this->logger->info("\033[1;32mTest 'change an education timing as an admin' succeed\033[0m");
  48. $this->logger->info("\033[1;34mStarting test... delete an education timing as an admin\033[0m");
  49. $this->loginAs($this->user);
  50. $this->delete('/api/education_timings/1');
  51. $this->logger->info("\033[1;32mTest 'delete an education timing as an admin' succeed\033[0m");
  52. $this->logger->info("\033[1;34mStarting test... change an education timing as an non admin\033[0m");
  53. $this->loginAsStudent($this->user);
  54. $this->put('/api/education_timings/1', [
  55. 'timing' => 60,
  56. ]);
  57. $this->assertResponseStatusCodeSame(404);
  58. $this->logger->info("\033[1;32mTest 'change an education timing as an admin' succeed\033[0m");
  59. $this->logger->info("\033[1;34mStarting test... delete an education timing as an non admin\033[0m");
  60. $this->loginAsStudent($this->user);
  61. $this->delete('/api/education_timings/1');
  62. $this->assertResponseStatusCodeSame(404);
  63. $this->logger->info("\033[1;32mTest 'delete an education timing as an non-admin' succeed\033[0m");
  64. $this->logger->info("\033[1;34mStarting test... intru of organization try to get an education timings\033[0m");
  65. $this->loginAsintruOfRoot($this->user);
  66. $this->get('/api/education_timings/1');
  67. $this->assertResponseStatusCodeSame(404);
  68. $this->logger->info("\033[1;32mTest 'intru of organization try to get an education timings' succeed\033[0m");
  69. $this->logger->info("\033[1;34mStarting test... intru of organization try to put an education timings\033[0m");
  70. $this->loginAsintruOfRoot($this->user);
  71. $this->put('/api/education_timings/1', [
  72. 'timing' => 60,
  73. 'organization' => '/api/organizations/1',
  74. ]);
  75. $this->assertResponseStatusCodeSame(404);
  76. $this->logger->info("\033[1;32mTest 'intru of organization try to put an education timings' succeed\033[0m");
  77. $this->logger->info("\033[1;34mStarting test... intru of organization try to delete an education timings\033[0m");
  78. $this->loginAsintruOfRoot($this->user);
  79. $this->delete('/api/education_timings/1');
  80. $this->assertResponseStatusCodeSame(404);
  81. $this->logger->info("\033[1;32mTest 'intru of organization try to delete an education timings' succeed\033[0m");
  82. $this->logger->info("\033[1;34mStarting test... intru of organization try to post an education timings\033[0m");
  83. $this->loginAsintruOfRoot($this->user);
  84. $this->post('/api/education_timings', [
  85. 'timing' => 45,
  86. 'organization' => '/api/organizations/1',
  87. ]);
  88. $this->assertResponseStatusCodeSame(400);
  89. $this->logger->info("\033[1;32mTest 'intru of organization try to post an education timings' succeed\033[0m");
  90. }
  91. }