AddressFeatureTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace Tests\Feature\Admin\Addresses;
  3. use App\Shop\Addresses\Address;
  4. use App\Shop\Customers\Customer;
  5. use App\Shop\Provinces\Province;
  6. use App\Shop\Cities\City;
  7. use App\Shop\Countries\Country;
  8. use Tests\TestCase;
  9. class AddressFeatureTest extends TestCase
  10. {
  11. /** @test */
  12. public function it_can_show_the_edit_page()
  13. {
  14. factory(City::class)->create();
  15. $address = factory(Address::class)->create();
  16. $this
  17. ->actingAs($this->employee, 'employee')
  18. ->get(route('admin.addresses.edit', $address->id))
  19. ->assertStatus(200)
  20. ->assertSee($address->alias)
  21. ->assertSee($address->address_1);
  22. }
  23. /** @test */
  24. public function it_can_show_the_create_address_page()
  25. {
  26. factory(Country::class)->create();
  27. $this
  28. ->actingAs($this->employee, 'employee')
  29. ->get(route('admin.addresses.create'))
  30. ->assertStatus(200)
  31. ->assertSee($this->customer->name);
  32. }
  33. /** @test */
  34. public function it_can_delete_the_address()
  35. {
  36. factory(City::class)->create();
  37. $address = factory(Address::class)->create();
  38. $this
  39. ->actingAs($this->employee, 'employee')
  40. ->delete(route('admin.addresses.destroy', $address->id))
  41. ->assertStatus(302)
  42. ->assertRedirect(route('admin.addresses.index'))
  43. ->assertSessionHas('message', 'Delete successful');
  44. }
  45. /** @test */
  46. public function it_can_show_the_address()
  47. {
  48. factory(City::class)->create();
  49. $address = factory(Address::class)->create();
  50. $this
  51. ->actingAs($this->employee, 'employee')
  52. ->get(route('admin.addresses.show', $address->id))
  53. ->assertStatus(200)
  54. ->assertSee($address->alias);
  55. ;
  56. }
  57. /** @test */
  58. public function it_can_search_for_the_address()
  59. {
  60. factory(City::class)->create();
  61. $address = factory(Address::class)->create();
  62. $this
  63. ->actingAs($this->employee, 'employee')
  64. ->get(route('admin.addresses.index', ['q' => $address->alias]))
  65. ->assertStatus(200)
  66. ->assertSee($address->alias);
  67. }
  68. /** @test */
  69. public function it_can_list_all_the_addresses()
  70. {
  71. factory(City::class)->create();
  72. $address = factory(Address::class)->create();
  73. $this
  74. ->actingAs($this->employee, 'employee')
  75. ->get(route('admin.addresses.index'))
  76. ->assertStatus(200)
  77. ->assertSee(htmlentities($address->alias, ENT_QUOTES))
  78. ->assertSee(htmlentities($address->address_1, ENT_QUOTES));
  79. }
  80. /** @test */
  81. public function it_can_update_the_address()
  82. {
  83. $address = factory(Address::class)->create();
  84. $data = [
  85. 'alias' => $this->faker->word,
  86. 'address_1' => $this->faker->streetName,
  87. 'status' => 1
  88. ];
  89. $this->actingAs($this->employee, 'employee')
  90. ->put(route('admin.addresses.update', $address->id), $data)
  91. ->assertStatus(302)
  92. ->assertRedirect(route('admin.addresses.edit', $address->id))
  93. ->assertSessionHas('message');
  94. }
  95. /** @test */
  96. public function it_errors_updating_the_address()
  97. {
  98. $this->actingAs($this->employee, 'employee')
  99. ->post(route('admin.addresses.store', ['alias' => null]))
  100. ->assertSessionHasErrors(['alias' => 'The alias field is required.']);
  101. }
  102. /** @test */
  103. public function it_can_create_address()
  104. {
  105. $country = factory(Country::class)->create();
  106. $province = factory(Province::class)->create();
  107. $city = factory(City::class)->create();
  108. $customer = factory(Customer::class)->create();
  109. $data = [
  110. 'alias' => $this->faker->word,
  111. 'address_1' => $this->faker->streetName,
  112. 'address_2' => $this->faker->streetAddress,
  113. 'zip' => $this->faker->postcode,
  114. 'city_id' => $city->id,
  115. 'province_id' => $province->id,
  116. 'country_id' => $country->id,
  117. 'customer_id' => $customer->id,
  118. 'status' => 1
  119. ];
  120. $this->actingAs($this->employee, 'employee')
  121. ->post(route('admin.addresses.store'), $data)
  122. ->assertStatus(302)
  123. ->assertRedirect(route('admin.addresses.index'))
  124. ->assertSessionHas('message');
  125. }
  126. }