CourierFeatureTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Shop\Couriers\Courier;
  4. use Tests\TestCase;
  5. class CourierFeatureTest extends TestCase
  6. {
  7. /** @test */
  8. public function it_can_list_all_couriers()
  9. {
  10. $courier = factory(Courier::class)->create();
  11. $this
  12. ->actingAs($this->employee, 'employee')
  13. ->get(route('admin.couriers.index'))
  14. ->assertStatus(200)
  15. ->assertSee(htmlentities($courier->name, ENT_QUOTES));
  16. }
  17. /** @test */
  18. public function it_can_delete_the_courier()
  19. {
  20. $courier = factory(Courier::class)->create();
  21. $this
  22. ->actingAs($this->employee, 'employee')
  23. ->delete(route('admin.couriers.destroy', $courier->id))
  24. ->assertStatus(302)
  25. ->assertRedirect(route('admin.couriers.index'))
  26. ->assertSessionHas('message', 'Delete successful');
  27. }
  28. /** @test */
  29. public function it_can_update_the_courier()
  30. {
  31. $courier = factory(Courier::class)->create();
  32. $data = [
  33. 'name' => $this->faker->word,
  34. 'description' => $this->faker->paragraph,
  35. 'url' => $this->faker->sentence,
  36. 'is_free' => 1,
  37. 'status' => 1
  38. ];
  39. $this
  40. ->actingAs($this->employee, 'employee')
  41. ->put(route('admin.couriers.update', $courier->id), $data)
  42. ->assertStatus(302)
  43. ->assertRedirect(route('admin.couriers.edit', $courier->id))
  44. ->assertSessionHas('message', 'Update successful');
  45. }
  46. /** @test */
  47. public function it_can_show_the_edit_page()
  48. {
  49. $courier = factory(Courier::class)->create();
  50. $this
  51. ->actingAs($this->employee, 'employee')
  52. ->get(route('admin.couriers.edit', $courier->id))
  53. ->assertStatus(200)
  54. ->assertSee(htmlentities($courier->name, ENT_QUOTES));
  55. }
  56. /** @test */
  57. public function it_can_show_the_create_page()
  58. {
  59. $this
  60. ->actingAs($this->employee, 'employee')
  61. ->get(route('admin.couriers.create'))
  62. ->assertStatus(200);
  63. }
  64. /** @test */
  65. public function it_can_create_courier()
  66. {
  67. $data = [
  68. 'name' => $this->faker->word,
  69. 'description' => $this->faker->paragraph,
  70. 'url' => $this->faker->sentence,
  71. 'is_free' => 1,
  72. 'status' => 1
  73. ];
  74. $this
  75. ->actingAs($this->employee, 'employee')
  76. ->post(route('admin.couriers.store'), $data)
  77. ->assertStatus(302)
  78. ->assertRedirect(route('admin.couriers.index'))
  79. ->assertSessionHas('message', 'Create successful');
  80. }
  81. /** @test */
  82. public function it_errors_updating_the_courier()
  83. {
  84. $courier = factory(Courier::class)->create();
  85. $this
  86. ->actingAs($this->employee, 'employee')
  87. ->put(route('admin.couriers.update', $courier->id), [])
  88. ->assertSessionHasErrors(['name' => 'The name field is required.']);
  89. }
  90. /** @test */
  91. public function it_errors_creating_the_courier_with_the_name_already_existing()
  92. {
  93. $courier = factory(Courier::class)->create();
  94. $this
  95. ->actingAs($this->employee, 'employee')
  96. ->post(route('admin.couriers.store'), ['name' => $courier->name])
  97. ->assertSessionHasErrors();
  98. }
  99. /** @test */
  100. public function it_errors_creating_the_courier()
  101. {
  102. $this
  103. ->actingAs($this->employee, 'employee')
  104. ->post(route('admin.couriers.store'), [])
  105. ->assertSessionHasErrors(['name' => 'The name field is required.']);
  106. }
  107. }