示例#1
0
 /**
  * Test grabbing image tags by tagId
  */
 public function testGetImageTagByTagId()
 {
     //Count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("imageTag");
     //Create new image and insert into database
     $imageTag = new ImageTag($this->imageTagImage->getImageId(), $this->imageTagTag->getTagId());
     $imageTag->insert($this->getPDO());
     //Get data from database and ensure the fields match our expectations
     $pdoImageTag = ImageTag::getImageTagByTagId($this->getPDO(), $this->imageTagTag->getTagId());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("imageTag"));
     $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Jpegery\\ImageTag", $pdoImageTag);
     //Grabs results from array and validate it
     $imageTagResults = $pdoImageTag[0];
     $this->assertEquals($imageTagResults->getTagId(), $this->imageTagTag->getTagId());
     $this->assertEquals($imageTagResults->getImageId(), $this->imageTagImage->getImageId());
 }
示例#2
0
 /**
  * test grabbing all Votes
  **/
 public function testGetAllValidVotes()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("vote");
     // create a new Vote and insert to into mySQL
     $vote = new Vote($this->voteProfile->getProfileId(), $this->voteImage->getImageId(), $this->VALID_VOTEVALUE);
     $vote->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $results = Vote::getAllvotes($this->getPDO());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("vote"));
     $this->assertCount(1, $results);
     $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Jpegery\\Vote", $results);
     // grab the result from the array and validate it
     $pdoVote = $results[0];
     $this->assertEquals($pdoVote->getVoteProfileId(), $this->voteProfile->getProfileId());
     $this->assertEquals($pdoVote->getVoteImageId(), $this->voteImage->getImageId());
     $this->assertEquals($pdoVote->getVoteValue(), $this->VALID_VOTEVALUE);
 }
示例#3
0
 /**
  * @expectedException \RangeException
  */
 public function testInsertInvalidCommentByTooMuchText()
 {
     //Create a new Comment and insert it into mySQL
     $comment = new Comment(null, $this->image->getImageId(), $this->profile->getProfileId(), $this->VALID_COMMENTDATE, $this->INVALID_TEXTLENGTH);
     $comment->insert($this->getPDO());
 }
示例#4
0
 //Perform actual POST, PUT, or DELETE
 if ($method === "PUT") {
     $image = Image::getImageByImageId($pdo, $id);
     if ($image === null) {
         throw new RuntimeException("Image does not exist", 404);
     }
     //Ensure the user is only editing their own content
     $security = $image->getImageProfileId();
     if ($security !== $_SESSION["profile"]->getProfileId()) {
         throw new RuntimeException("You cannot edit an image that is not yours.", 403);
     }
     $reply->message = "Image Successfully Updated";
 } elseif ($method === "POST") {
     $image = new Image(null, $_SESSION["profile"]->getProfileId(), $requestObject->imageType, $requestObject->imageFileName, $requestObject->imageText, null);
     $image->insert($pdo);
     $reply->imageId = $image->getImageId();
     $reply->message = "Image Successfully Posted";
 } elseif ($method === "DELETE") {
     $image = Image::getImageByImageId($pdo, $id);
     if ($image === null) {
         throw new RuntimeException("Image does not exist", 404);
     }
     $security = $image->getImageProfileId();
     if ($security !== $_SESSION["profile"]->getProfileId()) {
         throw new RuntimeException("You cannot delete an image that is not yours.", 403);
     }
     $image = Image::getImageByImageId($pdo, $id);
     if ($image === null) {
         throw new RuntimeException("Image does not exist", 404);
     }
     $image->delete($pdo);