|
- <?php
-
- use Framework\Testing\TestCase;
- use Framework\Testing\TestResponse;
-
- class WarehouseTest extends TestCase
- {
- public function testCreatingALocationRequiresLogin()
- {
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_SERVER['REQUEST_URI'] = '/locations/create';
-
- $_POST['csrf'] = csrf();
- $_POST['code'] = 'A1';
- $_POST['name'] = 'Aisle 1';
-
- $response = new TestResponse(app()->run());
-
- $this->assertTrue($response->isRedirecting());
- $this->assertEquals('/register', $response->redirectingTo());
- }
-
- public function testLoggedInUserCanCreateALocation()
- {
- session()->put('user_id', 1);
-
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_SERVER['REQUEST_URI'] = '/locations/create';
-
- $_POST['csrf'] = csrf();
- $_POST['code'] = 'A1';
- $_POST['name'] = 'Aisle 1';
- $_POST['description'] = '';
-
- $response = new TestResponse(app()->run());
-
- $this->assertTrue($response->isRedirecting());
-
- $_SERVER['REQUEST_METHOD'] = 'GET';
- $_SERVER['REQUEST_URI'] = '/locations';
-
- $content = app()->run()->content();
-
- $this->assertStringContainsString('Aisle 1', $content);
- }
-
- public function testReceivingStockIncreasesTheItemsQuantity()
- {
- session()->put('user_id', 1);
-
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_SERVER['REQUEST_URI'] = '/locations/create';
- $_POST = [
- 'csrf' => csrf(),
- 'code' => 'B1',
- 'name' => 'Bay 1',
- 'description' => '',
- ];
-
- $locationResponse = new TestResponse(app()->run());
- preg_match('#/locations/view/(\d+)#', $locationResponse->redirectingTo(), $locationMatch);
- $locationId = (int) $locationMatch[1];
-
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_SERVER['REQUEST_URI'] = '/items/create';
- $_POST = [
- 'csrf' => csrf(),
- 'sku' => 'SKU-1',
- 'name' => 'Widget',
- 'description' => '',
- 'reorder_level' => '',
- ];
-
- $itemResponse = new TestResponse(app()->run());
- preg_match('#/items/view/(\d+)#', $itemResponse->redirectingTo(), $itemMatch);
- $itemId = (int) $itemMatch[1];
-
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_SERVER['REQUEST_URI'] = "/items/receive/{$itemId}";
- $_POST = [
- 'csrf' => csrf(),
- 'location_id' => (string) $locationId,
- 'quantity' => '5',
- 'notes' => '',
- ];
-
- $receiveResponse = new TestResponse(app()->run());
- $this->assertTrue($receiveResponse->isRedirecting());
-
- $_SERVER['REQUEST_METHOD'] = 'GET';
- $_SERVER['REQUEST_URI'] = "/items/view/{$itemId}";
-
- $content = app()->run()->content();
-
- $this->assertStringContainsString('5 units in stock', $content);
- }
- }
|