mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-27 21:15:40 +02:00
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:
commit
558d202bf2
@ -883,6 +883,37 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
|||||||
* Cache for logInWithPermission()
|
* Cache for logInWithPermission()
|
||||||
*/
|
*/
|
||||||
protected $cache_generatedMembers = array();
|
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() {
|
public function testLayout() {
|
||||||
$self = $this;
|
$self = $this;
|
||||||
|
|
||||||
$this->useTestTheme('layouttest', function() use ($self) {
|
$this->useTestTheme(dirname(__FILE__), 'layouttest', function() use ($self) {
|
||||||
$template = new SSViewer(array('Page'));
|
$template = new SSViewer(array('Page'));
|
||||||
$self->assertEquals('Foo', $template->process(new ArrayData(array())));
|
$self->assertEquals('Foo', $template->process(new ArrayData(array())));
|
||||||
|
|
||||||
@ -1023,7 +1000,7 @@ after')
|
|||||||
*/
|
*/
|
||||||
public function testGetTemplatesByClass() {
|
public function testGetTemplatesByClass() {
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$this->useTestTheme('layouttest', function() use ($self) {
|
$this->useTestTheme(dirname(__FILE__), 'layouttest', function() use ($self) {
|
||||||
// Test passing a string
|
// Test passing a string
|
||||||
$templates = SSViewer::get_templates_by_class('SSViewerTest_Controller', '', 'Controller');
|
$templates = SSViewer::get_templates_by_class('SSViewerTest_Controller', '', 'Controller');
|
||||||
$self->assertCount(2, $templates);
|
$self->assertCount(2, $templates);
|
||||||
|
Loading…
Reference in New Issue
Block a user