示例#1
0
 public function testTree()
 {
     $c1 = new Comment();
     $c1->setContent('This is comment1');
     $this->em->persist($c1);
     $c2 = new Comment();
     $c2->setContent('This is comment2');
     $c2->setParent($c1);
     $this->em->persist($c2);
     $this->assertEquals($c1, $c2->getParent(), 'Parent comment match');
     $post = new Post();
     $post->setTitle('Commented post');
     $post->setContent('Content of the post');
     $this->em->persist($post);
     $c1->setPost($post);
     $this->em->persist($c1);
     $c3 = new Comment();
     $c3->setContent('This is comment3');
     $c3->setParent($c1);
     $this->em->persist($c3);
     $this->assertNull($c3->getPost(), 'Relation to Post does not propagate on children');
     $repository = $this->em->getRepository('Wurstpress\\CoreBundle\\Entity\\Comment');
     $this->em->flush();
     $this->assertEquals(2, $repository->childCount($c1, true), 'The number of direct replies to current comment should be 2');
     $this->assertEquals(2, $repository->childCount($c1), 'The number of all replies to current comment should be 2');
     $c4 = new Comment();
     $c4->setContent('This is comment4');
     $c4->setParent($c3);
     $this->em->persist($c4);
     $this->em->flush();
     $this->assertEquals(2, $repository->childCount($c1, true), 'The number of direct replies to current comment should be 2');
     $this->assertEquals(3, $repository->childCount($c1), 'The number of all replies to current comment should be 3');
 }
示例#2
0
 protected function getPost()
 {
     $post = new Post();
     $post->setTitle('7th post');
     $post->setContent('This is content');
     $this->em->persist($post);
     $this->em->flush();
     return $post;
 }
示例#3
0
 public function testTaggable()
 {
     $post = new Post();
     $post->setTitle('7th post');
     $post->setContent('This is content');
     $this->em->persist($post);
     $this->em->flush();
     $this->assertEquals('wurstpress_post', $post->getTaggableType(), 'taggable type is not correct');
     $this->assertEquals($post->getId(), $post->getTaggableId(), 'taggable id is not correct');
     $this->assertEquals(new ArrayCollection(), $post->getTags(), 'should be empty, but it isn\'t');
     $tagManager = $this->container->get('fpn_tag.tag_manager');
     $fooTag = $tagManager->loadOrCreateTag('foo');
     $tagManager->addTag($fooTag, $post);
     $tagManager->saveTagging($post);
     $tagManager->loadTagging($post);
     $this->assertEquals(1, count($post->getTags()), 'should be empty, but it isn\'t');
 }