$userId = filter_input(INPUT_GET, "userId", FILTER_VALIDATE_INT); // sanitize the movementDate $movementDate = filter_input(INPUT_GET, "movementDate", FILTER_VALIDATE_INT); // sanitize the movementType $movementType = filter_input(INPUT_GET, "movementType", FILTER_SANITIZE_STRING); // sanitize the page $page = filter_input(INPUT_GET, "page", FILTER_VALIDATE_INT); // grab the mySQL connection $pdo = connectToEncryptedMySql("/etc/apache2/capstone-mysql/invtext.ini"); // handle all RESTful calls to Movement // get some or all Movements if ($method === "GET") { // set an XSRF cookie on GET requests setXsrfCookie("/"); if (empty($movementId) === false) { $reply->data = Movement::getMovementByMovementId($pdo, $movementId)->toArray(); } else { if (empty($fromLocationId) === false) { $reply->data = Movement::getMovementByFromLocationId($pdo, $fromLocationId)->toArray(); } else { if (empty($toLocationId) === false) { $reply->data = Movement::getMovementByToLocationId($pdo, $toLocationId)->toArray(); } else { if (empty($productId) === false) { $reply->data = Movement::getMovementByProductId($pdo, $productId)->toArray(); } else { if (empty($userId) === false) { $reply->data = Movement::getMovementByUserId($pdo, $userId)->toArray(); } else { if (empty($movementDate) === false) { $movementDateTime = new DateTime();
/** * test inserting and grabbing a Movement with a null movementDate **/ public function testInsertValidMovementWithNullMovementDate() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("movement"); // create a new Movement and insert to into mySQL $movement = new Movement(null, $this->fromLocation->getLocationId(), $this->toLocation->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $this->user->getUserId(), $this->VALID_cost, null, $this->VALID_movementType, $this->VALID_price); $movement->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoMovement = Movement::getMovementByMovementId($this->getPDO(), $movement->getMovementId()); $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("movement")); $this->assertSame($pdoMovement->getFromLocationId(), $this->fromLocation->getLocationId()); $this->assertSame($pdoMovement->getToLocationId(), $this->toLocation->getLocationId()); $this->assertSame($pdoMovement->getProductId(), $this->product->getProductId()); $this->assertSame($pdoMovement->getUnitId(), $this->unitOfMeasure->getUnitId()); $this->assertSame($pdoMovement->getUserId(), $this->user->getUserId()); $this->assertSame($pdoMovement->getCost(), $this->VALID_cost); $this->assertInstanceOf('DateTime', $pdoMovement->getMovementDate()); $this->assertSame($pdoMovement->getMovementType(), $this->VALID_movementType); $this->assertSame($pdoMovement->getPrice(), $this->VALID_price); }