Esempio n. 1
0
 /**
  * Create dependant objects before running each test
  **/
 public final function setUp()
 {
     //Run the default setUp() method first
     parent::setUp();
     //create and insert profile to tag image
     $password = "******";
     $salt = bin2hex(openssl_random_pseudo_bytes(32));
     $verify = $salt;
     $hash = hash_pbkdf2("sha512", $password, $salt, 262144);
     $this->profile = new Profile(null, true, null, "Email", "myName", $hash, 1, "mynameagain", "867", $salt, $verify);
     $this->profile->insert($this->getPDO());
     //create an image to be tagged
     $this->imageTagImage = new Image(null, $this->profile->getProfileId(), "jpeg", "myfile", "theText", null);
     $this->imageTagImage->insert($this->getPDO());
     $this->imageTagTag = new Tag(null, "Photo");
     $this->imageTagTag->insert($this->getPDO());
 }
Esempio n. 2
0
 /**
  * test grabbing all tags
  **/
 public function testGetAllValidTags()
 {
     //count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("tag");
     //create a new Tag and insert it into mySQL
     $tag = new Tag(null, $this->VALID_TAGNAME);
     $tag->insert($this->getPDO());
     //grab the data from mySQL and enforce the fields match our expectations
     $results = Tag::getAllTags($this->getPDO());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("tag"));
     $this->assertCount(1, $results);
     $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Jpegery\\Tag", $results);
     //grab the result from the array and validate it
     $pdoTag = $results[0];
     $this->assertEquals($pdoTag->getTagId(), $tag->getTagId());
     $this->assertEquals($pdoTag->getTagName(), $this->VALID_TAGNAME);
 }
Esempio n. 3
0
 if ($method === "POST") {
     verifyXsrf();
     $requestContent = file_get_contents("php://input");
     $requestObject = json_decode($requestContent);
 }
 //ensure all fields are present
 if (empty($requestObject->imageId) === true) {
     throw new InvalidArgumentException("Image must have an ID", 405);
 }
 if (empty($requestObject->tagId) === true) {
     throw new InvalidArgumentException("Tag must have an ID", 405);
 }
 //perform actual POST or DELETE
 if ($method === "POST") {
     $tag = new Tag($requestObject->imageId, $requestObject->tagName);
     $tag->insert($pdo);
 } elseif ($method === "DELETE") {
     $image = imageTag::getImageTagByImageIdAndTagId($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 edit 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();