mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API moved useTestTheme to base Sapphire test class so that it can be used elsewhere (eg CMS test)
This commit is contained in:
parent
87b5451d2d
commit
5fff5afb47
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user