/** * @expectedException \Cx\Model\Base\ValidationException */ public function testValidationException() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $n = new \Cx\Core\ContentManager\Model\Entity\Node(); $n->setParent($nodeRepo->getRoot()); $nodeRepo->getRoot()->addChildren($n); self::$em->persist($n); self::$em->flush(); $p = new \Cx\Core\ContentManager\Model\Entity\Page(); $p->setNode($n); $p->setLang(1); $p->setTitle('validation testpage'); $p->setNodeIdShadowed($n->getId()); $p->setUseCustomContentForAllChannels(''); $p->setUseCustomApplicationTemplateForAllChannels(''); $p->setUseSkinForAllChannels(''); $p->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $p->setActive(1); //set disallowed module name $p->setModule('1|@f2'); $p->setCmd(''); self::$em->persist($n); self::$em->persist($p); //should raise exception self::$em->flush(); }
public function testPagesByLang() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $node = new \Cx\Core\ContentManager\Model\Entity\Node(); $node->setParent($nodeRepo->getRoot()); $nodeRepo->getRoot()->addChildren($node); self::$em->persist($node); self::$em->flush(); $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setNode($node); $p2->setNode($node); $p1->setLang(1); $p1->setTitle('testpage'); $p1->setNodeIdShadowed($node->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); $p2->setLang(2); $p2->setTitle('testpage2'); $p2->setNodeIdShadowed($node->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); self::$em->persist($node); self::$em->persist($p1); self::$em->persist($p2); self::$em->flush(); self::$em->refresh($node); // Refreshes the state of the given entity from the database, overwriting local changes. $id = $p1->getId(); $r = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $p = $r->find($id); $pages = $p->getNode()->getPagesByLang(); $this->assertArrayHasKey(2, $pages); $this->assertArrayHasKey(1, $pages); $this->assertEquals('testpage', $pages[1]->getTitle()); $this->assertEquals('testpage2', $pages[2]->getTitle()); }
protected function getResolvedFallbackPage() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $root = $nodeRepo->getRoot(); $n1 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n1->setParent($root); $root->addChildren($n1); self::$em->persist($n1); self::$em->flush(); //test if requesting this page... $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2->setLang(1); $p2->setTitle('pageThatsFallingBack'); $p2->setNode($n1); $p2->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_FALLBACK); $p2->setNodeIdShadowed($n1->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); //... will yield contents of this page as result. $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setLang(2); $p1->setTitle('pageThatHoldsTheContent'); $p1->setNode($n1); $p1->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_CONTENT); $p1->setContent('fallbackContent'); $p1->setNodeIdShadowed($n1->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); self::$em->persist($n1); self::$em->persist($p1); self::$em->persist($p2); self::$em->flush(); self::$em->refresh($n1); return false; $url = new Url('http://example.com/pageThatsFallingBack/'); $resolver = new Resolver($url, 1, self::$em, '', $this->mockFallbackLanguages, true); $resolver->resolve(); $p = $resolver->getPage(); return $p; }
public function testSlugReleasing() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $root = $nodeRepo->getRoot(); $n1 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n1->setParent($root); $root->addChildren($n1); $n2 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n2->setParent($root); $root->addChildren($n2); self::$em->persist($n1); self::$em->persist($n2); self::$em->flush(); $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setLang(1); $p1->setTitle('slug release testpage'); $p1->setNode($n1); $p1->setNodeIdShadowed($n1->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); self::$em->persist($root); self::$em->persist($n1); self::$em->persist($n2); self::$em->persist($p1); self::$em->flush(); $idp1 = $p1->getId(); $idn2 = $n2->getId(); self::$em->refresh($n1); self::$em->refresh($n2); $this->assertEquals('slug-release-testpage', $p1->getSlug()); $p1 = self::$em->find('Cx\\Core\\ContentManager\\Model\\Entity\\Page', $idp1); $n2 = self::$em->find('Cx\\Core\\ContentManager\\Model\\Entity\\Node', $idn2); //shouldn't provocate a slug conflict, since we delete the other page below $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2->setLang(1); $p2->setTitle('slug release testpage'); $p2->setNode($n2); $p2->setNodeIdShadowed($n2->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); self::$em->remove($p1); self::$em->flush(); self::$em->persist($p2); self::$em->flush(); $this->assertEquals('slug-release-testpage', $p2->getSlug()); }
public function testGetPathToPage() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $n1 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n1->setParent($nodeRepo->getRoot()); $nodeRepo->getRoot()->addChildren($n1); $n2 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n2->setParent($n1); $n1->addChildren($n2); self::$em->persist($n1); self::$em->persist($n2); self::$em->flush(); $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setLang(1); $p1->setTitle('root'); $p1->setNode($n1); $p1->setNodeIdShadowed($n1->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2->setLang(1); $p2->setTitle('child page'); $p2->setNode($n2); $p2->setNodeIdShadowed($n2->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); self::$em->persist($n1); self::$em->persist($n2); self::$em->persist($p1); self::$em->persist($p2); self::$em->flush(); $pageId = $p2->getId(); \Env::get('em')->refresh($n1); //make sure we re-fetch a correct state self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node')->verify(); $pageRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $page = $pageRepo->findOneById($pageId); $this->assertEquals('root/child-page', $pageRepo->getPath($page)); }
public function testTranslate() { $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node'); $pageRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $n1 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n1->setParent($nodeRepo->getRoot()); $nodeRepo->getRoot()->addChildren($n1); $n2 = new \Cx\Core\ContentManager\Model\Entity\Node(); $n2->setParent($n1); self::$em->persist($n1); self::$em->persist($n2); self::$em->flush(); $p1 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p1->setLang(1); $p1->setTitle('test translate root'); $p1->setNode($n1); $p1->setNodeIdShadowed($n1->getId()); $p1->setUseCustomContentForAllChannels(''); $p1->setUseCustomApplicationTemplateForAllChannels(''); $p1->setUseSkinForAllChannels(''); $p1->setCmd(''); $p1->setActive(1); $p2 = new \Cx\Core\ContentManager\Model\Entity\Page(); $p2->setLang(1); $p2->setTitle('child page'); $p2->setNode($n2); $p2->setNodeIdShadowed($n1->getId()); $p2->setUseCustomContentForAllChannels(''); $p2->setUseCustomApplicationTemplateForAllChannels(''); $p2->setUseSkinForAllChannels(''); $p2->setCmd(''); $p2->setActive(1); self::$em->persist($n1); self::$em->persist($n2); self::$em->persist($p1); self::$em->persist($p2); self::$em->flush(); $pageId = $p2->getId(); self::$em->refresh($n1); self::$em->refresh($n2); $pageToTranslate = $pageRepo->findOneById($pageId); // copy page following redirects $page = $pageToTranslate->copyToLang(2, true, true, true, true, true, false, true); $page->setActive(1); $pageToTranslate->setupPath(2); $page->setNodeIdShadowed($pageToTranslate->getId()); self::$em->persist($page); self::$em->flush(); $pageId = $page->getId(); // Translated page id self::$em->refresh($n1); self::$em->refresh($n2); $page = $pageRepo->findOneById($pageId); // Translated page $this->assertEquals('/test-translate-root/child-page', $page->getPath()); $this->assertEquals(2, $page->getLang()); //see if the parent node is really, really there. $parentPages = $page->getNode()->getParent()->getPagesByLang(); $this->assertArrayHasKey(2, $parentPages); $this->assertEquals('test translate root', $parentPages[2]->getTitle()); }