BrandFeatureTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Tests\Feature\Admin\Brands;
  3. use App\Shop\Brands\Brand;
  4. use Tests\TestCase;
  5. class BrandFeatureTest extends TestCase
  6. {
  7. /** @test */
  8. public function it_can_delete_the_brand()
  9. {
  10. $brand = factory(Brand::class)->create();
  11. $this->actingAs($this->employee, 'employee')
  12. ->delete(route('admin.brands.destroy', $brand->id), [])
  13. ->assertStatus(302)
  14. ->assertRedirect(route('admin.brands.index'))
  15. ->assertSessionHas(['message' => 'Delete successful!']);
  16. }
  17. /** @test */
  18. public function it_can_update_the_brand()
  19. {
  20. $brand = factory(Brand::class)->create();
  21. $data = ['name' => 'Hello Panda!'];
  22. $this->actingAs($this->employee, 'employee')
  23. ->put(route('admin.brands.update', $brand->id), $data)
  24. ->assertStatus(302)
  25. ->assertRedirect(route('admin.brands.edit', $brand->id))
  26. ->assertSessionHas(['message' => 'Update successful!']);
  27. }
  28. /** @test */
  29. public function it_can_show_the_edit_brand_form()
  30. {
  31. $brand = factory(Brand::class)->create();
  32. $this->actingAs($this->employee, 'employee')
  33. ->get(route('admin.brands.edit', $brand->id))
  34. ->assertStatus(200)
  35. ->assertSee($brand->name);
  36. }
  37. /** @test */
  38. public function it_can_list_all_the_brands()
  39. {
  40. $brand = factory(Brand::class)->create();
  41. $this->actingAs($this->employee, 'employee')
  42. ->get(route('admin.brands.index'))
  43. ->assertStatus(200)
  44. ->assertSee(htmlentities($brand->name, ENT_QUOTES));
  45. }
  46. /** @test */
  47. public function it_can_create_the_brand()
  48. {
  49. $this->actingAs($this->employee, 'employee')
  50. ->post(route('admin.brands.store'), ['name' => $this->faker->company])
  51. ->assertStatus(302)
  52. ->assertRedirect(route('admin.brands.index'))
  53. ->assertSessionHas(['message' => 'Create brand successful!']);
  54. }
  55. /** @test */
  56. public function it_can_see_the_brand_create_form()
  57. {
  58. $this
  59. ->actingAs($this->employee, 'employee')
  60. ->get(route('admin.brands.create'))
  61. ->assertSee('Name')
  62. ->assertSee('Create')
  63. ->assertSee('Back')
  64. ->assertStatus(200);
  65. }
  66. }