25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.8KB

  1. <?php
  2. use Framework\Testing\TestCase;
  3. use Framework\Testing\TestResponse;
  4. class WarehouseTest extends TestCase
  5. {
  6. public function testCreatingALocationRequiresLogin()
  7. {
  8. $_SERVER['REQUEST_METHOD'] = 'POST';
  9. $_SERVER['REQUEST_URI'] = '/locations/create';
  10. $_POST['csrf'] = csrf();
  11. $_POST['code'] = 'A1';
  12. $_POST['name'] = 'Aisle 1';
  13. $response = new TestResponse(app()->run());
  14. $this->assertTrue($response->isRedirecting());
  15. $this->assertEquals('/register', $response->redirectingTo());
  16. }
  17. public function testLoggedInUserCanCreateALocation()
  18. {
  19. session()->put('user_id', 1);
  20. $_SERVER['REQUEST_METHOD'] = 'POST';
  21. $_SERVER['REQUEST_URI'] = '/locations/create';
  22. $_POST['csrf'] = csrf();
  23. $_POST['code'] = 'A1';
  24. $_POST['name'] = 'Aisle 1';
  25. $_POST['description'] = '';
  26. $response = new TestResponse(app()->run());
  27. $this->assertTrue($response->isRedirecting());
  28. $_SERVER['REQUEST_METHOD'] = 'GET';
  29. $_SERVER['REQUEST_URI'] = '/locations';
  30. $content = app()->run()->content();
  31. $this->assertStringContainsString('Aisle 1', $content);
  32. }
  33. public function testReceivingStockIncreasesTheItemsQuantity()
  34. {
  35. session()->put('user_id', 1);
  36. $_SERVER['REQUEST_METHOD'] = 'POST';
  37. $_SERVER['REQUEST_URI'] = '/locations/create';
  38. $_POST = [
  39. 'csrf' => csrf(),
  40. 'code' => 'B1',
  41. 'name' => 'Bay 1',
  42. 'description' => '',
  43. ];
  44. $locationResponse = new TestResponse(app()->run());
  45. preg_match('#/locations/view/(\d+)#', $locationResponse->redirectingTo(), $locationMatch);
  46. $locationId = (int) $locationMatch[1];
  47. $_SERVER['REQUEST_METHOD'] = 'POST';
  48. $_SERVER['REQUEST_URI'] = '/items/create';
  49. $_POST = [
  50. 'csrf' => csrf(),
  51. 'sku' => 'SKU-1',
  52. 'name' => 'Widget',
  53. 'description' => '',
  54. 'reorder_level' => '',
  55. ];
  56. $itemResponse = new TestResponse(app()->run());
  57. preg_match('#/items/view/(\d+)#', $itemResponse->redirectingTo(), $itemMatch);
  58. $itemId = (int) $itemMatch[1];
  59. $_SERVER['REQUEST_METHOD'] = 'POST';
  60. $_SERVER['REQUEST_URI'] = "/items/receive/{$itemId}";
  61. $_POST = [
  62. 'csrf' => csrf(),
  63. 'location_id' => (string) $locationId,
  64. 'quantity' => '5',
  65. 'notes' => '',
  66. ];
  67. $receiveResponse = new TestResponse(app()->run());
  68. $this->assertTrue($receiveResponse->isRedirecting());
  69. $_SERVER['REQUEST_METHOD'] = 'GET';
  70. $_SERVER['REQUEST_URI'] = "/items/view/{$itemId}";
  71. $content = app()->run()->content();
  72. $this->assertStringContainsString('5 units in stock', $content);
  73. }
  74. }

Powered by TurnKey Linux.