Пример #1
0
 /**
  * Test grabbing Valid Notifications by productId
  **/
 public function testGetValidNotificationByProductId()
 {
     // 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 ProductAlert and insert to into mySQL
     $productAlert = new ProductAlert($this->alertLevel->getAlertId(), $newProduct->getProductId(), true);
     $productAlert->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() . "&getNotifications=true");
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $product = json_decode($body);
     $this->assertSame(200, $product->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);
 }
Пример #3
0
     $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();
             $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);
             }
Пример #4
0
 public function setUp()
 {
     parent::setUp();
     $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());
     $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());
     $productEnabled = true;
     $this->productAlert = new ProductAlert($this->alertLevel->getAlertId(), $this->product->getProductId(), $productEnabled);
     $this->productAlert->insert($this->getPDO());
     $this->VALID_notificationDateTime = DateTime::createFromFormat("Y-m-d H:i:s", "1985-06-28 04:26:03");
 }
Пример #5
0
     if (is_bool($emailStatus) === true) {
         $reply->data = Notification::getNotificationByEmailStatus($pdo, $emailStatus);
     } else {
         if (empty($notificationDateTime) === false) {
             $notificationDateTimeInt = new DateTime();
             $notificationDateTimeInt->setTimestamp($notificationDateTime / 1000);
             $reply->data = Notification::getNotificationByNotificationDateTime($pdo, $notificationDateTimeInt);
         } else {
             if (empty($alertId) === false) {
                 $reply->data = Notification::getProductByAlertId($pdo, $alertId);
             } else {
                 if ($page >= 0) {
                     $notifications = Notification::getAllNotifications($pdo, $page)->toArray();
                     foreach ($notifications as $index => $notification) {
                         $product = null;
                         $productAlert = ProductAlert::getProductAlertByAlertId($pdo, $notification->getAlertId());
                         if ($productAlert !== null) {
                             $product = Product::getProductByProductId($pdo, $productAlert->getProductId());
                         }
                         $notifications[$index] = json_decode(json_encode($notification));
                         $notifications[$index]->product = $product;
                     }
                     $reply->data = $notifications;
                 } else {
                     throw new InvalidArgumentException("no parameters given", 405);
                 }
             }
         }
     }
 }
 // post to a new Notification
Пример #6
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());
         }
     }
 }
 /**
  * test grabbing a ProductAlert by alertEnabled that does not exist
  *
  * PDOException
  **/
 public function testGetInvalidProductAlertByAlertEnabled()
 {
     // grab an alertEnabled that does not exist
     $pdoProductAlert = ProductAlert::getProductAlertByAlertEnabled($this->getPDO(), $this->INVALID_alertEnabled);
     $this->assertNull($pdoProductAlert);
 }