Example #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());
 }
Example #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);
 }
Example #3
0
    }
    //handle REST calls for PUT methods
    //If the user is logged in, allow to POST their own tag.
    if (empty($_SESSION["profile"]) !== false) {
        if ($method === "POST") {
            verifyXsrf();
            $requestContent = file_get_contents("php://input");
            $requestObject = json_decode($requestContent);
        }
        //ensure all fields are present
        if (empty($requestObject->tagId) === true) {
            throw new InvalidArgumentException("Tag must have an ID", 405);
        }
        if (empty($requestObject->tagName) === true) {
            throw new InvalidArgumentException("Tag must have a Name", 405);
        }
        if ($method === "POST") {
            $tag = new Tag(null, $requestObject->tagName);
            $tag->insert($pdo);
            $reply->imageId = $tag->getTagId();
        }
    }
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
}
header("Content-type: application/json");
if ($reply->data === null) {
    unset($reply->data);
}
echo json_encode($reply);