/**
  * test grabbing a Product by alertId
  **/
 public function testGetValidProductByAlertId()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("alertLevel");
     // create a new alertLevel and insert to into mySQL
     $alertLevel = new AlertLevel(null, $this->VALID_alertCode, $this->VALID_alertFrequency, $this->VALID_alertPoint, $this->VALID_alertOperator);
     $alertLevel->insert($this->getPDO());
     // create a new productAlert and insert to into mySQL
     $productAlert = new productAlert($alertLevel->getAlertId(), $this->product->getProductId(), true);
     $productAlert->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoProductArray = AlertLevel::getProductByAlertId($this->getPDO(), $alertLevel->getAlertId());
     for ($i = 0; $i < count($pdoProductArray); $i++) {
         if ($i === 0) {
             $this->assertSame($pdoProductArray[$i]->getAlertCode(), $this->VALID_alertCode);
             $this->assertSame($pdoProductArray[$i]->getAlertFrequency(), $this->VALID_alertFrequency);
             $this->assertSame($pdoProductArray[$i]->getAlertPoint(), $this->VALID_alertPoint);
             $this->assertSame($pdoProductArray[$i]->getAlertOperator(), $this->VALID_alertOperator);
         } 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 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());
         }
     }
 }
Example #3
0
 /**
  * The setter of the field product_id.
  * @param Product $product - the product related to the issue
  */
 public function setProduct(Product $product)
 {
     if ($product == NULL) {
         throw new InvalidArgumentException('[Model\\Issue] Invalid Model\\Product.');
     }
     $this->product_id = $product->getProductId();
 }
 /**
  * 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);
     }
 }
 /**
  * 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 Product by alertId
  **/
 public function testGetValidProductByAlertId()
 {
     // create a new AlertLevel
     $newAlertLevel = new AlertLevel(null, $this->VALID_alertCode, $this->VALID_alertFrequency, $this->VALID_alertPoint, $this->VALID_alertOperator);
     $newAlertLevel->insert($this->getPDO());
     // create a new ProductAlert
     $newProductAlert = new ProductAlert($newAlertLevel->getAlertId(), $this->product->getProductId(), true);
     $newProductAlert->insert($this->getPDO());
     // grab the data from guzzle
     $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/alert-level/?alertId=' . $newAlertLevel->getAlertId() . "&getProducts=true");
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $alertLevel = json_decode($body);
     $this->assertSame(200, $alertLevel->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 a ProductAlert by alertEnabled
  **/
 public function testGetValidProductAlertByAlertEnabled()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("productAlert");
     // create a new ProductAlert and insert to into mySQL
     $productAlert = new ProductAlert($this->alertLevel->getAlertId(), $this->product->getProductId(), $this->VALID_alertEnabled);
     $productAlert->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoProductAlert = ProductAlert::getProductAlertByAlertEnabled($this->getPDO(), $productAlert->isAlertEnabled());
     foreach ($pdoProductAlert as $pdoPA) {
         $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("productAlert"));
         $this->assertSame($pdoPA->getAlertId(), $this->alertLevel->getAlertId());
         $this->assertSame($pdoPA->getProductId(), $this->product->getProductId());
         $this->assertSame($pdoPA->isAlertEnabled(), $this->VALID_alertEnabled);
     }
 }
 /**
  * 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);
 }
Example #10
0
 /**
  * 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);
     }
 }
 /**
  * test deleting a valid Product
  **/
 public function testDeleteValidProduct()
 {
     // 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());
     // grab the data from guzzle and enforce the status' match our expectations
     $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/product/' . $newProduct->getProductId());
     $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/product/' . $newProduct->getProductId(), ['headers' => ['X-XSRF-TOKEN' => $this->getXsrfToken()]]);
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $product = json_decode($body);
     $this->assertSame(200, $product->status);
 }
