/** * @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; }
function _createTemporaryAlias() { global $objFWUser; $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setLang(0); $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_ALIAS); $page->setCmd(''); $page->setActive(true); //$page->setUsername($objFWUser->objUser->getUsername()); return $page; }
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()); }
/** * DO NOT CALL THIS METHOD! USE copyToLang() OR copyToNode() INSTEAD! * Copies data from another Page. * @param boolean $includeContent Whether to copy content. Defaults to true. * @param boolean $includeModuleAndCmd Whether to copy module and cmd. Defaults to true. * @param boolean $includeName Wheter to copy title, content title and slug. Defaults to true. * @param boolean $includeMetaData Wheter to copy meta data. Defaults to true. * @param boolean $includeProtection Wheter to copy protection. Defaults to true. * @param boolean $followRedirects Wheter to return a redirection page or the page its pointing at. Defaults to false, which returns the redirection page * @param boolean $followFallbacks Wheter to return a fallback page or the page its pointing at. Defaults to false, witch returns the fallback page * @param \Cx\Core\ContentManager\Model\Entity\Page Page to use as target * @return \Cx\Core\ContentManager\Model\Entity\Page The copy of $this or null on error */ public function copy($includeContent = true, $includeModuleAndCmd = true, $includeName = true, $includeMetaData = true, $includeProtection = true, $followRedirects = false, $followFallbacks = false, $page = null) { $targetPage = null; if ($followRedirects && $this->getType() == self::TYPE_REDIRECT) { $targetPage = $this->getTargetNodeId()->getPage($this->getTargetLangId()); } if ($followFallbacks && $this->getType() == self::TYPE_FALLBACK) { $fallbackLanguage = \FWLanguage::getFallbackLanguageIdById($this->getLang()); $targetPage = $this->getNode()->getPage($fallbackLanguage); } if ($targetPage) { return $targetPage->copy($includeContent, $includeModuleAndCmd, $includeName, $includeMetaData, $includeProtection, $followRedirects, $followFallbacks); } if (!$page) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); } if ($includeName) { $page->setContentTitle($this->getContentTitle()); $page->setTitle($this->getTitle()); $page->setSlug($this->getSlug()); } $newType = $this->getType(); if ($includeContent) { $page->setContent($this->getContent()); } else { $newType = self::TYPE_FALLBACK; } if ($includeModuleAndCmd) { $page->setModule($this->getModule()); $page->setCmd($this->getCmd()); } else { $page->setCmd(''); } if ($includeMetaData) { $page->setMetatitle($this->getMetatitle()); $page->setMetadesc($this->getMetadesc()); $page->setMetakeys($this->getMetakeys()); $page->setMetarobots($this->getMetarobots()); } $page->setNode($this->getNode()); $page->setActive($this->getActive()); $page->setDisplay($this->getDisplay()); $page->setLang($this->getLang()); $page->setType($newType); $page->setCaching($this->getCaching()); $page->setCustomContent($this->getCustomContent()); $page->setCssName($this->getCssName()); $page->setCssNavName($this->getCssNavName()); $page->setSkin($this->getSkin()); $page->setStart($this->getStart()); $page->setEnd($this->getEnd()); $page->setEditingStatus($this->getEditingStatus()); $page->setTarget($this->getTarget()); $page->setLinkTarget($this->getLinkTarget()); $page->setUpdatedBy(\FWUser::getFWUserObject()->objUser->getUsername()); if ($includeProtection) { if (!$this->copyProtection($page, true) || !$this->copyProtection($page, false)) { return null; } } return $page; }
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()); }
/** * Creates a page with the given parameters. * * This should be a constructor of Page. Since PHP does not support method * overloading and doctrine needs a constructor without parameters, it's * located here. * @param \Cx\Core\ContentManager\Model\Entity\Node $parentNode * @param int $lang Language id * @param string $title Page title * @param string $type Page type (fallback, content, application) * @param string $module Module name * @param string $cmd Module cmd * @param boolean $display Is page shown in navigation? * @param string $content HTML content * @return \Cx\Core\ContentManager\Model\Entity\Page Newly created page */ public function createPage($parentNode, $lang, $title, $type, $module, $cmd, $display, $content) { $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setNode($parentNode); $page->setNodeIdShadowed($parentNode->getId()); $page->setLang($lang); $page->setTitle($title); $page->setType($type); $page->setModule($module); $page->setCmd($cmd); $page->setActive(true); $page->setDisplay($display); $page->setContent($content); $page->setMetatitle($title); $page->setMetadesc($title); $page->setMetakeys($title); $page->setMetarobots('index'); $page->setMetatitle($title); $page->setUpdatedBy(\FWUser::getFWUserObject()->objUser->getUsername()); return $page; }
function _handleContentPage($formId = 0) { if (!$formId) { return; } $objDatabase = \Env::get('db'); $objFWUser = \FWUser::getFWUserObject(); $pageRepo = $this->em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $pages = array(); foreach ($pageRepo->findBy(array('module' => 'Contact', 'cmd' => $formId)) as $page) { if ($page) { $pages[$page->getLang()] = $page; } } $frontendLangIds = array_keys(\FWLanguage::getActiveFrontendLanguages()); $selectedLangIds = array_keys($this->arrForms[$formId]['lang']); // filter out only those languages that are active in the frontent. // we do want to create/update only the content pages of those languages. $selectedLangIds = array_intersect($selectedLangIds, $frontendLangIds); // Maybe there will already be a fallback page if we activate a new language. // So we use the fallback page to prevent the creation of a new page. foreach ($selectedLangIds as $selectedLangId) { if (!isset($pages[$selectedLangId])) { $fallbackPage = $pageRepo->findOneByModuleCmdLang('Contact', $formId, $selectedLangId); if (!empty($fallbackPage)) { $pages[$selectedLangId] = $fallbackPage; } } } $presentLangIds = array_keys($pages); // define which languages of the content pages have to be updated // $updateLangIds = array_intersect($selectedLangIds, $presentLangIds); // define which languages of the content pages have to be created // $newLangIds = array_diff($selectedLangIds, $updateLangIds); // define which languages of the content pages have to be removed $deleteLangIds = array_diff($presentLangIds, $selectedLangIds); $langIdsOfAssociatedPagesOfPageNode = array(); foreach ($presentLangIds as $langId) { $langIdsOfAssociatedPagesOfPageNode[$pages[$langId]->getId()] = array_keys($pages[$langId]->getNode()->getPagesByLang()); } foreach ($selectedLangIds as $langId) { $page = null; $node = null; if (isset($pages[$langId])) { // Content page already exists, so we will update this very page $page = $pages[$langId]; \DBG::msg("Page in lang {$langId} exists -> Update()"); } else { // Content page of the frontend language $langId doesn't exist yet. // Therefore we will either have to create a new node or we will have to // find a node to which we can attach our new page. // We will prefer the latter. \DBG::msg("Page doesn't exist in lang {$langId} -> Create()"); // Check if there exists already a content page to who's node we could attach our new page if (count($pages)) { if ($langId != \FWLanguage::getDefaultLangId() && isset($pages[\FWLanguage::getDefaultLangId()]) && !in_array($langId, $langIdsOfAssociatedPagesOfPageNode[$pages[\FWLanguage::getDefaultLangId()]->getId()])) { // if that is the case, we will attach our new page to this node $node = $pages[\FWLanguage::getDefaultLangId()]->getNode(); \DBG::msg("Page does exists in the default language"); \DBG::msg("Attach page to node {$node->getId()} of the page of the lang " . \FWLanguage::getDefaultLangId()); } else { foreach ($pages as $langIdOfPage => $page) { // Skip the page of the default frontend language - we just checked this page's node before if ($langIdOfPage == \FWLanguage::getDefaultLangId()) { continue; } // Check if there exists a node of the pages in the other languages that don't // have an associated page in the language we're going to create a new page if (!in_array($langId, $langIdsOfAssociatedPagesOfPageNode[$pages[$langIdOfPage]->getId()])) { $node = $pages[$langIdOfPage]->getNode(); \DBG::msg("Attach page to node {$node->getId()} of the page of the lang {$langIdOfPage}"); break; } } } } if ($node === null) { \DBG::msg("No node found -> Create()"); $root = $this->em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node')->getRoot(); // Create a new node $node = new \Cx\Core\ContentManager\Model\Entity\Node(); $node->setParent($root); $this->em->persist($node); } // Create a new Page $page = new \Cx\Core\ContentManager\Model\Entity\Page(); $page->setNode($node); // Set the following attributes only on new pages $page->setTitle($this->arrForms[$formId]['lang'][$langId]['name']); $page->setDisplay(false); $page->setActive(true); $page->setLang($langId); } $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION); $page->setModule('Contact'); $page->setCmd($formId); $content = $page->getContent(); //if the content is missing the placeholder {APPLICATION_DATA}, append the placeholder to the page's content. if (!preg_match_all('/\\{APPLICATION_DATA\\}/xi', $content, $matches)) { $content .= '{APPLICATION_DATA}'; } $page->setContent($content); $page->setSourceMode(true); $this->em->persist($page); // Remember newly created pages. We will need this for the creating of other new pages above in this method. if (!isset($pages[$langId])) { $pages[$langId] = $page; $langIdsOfAssociatedPagesOfPageNode[$pages[$langId]->getId()] = array($langId); } } //$this->em->flush(); // Delete those content pages of those languages that had been deactivated foreach ($deleteLangIds as $langId) { $page = $pages[$langId]; $node = $page->getNode(); \DBG::msg("Delete page: {$langId}"); //DBG::dump(count($node->getPages())); $this->em->remove($page); //$this->em->persist($page); //$this->em->flush(); //DBG::dump(count($node->getPages())); // TODO: Delete empty nodes } $this->em->flush(); }