/** * @dataProvider getData */ public function testGetCurrentTheme($storedValue, $expectedIndex) { $mockTheme1 = $this->mock(tubepress_api_theme_ThemeInterface::_); $mockTheme2 = $this->mock(tubepress_api_theme_ThemeInterface::_); $mockTheme3 = $this->mock(tubepress_api_theme_ThemeInterface::_); $mockTheme4 = $this->mock(tubepress_api_theme_ThemeInterface::_); $mockTheme1->shouldReceive('getName')->once()->andReturn('theme1'); $mockTheme2->shouldReceive('getName')->once()->andReturn('tubepress/default'); $mockTheme3->shouldReceive('getName')->once()->andReturn('tubepress/legacy-foobar'); $mockTheme4->shouldReceive('getName')->once()->andReturn('unknown/legacy-hiya'); $mockThemes = array($mockTheme1, $mockTheme2, $mockTheme3, $mockTheme4); $this->_mockContext->shouldReceive('get')->once()->with('option-name')->andReturn($storedValue); $this->_mockThemeRegistry->shouldReceive('getAll')->once()->andReturn($mockThemes); $actual = $this->_sut->getCurrentTheme(); $this->assertSame($mockThemes[$expectedIndex], $actual); }
public function getCSS() { $cssUrls = $this->getUrlsCSS(); $currentTheme = $this->_currentThemeService->getCurrentTheme(); $css = $this->_recursivelyGetFromTheme($currentTheme, 'getInlineCSS'); return $this->_templating->renderTemplate($this->_templateNameCss, array('inlineCSS' => $css, 'urls' => $cssUrls)); }
private function _isLegacyTheme() { $currentTheme = $this->_currentThemeService->getCurrentTheme(); $currentThemeName = $currentTheme->getName(); if (strpos($currentThemeName, '/legacy') !== false) { return true; } if (strpos($currentTheme->getParentThemeName(), '/legacy') !== false) { return true; } if (strpos($currentThemeName, 'unknown/') === 0) { return true; } if (strpos($currentTheme->getParentThemeName(), 'unknown/') === 0) { return true; } return false; }
/** * @param $templateName * * @return null|tubepress_api_theme_ThemeInterface */ private function _findThemeForTemplate($templateName) { $activeTheme = $this->_currentThemeService->getCurrentTheme(); $activeThemeName = $activeTheme->getName(); if (strpos($templateName, '::') !== false) { $exploded = explode('::', $templateName); if (count($exploded) === 2 && $this->_themeRegistry->getInstanceByName($exploded[0]) !== null) { $activeTheme = $this->_themeRegistry->getInstanceByName($exploded[0]); $activeThemeName = $activeTheme->getName(); $templateName = $exploded[1]; } } if ($this->_shouldLog) { $this->_logDebug(sprintf('Seeing if we can find <code>%s</code> in the theme hierarchy. %s.', $templateName, $this->_loggerPostfix($activeTheme))); } if (isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName]) && isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName])) { $cachedValue = $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName]; if ($this->_shouldLog) { if ($cachedValue) { $this->_logDebug(sprintf('Theme for template <code>%s</code> was found in the cache to be contained in theme <code>%s</code> version <code>%s</code>. %s.', $templateName, $cachedValue->getName(), $cachedValue->getVersion(), $this->_loggerPostfix($activeTheme))); } else { $this->_logDebug(sprintf('We already tried to find a theme that contains <code>%s</code> in the theme hierarchy but didn\'t find it anywhere. %s.', $templateName, $this->_loggerPostfix($activeTheme))); } } return $cachedValue ? $cachedValue : null; } else { if ($this->_shouldLog) { $this->_logDebug(sprintf('Looks like this is the first time searching for a theme that contains <code>%s</code>. %s.', $templateName, $this->_loggerPostfix($activeTheme))); } } do { $activeThemeName = $activeTheme->getName(); if ($activeTheme->hasTemplateSource($templateName)) { if (!isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName])) { $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName] = array(); } $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName] = $activeTheme; if ($this->_shouldLog) { $this->_logDebug(sprintf('Template source for <code>%s</code> was found in theme <code>%s</code> version <code>%s</code>. %s.', $templateName, $activeThemeName, $activeTheme->getVersion(), $this->_loggerPostfix($activeTheme))); } return $activeTheme; } $nextThemeNameToCheck = $activeTheme->getParentThemeName(); if ($nextThemeNameToCheck === null) { break; } if ($this->_shouldLog) { $this->_logDebug(sprintf('Template source for <code>%s</code> was not found in theme <code>%s</code>. Now trying its parent theme: <code>%s</code>.', $templateName, $activeTheme->getName(), $nextThemeNameToCheck)); } try { $activeTheme = $this->_themeRegistry->getInstanceByName($nextThemeNameToCheck); } catch (InvalidArgumentException $e) { if ($this->_shouldLog) { $this->_logger->error(sprintf('Unable to get the theme instance for <code>%s</code>. This should never happen!', $nextThemeNameToCheck)); } break; } } while ($activeTheme !== null); if (!isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName])) { $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName] = array(); } $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName] = false; if ($this->_shouldLog) { $this->_logDebug(sprintf('Unable to find source of template <code>%s</code> from theme hierarchy.', $templateName)); } return null; }
private function _legacyThemeInUse() { $currentTheme = $this->_currentThemeService->getCurrentTheme(); $currentThemeName = $currentTheme->getName(); return strpos($currentThemeName, '/legacy-') !== false || strpos($currentTheme->getParentThemeName(), '/legacy-') !== false; }