Example #12
0
                     }
                 }
             }
         }
     }
     // post to a new Product
 } else {
     if ($method === "POST") {
         // convert POSTed JSON to an object
         verifyXsrf();
         $requestContent = file_get_contents("php://input");
         $requestObject = json_decode($requestContent);
         $product = new Product(null, $requestObject->vendorId, $requestObject->description, $requestObject->leadTime, $requestObject->sku, $requestObject->title);
         $product->insert($pdo);
         unset($reply->data);
         $reply->productId = $product->getProductId();
         $reply->message = "Product created OK";
         // put to an existing Product
     } else {
         if ($method === "PUT") {
             // 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();
 /**
  * test grabbing an product by alert Id
  **/
 public function testGetValidNotificationsByAlertId()
 {
     // create a new notification and insert to into mySQL
     $notification = new Notification(null, $this->alertLevel->getAlertId(), $this->VALID_emailStatus, $this->VALID_notificationDateTime, $this->VALID_notificationHandle, $this->VALID_notificationContent);
     $notification->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoProductArray = Notification::getProductByAlertId($this->getPDO(), $notification->getAlertId());
     for ($i = 0; $i < count($pdoProductArray); $i++) {
         if ($i === 0) {
             $this->assertSame($pdoProductArray[$i]->getAlertId(), $this->alertLevel->getAlertId());
             $this->assertSame($pdoProductArray[$i]->getEmailStatus(), $this->VALID_emailStatus);
             $this->assertEquals($pdoProductArray[$i]->getNotificationDateTime(), $this->VALID_notificationDateTime);
             $this->assertSame($pdoProductArray[$i]->getNotificationHandle(), $this->VALID_notificationHandle);
             $this->assertSame($pdoProductArray[$i]->getNotificationContent(), $this->VALID_notificationContent);
         } 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());
         }
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->guzzle = new \GuzzleHttp\Client(['cookies' => true]);
     $this->VALID_notificationDateTime = DateTime::createFromFormat("Y-m-d H:i:s", "2015-09-26 08:45:25");
     $this->INVALID_notificationDateTime = DateTime::createFromFormat("Y-m-d H:i:s", "2015-14-26 06:25:25");
     $alertId = null;
     $alertCode = "33";
     $alertFrequency = "11";
     $alertLevel = "100.01";
     $alertOperator = "1";
     $this->alertLevel = new AlertLevel($alertId, $alertCode, $alertFrequency, $alertLevel, $alertOperator);
     $this->alertLevel->insert($this->getPDO());
     $vendorId = null;
     $contactName = "Trevor Rigler";
     $vendorEmail = "*****@*****.**";
     $vendorName = "TruFork";
     $vendorPhoneNumber = "5053594687";
     $vendor = new Vendor($vendorId, $contactName, $vendorEmail, $vendorName, $vendorPhoneNumber);
     $vendor->insert($this->getPDO());
     $productId = null;
     $vendorId = $vendor->getVendorId();
     $description = "A glorius bead to use";
     $leadTime = 10;
     $sku = "TGT354";
     $title = "Bead-Green-Blue-Circular";
     $this->product = new Product($productId, $vendorId, $description, $leadTime, $sku, $title);
     $this->product->insert($this->getPDO());
     $alertId1 = $this->alertLevel->getAlertId();
     $productId1 = $this->product->getProductId();
     $alertEnabled = true;
     $this->productAlert = new ProductAlert($alertId1, $productId1, $alertEnabled);
     $this->productAlert->insert($this->getPDO());
 }
Example #15
0
 /**
  * test grabbing product by notification
  **/
 public function testGetValidNotificationByProductId()
 {
     // 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());
     // create a new product and insert to into mySQL
     $productAlert = new ProductAlert($this->alertLevel->getAlertId(), $product->getProductId(), true);
     $productAlert->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoNotificationArray = Product::getNotificationByProductId($this->getPDO(), $product->getProductId());
     for ($i = 0; $i < count($pdoNotificationArray); $i++) {
         if ($i === 0) {
             $this->assertSame($pdoNotificationArray[$i]->getVendorId(), $this->vendor->getVendorId());
             $this->assertSame($pdoNotificationArray[$i]->getDescription(), $this->VALID_description);
             $this->assertSame($pdoNotificationArray[$i]->getLeadTime(), $this->VALID_leadTime);
             $this->assertSame($pdoNotificationArray[$i]->getSku(), $this->VALID_sku);
             $this->assertSame($pdoNotificationArray[$i]->getTitle(), $this->VALID_title);
         } else {
             $this->assertSame($pdoNotificationArray[$i]->getNotificationId(), $this->notification->getNotificationId());
             $this->assertSame($pdoNotificationArray[$i]->getAlertId(), $this->notification->getAlertId());
             $this->assertSame($pdoNotificationArray[$i]->getEmailStatus(), $this->notification->getEmailStatus());
             $this->assertEquals($pdoNotificationArray[$i]->getNotificationDateTime(), $this->notification->getNotificationDateTime());
             $this->assertSame($pdoNotificationArray[$i]->getNotificationHandle(), $this->notification->getNotificationHandle());
             $this->assertSame($pdoNotificationArray[$i]->getNotificationContent(), $this->notification->getNotificationContent());
         }
     }
 }
Example #16
0
 /**
  * @testdox ShoppingCart::getItemAmount($productId) will return the product price multiplied by its quantity.
  */
 public function testGetItemAmountWillReturnTheProductPriceMultipliedByItsQuantity()
 {
     $productPrice = 100;
     $quantity = 5;
     $product = new Product(123, 'item 0', $productPrice, 1, 2, 15, 30);
     $productId = $product->getProductId();
     $cart = new ShoppingCart();
     $cart->addItem($product, $quantity);
     $this->assertEquals($productPrice * $quantity, $cart->getItemAmount($productId));
 }
Example #17
0
    $price = $row[3];
    $product = new Product($productId, $name, $price);
    echo '<div class="col-md-3 col-sm-6">
        <a class = "link" href ="">
            <div class="single-shop-product">
                <div class="product-upper">
                    <img src="" alt="">
                </div>
                <h2><a href="?controller=pages&action=singleproduct">' . $product->getName() . '</a></h2>
                <div class="product-carousel-price">
                    <ins>$' . $product->getPrice() . '</ins>
                </div>  

                <div class="product-option-shop">
                <form role="form" class="form" method="post" action="?controller=control&action=addtocart">
                    <input type="text" hidden="true" value="' . $product->getProductId() . '" name="productid">
                    <div style="display: inline;">
                    <label>Quantity</label>
                    <input type="number" name="quantity" class="form-control">
                    </div>
                    <div style="display: inline;">
                    <input type="submit" value="Add to cart" class="btn">
                </form>
                    
                    <a class="add_to_cart_button btn" href="?controller=pages&action=singleproduct">View Product</a><br><br>
                    </div>
                    <p></p>
                </div>                       
            </div>
        </a>
    </div>';