2008-10-17 17:21:33 +02:00
|
|
|
<?php
|
2016-07-13 14:36:52 +02:00
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Assets\Filesystem;
|
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Core\Convert;
|
|
|
|
use SilverStripe\Core\Manifest\SS_ClassManifest;
|
|
|
|
use SilverStripe\Core\Manifest\SS_ClassLoader;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
use SilverStripe\i18n\i18n;
|
|
|
|
use SilverStripe\i18n\i18nTextCollector;
|
|
|
|
use SilverStripe\i18n\i18nTextCollector_Writer_RailsYaml;
|
2016-07-19 04:09:15 +02:00
|
|
|
use SilverStripe\View\ThemeResourceLoader;
|
2016-07-13 14:36:52 +02:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-10-17 17:21:33 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class i18nTextCollectorTest extends SapphireTest {
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
/**
|
|
|
|
* @var string $tmpBasePath Used to write language files.
|
2012-03-24 04:38:57 +01:00
|
|
|
* We don't want to store them inside framework (or in any web-accessible place)
|
2008-10-17 17:21:33 +02:00
|
|
|
* in case something goes wrong with the file parsing.
|
|
|
|
*/
|
|
|
|
protected $alternateBaseSavePath;
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
/**
|
|
|
|
* @var string $alternateBasePath Fake webroot with a single module
|
|
|
|
* /i18ntestmodule which contains some files with _t() calls.
|
|
|
|
*/
|
|
|
|
protected $alternateBasePath;
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-03-23 04:43:50 +01:00
|
|
|
protected $manifest;
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setUp() {
|
2008-10-17 17:21:33 +02:00
|
|
|
parent::setUp();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-03-30 08:49:11 +02:00
|
|
|
$this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot";
|
2016-08-19 00:51:35 +02:00
|
|
|
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_folder', $this->alternateBasePath);
|
2008-10-17 17:21:33 +02:00
|
|
|
$this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
|
2013-12-19 20:44:22 +01:00
|
|
|
Filesystem::makeFolder($this->alternateBaseSavePath);
|
2008-10-29 22:07:17 +01:00
|
|
|
|
2011-03-23 04:43:50 +01:00
|
|
|
// Push a class and template loader running from the fake webroot onto
|
|
|
|
// the stack.
|
|
|
|
$this->manifest = new SS_ClassManifest(
|
|
|
|
$this->alternateBasePath, false, true, false
|
2008-10-17 17:21:33 +02:00
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2016-07-13 14:36:52 +02:00
|
|
|
// Replace old template loader with new one with alternate base path
|
2016-07-19 04:09:15 +02:00
|
|
|
$this->_oldLoader = ThemeResourceLoader::instance();
|
|
|
|
ThemeResourceLoader::set_instance(new ThemeResourceLoader($this->alternateBasePath));
|
2008-10-17 17:21:33 +02:00
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function tearDown() {
|
2016-07-19 04:09:15 +02:00
|
|
|
ThemeResourceLoader::set_instance($this->_oldLoader);
|
2016-06-15 06:03:16 +02:00
|
|
|
// Pop if added during testing
|
|
|
|
if(SS_ClassLoader::instance()->getManifest() === $this->manifest) {
|
|
|
|
SS_ClassLoader::instance()->popManifest();
|
|
|
|
}
|
2008-12-04 23:38:32 +01:00
|
|
|
parent::tearDown();
|
2008-10-17 17:21:33 +02:00
|
|
|
}
|
2009-07-09 03:02:43 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testConcatenationInEntityValues() {
|
2009-07-09 03:02:43 +02:00
|
|
|
$c = new i18nTextCollector();
|
|
|
|
|
|
|
|
$php = <<<PHP
|
|
|
|
_t(
|
|
|
|
'Test.CONCATENATED',
|
2009-07-09 04:37:01 +02:00
|
|
|
'Line 1 and ' .
|
|
|
|
'Line \'2\' and ' .
|
|
|
|
'Line "3"',
|
2012-04-14 00:16:30 +02:00
|
|
|
|
2009-07-09 03:02:43 +02:00
|
|
|
'Comment'
|
|
|
|
);
|
2009-07-09 04:37:01 +02:00
|
|
|
|
|
|
|
_t(
|
|
|
|
'Test.CONCATENATED2',
|
2016-01-06 00:34:58 +01:00
|
|
|
"Line \"4\" and " .
|
2009-07-09 04:37:01 +02:00
|
|
|
"Line 5");
|
2009-07-09 03:02:43 +02:00
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromCode($php, 'mymodule'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.CONCATENATED' => array("Line 1 and Line '2' and Line \"3\"",'Comment'),
|
|
|
|
'Test.CONCATENATED2' => array("Line \"4\" and Line 5")
|
2009-07-09 03:02:43 +02:00
|
|
|
)
|
|
|
|
);
|
2012-04-16 07:24:48 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCollectFromNewTemplateSyntaxUsingParserSubclass() {
|
2012-04-16 07:24:48 +02:00
|
|
|
$c = new i18nTextCollector();
|
|
|
|
|
|
|
|
$html = <<<SS
|
|
|
|
<% _t('Test.SINGLEQUOTE','Single Quote'); %>
|
|
|
|
<%t i18nTestModule.NEWMETHODSIG "New _t method signature test" %>
|
2012-09-26 23:34:00 +02:00
|
|
|
<%t i18nTestModule.INJECTIONS_0 "Hello {name} {greeting}, and {goodbye}" name="Mark" greeting="welcome" goodbye="bye" %>
|
|
|
|
<%t i18nTestModule.INJECTIONS_1 "Hello {name} {greeting}, and {goodbye}" name="Paul" greeting="welcome" goodbye="cya" %>
|
|
|
|
<%t i18nTestModule.INJECTIONS_2 "Hello {name} {greeting}" is "context (ignored)" name="Steffen" greeting="Wilkommen" %>
|
2012-04-16 07:24:48 +02:00
|
|
|
<%t i18nTestModule.INJECTIONS_3 name="Cat" greeting='meow' goodbye="meow" %>
|
|
|
|
<%t i18nTestModule.INJECTIONS_4 name=\$absoluteBaseURL greeting=\$get_locale goodbye="global calls" %>
|
|
|
|
SS;
|
|
|
|
$c->collectFromTemplate($html, 'mymodule', 'Test');
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromTemplate($html, 'mymodule', 'Test'),
|
|
|
|
array(
|
2012-04-18 07:23:57 +02:00
|
|
|
'Test.SINGLEQUOTE' => array('Single Quote'),
|
2012-04-16 07:24:48 +02:00
|
|
|
'i18nTestModule.NEWMETHODSIG' => array("New _t method signature test",null,null),
|
2012-09-26 23:34:00 +02:00
|
|
|
'i18nTestModule.INJECTIONS_0' => array("Hello {name} {greeting}, and {goodbye}", null, null),
|
|
|
|
'i18nTestModule.INJECTIONS_1' => array("Hello {name} {greeting}, and {goodbye}", null, null),
|
|
|
|
'i18nTestModule.INJECTIONS_2' => array("Hello {name} {greeting}", null, "context (ignored)"),
|
2012-04-16 07:24:48 +02:00
|
|
|
'i18nTestModule.INJECTIONS_3' => array(null, null, null),
|
|
|
|
'i18nTestModule.INJECTIONS_4' => array(null, null, null),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCollectFromTemplateSimple() {
|
2008-10-17 17:21:33 +02:00
|
|
|
$c = new i18nTextCollector();
|
|
|
|
|
|
|
|
$html = <<<SS
|
|
|
|
<% _t('Test.SINGLEQUOTE','Single Quote'); %>
|
|
|
|
SS;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromTemplate($html, 'mymodule', 'Test'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.SINGLEQUOTE' => array('Single Quote')
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$html = <<<SS
|
|
|
|
<% _t( "Test.DOUBLEQUOTE", "Double Quote and Spaces" ); %>
|
|
|
|
SS;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromTemplate($html, 'mymodule', 'Test'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.DOUBLEQUOTE' => array("Double Quote and Spaces")
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$html = <<<SS
|
|
|
|
<% _t("Test.NOSEMICOLON","No Semicolon") %>
|
|
|
|
SS;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromTemplate($html, 'mymodule', 'Test'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.NOSEMICOLON' => array("No Semicolon")
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCollectFromTemplateAdvanced() {
|
2008-10-17 17:21:33 +02:00
|
|
|
$c = new i18nTextCollector();
|
|
|
|
|
|
|
|
$html = <<<SS
|
|
|
|
<% _t(
|
|
|
|
'NEWLINES',
|
|
|
|
'New Lines'
|
|
|
|
) %>
|
|
|
|
SS;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromTemplate($html, 'mymodule', 'Test'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.NEWLINES' => array("New Lines")
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$html = <<<SS
|
|
|
|
<% _t(
|
|
|
|
'Test.PRIOANDCOMMENT',
|
|
|
|
' Prio and Value with "Double Quotes"',
|
|
|
|
'Comment with "Double Quotes"'
|
|
|
|
) %>
|
|
|
|
SS;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromTemplate($html, 'mymodule', 'Test'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.PRIOANDCOMMENT' => array(' Prio and Value with "Double Quotes"','Comment with "Double Quotes"')
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$html = <<<SS
|
|
|
|
<% _t(
|
|
|
|
'Test.PRIOANDCOMMENT',
|
|
|
|
" Prio and Value with 'Single Quotes'",
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
"Comment with 'Single Quotes'"
|
|
|
|
) %>
|
|
|
|
SS;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromTemplate($html, 'mymodule', 'Test'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.PRIOANDCOMMENT' => array(" Prio and Value with 'Single Quotes'","Comment with 'Single Quotes'")
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCollectFromCodeSimple() {
|
2008-10-17 17:21:33 +02:00
|
|
|
$c = new i18nTextCollector();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$php = <<<PHP
|
|
|
|
_t('Test.SINGLEQUOTE','Single Quote');
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromCode($php, 'mymodule'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.SINGLEQUOTE' => array('Single Quote')
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$php = <<<PHP
|
|
|
|
_t( "Test.DOUBLEQUOTE", "Double Quote and Spaces" );
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromCode($php, 'mymodule'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.DOUBLEQUOTE' => array("Double Quote and Spaces")
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCollectFromCodeAdvanced() {
|
2008-10-17 17:21:33 +02:00
|
|
|
$c = new i18nTextCollector();
|
|
|
|
|
|
|
|
$php = <<<PHP
|
|
|
|
_t(
|
|
|
|
'Test.NEWLINES',
|
|
|
|
'New Lines'
|
|
|
|
);
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromCode($php, 'mymodule'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.NEWLINES' => array("New Lines")
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$php = <<<PHP
|
|
|
|
_t(
|
|
|
|
'Test.PRIOANDCOMMENT',
|
|
|
|
' Value with "Double Quotes"',
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
'Comment with "Double Quotes"'
|
|
|
|
);
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromCode($php, 'mymodule'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.PRIOANDCOMMENT' => array(' Value with "Double Quotes"','Comment with "Double Quotes"')
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$php = <<<PHP
|
|
|
|
_t(
|
|
|
|
'Test.PRIOANDCOMMENT',
|
|
|
|
" Value with 'Single Quotes'",
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
"Comment with 'Single Quotes'"
|
|
|
|
);
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromCode($php, 'mymodule'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.PRIOANDCOMMENT' => array(" Value with 'Single Quotes'","Comment with 'Single Quotes'")
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$php = <<<PHP
|
|
|
|
_t(
|
|
|
|
'Test.PRIOANDCOMMENT',
|
|
|
|
'Value with \'Escaped Single Quotes\''
|
|
|
|
);
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromCode($php, 'mymodule'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.PRIOANDCOMMENT' => array("Value with 'Escaped Single Quotes'")
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$php = <<<PHP
|
|
|
|
_t(
|
|
|
|
'Test.PRIOANDCOMMENT',
|
|
|
|
"Doublequoted Value with 'Unescaped Single Quotes'"
|
|
|
|
);
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromCode($php, 'mymodule'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.PRIOANDCOMMENT' => array("Doublequoted Value with 'Unescaped Single Quotes'")
|
2008-10-17 17:21:33 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testNewlinesInEntityValues() {
|
2008-11-01 19:55:27 +01:00
|
|
|
$c = new i18nTextCollector();
|
|
|
|
|
|
|
|
$php = <<<PHP
|
|
|
|
_t(
|
|
|
|
'Test.NEWLINESINGLEQUOTE',
|
|
|
|
'Line 1
|
|
|
|
Line 2'
|
|
|
|
);
|
|
|
|
PHP;
|
2009-11-21 02:43:54 +01:00
|
|
|
|
|
|
|
$eol = PHP_EOL;
|
2008-11-01 19:55:27 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromCode($php, 'mymodule'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.NEWLINESINGLEQUOTE' => array("Line 1{$eol}Line 2")
|
2008-11-01 19:55:27 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$php = <<<PHP
|
|
|
|
_t(
|
|
|
|
'Test.NEWLINEDOUBLEQUOTE',
|
|
|
|
"Line 1
|
|
|
|
Line 2"
|
|
|
|
);
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
|
|
|
$c->collectFromCode($php, 'mymodule'),
|
|
|
|
array(
|
2012-04-14 00:16:30 +02:00
|
|
|
'Test.NEWLINEDOUBLEQUOTE' => array("Line 1{$eol}Line 2")
|
2008-11-01 19:55:27 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2009-07-09 03:02:43 +02:00
|
|
|
|
2012-04-16 07:24:48 +02:00
|
|
|
/**
|
|
|
|
* Test extracting entities from the new _t method signature
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCollectFromCodeNewSignature() {
|
2012-04-16 07:24:48 +02:00
|
|
|
$c = new i18nTextCollector();
|
|
|
|
|
|
|
|
$php = <<<PHP
|
|
|
|
_t('i18nTestModule.NEWMETHODSIG',"New _t method signature test");
|
2012-09-26 23:34:00 +02:00
|
|
|
_t('i18nTestModule.INJECTIONS1','_DOES_NOT_EXIST', "Hello {name} {greeting}. But it is late, {goodbye}",
|
|
|
|
array("name"=>"Mark", "greeting"=>"welcome", "goodbye"=>"bye"));
|
|
|
|
_t('i18nTestModule.INJECTIONS2', "Hello {name} {greeting}. But it is late, {goodbye}",
|
|
|
|
array("name"=>"Paul", "greeting"=>"good you are here", "goodbye"=>"see you"));
|
|
|
|
_t("i18nTestModule.INJECTIONS3", "Hello {name} {greeting}. But it is late, {goodbye}",
|
|
|
|
"New context (this should be ignored)",
|
|
|
|
array("name"=>"Steffen", "greeting"=>"willkommen", "goodbye"=>"wiedersehen"));
|
2012-04-16 07:24:48 +02:00
|
|
|
_t('i18nTestModule.INJECTIONS4', array("name"=>"Cat", "greeting"=>"meow", "goodbye"=>"meow"));
|
2013-05-05 02:19:31 +02:00
|
|
|
_t('i18nTestModule.INJECTIONS5','_DOES_NOT_EXIST', "Hello {name} {greeting}. But it is late, {goodbye}",
|
|
|
|
["name"=>"Mark", "greeting"=>"welcome", "goodbye"=>"bye"]);
|
|
|
|
_t('i18nTestModule.INJECTIONS6', "Hello {name} {greeting}. But it is late, {goodbye}",
|
|
|
|
["name"=>"Paul", "greeting"=>"good you are here", "goodbye"=>"see you"]);
|
|
|
|
_t("i18nTestModule.INJECTIONS7", "Hello {name} {greeting}. But it is late, {goodbye}",
|
|
|
|
"New context (this should be ignored)",
|
|
|
|
["name"=>"Steffen", "greeting"=>"willkommen", "goodbye"=>"wiedersehen"]);
|
|
|
|
_t('i18nTestModule.INJECTIONS8', ["name"=>"Cat", "greeting"=>"meow", "goodbye"=>"meow"]);
|
2012-04-16 07:24:48 +02:00
|
|
|
PHP;
|
|
|
|
|
|
|
|
$collectedTranslatables = $c->collectFromCode($php, 'mymodule');
|
|
|
|
|
|
|
|
$expectedArray = (array(
|
2012-04-18 07:23:57 +02:00
|
|
|
'i18nTestModule.NEWMETHODSIG' => array("New _t method signature test"),
|
2012-09-26 23:34:00 +02:00
|
|
|
'i18nTestModule.INJECTIONS1' => array("_DOES_NOT_EXIST",
|
|
|
|
"Hello {name} {greeting}. But it is late, {goodbye}"),
|
2012-04-18 07:23:57 +02:00
|
|
|
'i18nTestModule.INJECTIONS2' => array("Hello {name} {greeting}. But it is late, {goodbye}"),
|
2012-09-26 23:34:00 +02:00
|
|
|
'i18nTestModule.INJECTIONS3' => array("Hello {name} {greeting}. But it is late, {goodbye}",
|
|
|
|
"New context (this should be ignored)"),
|
2013-05-05 02:19:31 +02:00
|
|
|
'i18nTestModule.INJECTIONS5' => array("_DOES_NOT_EXIST",
|
|
|
|
"Hello {name} {greeting}. But it is late, {goodbye}"),
|
|
|
|
'i18nTestModule.INJECTIONS6' => array("Hello {name} {greeting}. But it is late, {goodbye}"),
|
|
|
|
'i18nTestModule.INJECTIONS7' => array("Hello {name} {greeting}. But it is late, {goodbye}",
|
|
|
|
"New context (this should be ignored)"),
|
2012-04-16 07:24:48 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
ksort($expectedArray);
|
|
|
|
|
|
|
|
$this->assertEquals($collectedTranslatables, $expectedArray);
|
|
|
|
}
|
|
|
|
|
2012-04-14 01:01:59 +02:00
|
|
|
/**
|
|
|
|
* @todo Should be in a separate test suite, but don't want to duplicate setup logic
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testYamlWriter() {
|
2012-04-14 01:01:59 +02:00
|
|
|
$writer = new i18nTextCollector_Writer_RailsYaml();
|
|
|
|
$entities = array(
|
|
|
|
'Level1.Level2.EntityName' => array('Text', 'Context'),
|
|
|
|
'Level1.OtherEntityName' => array('Other Text', 'Other Context'),
|
2015-03-10 01:42:22 +01:00
|
|
|
'Level1.BoolTest' => array('True'),
|
|
|
|
'Level1.FlagTest' => array('No'),
|
|
|
|
'Level1.TextTest' => array('Maybe')
|
2012-04-14 01:01:59 +02:00
|
|
|
);
|
|
|
|
$yaml = <<<YAML
|
|
|
|
de:
|
|
|
|
Level1:
|
|
|
|
Level2:
|
|
|
|
EntityName: Text
|
|
|
|
OtherEntityName: 'Other Text'
|
2015-03-10 01:42:22 +01:00
|
|
|
BoolTest: 'True'
|
|
|
|
FlagTest: 'No'
|
|
|
|
TextTest: Maybe
|
2012-04-14 01:01:59 +02:00
|
|
|
|
|
|
|
YAML;
|
2012-10-16 06:10:54 +02:00
|
|
|
$this->assertEquals($yaml, Convert::nl2os($writer->getYaml($entities, 'de')));
|
2012-04-14 01:01:59 +02:00
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCollectFromIncludedTemplates() {
|
2008-10-17 17:21:33 +02:00
|
|
|
$c = new i18nTextCollector();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-29 22:07:17 +01:00
|
|
|
$templateFilePath = $this->alternateBasePath . '/i18ntestmodule/templates/Layout/i18nTestModule.ss';
|
2008-10-17 19:44:14 +02:00
|
|
|
$html = file_get_contents($templateFilePath);
|
2008-11-06 03:50:14 +01:00
|
|
|
$matches = $c->collectFromTemplate($html, 'mymodule', 'RandomNamespace');
|
2015-07-05 06:53:21 +02:00
|
|
|
|
|
|
|
$this->assertArrayHasKey('RandomNamespace.LAYOUTTEMPLATENONAMESPACE', $matches);
|
2008-10-17 17:21:33 +02:00
|
|
|
$this->assertEquals(
|
2015-07-05 06:53:21 +02:00
|
|
|
$matches['RandomNamespace.LAYOUTTEMPLATENONAMESPACE'],
|
2012-04-14 00:16:30 +02:00
|
|
|
array('Layout Template no namespace')
|
2008-11-06 03:50:14 +01:00
|
|
|
);
|
|
|
|
$this->assertArrayHasKey('RandomNamespace.SPRINTFNONAMESPACE', $matches);
|
|
|
|
$this->assertEquals(
|
|
|
|
$matches['RandomNamespace.SPRINTFNONAMESPACE'],
|
2012-04-14 00:16:30 +02:00
|
|
|
array('My replacement no namespace: %s')
|
2008-11-06 03:50:14 +01:00
|
|
|
);
|
|
|
|
$this->assertArrayHasKey('i18nTestModule.LAYOUTTEMPLATE', $matches);
|
|
|
|
$this->assertEquals(
|
|
|
|
$matches['i18nTestModule.LAYOUTTEMPLATE'],
|
2012-04-14 00:16:30 +02:00
|
|
|
array('Layout Template')
|
2008-11-06 03:50:14 +01:00
|
|
|
);
|
|
|
|
$this->assertArrayHasKey('i18nTestModule.SPRINTFNAMESPACE', $matches);
|
|
|
|
$this->assertEquals(
|
|
|
|
$matches['i18nTestModule.SPRINTFNAMESPACE'],
|
2012-04-14 00:16:30 +02:00
|
|
|
array('My replacement: %s')
|
2008-11-06 03:50:14 +01:00
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Includes should not automatically inject translations into parent templates
|
|
|
|
$this->assertArrayNotHasKey('i18nTestModule.WITHNAMESPACE', $matches);
|
|
|
|
$this->assertArrayNotHasKey('i18nTestModuleInclude.ss.NONAMESPACE', $matches);
|
|
|
|
$this->assertArrayNotHasKey('i18nTestModuleInclude.ss.SPRINTFINCLUDENAMESPACE', $matches);
|
|
|
|
$this->assertArrayNotHasKey('i18nTestModuleInclude.ss.SPRINTFINCLUDENONAMESPACE', $matches);
|
2008-10-17 17:21:33 +02:00
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCollectFromThemesTemplates() {
|
2010-11-18 20:00:13 +01:00
|
|
|
$c = new i18nTextCollector();
|
2016-08-19 00:51:35 +02:00
|
|
|
Config::inst()->update('SilverStripe\\View\\SSViewer', 'theme', 'testtheme1');
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Collect from layout
|
|
|
|
$layoutFilePath = $this->alternateBasePath . '/themes/testtheme1/templates/Layout/i18nTestTheme1.ss';
|
|
|
|
$layoutHTML = file_get_contents($layoutFilePath);
|
|
|
|
$layoutMatches = $c->collectFromTemplate($layoutHTML, 'themes/testtheme1', 'i18nTestTheme1.ss');
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// all entities from i18nTestTheme1.ss
|
2010-11-18 20:00:13 +01:00
|
|
|
$this->assertEquals(
|
2015-07-05 06:53:21 +02:00
|
|
|
array(
|
|
|
|
'i18nTestTheme1.LAYOUTTEMPLATE'
|
|
|
|
=> array('Theme1 Layout Template'),
|
|
|
|
'i18nTestTheme1.SPRINTFNAMESPACE'
|
|
|
|
=> array('Theme1 My replacement: %s'),
|
|
|
|
'i18nTestTheme1.ss.LAYOUTTEMPLATENONAMESPACE'
|
|
|
|
=> array('Theme1 Layout Template no namespace'),
|
|
|
|
'i18nTestTheme1.ss.SPRINTFNONAMESPACE'
|
|
|
|
=> array('Theme1 My replacement no namespace: %s'),
|
|
|
|
),
|
|
|
|
$layoutMatches
|
2010-11-18 20:00:13 +01:00
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Collect from include
|
|
|
|
$includeFilePath = $this->alternateBasePath . '/themes/testtheme1/templates/Includes/i18nTestTheme1Include.ss';
|
|
|
|
$includeHTML = file_get_contents($includeFilePath);
|
|
|
|
$includeMatches = $c->collectFromTemplate($includeHTML, 'themes/testtheme1', 'i18nTestTheme1Include.ss');
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// all entities from i18nTestTheme1Include.ss
|
2010-11-18 20:00:13 +01:00
|
|
|
$this->assertEquals(
|
2015-07-05 06:53:21 +02:00
|
|
|
array(
|
|
|
|
'i18nTestTheme1Include.SPRINTFINCLUDENAMESPACE'
|
|
|
|
=> array('Theme1 My include replacement: %s'),
|
|
|
|
'i18nTestTheme1Include.WITHNAMESPACE'
|
|
|
|
=> array('Theme1 Include Entity with Namespace'),
|
|
|
|
'i18nTestTheme1Include.ss.NONAMESPACE'
|
|
|
|
=> array('Theme1 Include Entity without Namespace'),
|
|
|
|
'i18nTestTheme1Include.ss.SPRINTFINCLUDENONAMESPACE'
|
|
|
|
=> array('Theme1 My include replacement no namespace: %s')
|
|
|
|
),
|
|
|
|
$includeMatches
|
2010-11-18 20:00:13 +01:00
|
|
|
);
|
|
|
|
}
|
2013-06-02 20:17:28 +02:00
|
|
|
|
|
|
|
public function testCollectMergesWithExisting() {
|
2016-01-06 00:34:58 +01:00
|
|
|
i18n::set_locale('en_US');
|
2016-08-19 00:51:35 +02:00
|
|
|
i18n::config()->update('default_locale', 'en_US');
|
2016-06-15 06:03:16 +02:00
|
|
|
i18n::include_by_locale('en');
|
|
|
|
i18n::include_by_locale('en_US');
|
2013-06-02 20:17:28 +02:00
|
|
|
|
|
|
|
$c = new i18nTextCollector();
|
2016-08-19 00:51:35 +02:00
|
|
|
$c->setWriter(new i18nTextCollector_Writer_RailsYaml());
|
2013-06-02 20:17:28 +02:00
|
|
|
$c->basePath = $this->alternateBasePath;
|
|
|
|
$c->baseSavePath = $this->alternateBaseSavePath;
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2013-06-02 20:17:28 +02:00
|
|
|
$entitiesByModule = $c->collect(null, true /* merge */);
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
'i18nTestModule.ENTITY',
|
|
|
|
$entitiesByModule['i18ntestmodule'],
|
|
|
|
'Retains existing entities'
|
|
|
|
);
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
'i18nTestModule.NEWENTITY',
|
|
|
|
$entitiesByModule['i18ntestmodule'],
|
|
|
|
'Adds new entities'
|
|
|
|
);
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCollectFromFilesystemAndWriteMasterTables() {
|
2010-10-19 00:33:41 +02:00
|
|
|
$local = i18n::get_locale();
|
|
|
|
i18n::set_locale('en_US'); //set the locale to the US locale expected in the asserts
|
2016-08-19 00:51:35 +02:00
|
|
|
i18n::config()->update('default_locale', 'en_US');
|
2010-10-19 00:33:41 +02:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$c = new i18nTextCollector();
|
2016-08-19 00:51:35 +02:00
|
|
|
$c->setWriter(new i18nTextCollector_Writer_RailsYaml());
|
2008-10-17 17:21:33 +02:00
|
|
|
$c->basePath = $this->alternateBasePath;
|
|
|
|
$c->baseSavePath = $this->alternateBaseSavePath;
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 19:44:14 +02:00
|
|
|
$c->run();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 19:44:14 +02:00
|
|
|
// i18ntestmodule
|
2016-08-19 00:51:35 +02:00
|
|
|
$moduleLangFile = "{$this->alternateBaseSavePath}/i18ntestmodule/lang/" . $c->getDefaultLocale() . '.yml';
|
2008-10-17 17:21:33 +02:00
|
|
|
$this->assertTrue(
|
|
|
|
file_exists($moduleLangFile),
|
|
|
|
'Master language file can be written to modules /lang folder'
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent = file_get_contents($moduleLangFile);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" ADDITION: Addition\n",
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" ENTITY: 'Entity with \"Double Quotes\"'\n",
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" MAINTEMPLATE: 'Main Template'\n",
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" OTHERENTITY: 'Other Entity'\n",
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" WITHNAMESPACE: 'Include Entity with Namespace'\n",
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" NONAMESPACE: 'Include Entity without Namespace'\n",
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent
|
2008-10-17 19:44:14 +02:00
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 19:44:14 +02:00
|
|
|
// i18nothermodule
|
2016-08-19 00:51:35 +02:00
|
|
|
$otherModuleLangFile = "{$this->alternateBaseSavePath}/i18nothermodule/lang/" . $c->getDefaultLocale() . '.yml';
|
2008-10-17 19:44:14 +02:00
|
|
|
$this->assertTrue(
|
2008-11-01 23:47:02 +01:00
|
|
|
file_exists($otherModuleLangFile),
|
2008-10-17 19:44:14 +02:00
|
|
|
'Master language file can be written to modules /lang folder'
|
|
|
|
);
|
2008-11-01 23:47:02 +01:00
|
|
|
$otherModuleLangFileContent = file_get_contents($otherModuleLangFile);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" ENTITY: 'Other Module Entity'\n",
|
2008-11-01 23:47:02 +01:00
|
|
|
$otherModuleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" MAINTEMPLATE: 'Main Template Other Module'\n",
|
2008-11-01 23:47:02 +01:00
|
|
|
$otherModuleLangFileContent
|
2008-10-17 17:21:33 +02:00
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2010-11-18 20:00:13 +01:00
|
|
|
// testtheme1
|
2016-08-19 00:51:35 +02:00
|
|
|
$theme1LangFile = "{$this->alternateBaseSavePath}/themes/testtheme1/lang/" . $c->getDefaultLocale() . '.yml';
|
2010-11-18 20:00:13 +01:00
|
|
|
$this->assertTrue(
|
|
|
|
file_exists($theme1LangFile),
|
|
|
|
'Master theme language file can be written to themes/testtheme1 /lang folder'
|
|
|
|
);
|
|
|
|
$theme1LangFileContent = file_get_contents($theme1LangFile);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" MAINTEMPLATE: 'Theme1 Main Template'\n",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" LAYOUTTEMPLATE: 'Theme1 Layout Template'\n",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" SPRINTFNAMESPACE: 'Theme1 My replacement: %s'\n",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" LAYOUTTEMPLATENONAMESPACE: 'Theme1 Layout Template no namespace'\n",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" SPRINTFNONAMESPACE: 'Theme1 My replacement no namespace: %s'\n",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2010-11-18 20:00:13 +01:00
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" SPRINTFINCLUDENAMESPACE: 'Theme1 My include replacement: %s'\n",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" WITHNAMESPACE: 'Theme1 Include Entity with Namespace'\n",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" NONAMESPACE: 'Theme1 Include Entity without Namespace'\n",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" SPRINTFINCLUDENONAMESPACE: 'Theme1 My include replacement no namespace: %s'\n",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2010-11-18 20:00:13 +01:00
|
|
|
// testtheme2
|
2016-08-19 00:51:35 +02:00
|
|
|
$theme2LangFile = "{$this->alternateBaseSavePath}/themes/testtheme2/lang/" . $c->getDefaultLocale() . '.yml';
|
2010-11-18 20:00:13 +01:00
|
|
|
$this->assertTrue(
|
|
|
|
file_exists($theme2LangFile),
|
|
|
|
'Master theme language file can be written to themes/testtheme2 /lang folder'
|
|
|
|
);
|
|
|
|
$theme2LangFileContent = file_get_contents($theme2LangFile);
|
|
|
|
$this->assertContains(
|
2016-08-19 00:51:35 +02:00
|
|
|
" MAINTEMPLATE: 'Theme2 Main Template'\n",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme2LangFileContent
|
|
|
|
);
|
2010-10-19 00:33:41 +02:00
|
|
|
|
|
|
|
i18n::set_locale($local); //set the locale to the US locale expected in the asserts
|
2008-10-17 17:21:33 +02:00
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCollectFromEntityProvidersInCustomObject() {
|
2008-10-29 22:07:17 +01:00
|
|
|
$c = new i18nTextCollector();
|
2011-03-30 08:49:11 +02:00
|
|
|
|
|
|
|
$filePath = $this->getCurrentAbsolutePath() . '/i18nTextCollectorTestMyObject.php';
|
2008-10-29 22:07:17 +01:00
|
|
|
$matches = $c->collectFromEntityProviders($filePath);
|
|
|
|
$this->assertEquals(
|
|
|
|
array_keys($matches),
|
|
|
|
array(
|
|
|
|
'i18nTextCollectorTestMyObject.PLURALNAME',
|
|
|
|
'i18nTextCollectorTestMyObject.SINGULARNAME',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'My Object',
|
|
|
|
$matches['i18nTextCollectorTestMyObject.SINGULARNAME'][0]
|
|
|
|
);
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
/**
|
|
|
|
* Test that duplicate keys are resolved to the appropriate modules
|
|
|
|
*/
|
|
|
|
public function testResolveDuplicates() {
|
2016-06-15 06:03:16 +02:00
|
|
|
SS_ClassLoader::instance()->pushManifest($this->manifest);
|
2015-07-05 06:53:21 +02:00
|
|
|
$collector = new i18nTextCollectorTest_Collector();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Dummy data as collected
|
|
|
|
$data1 = array(
|
2016-06-15 06:03:16 +02:00
|
|
|
'i18ntestmodule' => array(
|
|
|
|
'i18nTestModule.PLURALNAME' => array('Data Objects'),
|
|
|
|
'i18nTestModule.SINGULARNAME' => array('Data Object')
|
2015-07-05 06:53:21 +02:00
|
|
|
),
|
|
|
|
'mymodule' => array(
|
2016-06-15 06:03:16 +02:00
|
|
|
'i18nTestModule.PLURALNAME' => array('Ignored String'),
|
|
|
|
'i18nTestModule.STREETNAME' => array('Shortland Street')
|
2015-07-05 06:53:21 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$expected = array(
|
2016-06-15 06:03:16 +02:00
|
|
|
'i18ntestmodule' => array(
|
|
|
|
'i18nTestModule.PLURALNAME' => array('Data Objects'),
|
|
|
|
'i18nTestModule.SINGULARNAME' => array('Data Object')
|
2015-07-05 06:53:21 +02:00
|
|
|
),
|
|
|
|
'mymodule' => array(
|
2016-06-15 06:03:16 +02:00
|
|
|
// Because this key doesn't exist in i18ntestmodule strings
|
|
|
|
'i18nTestModule.STREETNAME' => array('Shortland Street')
|
2015-07-05 06:53:21 +02:00
|
|
|
)
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
$resolved = $collector->resolveDuplicateConflicts_Test($data1);
|
|
|
|
$this->assertEquals($expected, $resolved);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Test getConflicts
|
|
|
|
$data2 = array(
|
|
|
|
'module1' => array(
|
2016-06-15 06:03:16 +02:00
|
|
|
'i18ntestmodule.ONE' => array('One'),
|
|
|
|
'i18ntestmodule.TWO' => array('Two'),
|
|
|
|
'i18ntestmodule.THREE' => array('Three'),
|
2015-07-05 06:53:21 +02:00
|
|
|
),
|
|
|
|
'module2' => array(
|
2016-06-15 06:03:16 +02:00
|
|
|
'i18ntestmodule.THREE' => array('Three'),
|
2015-07-05 06:53:21 +02:00
|
|
|
),
|
|
|
|
'module3' => array(
|
2016-06-15 06:03:16 +02:00
|
|
|
'i18ntestmodule.TWO' => array('Two'),
|
|
|
|
'i18ntestmodule.THREE' => array('Three'),
|
2015-07-05 06:53:21 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$conflictsA = $collector->getConflicts_Test($data2);
|
|
|
|
sort($conflictsA);
|
|
|
|
$this->assertEquals(
|
2016-06-15 06:03:16 +02:00
|
|
|
array('i18ntestmodule.THREE', 'i18ntestmodule.TWO'),
|
2015-07-05 06:53:21 +02:00
|
|
|
$conflictsA
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Removing module3 should remove a conflict
|
|
|
|
unset($data2['module3']);
|
|
|
|
$conflictsB = $collector->getConflicts_Test($data2);
|
|
|
|
$this->assertEquals(
|
2016-06-15 06:03:16 +02:00
|
|
|
array('i18ntestmodule.THREE'),
|
2015-07-05 06:53:21 +02:00
|
|
|
$conflictsB
|
|
|
|
);
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
/**
|
|
|
|
* Test ability for textcollector to detect modules
|
|
|
|
*/
|
|
|
|
public function testModuleDetection() {
|
2016-06-15 06:03:16 +02:00
|
|
|
SS_ClassLoader::instance()->pushManifest($this->manifest);
|
2015-07-05 06:53:21 +02:00
|
|
|
$collector = new i18nTextCollectorTest_Collector();
|
|
|
|
$modules = $collector->getModules_Test($this->alternateBasePath);
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'i18nnonstandardmodule',
|
|
|
|
'i18nothermodule',
|
|
|
|
'i18ntestmodule',
|
|
|
|
'themes/testtheme1',
|
|
|
|
'themes/testtheme2'
|
|
|
|
),
|
|
|
|
$modules
|
|
|
|
);
|
2016-06-15 06:03:16 +02:00
|
|
|
|
|
|
|
$this->assertEquals('i18ntestmodule', $collector->findModuleForClass_Test('i18nTestNamespacedClass'));
|
|
|
|
$this->assertEquals(
|
|
|
|
'i18ntestmodule',
|
|
|
|
$collector->findModuleForClass_Test('i18nTest\\i18nTestNamespacedClass')
|
|
|
|
);
|
|
|
|
$this->assertEquals('i18ntestmodule', $collector->findModuleForClass_Test('i18nTestSubModule'));
|
2015-07-05 06:53:21 +02:00
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
/**
|
|
|
|
* Test that text collector can detect module file lists properly
|
|
|
|
*/
|
|
|
|
public function testModuleFileList() {
|
|
|
|
$collector = new i18nTextCollectorTest_Collector();
|
|
|
|
$collector->basePath = $this->alternateBasePath;
|
|
|
|
$collector->baseSavePath = $this->alternateBaseSavePath;
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Non-standard modules can't be safely filtered, so just index everything
|
|
|
|
$nonStandardFiles = $collector->getFileListForModule_Test('i18nnonstandardmodule');
|
|
|
|
$nonStandardRoot = $this->alternateBasePath . '/i18nnonstandardmodule';
|
|
|
|
$this->assertEquals(3, count($nonStandardFiles));
|
|
|
|
$this->assertArrayHasKey("{$nonStandardRoot}/_config.php", $nonStandardFiles);
|
|
|
|
$this->assertArrayHasKey("{$nonStandardRoot}/phpfile.php", $nonStandardFiles);
|
|
|
|
$this->assertArrayHasKey("{$nonStandardRoot}/template.ss", $nonStandardFiles);
|
|
|
|
|
|
|
|
// Normal module should have predictable dir structure
|
|
|
|
$testFiles = $collector->getFileListForModule_Test('i18ntestmodule');
|
|
|
|
$testRoot = $this->alternateBasePath . '/i18ntestmodule';
|
2016-06-15 06:03:16 +02:00
|
|
|
$this->assertEquals(7, count($testFiles));
|
2015-07-05 06:53:21 +02:00
|
|
|
// Code in code folder is detected
|
|
|
|
$this->assertArrayHasKey("{$testRoot}/code/i18nTestModule.php", $testFiles);
|
|
|
|
$this->assertArrayHasKey("{$testRoot}/code/subfolder/_config.php", $testFiles);
|
|
|
|
$this->assertArrayHasKey("{$testRoot}/code/subfolder/i18nTestSubModule.php", $testFiles);
|
2016-06-15 06:03:16 +02:00
|
|
|
$this->assertArrayHasKey("{$testRoot}/code/subfolder/i18nTestNamespacedClass.php", $testFiles);
|
2015-07-05 06:53:21 +02:00
|
|
|
// Templates in templates folder is detected
|
|
|
|
$this->assertArrayHasKey("{$testRoot}/templates/Includes/i18nTestModuleInclude.ss", $testFiles);
|
|
|
|
$this->assertArrayHasKey("{$testRoot}/templates/Layout/i18nTestModule.ss", $testFiles);
|
|
|
|
$this->assertArrayHasKey("{$testRoot}/templates/i18nTestModule.ss", $testFiles);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Standard modules with code in odd places should only have code in those directories detected
|
|
|
|
$otherFiles = $collector->getFileListForModule_Test('i18nothermodule');
|
|
|
|
$otherRoot = $this->alternateBasePath . '/i18nothermodule';
|
|
|
|
$this->assertEquals(3, count($otherFiles));
|
|
|
|
// Only detect well-behaved files
|
|
|
|
$this->assertArrayHasKey("{$otherRoot}/code/i18nOtherModule.php", $otherFiles);
|
|
|
|
$this->assertArrayHasKey("{$otherRoot}/code/i18nTestModuleDecorator.php", $otherFiles);
|
|
|
|
$this->assertArrayHasKey("{$otherRoot}/templates/i18nOtherModule.ss", $otherFiles);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Themes should detect all ss files only
|
|
|
|
$theme1Files = $collector->getFileListForModule_Test('themes/testtheme1');
|
|
|
|
$theme1Root = $this->alternateBasePath . '/themes/testtheme1/templates';
|
|
|
|
$this->assertEquals(3, count($theme1Files));
|
|
|
|
// Find only ss files
|
|
|
|
$this->assertArrayHasKey("{$theme1Root}/Includes/i18nTestTheme1Include.ss", $theme1Files);
|
|
|
|
$this->assertArrayHasKey("{$theme1Root}/Layout/i18nTestTheme1.ss", $theme1Files);
|
|
|
|
$this->assertArrayHasKey("{$theme1Root}/i18nTestTheme1Main.ss", $theme1Files);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Only 1 file here
|
|
|
|
$theme2Files = $collector->getFileListForModule_Test('themes/testtheme2');
|
|
|
|
$this->assertEquals(1, count($theme2Files));
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
$this->alternateBasePath . '/themes/testtheme2/templates/i18nTestTheme2.ss',
|
|
|
|
$theme2Files
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assist with testing of specific protected methods
|
|
|
|
*/
|
|
|
|
class i18nTextCollectorTest_Collector extends i18nTextCollector implements TestOnly {
|
|
|
|
public function getModules_Test($directory) {
|
|
|
|
return $this->getModules($directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function resolveDuplicateConflicts_Test($entitiesByModule) {
|
|
|
|
return $this->resolveDuplicateConflicts($entitiesByModule);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFileListForModule_Test($module) {
|
2016-06-15 06:03:16 +02:00
|
|
|
return $this->getFileListForModule($module);
|
2015-07-05 06:53:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getConflicts_Test($entitiesByModule) {
|
2016-06-15 06:03:16 +02:00
|
|
|
return $this->getConflicts($entitiesByModule);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function findModuleForClass_Test($class) {
|
|
|
|
return $this->findModuleForClass($class);
|
2015-07-05 06:53:21 +02:00
|
|
|
}
|
2008-10-29 22:07:17 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
}
|