Exemplo n.º 1
0
 public function testRemoval()
 {
     $page = new Page();
     $page->setTitle('Default page')->setSlug('default')->setEnabled(true);
     $child = new Page();
     $child->setTitle('Child page')->setSlug('child')->setEnabled(true)->setParent($page);
     $page->addChild($child);
     $kernel = static::getKernel();
     /** @var EntityManager $em */
     $em = $kernel->getContainer()->get('doctrine')->getManager();
     $em->persist($page);
     $em->persist($child);
     $em->flush();
     $page = $em->getRepository(get_class($page))->find($page->getId());
     $children = $page->getChildren();
     /** @var Page $first */
     $first = $children[0];
     $this->assertEquals($child->getId(), $first->getId());
     $page->removeChild($child);
     $child->setParent(null);
     $em->remove($page);
     $em->flush();
     $child = $em->getRepository(get_class($child))->find($child->getId());
     $this->assertNull($child->getParent());
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 protected static function createClient(array $options = array(), array $server = array())
 {
     $client = parent::createClient($options, $server);
     $homepage = new Page();
     $homepage->setHomepage(true)->setEnabled(true)->setSlug('home')->setTitle('My homepage')->setContent('Hello world!');
     /** @var EntityManager $em */
     $em = $client->getKernel()->getContainer()->get('doctrine')->getManager();
     $em->persist($homepage);
     $em->flush();
     return $client;
 }
Exemplo n.º 3
0
 public function testCategory()
 {
     $homepage = new Page();
     $homepage->setHomepage(true)->setEnabled(false)->setSlug('home')->setTitle('My homepage')->setHost('localhost')->setContent('Hello world!');
     $category = new Category();
     $category->setName('Default category')->setSlug('default');
     $homepage->setCategory($category);
     $kernel = static::getKernel();
     /** @var EntityManager $em */
     $em = $kernel->getContainer()->get('doctrine')->getManager();
     $em->persist($homepage);
     $em->persist($category);
     $em->flush();
     /** @var Page $homepage */
     $homepage = $em->getRepository(get_class($homepage))->find($homepage->getId());
     $this->assertEquals($homepage->getCategory(), $category);
     $this->assertEquals($category->getName(), (string) $category);
     $this->assertFalse($category->isEnabled());
     // Base value
 }
 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()));
 }