Merge pull request #2746 from micmania1/move-test-theme-setup

API moved useTestTheme to base Sapphire test class so that it can be used elsewhere
This commit is contained in:
Ingo Schommer 2014-01-30 18:08:21 -08:00
commit 558d202bf2
2 changed files with 33 additions and 25 deletions

View File

@ -883,6 +883,37 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
* Cache for logInWithPermission()
*/
protected $cache_generatedMembers = array();
/**
* Test against a theme.
*
* @param $themeBaseDir string - themes directory
* @param $theme string - theme name
* @param $callback Closure
*/
protected function useTestTheme($themeBaseDir, $theme, $callback) {
global $project;
$manifest = new SS_TemplateManifest($themeBaseDir, $project, true, true);
SS_TemplateLoader::instance()->pushManifest($manifest);
$origTheme = Config::inst()->get('SSViewer', 'theme');
Config::inst()->update('SSViewer', 'theme', $theme);
$e = null;
try { $callback(); }
catch (Exception $e) { /* NOP for now, just save $e */ }
// Remove all the test themes we created
SS_TemplateLoader::instance()->popManifest();
Config::inst()->update('SSViewer', 'theme', $origTheme);
if ($e) throw $e;
}
}

View File

@ -983,33 +983,10 @@ after')
);
}
protected function useTestTheme($theme, $callback) {
global $project;
$themeBaseDir = dirname(__FILE__);
$manifest = new SS_TemplateManifest($themeBaseDir, $project, true, true);
SS_TemplateLoader::instance()->pushManifest($manifest);
$origTheme = Config::inst()->get('SSViewer', 'theme');
Config::inst()->update('SSViewer', 'theme', $theme);
$e = null;
try { $callback(); }
catch (Exception $e) { /* NOP for now, just save $e */ }
// Remove all the test themes we created
SS_TemplateLoader::instance()->popManifest();
Config::inst()->update('SSViewer', 'theme', $origTheme);
if ($e) throw $e;
}
public function testLayout() {
$self = $this;
$this->useTestTheme('layouttest', function() use ($self) {
$this->useTestTheme(dirname(__FILE__), 'layouttest', function() use ($self) {
$template = new SSViewer(array('Page'));
$self->assertEquals('Foo', $template->process(new ArrayData(array())));
@ -1023,7 +1000,7 @@ after')
*/
public function testGetTemplatesByClass() {
$self = $this;
$this->useTestTheme('layouttest', function() use ($self) {
$this->useTestTheme(dirname(__FILE__), 'layouttest', function() use ($self) {
// Test passing a string
$templates = SSViewer::get_templates_by_class('SSViewerTest_Controller', '', 'Controller');
$self->assertCount(2, $templates);