EducationTimingTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 testEducationTimingsCollection()
  11. {
  12. $this->loginAs($this->user);
  13. $this->get('/api/education_timings');
  14. $this->assertResponseIsSuccessful();
  15. $this->assertResponseStatusCodeSame(200);
  16. $this->assertJsonContains([
  17. 'hydra:member' => [
  18. [
  19. 'organization' => '/api/organizations/1',
  20. 'timing' => 45
  21. ]
  22. ]
  23. ]);
  24. }
  25. public function testEducationTimingsCreate()
  26. {
  27. $this->loginAs($this->user);
  28. $this->assertResponseIsSuccessful();
  29. $this->post('/api/education_timings', [
  30. "timing" => 60,
  31. ]);
  32. $this->assertResponseStatusCodeSame(201);
  33. // $responseContent = $this->client->getResponse()->getContent();
  34. // echo "\nResponse after POST: " . $responseContent;
  35. $this->assertJsonContains([
  36. '@context' => '/api/contexts/EducationTiming',
  37. '@id' => '/api/education_timings/3',
  38. '@type' => 'EducationTiming',
  39. "id" => 3,
  40. 'timing' => 60,
  41. 'organization' => '/api/organizations/1',
  42. 'educationStudents' => [],
  43. 'educationCurriculums' => [],
  44. ]);
  45. }
  46. public function testPutEducationTimings()
  47. {
  48. $this->loginAs($this->user);
  49. $this->assertResponseIsSuccessful();
  50. $this->put('/api/education_timings/1', [
  51. "timing" => 60,
  52. ]);
  53. }
  54. public function testDeleteEducationTimings()
  55. {
  56. $this->loginAs($this->user);
  57. $this->assertResponseIsSuccessful();
  58. $this->delete('/api/education_timings/1');
  59. }
  60. public function testPutWithNoRoles()
  61. {
  62. // attention : vériier que l'on a pas les droits
  63. $this->loginAsStudent($this->user);
  64. $this->assertResponseIsSuccessful();
  65. $this->put('/api/education_timings/1', [
  66. "timing" => 60,
  67. ]);
  68. // erreur
  69. $this->assertResponseStatusCodeSame(200);
  70. }
  71. public function testDeleteWithNoRoles()
  72. {
  73. // attention : vériier que l'on a pas les droits
  74. $this->loginAsStudent($this->user);
  75. $this->assertResponseIsSuccessful();
  76. $this->delete('/api/education_timings/1');
  77. $this->assertResponseStatusCodeSame(204);
  78. }
  79. // attention un eleve ne peut pas créer/modifier un educationTiming
  80. // public function testPostWithNoRoles()
  81. // {
  82. // // attention : vériier que l'on a pas les droits
  83. // $this->loginAsStudent($this->user);
  84. // $this->assertResponseIsSuccessful();
  85. // $this->put('/api/education_timings/1', [
  86. // "timing" => 60,
  87. // ]);
  88. // $this->assertResponseStatusCodeSame(404);
  89. // }
  90. public function testgetFromOtherOrganization()
  91. {
  92. $this->loginAsintruOfRoot($this->user);
  93. $this->assertResponseIsSuccessful();
  94. $this->get('/api/education_timings/1');
  95. $this->assertResponseStatusCodeSame(404);
  96. }
  97. public function testPutFromOtherOrganization()
  98. {
  99. $this->loginAsintruOfRoot($this->user);
  100. $this->assertResponseIsSuccessful();
  101. $this->put('/api/education_timings/1', [
  102. "timing" => 60,
  103. "organization" => "/api/organizations/1",
  104. ]);
  105. // not found -> l'id de cet educationTiming n'existe pas dans l'organisation de l'intru
  106. $this->assertResponseStatusCodeSame(404);
  107. }
  108. public function testDeleteFromOtherOrganization()
  109. {
  110. $this->loginAsintruOfRoot($this->user);
  111. $this->assertResponseIsSuccessful();
  112. $this->delete('/api/education_timings/1');
  113. $this->assertResponseStatusCodeSame(404);
  114. }
  115. public function testPostFromOtherOrganization()
  116. {
  117. $this->loginAsintruOfRoot($this->user);
  118. $this->assertResponseIsSuccessful();
  119. $this->post('/api/education_timings', [
  120. "timing" => 45,
  121. "organization" => "/api/organizations/1",
  122. ]);
  123. $this->assertResponseStatusCodeSame(400);
  124. }
  125. }