public function testWithPages() { $client = static::createClient(); $category = new Category(); $category->setSlug('default')->setName('Default Category')->setDescription('Hello world!')->setEnabled(true); /** @var EntityManager $em */ $em = $client->getKernel()->getContainer()->get('doctrine')->getManager(); $em->persist($category); $em->flush(); $page1 = new Page(); $page1->setEnabled(true)->setSlug('home')->setTitle('My homepage')->setHost('localhost')->setContent('Hello world!')->setCategory($category); $page2 = new Page(); $page2->setEnabled(true)->setSlug('about')->setTitle('About page')->setHost('localhost')->setContent('We.are.the.robots.')->setCategory($category); $em->persist($page1); $em->persist($page2); $em->flush(); $crawler = $client->request('GET', '/category/' . $category->getTree()); $section1 = $crawler->filter('section')->eq(0); $this->assertEquals($page1->getTitle(), trim($section1->filter('article > h2 > a')->html())); $this->assertContains($page1->getContent(), trim($section1->filter('article')->html())); $section2 = $crawler->filter('section')->eq(1); $this->assertEquals($page2->getTitle(), trim($section2->filter('article > h2 > a')->html())); $this->assertContains($page2->getContent(), trim($section2->filter('article')->html())); }
public function testRemoval() { $category = new Category(); $category->setName('Default category')->setSlug('default')->setEnabled(true); $child = new Category(); $child->setName('Child category')->setSlug('child')->setEnabled(true)->setParent($category); $category->addChild($child); $kernel = static::getKernel(); /** @var EntityManager $em */ $em = $kernel->getContainer()->get('doctrine')->getManager(); $em->persist($category); $em->persist($child); $em->flush(); $category = $em->getRepository(get_class($category))->find($category->getId()); $children = $category->getChildren(); $first = $children[0]; $this->assertEquals($child->getId(), $first->getId()); $category->removeChild($child); $child->setParent(null); $em->remove($category); $em->flush(); $child = $em->getRepository(get_class($child))->find($child->getId()); $this->assertNull($child->getParent()); }