/** * Test assignParent */ public function testAssignParent() { //Add two "parent" posts $builders = array(); $builders[] = FixtureBuilder::build('posts', array('post_id' => 550, 'author_user_id' => 19, 'author_username' => 'linkbaiter', 'author_fullname' => 'Link Baiter', 'post_text' => 'This is parent post 1', 'reply_count_cache' => 1, 'retweet_count_cache' => 0)); $builders[] = FixtureBuilder::build('posts', array('post_id' => 551, 'author_user_id' => 19, 'author_fullname' => 'Link Baiter', 'post_text' => 'This is parent post 2', 'reply_count_cache' => 0, 'retweet_count_cache' => 0)); //Add a post with the parent post 550 $builders[] = FixtureBuilder::build('posts', array('post_id' => 552, 'author_user_id' => 19, 'author_username' => 'linkbaiter', 'author_fullname' => 'Link Baiter', 'post_text' => 'This is a reply with the wrong parent', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'in_reply_to_post_id' => 550)); $pdao = new PostMySQLDAO(); $post = $pdao->getPost(552, 'twitter'); //Assert parent post is 550 $this->assertEqual($post->in_reply_to_post_id, 550); //Change parent post to 551 $pdao->assignParent(551, 552, 'twitter'); $child_post = $pdao->getPost(552, 'twitter'); //Assert parent post is now 551 $this->assertEqual($child_post->in_reply_to_post_id, 551); //Assert old parent post has one fewer reply total $old_parent = $pdao->getPost(550, 'twitter'); $this->assertEqual($old_parent->reply_count_cache, 0); //Assert new parent post has one more reply total $new_parent = $pdao->getPost(551, 'twitter'); $this->assertEqual($new_parent->reply_count_cache, 1); }
/** * Test assignParent */ function testAssignParent() { //Add two "parent" posts $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES (550, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is parent post 1', 'web', '2006-03-01 00:01:00', 1, 0);"; PDODAO::$PDO->exec($q); $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES (551, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is parent post 2', 'web', '2006-03-01 00:01:00', 0, 0);"; PDODAO::$PDO->exec($q); //Add a post with the parent post 550 $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache, in_reply_to_post_id) VALUES (552, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is a reply with the wrong parent', 'web', '2006-03-01 00:01:00', 0, 0, 550);"; PDODAO::$PDO->exec($q); $pdao = new PostMySQLDAO(); $post = $pdao->getPost(552); //Assert parent post is 550 $this->assertEqual($post->in_reply_to_post_id, 550); //Change parent post to 551 $pdao->assignParent(551, 552); $child_post = $pdao->getPost(552); //Assert parent post is now 551 $this->assertEqual($child_post->in_reply_to_post_id, 551); //Assert old parent post has one fewer reply total $old_parent = $pdao->getPost(550); $this->assertEqual($old_parent->mention_count_cache, 0); //Assert new parent post has one more reply total $new_parent = $pdao->getPost(551); $this->assertEqual($new_parent->mention_count_cache, 1); }