示例#1
0
 /**
  * test grabbing all Tweets
  **/
 public function testGetAllValidTweets()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("tweet");
     // create a new Tweet and insert to into mySQL
     $tweet = new Tweet(null, $this->profile->getProfileId(), $this->VALID_TWEETCONTENT, $this->VALID_TWEETDATE);
     $tweet->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $results = Tweet::getAllTweets($this->getPDO());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("tweet"));
     $this->assertCount(1, $results);
     $this->assertContainsOnlyInstancesOf("Tweet", $results);
     // grab the result from the array and validate it
     $pdoTweet = $results[0];
     $this->assertEquals($pdoTweet->getProfileId(), $this->profile->getProfileId());
     $this->assertEquals($pdoTweet->getTweetContent(), $this->VALID_TWEETCONTENT);
     $this->assertEquals($pdoTweet->getTweetDate(), $this->VALID_TWEETDATE);
 }
示例#2
0
 if (in_array($format, $validFormats) === false) {
     throw new InvalidArgumentException("invalid format", 405);
 }
 if ($method === "DELETE" && (empty($id) === true || $id < 0)) {
     throw new InvalidArgumentException("id cannot be empty or negative", 405);
 }
 // grab the mySQL connection
 $pdo = connectToEncryptedMySql("/etc/apache2/data-design/dmcdonald21.ini");
 // handle all RESTful calls to Tweet
 if ($class === "tweet") {
     // get some or all Tweets
     if ($method === "GET") {
         if (empty($id) === false) {
             $reply->data = Tweet::getTweetByTweetId($pdo, $id);
         } else {
             $reply->data = Tweet::getAllTweets($pdo)->toArray();
         }
         // post to an existing Tweet
     } else {
         if ($method === "POST") {
             // convert POSTed JSON to an object
             verifyXsrf();
             $requestContent = file_get_contents("php://input");
             $requestObject = json_decode($requestContent);
             if (empty($id) === true || $id < 0) {
                 $tweet = new Tweet(null, 1, "empty tweet");
             } else {
                 $tweet = Tweet::getTweetByTweetId($pdo, $id);
             }
             $tweet->setProfileId($requestObject->profileId);
             $tweet->setTweetContent($requestObject->tweetContent);