MINOR: Updated the i18n tests to use mock template and class manifests.

This commit is contained in:
ajshort 2011-03-23 14:43:50 +11:00
parent 2c22dee176
commit 1a0ced4adc
3 changed files with 21 additions and 67 deletions

View File

@ -1,3 +1 @@
<?php <?php
Object::extend('i18nTestModule', 'i18nTestModuleDecorator');
?>

View File

@ -30,40 +30,16 @@ class i18nTest extends SapphireTest {
$this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot'; $this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
FileSystem::makeFolder($this->alternateBaseSavePath); FileSystem::makeFolder($this->alternateBaseSavePath);
// SSViewer and ManifestBuilder don't support different webroots, hence we set the paths manually // Push a template loader running from the fake webroot onto the stack.
global $_CLASS_MANIFEST; $manifest = new SS_TemplateManifest($this->alternateBasePath, false, true);
$_CLASS_MANIFEST['i18nTestModule'] = $this->alternateBasePath . '/i18ntestmodule/code/i18nTestModule.php'; $manifest->regenerate(false);
$_CLASS_MANIFEST['i18nTestModule_Addition'] = $this->alternateBasePath . '/i18ntestmodule/code/i18nTestModule.php'; SS_TemplateLoader::instance()->pushManifest($manifest);
$_CLASS_MANIFEST['i18nTestModuleDecorator'] = $this->alternateBasePath . '/i18nothermodule/code/i18nTestModuleDecorator.php';
global $_ALL_CLASSES;
$_ALL_CLASSES['parents']['i18nTestModule'] = array('DataObject'=>'DataObject','Object'=>'Object');
$_ALL_CLASSES['parents']['i18nTestModule_Addition'] = array('Object'=>'Object');
$_ALL_CLASSES['parents']['i18nTestModuleDecorator'] = array('DataObjectDecorator'=>'DataObjectDecorator','Object'=>'Object');
global $_TEMPLATE_MANIFEST;
$_TEMPLATE_MANIFEST['i18nTestModule.ss'] = array(
'main' => $this->alternateBasePath . '/i18ntestmodule/templates/i18nTestModule.ss',
'Layout' => $this->alternateBasePath . '/i18ntestmodule/templates/Layout/i18nTestModule.ss',
);
$_TEMPLATE_MANIFEST['i18nTestModuleInclude.ss'] = array(
'Includes' => $this->alternateBasePath . '/i18ntestmodule/templates/Includes/i18nTestModuleInclude.ss',
);
$this->originalLocale = i18n::get_locale(); $this->originalLocale = i18n::get_locale();
} }
function tearDown() { function tearDown() {
//FileSystem::removeFolder($this->tmpBasePath); SS_TemplateLoader::instance()->popManifest();
global $_CLASS_MANIFEST;
unset($_CLASS_MANIFEST['i18nTestModule']);
unset($_CLASS_MANIFEST['i18nTestModule_Addition']);
global $_TEMPLATE_MANIFEST;
unset($_TEMPLATE_MANIFEST['i18nTestModule.ss']);
unset($_TEMPLATE_MANIFEST['i18nTestModuleInclude.ss']);
i18n::set_locale($this->originalLocale); i18n::set_locale($this->originalLocale);
parent::tearDown(); parent::tearDown();

View File

@ -18,6 +18,8 @@ class i18nTextCollectorTest extends SapphireTest {
*/ */
protected $alternateBasePath; protected $alternateBasePath;
protected $manifest;
function setUp() { function setUp() {
parent::setUp(); parent::setUp();
@ -25,46 +27,19 @@ class i18nTextCollectorTest extends SapphireTest {
$this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot'; $this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
FileSystem::makeFolder($this->alternateBaseSavePath); FileSystem::makeFolder($this->alternateBaseSavePath);
// SSViewer and ManifestBuilder don't support different webroots, hence we set the paths manually // Push a class and template loader running from the fake webroot onto
global $_CLASS_MANIFEST; // the stack.
$_CLASS_MANIFEST['i18nTestModule'] = $this->alternateBasePath . '/i18ntestmodule/code/i18nTestModule.php'; $this->manifest = new SS_ClassManifest(
$_CLASS_MANIFEST['i18nTestModule_Addition'] = $this->alternateBasePath . '/i18ntestmodule/code/i18nTestModule.php'; $this->alternateBasePath, false, true, false
$_CLASS_MANIFEST['i18nTestModuleDecorator'] = $this->alternateBasePath . '/i18nothermodule/code/i18nTestModuleDecorator.php';
global $_ALL_CLASSES;
$_ALL_CLASSES['parents']['i18nTestModule'] = array('DataObject'=>'DataObject','Object'=>'Object');
$_ALL_CLASSES['parents']['i18nTestModule_Addition'] = array('Object'=>'Object');
$_ALL_CLASSES['parents']['i18nTestModuleDecorator'] = array('DataObjectDecorator'=>'DataObjectDecorator','Object'=>'Object');
global $_TEMPLATE_MANIFEST;
$_TEMPLATE_MANIFEST['i18nTestModule.ss'] = array(
'main' => $this->alternateBasePath . '/i18ntestmodule/templates/i18nTestModule.ss',
'Layout' => $this->alternateBasePath . '/i18ntestmodule/templates/Layout/i18nTestModule.ss',
);
$_TEMPLATE_MANIFEST['i18nTestModuleInclude.ss'] = array(
'Includes' => $this->alternateBasePath . '/i18ntestmodule/templates/Includes/i18nTestModuleInclude.ss',
); );
$_TEMPLATE_MANIFEST['i18nTestTheme1.ss'] = array( $manifest = new SS_TemplateManifest($this->alternateBasePath, false, true);
'main' => $this->alternateBasePath . '/themes/testtheme1/templates/i18nTestTheme1.ss', $manifest->regenerate(false);
'Layout' => $this->alternateBasePath . '/themes/testtheme1/templates/Layout/i18nTestTheme1.ss', SS_TemplateLoader::instance()->pushManifest($manifest);
);
$_TEMPLATE_MANIFEST['i18nTestTheme1Include.ss'] = array(
'Includes' => $this->alternateBasePath . '/themes/testtheme1/templates/Includes/i18nTestTheme1Include.ss',
);
} }
function tearDown() { function tearDown() {
//FileSystem::removeFolder($this->tmpBasePath); SS_TemplateLoader::instance()->popManifest();
global $_CLASS_MANIFEST;
unset($_CLASS_MANIFEST['i18nTestModule']);
unset($_CLASS_MANIFEST['i18nTestModule_Addition']);
global $_TEMPLATE_MANIFEST;
unset($_TEMPLATE_MANIFEST['i18nTestModule.ss']);
unset($_TEMPLATE_MANIFEST['i18nTestModuleInclude.ss']);
parent::tearDown(); parent::tearDown();
} }
@ -413,6 +388,9 @@ PHP;
function testCollectFromThemesTemplates() { function testCollectFromThemesTemplates() {
$c = new i18nTextCollector(); $c = new i18nTextCollector();
$theme = SSViewer::current_theme();
SSViewer::set_theme('testtheme1');
$templateFilePath = $this->alternateBasePath . '/themes/testtheme1/templates/Layout/i18nTestTheme1.ss'; $templateFilePath = $this->alternateBasePath . '/themes/testtheme1/templates/Layout/i18nTestTheme1.ss';
$html = file_get_contents($templateFilePath); $html = file_get_contents($templateFilePath);
$matches = $c->collectFromTemplate($html, 'themes/testtheme1', 'i18nTestTheme1.ss'); $matches = $c->collectFromTemplate($html, 'themes/testtheme1', 'i18nTestTheme1.ss');
@ -462,6 +440,8 @@ PHP;
$matches['i18nTestTheme1Include.ss.SPRINTFINCLUDENONAMESPACE'], $matches['i18nTestTheme1Include.ss.SPRINTFINCLUDENONAMESPACE'],
array('Theme1 My include replacement no namespace: %s', null, null) array('Theme1 My include replacement no namespace: %s', null, null)
); );
SSViewer::set_theme($theme);
} }
function testCollectFromFilesystemAndWriteMasterTables() { function testCollectFromFilesystemAndWriteMasterTables() {