/** * 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()); }
/** * 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); }
<?php require_once __DIR__ . "/php/classes/autoload.php"; require_once __DIR__ . "/lib/xsrf.php"; require_once "/etc/apache2/capstone-mysql/encrypted-config.php"; use Edu\Cnm\Jpegery\Profile; use Edu\Cnm\Jpegery\Image; if (session_status() !== PHP_SESSION_ACTIVE) { session_start(); } $reply = new stdClass(); $reply->status = 200; try { $pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/jpegery.ini"); $caption = filter_input(INPUT_POST, "caption", FILTER_SANITIZE_STRING); $image = new Image(null, $_SESSION["profile"]->getProfileId(), "temporaryType", "temporaryName", $caption, null); $image->insert($pdo); $image->imageUpload(); //Connect to encrypted mySQL $image->update($pdo); $reply->message = "This worked. Or didn't and you somehow screwed it up so much you got a false positive. Either way, good job."; $reply->data = $image; } catch (Exception $exception) { $reply->status = $exception->getCode(); $reply->data = $exception->getMessage(); } //Echo the json, encode the $reply. header("Content-type: application/html"); echo json_encode($reply);
/** * @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()); }
$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); $deletedObject = new stdClass(); $deletedObject->imageId = $id; $reply->message = "Image Successfully Deleted"; } } } } catch (Exception $exception) { $reply->status = $exception->getCode(); $reply->message = $exception->getMessage(); } header("Content-type: application/json");