CreateProductPageTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Shop\Employees\Employee;
  4. use App\Shop\Employees\Repositories\EmployeeRepository;
  5. use App\Shop\Roles\Repositories\RoleRepository;
  6. use App\Shop\Roles\Role;
  7. use Tests\TestCase;
  8. class CreateProductPageTest extends TestCase
  9. {
  10. /** @test */
  11. public function it_should_not_show_to_customers()
  12. {
  13. $this
  14. ->actingAs($this->customer, 'web')
  15. ->get(route('admin.products.create'))
  16. ->assertStatus(302)
  17. ->assertSessionHas(['error' => 'You must be an employee to see this page']);
  18. }
  19. /** @test */
  20. public function it_should_show_to_admin_role()
  21. {
  22. $this
  23. ->actingAs($this->employee, 'employee')
  24. ->get(route('admin.products.create'))
  25. ->assertStatus(200);
  26. }
  27. /** @test */
  28. public function it_should_not_show_to_non_admin_role()
  29. {
  30. $employee = factory(Employee::class)->create();
  31. $roleRepo = new RoleRepository(new Role);
  32. $admin = $roleRepo->createRole(['name' => 'user']);
  33. $employeeRepo = new EmployeeRepository($employee);
  34. $employeeRepo->syncRoles([$admin->id]);
  35. $this
  36. ->actingAs($employee, 'employee')
  37. ->get(route('admin.products.create'))
  38. ->assertStatus(403)
  39. ->assertSee('Sorry, this page is restricted to authorized users only.');
  40. }
  41. /** @test */
  42. public function it_should_not_show_to_employees_without_any_role()
  43. {
  44. $employee = factory(Employee::class)->create();
  45. $this
  46. ->actingAs($employee, 'employee')
  47. ->get(route('admin.products.create'))
  48. ->assertStatus(403)
  49. ->assertSee('Sorry, this page is restricted to authorized users only.');
  50. }
  51. }