/**
  * Test grabbing Valid FinishedProduct by productId
  **/
 public function testGetValidFinishedProductByProductId()
 {
     // create a new product and insert to into mySQL
     $finishedProduct1 = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title);
     $finishedProduct1->insert($this->getPDO());
     $description = "Today is Thursday";
     $leadTime = 38;
     $sku = "302840779045";
     $title = "This is a title.";
     $rawMaterial = new Product(null, $this->vendor->getVendorId(), $description, $leadTime, $sku, $title);
     $rawMaterial->insert($this->getPDO());
     $finishedProductId = $finishedProduct1->getProductId();
     $rawMaterialId = $rawMaterial->getProductId();
     $rawQuantity = 56;
     $finishedProduct = new FinishedProduct($finishedProductId, $rawMaterialId, $rawQuantity);
     $finishedProduct->insert($this->getPDO());
     // grab the data from guzzle
     $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/product/?productId=' . $finishedProduct1->getProductId() . "&getFinishedProducts=true");
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $product = json_decode($body);
     $this->assertSame(200, $product->status);
 }
 /**
  * test grabbing a FinishedProduct by rawMaterialId that does not exist
  **/
 public function testGetInvalidFinishedProductByRawMaterialId()
 {
     // grab an rawMaterialId that does not exist
     $finishedProduct = FinishedProduct::getFinishedProductByRawMaterialId($this->getPDO(), $this->rawMaterial->getProductId());
     foreach ($finishedProduct as $fP) {
         $this->assertNull($fP);
     }
 }
示例#3
0
     // convert PUTed JSON to an object
     verifyXsrf();
     $requestContent = file_get_contents("php://input");
     $requestObject = json_decode($requestContent);
     $product = new Product($productId, $requestObject->vendorId, $requestObject->description, $requestObject->leadTime, $requestObject->sku, $requestObject->title);
     $product->update($pdo);
     $reply->data = "Product updated OK";
     // delete an existing Product
 } else {
     if ($method === "DELETE") {
         verifyXsrf();
         $productAlerts = ProductAlert::getProductAlertByProductId($pdo, $productId);
         foreach ($productAlerts as $productAlert) {
             $productAlert->delete($pdo);
         }
         $finishedProducts = FinishedProduct::getFinishedProductByRawMaterialId($pdo, $productId);
         foreach ($finishedProducts as $finishedProduct) {
             $finishedProduct->delete($pdo);
         }
         $productLocations = ProductLocation::getProductLocationByProductId($pdo, $productId);
         foreach ($productLocations as $productLocation) {
             $productLocation->delete($pdo);
         }
         $movements = Movement::getMovementByProductId($pdo, $productId);
         foreach ($movements as $movement) {
             $movement->delete($pdo);
         }
         $product = Product::getProductByProductId($pdo, $productId);
         $product->delete($pdo);
         $reply->data = "Product deleted OK";
     }
示例#4
0
 /**
  * test grabbing finished product by product
  **/
 public function testGetValidFinishedProductByProductId()
 {
     // create a new product and insert to into mySQL
     $finishedProduct1 = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title);
     $finishedProduct1->insert($this->getPDO());
     $description = "Today is Thursday";
     $leadTime = 38;
     $sku = "302840779045";
     $title = "This is a title.";
     $rawMaterial = new Product(null, $this->vendor->getVendorId(), $description, $leadTime, $sku, $title);
     $rawMaterial->insert($this->getPDO());
     $finishedProductId = $finishedProduct1->getProductId();
     $rawMaterialId = $rawMaterial->getProductId();
     $rawQuantity = 56;
     $finishedProduct = new FinishedProduct($finishedProductId, $rawMaterialId, $rawQuantity);
     $finishedProduct->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoFinishedProductArray = Product::getFinishedProductByProductId($this->getPDO(), $finishedProduct1->getProductId());
     for ($i = 0; $i < count($pdoFinishedProductArray); $i++) {
         if ($i === 0) {
             $this->assertSame($pdoFinishedProductArray[$i]->getVendorId(), $this->vendor->getVendorId());
             $this->assertSame($pdoFinishedProductArray[$i]->getDescription(), $this->VALID_description);
             $this->assertSame($pdoFinishedProductArray[$i]->getLeadTime(), $this->VALID_leadTime);
             $this->assertSame($pdoFinishedProductArray[$i]->getSku(), $this->VALID_sku);
             $this->assertSame($pdoFinishedProductArray[$i]->getTitle(), $this->VALID_title);
         } else {
             $this->assertSame($pdoFinishedProductArray[$i]->getFinishedProductId(), $finishedProduct->getFinishedProductId());
             $this->assertSame($pdoFinishedProductArray[$i]->getRawMaterialId(), $finishedProduct->getRawMaterialId());
             $this->assertSame($pdoFinishedProductArray[$i]->getRawQuantity(), $finishedProduct->getRawQuantity());
         }
     }
 }