/** * 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; } } }
/** * @dataProvider populateArguments */ public function testPopulate($skip, $times) { $this->blockRepository->expects($this->exactly($times))->method('startTransaction'); $this->blockRepository->expects($this->exactly($times))->method('commit'); $this->blockRepository->expects($this->never())->method('rollback'); $slots = array('content' => new Slot('content', array('repeated' => 'page')), 'logo' => new Slot('logo', array('repeated' => 'site'))); $this->themeSlots->expects($this->once())->method('getSlots')->will($this->returnValue($slots)); $this->template->expects($this->once())->method('getSlots')->will($this->returnValue(array('content', 'logo'))); $block = $this->getMock('RedKiteLabs\\RedKiteCms\\RedKiteCmsBundle\\Model\\Block'); $block->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->blockManager->expects($this->any())->method('get')->will($this->returnValue($block)); $this->blockRepository->expects($this->any())->method('setRepositoryObject')->will($this->returnSelf()); $this->blockManager->expects($this->any())->method('save')->will($this->returnValue(true)); $this->initEventsDispatcher('template_manager.before_populate', 'template_manager.after_populate', 'template_manager.before_populate_commit'); $templateManager = new TemplateManager($this->eventsHandler, $this->factoryRepository, $this->factory, $this->validator); $templateManager->refresh($this->themeSlots, $this->template); $result = $templateManager->populate(2, 2, $skip); $this->assertTrue($result); }