예제 #1
0
 $alertId = filter_input(INPUT_GET, "alertId", FILTER_VALIDATE_INT);
 // sanitize the alertCode
 $alertCode = filter_input(INPUT_GET, "alertCode", FILTER_SANITIZE_STRING);
 // sanitize getProducts
 $getProducts = filter_input(INPUT_GET, "getProducts", FILTER_VALIDATE_BOOLEAN);
 // grab the mySQL connection
 $pdo = connectToEncryptedMySql("/etc/apache2/capstone-mysql/invtext.ini");
 // handle all RESTful calls to AlertLevel
 // get some or all AlertLevels
 if ($method === "GET") {
     // set an XSRF cookie on GET requests
     setXsrfCookie("/");
     $reply->getProducts = $getProducts;
     if (empty($alertId) === false) {
         if ($getProducts === true) {
             $reply->data = AlertLevel::getProductByAlertId($pdo, $alertId);
         } else {
             $reply->data = AlertLevel::getAlertLevelByAlertId($pdo, $alertId);
         }
     } else {
         if (empty($alertCode) === false) {
             $reply->data = AlertLevel::getAlertLevelByAlertCode($pdo, $alertCode)->toArray();
         } else {
             $reply->data = AlertLevel::getAllAlertLevels($pdo)->toArray();
         }
     }
     // post a new AlertLevel
 } else {
     if ($method === "POST") {
         // convert POSTed JSON to an object
         verifyXsrf();
예제 #2
0
 /**
  * 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());
         }
     }
 }