2008-10-17 17:21:33 +02:00
|
|
|
<?php
|
|
|
|
/**
|
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";
|
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
|
|
|
|
2012-11-02 08:28:39 +01:00
|
|
|
$manifest = new SS_TemplateManifest($this->alternateBasePath, null, false, true);
|
2011-03-23 04:43:50 +01:00
|
|
|
$manifest->regenerate(false);
|
|
|
|
SS_TemplateLoader::instance()->pushManifest($manifest);
|
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() {
|
2011-03-23 04:43:50 +01:00
|
|
|
SS_TemplateLoader::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);
|
|
|
|
}
|
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
/**
|
|
|
|
* Input for langArrayCodeForEntitySpec() should be suitable for insertion
|
|
|
|
* into single-quoted strings, so needs to be escaped already.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testPhpWriterLangArrayCodeForEntity() {
|
2012-04-14 00:16:30 +02:00
|
|
|
$c = new i18nTextCollector_Writer_Php();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$this->assertEquals(
|
2012-04-14 00:16:30 +02:00
|
|
|
$c->langArrayCodeForEntitySpec('Test.SIMPLE', array('Simple Value'), 'en_US'),
|
|
|
|
"\$lang['en_US']['Test']['SIMPLE'] = 'Simple Value';" . PHP_EOL
|
2008-10-17 17:21:33 +02:00
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
// single quotes should be properly escaped by the parser already
|
2012-09-26 23:34:00 +02:00
|
|
|
$c->langArrayCodeForEntitySpec('Test.ESCAPEDSINGLEQUOTES',
|
|
|
|
array("Value with 'Escaped Single Quotes'"), 'en_US'),
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en_US']['Test']['ESCAPEDSINGLEQUOTES'] = 'Value with \'Escaped Single Quotes\'';" . PHP_EOL
|
2008-10-17 17:21:33 +02:00
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$this->assertEquals(
|
2012-04-14 00:16:30 +02:00
|
|
|
$c->langArrayCodeForEntitySpec('Test.DOUBLEQUOTES', array('Value with "Double Quotes"'), 'en_US'),
|
|
|
|
"\$lang['en_US']['Test']['DOUBLEQUOTES'] = 'Value with \"Double Quotes\"';" . PHP_EOL
|
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
|
2012-04-14 00:16:30 +02:00
|
|
|
\$lang['en_US']['Test']['PRIOANDCOMMENT'] = array (
|
|
|
|
0 => 'Value with \'Single Quotes\'',
|
|
|
|
1 => 'Comment with \'Single Quotes\'',
|
2008-10-17 17:21:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
2012-09-26 23:34:00 +02:00
|
|
|
$c->langArrayCodeForEntitySpec('Test.PRIOANDCOMMENT',
|
|
|
|
array("Value with 'Single Quotes'","Comment with 'Single Quotes'"), 'en_US'),
|
2008-10-17 17:21:33 +02:00
|
|
|
$php
|
|
|
|
);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$php = <<<PHP
|
2012-04-14 00:16:30 +02:00
|
|
|
\$lang['en_US']['Test']['PRIOANDCOMMENT'] = array (
|
|
|
|
0 => 'Value with "Double Quotes"',
|
|
|
|
1 => 'Comment with "Double Quotes"',
|
2008-10-17 17:21:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
2012-09-26 23:34:00 +02:00
|
|
|
$c->langArrayCodeForEntitySpec('Test.PRIOANDCOMMENT',
|
|
|
|
array('Value with "Double Quotes"','Comment with "Double Quotes"'), 'en_US'),
|
2008-10-17 17:21:33 +02:00
|
|
|
$php
|
|
|
|
);
|
|
|
|
}
|
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();
|
2013-03-21 19:48:54 +01:00
|
|
|
Config::inst()->update('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() {
|
|
|
|
$defaultlocal = i18n::default_locale();
|
|
|
|
$local = i18n::get_locale();
|
2016-01-06 00:34:58 +01:00
|
|
|
i18n::set_locale('en_US');
|
2013-06-02 20:17:28 +02:00
|
|
|
i18n::set_default_locale('en_US');
|
|
|
|
|
|
|
|
$c = new i18nTextCollector();
|
|
|
|
$c->setWriter(new i18nTextCollector_Writer_Php());
|
|
|
|
$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
|
|
|
$defaultlocal = i18n::default_locale();
|
|
|
|
$local = i18n::get_locale();
|
|
|
|
i18n::set_locale('en_US'); //set the locale to the US locale expected in the asserts
|
|
|
|
i18n::set_default_locale('en_US');
|
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
$c = new i18nTextCollector();
|
2012-04-14 00:16:30 +02:00
|
|
|
$c->setWriter(new i18nTextCollector_Writer_Php());
|
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
|
2008-10-17 17:21:33 +02:00
|
|
|
$moduleLangFile = "{$this->alternateBaseSavePath}/i18ntestmodule/lang/" . $c->getDefaultLocale() . '.php';
|
|
|
|
$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(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestModule']['ADDITION'] = 'Addition';",
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestModule']['ENTITY'] = array (
|
|
|
|
0 => 'Entity with \"Double Quotes\"',
|
|
|
|
1 => 'Comment for entity',
|
2008-11-01 23:47:02 +01:00
|
|
|
);",
|
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestModule']['MAINTEMPLATE'] = 'Main Template';",
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestModule']['OTHERENTITY'] = 'Other Entity';",
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestModule']['WITHNAMESPACE'] = 'Include Entity with Namespace';",
|
2008-11-01 23:47:02 +01:00
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestModuleInclude.ss']['NONAMESPACE'] = 'Include Entity without Namespace';",
|
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
|
2008-11-01 23:47:02 +01:00
|
|
|
$otherModuleLangFile = "{$this->alternateBaseSavePath}/i18nothermodule/lang/" . $c->getDefaultLocale() . '.php';
|
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(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nOtherModule']['ENTITY'] = 'Other Module Entity';",
|
2008-11-01 23:47:02 +01:00
|
|
|
$otherModuleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nOtherModule']['MAINTEMPLATE'] = 'Main Template Other Module';",
|
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
|
|
|
|
$theme1LangFile = "{$this->alternateBaseSavePath}/themes/testtheme1/lang/" . $c->getDefaultLocale() . '.php';
|
|
|
|
$this->assertTrue(
|
|
|
|
file_exists($theme1LangFile),
|
|
|
|
'Master theme language file can be written to themes/testtheme1 /lang folder'
|
|
|
|
);
|
|
|
|
$theme1LangFileContent = file_get_contents($theme1LangFile);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestTheme1']['MAINTEMPLATE'] = 'Theme1 Main Template';",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestTheme1']['LAYOUTTEMPLATE'] = 'Theme1 Layout Template';",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestTheme1']['SPRINTFNAMESPACE'] = 'Theme1 My replacement: %s';",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestTheme1.ss']['LAYOUTTEMPLATENONAMESPACE'] = 'Theme1 Layout Template no namespace';",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestTheme1.ss']['SPRINTFNONAMESPACE'] = 'Theme1 My replacement no namespace: %s';",
|
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(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestTheme1Include']['SPRINTFINCLUDENAMESPACE'] = 'Theme1 My include replacement: %s';",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestTheme1Include']['WITHNAMESPACE'] = 'Theme1 Include Entity with Namespace';",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestTheme1Include.ss']['NONAMESPACE'] = 'Theme1 Include Entity without Namespace';",
|
2010-11-18 20:00:13 +01:00
|
|
|
$theme1LangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
2012-09-26 23:34:00 +02:00
|
|
|
"\$lang['en']['i18nTestTheme1Include.ss']['SPRINTFINCLUDENONAMESPACE'] ="
|
|
|
|
. " 'Theme1 My include replacement no namespace: %s';",
|
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
|
|
|
|
$theme2LangFile = "{$this->alternateBaseSavePath}/themes/testtheme2/lang/" . $c->getDefaultLocale() . '.php';
|
|
|
|
$this->assertTrue(
|
|
|
|
file_exists($theme2LangFile),
|
|
|
|
'Master theme language file can be written to themes/testtheme2 /lang folder'
|
|
|
|
);
|
|
|
|
$theme2LangFileContent = file_get_contents($theme2LangFile);
|
|
|
|
$this->assertContains(
|
2012-04-14 00:16:30 +02:00
|
|
|
"\$lang['en']['i18nTestTheme2']['MAINTEMPLATE'] = 'Theme2 Main Template';",
|
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
|
2012-09-26 23:34:00 +02:00
|
|
|
i18n::set_default_locale($defaultlocal);
|
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() {
|
|
|
|
$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(
|
|
|
|
'framework' => array(
|
|
|
|
'DataObject.PLURALNAME' => array('Data Objects'),
|
|
|
|
'DataObject.SINGULARNAME' => array('Data Object')
|
|
|
|
),
|
|
|
|
'mymodule' => array(
|
|
|
|
'DataObject.PLURALNAME' => array('Ignored String'),
|
|
|
|
'DataObject.STREETNAME' => array('Shortland Street')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'framework' => array(
|
|
|
|
'DataObject.PLURALNAME' => array('Data Objects'),
|
|
|
|
// Because DataObject is in framework module
|
|
|
|
'DataObject.SINGULARNAME' => array('Data Object')
|
|
|
|
),
|
|
|
|
'mymodule' => array(
|
|
|
|
// Because this key doesn't exist in framework strings
|
|
|
|
'DataObject.STREETNAME' => array('Shortland Street')
|
|
|
|
)
|
|
|
|
);
|
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(
|
|
|
|
'DataObject.ONE' => array('One'),
|
|
|
|
'DataObject.TWO' => array('Two'),
|
|
|
|
'DataObject.THREE' => array('Three'),
|
|
|
|
),
|
|
|
|
'module2' => array(
|
|
|
|
'DataObject.THREE' => array('Three'),
|
|
|
|
),
|
|
|
|
'module3' => array(
|
|
|
|
'DataObject.TWO' => array('Two'),
|
|
|
|
'DataObject.THREE' => array('Three'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$conflictsA = $collector->getConflicts_Test($data2);
|
|
|
|
sort($conflictsA);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('DataObject.THREE', 'DataObject.TWO'),
|
|
|
|
$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(
|
|
|
|
array('DataObject.THREE'),
|
|
|
|
$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() {
|
|
|
|
$collector = new i18nTextCollectorTest_Collector();
|
|
|
|
$modules = $collector->getModules_Test($this->alternateBasePath);
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'i18nnonstandardmodule',
|
|
|
|
'i18nothermodule',
|
|
|
|
'i18ntestmodule',
|
|
|
|
'themes/testtheme1',
|
|
|
|
'themes/testtheme2'
|
|
|
|
),
|
|
|
|
$modules
|
|
|
|
);
|
|
|
|
}
|
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';
|
|
|
|
$this->assertEquals(6, count($testFiles));
|
|
|
|
// 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);
|
|
|
|
// 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) {
|
|
|
|
return parent::getFileListForModule($module);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getConflicts_Test($entitiesByModule) {
|
|
|
|
return parent::getConflicts($entitiesByModule);
|
|
|
|
}
|
2008-10-29 22:07:17 +01:00
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
}
|