/** * test grabbing location by productId **/ public function testGetValidProductByLocationId() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("location"); // create a new location and insert to into mySQL $location = new Location(null, $this->VALID_storageCode, $this->VALID_description); $location->insert($this->getPDO()); $quantity = 5.9; // create a new location and insert to into mySQL $productLocation = new productLocation($location->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity); $productLocation->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoProductArray = Location::getProductByLocationId($this->getPDO(), $location->getLocationId()); for ($i = 0; $i < count($pdoProductArray); $i++) { if ($i === 0) { $this->assertSame($pdoProductArray[$i]->getStorageCode(), $this->VALID_storageCode); $this->assertSame($pdoProductArray[$i]->getDescription(), $this->VALID_description); } else { $this->assertSame($pdoProductArray[$i]->getProductId(), $this->product->getProductId()); $this->assertSame($pdoProductArray[$i]->getVendorId(), $this->product->getVendorId()); $this->assertSame($pdoProductArray[$i]->getDescription(), $this->product->getDescription()); $this->assertSame($pdoProductArray[$i]->getSku(), $this->product->getSku()); $this->assertSame($pdoProductArray[$i]->getTitle(), $this->product->getTitle()); } } }
/** * Test Posting Valid Movement **/ public function testPostValidMovement() { // create a new Movement $newMovement = new Movement(null, $this->fromLocation->getLocationId(), $this->toLocation->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $this->user->getUserId(), $this->VALID_cost, $this->VALID_movementDate, $this->VALID_movementType, $this->VALID_price); // run a get request to establish session tokens $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/movement/?page=0'); // grab the data from guzzle and enforce the status' match our expectations $response = $this->guzzle->post('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/movement/', ['headers' => ['X-XSRF-TOKEN' => $this->getXsrfToken()], 'json' => $newMovement]); $this->assertSame($response->getStatusCode(), 200); $body = $response->getBody(); $movement = json_decode($body); $this->assertSame(200, $movement->status); }
/** * Test grabbing Valid UnitOfMeasure by productId **/ public function testGetValidUnitOfMeasureByProductId() { // create a new Product $newProduct = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title); $newProduct->insert($this->getPDO()); // create a new ProductLocation $quantity = 1.5; $newProductLocation = new ProductLocation($this->location->getLocationId(), $newProduct->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity); $newProductLocation->insert($this->getPDO()); // grab the data from guzzle $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/product/?productId=' . $newProduct->getProductId() . "&getUnitOfMeasure=true"); $this->assertSame($response->getStatusCode(), 200); $body = $response->getBody(); $product = json_decode($body); $this->assertSame(200, $product->status); }
/** * test grabbing a ProductLocation by productId **/ public function testGetValidProductLocationByProductId() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("productLocation"); // create a new ProductLocation and insert to into mySQL $productLocation = new ProductLocation($this->location->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $this->VALID_quantity); $productLocation->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoProductLocation = ProductLocation::getProductLocationByProductId($this->getPDO(), $this->product->getProductId()); foreach ($pdoProductLocation as $pdoPL) { $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("productLocation")); $this->assertSame($pdoPL->getLocationId(), $this->location->getLocationId()); $this->assertSame($pdoPL->getUnitId(), $this->unitOfMeasure->getUnitId()); $this->assertSame($pdoPL->getQuantity(), $this->VALID_quantity); } }
/** * Test grabbing Valid Product by LocationId **/ public function testGetValidProductByLocationId() { // create a new location and insert to into mySQL $newLocation = new Location(null, $this->VALID_storageCode, $this->VALID_description); $newLocation->insert($this->getPDO()); $quantity = 5.9; // create a new location and insert to into mySQL $productLocation = new productLocation($newLocation->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity); $productLocation->insert($this->getPDO()); // grab the data from guzzle $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/location/?locationId=' . $newLocation->getLocationId() . "&getProducts=true"); $this->assertSame($response->getStatusCode(), 200); $body = $response->getBody(); $location = json_decode($body); echo $body . PHP_EOL; $this->assertSame(200, $location->status); }
/** * test grabbing unit of measure by the product id **/ public function testGetValidUnitOfMeasurementByProductId() { // create a new product and insert to into mySQL $product = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title); $product->insert($this->getPDO()); $quantity = 5.9; // create a new product and insert to into mySQL $productLocation = new ProductLocation($this->location->getLocationId(), $product->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity); $productLocation->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoUnitOfMeasureArray = Product::getUnitOfMeasureByProductId($this->getPDO(), $product->getProductId()); for ($i = 0; $i < count($pdoUnitOfMeasureArray); $i++) { if ($i === 0) { $this->assertSame($pdoUnitOfMeasureArray[$i]->getVendorId(), $this->vendor->getVendorId()); $this->assertSame($pdoUnitOfMeasureArray[$i]->getDescription(), $this->VALID_description); $this->assertSame($pdoUnitOfMeasureArray[$i]->getLeadTime(), $this->VALID_leadTime); $this->assertSame($pdoUnitOfMeasureArray[$i]->getSku(), $this->VALID_sku); $this->assertSame($pdoUnitOfMeasureArray[$i]->getTitle(), $this->VALID_title); } else { $this->assertSame($pdoUnitOfMeasureArray[$i]->getUnitId(), $this->unitOfMeasure->getUnitId()); $this->assertSame($pdoUnitOfMeasureArray[$i]->getUnitCode(), $this->unitOfMeasure->getUnitCode()); $this->assertSame($pdoUnitOfMeasureArray[$i]->getQuantity(), $this->unitOfMeasure->getQuantity()); } } }
/** * test inserting a Unit Of Measure and regrabbing it from mySQL **/ public function testGetValidLocationrByLocationId() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("unitOfMeasure"); // create a new unit of measure and insert to into mySQL $unitOfMeasure = new UnitOfMeasure(null, $this->VALID_unitCode, $this->VALID_quantity); $unitOfMeasure->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoUnitOfMeasure = UnitOfMeasure::getUnitOfMeasureByUnitId($this->getPDO(), $unitOfMeasure->getUnitId()); $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("unitOfMeasure")); $this->assertSame($pdoUnitOfMeasure->getUnitCode(), $this->VALID_unitCode); $this->assertSame($pdoUnitOfMeasure->getQuantity(), $this->VALID_quantity); }
/** * test grabbing a Movement by movementType **/ public function testGetValidAllMovements() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("movement"); // create a new Movement and insert to into mySQL $movement = new Movement(null, $this->fromLocation->getLocationId(), $this->toLocation->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $this->user->getUserId(), $this->VALID_cost, $this->VALID_movementDate, $this->VALID_movementType, $this->VALID_price); $movement->insert($this->getPDO()); $page = 1; // grab the data from mySQL and enforce the fields match our expectations $pdoMovement = Movement::getAllMovements($this->getPDO(), $page); foreach ($pdoMovement as $pdoM) { $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("movement")); $this->assertSame($pdoM->getFromLocationId(), $this->fromLocation->getLocationId()); $this->assertSame($pdoM->getToLocationId(), $this->toLocation->getLocationId()); $this->assertSame($pdoM->getProductId(), $this->product->getProductId()); $this->assertSame($pdoM->getUnitId(), $this->unitOfMeasure->getUnitId()); $this->assertSame($pdoM->getUserId(), $this->user->getUserId()); $this->assertSame($pdoM->getCost(), $this->VALID_cost); $this->assertEquals($pdoM->getMovementDate(), $this->VALID_movementDate); $this->assertSame($pdoM->getMovementType(), $this->VALID_movementType); $this->assertSame($pdoM->getPrice(), $this->VALID_price); } }