/** * 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); }
/** * 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); }
/** * 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 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); } }