CustomersFeatureTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Shop\Addresses\Address;
  4. use App\Shop\Cities\City;
  5. use App\Shop\Countries\Country;
  6. use App\Shop\Customers\Customer;
  7. use App\Shop\Customers\Repositories\CustomerRepository;
  8. use App\Shop\Provinces\Province;
  9. use Tests\TestCase;
  10. class CustomersFeatureTest extends TestCase
  11. {
  12. /** @test */
  13. public function it_can_edit_the_customer_address()
  14. {
  15. factory(Country::class)->create();
  16. factory(Province::class)->create();
  17. factory(City::class)->create();
  18. $customer = factory(Customer::class)->create();
  19. $address = factory(Address::class)->create();
  20. $customerRepo = new CustomerRepository($customer);
  21. $attachedAddress = $customerRepo->attachAddress($address);
  22. $this
  23. ->actingAs($this->employee, 'employee')
  24. ->get(route('admin.customers.addresses.edit', [$customer->id, $attachedAddress->id]))
  25. ->assertStatus(200)
  26. ->assertSee($address->alias);
  27. }
  28. /** @test */
  29. public function it_can_show_the_customer_address()
  30. {
  31. factory(City::class)->create();
  32. $customer = factory(Customer::class)->create();
  33. $address = factory(Address::class)->create();
  34. $customerRepo = new CustomerRepository($customer);
  35. $customerRepo->attachAddress($address);
  36. $this
  37. ->actingAs($this->employee, 'employee')
  38. ->get(route('admin.customers.addresses.show', [$customer->id, $address->id]))
  39. ->assertStatus(200)
  40. ->assertSee($address->alias);
  41. }
  42. /** @test */
  43. public function it_can_delete_the_customer()
  44. {
  45. $customer = factory(Customer::class)->create();
  46. $this
  47. ->actingAs($this->employee, 'employee')
  48. ->delete(route('admin.customers.destroy', $customer->id))
  49. ->assertStatus(302)
  50. ->assertRedirect(route('admin.customers.index'))
  51. ->assertSessionHas('message', 'Delete successful');
  52. }
  53. /** @test */
  54. public function it_can_show_the_create_and_edit_page()
  55. {
  56. $customer = factory(Customer::class)->create();
  57. $this
  58. ->actingAs($this->employee, 'employee')
  59. ->get(route('admin.customers.create'))
  60. ->assertStatus(200);
  61. $this
  62. ->actingAs($this->employee, 'employee')
  63. ->get(route('admin.customers.edit', $customer->id))
  64. ->assertStatus(200)
  65. ->assertSee(htmlentities($customer->name, ENT_QUOTES));
  66. }
  67. /** @test */
  68. public function it_can_search_for_the_customer()
  69. {
  70. $customer = factory(Customer::class)->create();
  71. $param = ['q' => str_slug($customer->name, 5)];
  72. $this
  73. ->actingAs($this->employee, 'employee')
  74. ->get(route('admin.customers.index', $param))
  75. ->assertStatus(200);
  76. }
  77. /** @test */
  78. public function it_can_update_the_customers_password()
  79. {
  80. $customer = factory(Customer::class)->create();
  81. $data = [
  82. 'name' => $this->faker->name,
  83. 'email' => $this->faker->email,
  84. 'password' => 'unknown'
  85. ];
  86. $this->actingAs($this->employee, 'employee')
  87. ->put(route('admin.customers.update', $customer->id), $data)
  88. ->assertStatus(302)
  89. ->assertRedirect(route('admin.customers.edit', $customer->id));
  90. }
  91. /** @test */
  92. public function it_can_show_all_the_customers()
  93. {
  94. factory(Customer::class, 20)->create();
  95. $this->actingAs($this->employee, 'employee')
  96. ->get(route('admin.customers.index'))
  97. ->assertViewHas(['customers']);
  98. }
  99. /** @test */
  100. public function it_can_show_the_customer()
  101. {
  102. $customer = factory(Customer::class)->create();
  103. $this->actingAs($this->employee, 'employee')
  104. ->get(route('admin.customers.show', $customer->id))
  105. ->assertViewHas(['customer'])
  106. ->assertSeeText(htmlentities($customer->name, ENT_QUOTES));
  107. }
  108. /** @test */
  109. public function it_can_update_the_customer()
  110. {
  111. $customer = factory(Customer::class)->create();
  112. $data = [
  113. 'name' => $this->faker->name,
  114. 'email' => $this->faker->email
  115. ];
  116. $this->actingAs($this->employee, 'employee')
  117. ->put(route('admin.customers.update', $customer->id), $data)
  118. ->assertStatus(302)
  119. ->assertRedirect(route('admin.customers.edit', $customer->id));
  120. $this->assertDatabaseHas('customers', $data);
  121. }
  122. /** @test */
  123. public function it_can_create_the_customer()
  124. {
  125. $data = [
  126. 'name' => $this->faker->name,
  127. 'email' => $this->faker->email,
  128. 'password' => 'secret!!'
  129. ];
  130. $this->actingAs($this->employee, 'employee')
  131. ->post(route('admin.customers.store'), $data)
  132. ->assertStatus(302)
  133. ->assertRedirect(route('admin.customers.index'));
  134. $created = collect($data)->except('password');
  135. $this->assertDatabaseHas('customers', $created->all());
  136. }
  137. }