/** * test grabbing valid product by alertId **/ public function testGetValidProductByAlertId() { // create a new notification and insert to into mySQL $newNotification = new Notification(null, $this->alertLevel->getAlertId(), $this->VALID_emailStatus, $this->VALID_notificationDateTime, $this->VALID_notificationHandle, $this->VALID_notificationContent); $newNotification->insert($this->getPDO()); // grab the data from guzzle $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/notification/?alertId=' . $newNotification->getAlertId()); $this->assertSame($response->getStatusCode(), 200); $body = $response->getBody(); $notification = json_decode($body); $this->assertSame(200, $notification->status); }
/** * 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()); } } }
/** * 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()); } } }