function testMultilevelThreadedCommentsCorrectParents() { $post_id = $this->factory->post->create(array('post_title' => 'Gobbles')); $comment_id = $this->factory->comment->create(array('comment_post_ID' => $post_id)); $comment2_id = $this->factory->comment->create(array('comment_post_ID' => $post_id)); $comment2_child_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_parent' => $comment2_id)); $comment2_grandchild_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_parent' => $comment2_child_id)); $post = new TimberPost($post_id); $comments = $post->get_comments(); $children = $comments[1]->children(); $this->assertEquals($comment2_id, $children[0]->comment_parent); $grandchild = $children[1]; $this->assertEquals($comment2_child_id, $grandchild->comment_parent); }
function testCommentWithChildren() { $kramer = $this->factory->user->create(array('display_name' => 'Cosmo Kramer')); $post_id = $this->factory->post->create(); $comment_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'These pretzels are making me thirsty.', 'user_id' => $kramer)); sleep(2); $comment_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'Perhaps there’s more to Newman than meets the eye.')); $child_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'No, there’s less.', 'comment_parent' => $comment_id)); $post = new TimberPost($post_id); $comments = $post->get_comments(); $this->assertEquals(2, count($comments)); $this->assertEquals(1, count($comments[1]->children)); $twig_string = '{{comment.author.name}}'; $result = Timber::compile_string($twig_string, array('comment' => $comments[0])); $this->assertEquals('Cosmo Kramer', $result); }