CycleTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 testCycleCollection()
  8. {
  9. $this->loginAs($this->user);
  10. $this->assertResponseIsSuccessful();
  11. $this->get('/api/cycles');
  12. $this->assertResponseStatusCodeSame(200);
  13. }
  14. public function testCycleById()
  15. {
  16. $this->loginAs($this->user);
  17. $this->assertResponseIsSuccessful();
  18. $this->get('/api/cycles/1');
  19. $this->assertResponseStatusCodeSame(200);
  20. $this->assertJsonContains([
  21. 'label' => 'Cycle 1'
  22. ]);
  23. }
  24. public function testPutCycle()
  25. {
  26. $this->loginAs($this->user);
  27. $this->assertResponseIsSuccessful();
  28. $this->put('/api/cycles/1', [
  29. 'label' => 'new label'
  30. ]);
  31. $this->assertResponseStatusCodeSame(200);
  32. $this->assertJsonContains([
  33. 'label' => 'new label'
  34. ]);
  35. }
  36. public function testDeleteCycle()
  37. {
  38. $this->loginAs($this->user);
  39. $this->assertResponseIsSuccessful();
  40. $this->delete('/api/cycles/1');
  41. $this->assertResponseStatusCodeSame(405);
  42. }
  43. public function testCycleWithBadTypeCycleEnum()
  44. {
  45. $this->loginAs($this->user);
  46. $this->assertResponseIsSuccessful();
  47. $this->put('/api/cycles/1', [
  48. 'cycleEnum' => 'bad type'
  49. ]);
  50. $this->assertResponseStatusCodeSame(400);
  51. }
  52. public function testCycleGetHasNoRole()
  53. {
  54. $this->loginAsStudent($this->user);
  55. $this->get('/api/cycles/1');
  56. $this->validateCollectionSchema(Cycle::class, 403);
  57. $this->assertJsonContains([
  58. "hydra:description" => "Access Denied."
  59. ]);
  60. }
  61. public function testWithNoROle()
  62. {
  63. $this->loginAsStudent($this->user);
  64. $this->get('/api/cycles');
  65. $this->assertResponseStatusCodeSame(403);
  66. }
  67. public function testGetAsIntruder()
  68. {
  69. $this->loginAsintruOfRoot($this->user);
  70. $this->assertResponseIsSuccessful();
  71. $this->get('/api/cycles/1');
  72. $this->assertResponseStatusCodeSame(404);
  73. }
  74. public function testPutsAsIntruder()
  75. {
  76. $this->loginAsintruOfRoot($this->user);
  77. $this->assertResponseIsSuccessful();
  78. $this->put('/api/cycles/1', [
  79. 'label' => 'new label',
  80. 'organization' => '/api/organizations/1'
  81. ]);
  82. $this->assertResponseStatusCodeSame(404);
  83. $this->assertJsonContains([
  84. "hydra:title" => "An error occurred",
  85. "hydra:description" => "Not Found"
  86. ]);
  87. }
  88. public function testDeleteAsIntruder()
  89. {
  90. $this->loginAsintruOfRoot($this->user);
  91. $this->assertResponseIsSuccessful();
  92. $this->delete('/api/cycles/1');
  93. $this->assertResponseStatusCodeSame(405);
  94. $this->assertJsonContains([
  95. "hydra:title" => "An error occurred"
  96. ]);
  97. }
  98. public function testPostAsIntruder()
  99. {
  100. $this->loginAsintruOfRoot($this->user);
  101. $this->assertResponseIsSuccessful();
  102. $this->post('/api/cycles', [
  103. 'label' => 'new label',
  104. 'organization' => '/api/organizations/1'
  105. ]);
  106. $this->assertResponseStatusCodeSame(405);
  107. $this->assertJsonContains([
  108. "hydra:title" => "An error occurred"
  109. ]);
  110. }
  111. }