public function delete($id) { try { $tweet = new Tweet($id); if (UserHelper::getProfileId() != $tweet->getProfileId() and !UserHelper::isEditor()) { throw new fValidationException('not allowed'); } $tweet->delete(); $this->ajaxReturn(array('result' => 'success')); } catch (fException $e) { $this->ajaxReturn(array('result' => 'failure', 'message' => $e->getMessage())); } }
/** * test creating a Tweet and then deleting it **/ public function testDeleteValidTweet() { // 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()); // delete the Tweet from mySQL $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("tweet")); $tweet->delete($this->getPDO()); // grab the data from mySQL and enforce the Tweet does not exist $pdoTweet = Tweet::getTweetByTweetId($this->getPDO(), $tweet->getTweetId()); $this->assertNull($pdoTweet); $this->assertEquals($numRows, $this->getConnection()->getRowCount("tweet")); }
<?php require_once "/etc/apache2/capstone-mysql/encrypted-config.php"; $pdo = connectToEncryptedMySQL("/etc/apache2/data-design/dmartinez337.ini"); $tweet = new Tweet(null, 1, "this is from PHP"); $tweet->insert($pdo); $tweet->setTweetContent("now I changed the message"); $tweet->update($pdo); $tweet->delete($pdo);