/** * Sets up the PageTree object * * @param ThemeInterface $theme * @param TemplateManager $templateManager * @param PageBlocksInterface $pageBlocks * @param Template $template * @return self */ public function setUp(ThemeInterface $theme, TemplateManager $templateManager, PageBlocksInterface $pageBlocks, Template $template = null) { $this->templateManager = $templateManager; $this->pageBlocks = $pageBlocks; $this->theme = $theme; $this->dispatch(PageTreeEvent\PageTreeEvents::BEFORE_PAGE_TREE_SETUP, new PageTreeEvent\BeforePageTreeSetupEvent($this)); $language = $this->getLanguage(); $page = $this->getPage(); if (null !== $language && null !== $page) { $this->pageBlocks->refresh($language->getId(), $page->getId()); } $options = array(); if (null !== $language) { $options["language"] = $language->getLanguageName(); } $templateName = ""; if (null !== $page) { $options["page"] = $page->getPageName(); $templateName = $page->getTemplateName(); } $this->template = null === $template ? $this->theme->getTemplate($templateName) : $template; if (null === $this->template) { return $this; } $this->assetsManager->withExtraAssets($this->cmsMode)->setUp($this->template, $options); $this->templateManager->refresh($this->theme->getThemeSlots(), $this->template, $this->pageBlocks); $this->setUpMetaTags($this->getSeo()); $this->dispatch(PageTreeEvent\PageTreeEvents::AFTER_PAGE_TREE_SETUP, new PageTreeEvent\AfterPageTreeSetupEvent($this)); return $this; }
/** * Changes the website templates with the new ones provided into the $templatesMap * array * * @param ThemeInterface $theme * @param array $templatesMap * @throws \Exception */ protected function changeTemplate(ThemeInterface $theme, array $templatesMap) { $ignoreRepeatedSlots = false; foreach ($this->languagesRepository->activeLanguages() as $language) { foreach ($this->pagesRepository->activePages() as $page) { $templateName = $page->getTemplateName(); if (!array_key_exists($templateName, $templatesMap)) { continue; } $page->setTemplateName($templatesMap[$templateName]); $page->save(); $template = $theme->getTemplate($page->getTemplateName()); $this->templateManager->refresh($theme->getThemeSlots(), $template); $this->templateManager->populate($language->getId(), $page->getId(), $ignoreRepeatedSlots); $ignoreRepeatedSlots = true; } } }
protected static function populateDb() { $client = static::createClient(array('environment' => 'rkcms_test', 'debug' => true)); $connection = \Propel::getConnection(); $configuration = $connection->getConfiguration(); $adapter = $configuration->getParameter('datasources.default.adapter'); switch ($adapter) { case "mysql": $queries = array('SET FOREIGN_KEY_CHECKS=0;', 'TRUNCATE al_block;', 'TRUNCATE al_configuration;', 'TRUNCATE al_language;', 'TRUNCATE al_locked_resource;', 'TRUNCATE al_page;', 'TRUNCATE al_seo;', 'TRUNCATE al_role;', 'TRUNCATE al_user;', 'INSERT INTO al_language (language_name) VALUES(\'-\');', 'INSERT INTO al_page (page_name) VALUES(\'-\');', 'INSERT INTO al_configuration (parameter, value) VALUES(\'language\', \'en\');', 'SET FOREIGN_KEY_CHECKS=1;'); break; case "pgsql": $queries = array('TRUNCATE al_configuration RESTART IDENTITY;', 'TRUNCATE al_page RESTART IDENTITY CASCADE;', 'TRUNCATE al_language RESTART IDENTITY CASCADE;', 'TRUNCATE al_block RESTART IDENTITY CASCADE;', 'TRUNCATE al_locked_resource RESTART IDENTITY;', 'TRUNCATE al_seo RESTART IDENTITY CASCADE;', 'TRUNCATE al_user RESTART IDENTITY CASCADE;', 'TRUNCATE al_role RESTART IDENTITY CASCADE;', 'INSERT INTO al_language (language_name) VALUES(\'-\');', 'INSERT INTO al_page (page_name) VALUES(\'-\');', 'INSERT INTO al_configuration (parameter, value) VALUES(\'language\', \'en\');'); break; case "sqlite": $queries = array('DELETE FROM al_block;', 'DELETE FROM al_configuration;', 'DELETE FROM al_language;', 'DELETE FROM al_locked_resource;', 'DELETE FROM al_page;', 'DELETE FROM al_seo;', 'DELETE FROM al_role;', 'DELETE FROM al_user;', 'INSERT INTO al_language (language_name) VALUES(\'-\');', 'INSERT INTO al_page (page_name) VALUES(\'-\');', 'INSERT INTO al_configuration (parameter, value) VALUES(\'language\', \'en\');'); break; } foreach ($queries as $query) { $statement = $connection->prepare($query); $statement->execute(); } $factoryRepository = new FactoryRepository('Propel'); $themes = $client->getContainer()->get('red_kite_labs_theme_engine.themes'); $theme = $themes->getTheme('BootbusinessThemeBundle'); $template = $theme->getTemplate('home'); $eventsHandler = $client->getContainer()->get('red_kite_cms.events_handler'); $pageBlocks = new PageBlocks($factoryRepository); $templateManager = new TemplateManager($eventsHandler, $factoryRepository, $client->getContainer()->get('red_kite_cms.block_manager_factory')); $templateManager->refresh($theme->getThemeSlots(), $template, $pageBlocks); $alLanguageManager = new LanguageManager($eventsHandler, $factoryRepository, new Validator\ParametersValidatorLanguageManager($factoryRepository)); foreach (self::$languages as $language) { $alLanguageManager->set(null)->save($language); } $alPageManager = new PageManager($eventsHandler, $templateManager, $factoryRepository, new Validator\ParametersValidatorPageManager($factoryRepository)); foreach (self::$pages as $page) { if (isset($page["TemplateName"])) { $templateManager->refresh($theme->getThemeSlots(), $theme->getTemplate($page["TemplateName"]), $pageBlocks); $alPageManager->setTemplateManager($templateManager); } $alPageManager->set(null)->save($page); } $roles = array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_SUPER_ADMIN'); foreach ($roles as $role) { $alRole = new Role(); $alRole->setRole($role); $alRole->save(); self::$roles[$role] = $alRole->getId(); } self::addUser('admin', 'admin', self::$roles['ROLE_ADMIN']); }
public function testClearPageBlocks() { $this->blockRepository->expects($this->exactly(3))->method('startTransaction'); $this->blockRepository->expects($this->exactly(3))->method('commit'); $this->blockRepository->expects($this->never())->method('rollback'); $slots = array('test' => new Slot('test', array('repeated' => 'page'))); $this->themeSlots->expects($this->once())->method('getSlots')->will($this->returnValue($slots)); $this->template->expects($this->once())->method('getSlots')->will($this->returnValue(array('test'))); $block = $this->getMock('RedKiteLabs\\RedKiteCms\\RedKiteCmsBundle\\Model\\Block'); $block->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->pageBlocks->expects($this->once())->method('getSlotBlocks')->will($this->returnValue(array($block))); $this->pageBlocks->expects($this->once())->method('getBlocks')->will($this->returnValue(array('test' => array($block)))); $this->blockManager->expects($this->once())->method('delete')->will($this->returnValue(true)); $this->initEventsDispatcher('template_manager.before_clear_blocks', 'template_manager.after_clear_blocks', 'template_manager.before_clear_blocks_commit'); $templateManager = new TemplateManager($this->eventsHandler, $this->factoryRepository, $this->factory, $this->validator); $templateManager->refresh($this->themeSlots, $this->template, $this->pageBlocks); $result = $templateManager->clearPageBlocks(3, 3); $this->assertTrue($result); }