CycleTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Tests\Application\Education;
  3. use App\Entity\Education\Cycle;
  4. use App\Tests\Application\OtWebTestCase;
  5. class CycleTest extends OtWebTestCase
  6. {
  7. public function testCycleResource()
  8. {
  9. $this->logger->info("\033[1;34mStarting test... Retrieve the list of all cycle for an admin user\033[0m");
  10. $this->loginAs($this->user);
  11. $this->get('/api/cycles');
  12. $this->assertResponseStatusCodeSame(200);
  13. $this->logger->info("\033[1;32mTest 'test get cycle collection' succeed\033[0m");
  14. $this->logger->info("\033[1;34mStarting test... Get cycle by id a an admin \033[0m");
  15. $this->loginAs($this->user);
  16. $this->get('/api/cycles/1');
  17. $this->assertResponseStatusCodeSame(200);
  18. $this->assertJsonContains([
  19. 'label' => 'Cycle 1',
  20. ]);
  21. $this->logger->info("\033[1;32mTest 'Get cycle by id a an admin' succeed\033[0m");
  22. $this->logger->info("\033[1;34mStarting test... Change a cycle a an admin \033[0m");
  23. $this->loginAs($this->user);
  24. $this->put('/api/cycles/1', [
  25. 'label' => 'new label',
  26. ]);
  27. $this->assertResponseStatusCodeSame(200);
  28. $this->assertJsonContains([
  29. 'label' => 'new label',
  30. ]);
  31. $this->logger->info("\033[1;32mTest 'Change a cycle a an admin' succeed\033[0m");
  32. $this->logger->info("\033[1;34mStarting test... Delete a cycle a an admin \033[0m");
  33. $this->loginAs($this->user);
  34. $this->delete('/api/cycles/1');
  35. $this->assertResponseStatusCodeSame(405);
  36. $this->logger->info("\033[1;32mTest 'Delete a cycle a an admin ' succeed\033[0m");
  37. $this->logger->info("\033[1;34mStarting test... Put a bad cycle enum cycle a an admin \033[0m");
  38. $this->loginAs($this->user);
  39. $this->put('/api/cycles/1', [
  40. 'cycleEnum' => 'bad type',
  41. ]);
  42. $this->assertResponseStatusCodeSame(400);
  43. $this->logger->info("\033[1;32mTest 'Put a bad cycle enum cycle a an admin ' succeed\033[0m");
  44. $this->logger->info("\033[1;34mStarting test... Get a cycle as an non admin\033[0m");
  45. $this->loginAsStudent($this->user);
  46. $this->get('/api/cycles/1');
  47. $this->validateCollectionSchema(Cycle::class, 403);
  48. $this->assertJsonContains([
  49. 'hydra:description' => 'Access Denied.',
  50. ]);
  51. $this->logger->info("\033[1;32mTest 'Get a cycle as an non admin' succeed\033[0m");
  52. $this->logger->info("\033[1;34mStarting test... Get all cycle as an non admin\033[0m");
  53. $this->loginAsStudent($this->user);
  54. $this->get('/api/cycles');
  55. $this->assertResponseStatusCodeSame(403);
  56. $this->logger->info("\033[1;32mTest 'Get all cycle as an non admin' succeed\033[0m");
  57. $this->logger->info("\033[1;34mStarting test... Get all cycle as an intruder of organization\033[0m");
  58. $this->loginAsintruOfRoot($this->user);
  59. $this->get('/api/cycles/1');
  60. $this->assertResponseStatusCodeSame(404);
  61. $this->logger->info("\033[1;32mTest 'Get all cycle as an intruder of organization' succeed\033[0m");
  62. $this->logger->info("\033[1;34mStarting test... Change a cycle as an intruder of organization\033[0m");
  63. $this->loginAsintruOfRoot($this->user);
  64. $this->put('/api/cycles/1', [
  65. 'label' => 'new label',
  66. 'organization' => '/api/organizations/1',
  67. ]);
  68. $this->assertResponseStatusCodeSame(404);
  69. $this->assertJsonContains([
  70. 'hydra:title' => 'An error occurred',
  71. 'hydra:description' => 'Not Found',
  72. ]);
  73. $this->logger->info("\033[1;32mTest 'Change a cycle as an intruder of organization' succeed\033[0m");
  74. $this->logger->info("\033[1;34mStarting test... delete a cycle as an intruder of organization\033[0m");
  75. $this->loginAsintruOfRoot($this->user);
  76. $this->delete('/api/cycles/1');
  77. $this->assertResponseStatusCodeSame(405);
  78. $this->assertJsonContains([
  79. 'hydra:title' => 'An error occurred',
  80. ]);
  81. $this->logger->info("\033[1;32mTest 'delete a cycle as an intruder of organization' succeed\033[0m");
  82. $this->logger->info("\033[1;34mStarting test... Post a cycle as an intruder of organization\033[0m");
  83. $this->loginAsintruOfRoot($this->user);
  84. $this->post('/api/cycles', [
  85. 'label' => 'new label',
  86. 'organization' => '/api/organizations/1',
  87. ]);
  88. $this->assertResponseStatusCodeSame(405);
  89. $this->assertJsonContains([
  90. 'hydra:title' => 'An error occurred',
  91. ]);
  92. $this->logger->info("\033[1;32mTest 'Post a cycle as an intruder of organization' succeed\033[0m");
  93. }
  94. }