Пример #1
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 posting a Notification
  **/
 public function testPostValidNotification()
 {
     //create a new Notification
     $newNotification = new Notification(null, $this->alertLevel->getAlertId(), $this->VALID_emailStatus, $this->VALID_notificationDateTime, $this->VALID_notificationHandle, $this->VALID_notificationContent);
     //run a get request to establish session tokens
     $this->guzzle->get('http://bootcamp-coders.cnm.edu/~invtext/backend/php/api/notification/?page=0');
     // grab the data from guzzle and enforce the status matches our expectations
     $response = $this->guzzle->post('http://bootcamp-coders.cnm.edu/~invtext/backend/php/api/notification/', ['headers' => ['X-XSRF-TOKEN' => $this->getXsrfToken()], 'json' => $newNotification]);
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $notification = json_decode($body);
     $this->assertSame(200, $notification->status);
 }
Пример #3
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 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 ability to Put valid AlertLevel
  **/
 public function testPutValidAlertLevel()
 {
     // create a new AlertLevel
     $newAlertLevel = new AlertLevel(null, $this->VALID_alertCode, $this->VALID_alertFrequency, $this->VALID_alertPoint, $this->VALID_alertOperator);
     $newAlertLevel->insert($this->getPDO());
     // run a get request to establish session tokens
     $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/alert-level/');
     // grab the data from guzzle and enforce the status' match our expectations
     $response = $this->guzzle->put('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/alert-level/' . $newAlertLevel->getAlertId(), ['headers' => ['X-XSRF-TOKEN' => $this->getXsrfToken()], 'json' => $newAlertLevel]);
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $alertLevel = json_decode($body);
     $this->assertSame(200, $alertLevel->status);
 }
Пример #6
0
            $alertLevel->insert($pdo);
            $reply->data = "AlertLevel created OK";
            // delete an existing AlertLevel
        } else {
            if ($method === "DELETE") {
                verifyXsrf();
                $alertLevel = AlertLevel::getAlertLevelByAlertId($pdo, $alertId);
                $alertLevel->delete($pdo);
                $reply->data = "AlertLevel deleted OK";
                // put to an existing AlertLevel
            } else {
                if ($method === "PUT") {
                    // convert PUTed JSON to an object
                    verifyXsrf();
                    $requestContent = file_get_contents("php://input");
                    $requestObject = json_decode($requestContent);
                    $alertLevel = new AlertLevel($alertId, $requestObject->alertCode, $requestObject->alertFrequency, $requestObject->alertPoint, $requestObject->alertOperator);
                    $alertLevel->update($pdo);
                    $reply->data = "AlertLevel Updated Ok";
                }
            }
        }
    }
    // create an exception to pass back to the RESTful caller
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
    unset($reply->data);
}
header("Content-type: application/json");
echo json_encode($reply);
Пример #7
0
 /**
  * test grabbing all AlertLevels
  **/
 public function testGetValidAllAlertLevels()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("alertLevel");
     // create a new alert level 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());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoAlertLevel = AlertLevel::getAllAlertLevels($this->getPDO());
     foreach ($pdoAlertLevel as $al) {
         $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("alertLevel"));
         $this->assertSame($al->getAlertCode(), $this->VALID_alertCode);
         $this->assertSame($al->getAlertFrequency(), $this->VALID_alertFrequency);
         $this->assertSame($al->getAlertPoint(), $this->VALID_alertPoint);
         $this->assertSame($al->getAlertOperator(), $this->VALID_alertOperator);
     }
 }
Пример #8
0
 /**
  * test grabbing all Notifications
  **/
 public function testGetValidAllNotifications()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("notification");
     // 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
     $pdoNotification = Notification::getAllNotifications($this->getPDO(), $this->VALID_notificationId);
     foreach ($pdoNotification as $note) {
         $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("notification"));
         $this->assertSame($note->getAlertId(), $this->alertLevel->getAlertId());
         $this->assertSame($note->getEmailStatus(), $this->VALID_emailStatus);
         $this->assertEquals($note->getNotificationDateTime(), $this->VALID_notificationDateTime);
         $this->assertSame($note->getNotificationHandle(), $this->VALID_notificationHandle2);
         $this->assertSame($note->getNotificationContent(), $this->VALID_notificationContent);
     }
 }
\t\t\t\t\t</tr>
\t\t\t\t</thead>
\t\t\t\t<tbody>
EOF;
    $allProducts = Product::getAllProducts($pdo, 0);
    foreach ($allProducts as $product) {
        $numberOfProducts = 0;
        // Make an array of product location from the above product
        $productLocations = ProductLocation::getProductLocationByProductId($pdo, $product->getProductId());
        foreach ($productLocations as $productLocation) {
            $numberOfProducts = $numberOfProducts + $productLocation->getQuantity();
        }
        // check if levels trigger notification according to alert operator
        $productAlerts = ProductAlert::getProductAlertByProductId($pdo, $product->getProductId());
        foreach ($productAlerts as $productAlert) {
            $alertLevel = AlertLevel::getAlertLevelByAlertId($pdo, $productAlert->getAlertId());
            if ($alertLevel->getAlertOperator() === "<" && $numberOfProducts < $alertLevel->getAlertPoint() || $alertLevel->getAlertOperator() === ">" && $numberOfProducts > $alertLevel->getAlertPoint()) {
                // give warning
                $productTitle = $product->getTitle();
                $vendor = Vendor::getVendorByVendorId($pdo, $product->getVendorId());
                $vendorName = $vendor->getVendorName();
                $message = $message . <<<EOF
\t\t\t\t<tr>
\t\t\t\t\t<td>{$productTitle}</td>
\t\t\t\t\t<td>{$numberOfProducts}</td>
\t\t\t\t\t<td>{$vendorName}</td>
\t\t\t\t</tr>
EOF;
            }
        }
    }