2008-10-17 17:21:33 +02:00
|
|
|
<?php
|
2016-07-13 14:36:52 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\i18n\Tests;
|
|
|
|
|
2017-01-18 04:58:48 +01:00
|
|
|
use PHPUnit_Framework_Error_Notice;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Assets\Filesystem;
|
2017-03-14 03:20:51 +01:00
|
|
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\i18n\i18n;
|
2017-01-18 04:58:48 +01:00
|
|
|
use SilverStripe\i18n\TextCollection\i18nTextCollector;
|
|
|
|
use SilverStripe\i18n\Messages\YamlWriter;
|
2016-10-14 03:30:05 +02:00
|
|
|
use SilverStripe\i18n\Tests\i18nTextCollectorTest\Collector;
|
2016-07-13 14:36:52 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class i18nTextCollectorTest extends SapphireTest
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
use i18nTestManifest;
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-18 04:58:48 +01:00
|
|
|
* @var string
|
2016-12-16 05:34:21 +01:00
|
|
|
*/
|
2017-01-18 04:58:48 +01:00
|
|
|
protected $alternateBaseSavePath = null;
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2017-03-24 04:00:54 +01:00
|
|
|
protected function setUp()
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2017-01-18 04:58:48 +01:00
|
|
|
$this->setupManifest();
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2017-01-18 04:58:48 +01:00
|
|
|
$this->alternateBaseSavePath = TEMP_FOLDER . DIRECTORY_SEPARATOR . 'i18nTextCollectorTest_webroot';
|
2016-12-16 05:34:21 +01:00
|
|
|
Filesystem::makeFolder($this->alternateBaseSavePath);
|
|
|
|
}
|
|
|
|
|
2017-03-24 04:00:54 +01:00
|
|
|
protected function tearDown()
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
if (is_dir($this->alternateBaseSavePath)) {
|
|
|
|
Filesystem::removeFolder($this->alternateBaseSavePath);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2017-01-18 04:58:48 +01:00
|
|
|
|
|
|
|
$this->tearDownManifest();
|
2016-12-16 05:34:21 +01:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConcatenationInEntityValues()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-03-14 03:20:51 +01:00
|
|
|
$module = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$php = <<<PHP
|
2009-07-09 03:02:43 +02:00
|
|
|
_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;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
2017-01-25 04:35:13 +01:00
|
|
|
'Test.CONCATENATED' => [
|
|
|
|
'default' => "Line 1 and Line '2' and Line \"3\"",
|
|
|
|
'comment' => 'Comment'
|
|
|
|
],
|
2017-01-18 04:58:48 +01:00
|
|
|
'Test.CONCATENATED2' => "Line \"4\" and Line 5"
|
|
|
|
),
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $module)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollectFromNewTemplateSyntaxUsingParserSubclass()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-01-25 04:35:13 +01:00
|
|
|
$c->setWarnOnEmptyDefault(false);
|
2017-03-14 03:20:51 +01:00
|
|
|
$mymodule = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2017-01-25 04:35:13 +01:00
|
|
|
|
2017-01-18 04:58:48 +01:00
|
|
|
$html = <<<SS
|
|
|
|
<% _t('Test.SINGLEQUOTE','Single Quote'); %>
|
2012-04-16 07:24:48 +02:00
|
|
|
<%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" %>
|
2017-01-25 04:35:13 +01:00
|
|
|
<%t i18nTestModule.INJECTIONS_9 "An item|{count} items" is "Test Pluralisation" count=4 %>
|
2012-04-16 07:24:48 +02:00
|
|
|
SS;
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, null, $mymodule);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[
|
|
|
|
'Test.SINGLEQUOTE' => 'Single Quote',
|
|
|
|
'i18nTestModule.NEWMETHODSIG' => "New _t method signature test",
|
|
|
|
'i18nTestModule.INJECTIONS_0' => "Hello {name} {greeting}, and {goodbye}",
|
|
|
|
'i18nTestModule.INJECTIONS_1' => "Hello {name} {greeting}, and {goodbye}",
|
2017-01-25 04:35:13 +01:00
|
|
|
'i18nTestModule.INJECTIONS_2' => [
|
|
|
|
'default' => "Hello {name} {greeting}",
|
|
|
|
'comment' => 'context (ignored)',
|
|
|
|
],
|
|
|
|
'i18nTestModule.INJECTIONS_9' => [
|
|
|
|
'one' => 'An item',
|
|
|
|
'other' => '{count} items',
|
|
|
|
'comment' => 'Test Pluralisation'
|
|
|
|
],
|
2017-01-18 04:58:48 +01:00
|
|
|
],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
2017-01-25 04:35:13 +01:00
|
|
|
|
|
|
|
// Test warning is raised on empty default
|
|
|
|
$c->setWarnOnEmptyDefault(true);
|
|
|
|
$this->setExpectedException(
|
|
|
|
PHPUnit_Framework_Error_Notice::class,
|
|
|
|
'Missing localisation default for key i18nTestModule.INJECTIONS_3'
|
|
|
|
);
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, null, $mymodule);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollectFromTemplateSimple()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-03-14 03:20:51 +01:00
|
|
|
$mymodule = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$html = <<<SS
|
2008-10-17 17:21:33 +02:00
|
|
|
<% _t('Test.SINGLEQUOTE','Single Quote'); %>
|
|
|
|
SS;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.SINGLEQUOTE' => 'Single Quote' ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$html = <<<SS
|
2008-10-17 17:21:33 +02:00
|
|
|
<% _t( "Test.DOUBLEQUOTE", "Double Quote and Spaces" ); %>
|
|
|
|
SS;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.DOUBLEQUOTE' => "Double Quote and Spaces" ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$html = <<<SS
|
2008-10-17 17:21:33 +02:00
|
|
|
<% _t("Test.NOSEMICOLON","No Semicolon") %>
|
|
|
|
SS;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.NOSEMICOLON' => "No Semicolon" ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollectFromTemplateAdvanced()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-01-25 04:35:13 +01:00
|
|
|
$c->setWarnOnEmptyDefault(false);
|
2017-03-14 03:20:51 +01:00
|
|
|
$mymodule = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$html = <<<SS
|
2008-10-17 17:21:33 +02:00
|
|
|
<% _t(
|
|
|
|
'NEWLINES',
|
|
|
|
'New Lines'
|
|
|
|
) %>
|
|
|
|
SS;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.NEWLINES' => "New Lines" ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, 'Test', $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$html = <<<SS
|
2008-10-17 17:21:33 +02:00
|
|
|
<% _t(
|
|
|
|
'Test.PRIOANDCOMMENT',
|
|
|
|
' Prio and Value with "Double Quotes"',
|
|
|
|
'Comment with "Double Quotes"'
|
|
|
|
) %>
|
|
|
|
SS;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-25 04:35:13 +01:00
|
|
|
[ 'Test.PRIOANDCOMMENT' => [
|
|
|
|
'default' => ' Prio and Value with "Double Quotes"',
|
|
|
|
'comment' => 'Comment with "Double Quotes"',
|
|
|
|
]],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, 'Test', $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$html = <<<SS
|
2008-10-17 17:21:33 +02:00
|
|
|
<% _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;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-25 04:35:13 +01:00
|
|
|
[ 'Test.PRIOANDCOMMENT' => [
|
|
|
|
'default' => " Prio and Value with 'Single Quotes'",
|
|
|
|
'comment' => "Comment with 'Single Quotes'",
|
|
|
|
]],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, 'Test', $mymodule)
|
2017-01-25 04:35:13 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Test empty
|
|
|
|
$html = <<<SS
|
|
|
|
<% _t('Test.PRIOANDCOMMENT') %>
|
|
|
|
SS;
|
|
|
|
$this->assertEquals(
|
|
|
|
[],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
2017-01-25 04:35:13 +01:00
|
|
|
|
|
|
|
// Test warning is raised on empty default
|
|
|
|
$c->setWarnOnEmptyDefault(true);
|
|
|
|
$this->setExpectedException(
|
|
|
|
PHPUnit_Framework_Error_Notice::class,
|
|
|
|
'Missing localisation default for key Test.PRIOANDCOMMENT'
|
|
|
|
);
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromTemplate($html, 'Test', $mymodule);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2008-10-17 17:21:33 +02:00
|
|
|
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testCollectFromCodeSimple()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-03-14 03:20:51 +01:00
|
|
|
$mymodule = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$php = <<<PHP
|
2008-10-17 17:21:33 +02:00
|
|
|
_t('Test.SINGLEQUOTE','Single Quote');
|
|
|
|
PHP;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.SINGLEQUOTE' => 'Single Quote' ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$php = <<<PHP
|
2008-10-17 17:21:33 +02:00
|
|
|
_t( "Test.DOUBLEQUOTE", "Double Quote and Spaces" );
|
|
|
|
PHP;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.DOUBLEQUOTE' => "Double Quote and Spaces" ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollectFromCodeAdvanced()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-03-14 03:20:51 +01:00
|
|
|
$mymodule = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$php = <<<PHP
|
2008-10-17 17:21:33 +02:00
|
|
|
_t(
|
|
|
|
'Test.NEWLINES',
|
|
|
|
'New Lines'
|
|
|
|
);
|
|
|
|
PHP;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.NEWLINES' => "New Lines" ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$php = <<<PHP
|
2008-10-17 17:21:33 +02:00
|
|
|
_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;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-25 04:35:13 +01:00
|
|
|
[
|
|
|
|
'Test.PRIOANDCOMMENT' => [
|
|
|
|
'default' => ' Value with "Double Quotes"',
|
|
|
|
'comment' => 'Comment with "Double Quotes"',
|
|
|
|
]
|
|
|
|
],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$php = <<<PHP
|
2008-10-17 17:21:33 +02:00
|
|
|
_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;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-25 04:35:13 +01:00
|
|
|
[ 'Test.PRIOANDCOMMENT' => [
|
|
|
|
'default' => " Value with 'Single Quotes'",
|
|
|
|
'comment' => "Comment with 'Single Quotes'"
|
|
|
|
] ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$php = <<<PHP
|
2008-10-17 17:21:33 +02:00
|
|
|
_t(
|
|
|
|
'Test.PRIOANDCOMMENT',
|
|
|
|
'Value with \'Escaped Single Quotes\''
|
|
|
|
);
|
|
|
|
PHP;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.PRIOANDCOMMENT' => "Value with 'Escaped Single Quotes'" ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$php = <<<PHP
|
2008-10-17 17:21:33 +02:00
|
|
|
_t(
|
|
|
|
'Test.PRIOANDCOMMENT',
|
|
|
|
"Doublequoted Value with 'Unescaped Single Quotes'"
|
2017-01-25 04:35:13 +01:00
|
|
|
|
|
|
|
|
2008-10-17 17:21:33 +02:00
|
|
|
);
|
|
|
|
PHP;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.PRIOANDCOMMENT' => "Doublequoted Value with 'Unescaped Single Quotes'"],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2017-01-26 05:20:08 +01:00
|
|
|
public function testCollectFromCodeNamespace()
|
|
|
|
{
|
|
|
|
$c = i18nTextCollector::create();
|
2017-03-14 03:20:51 +01:00
|
|
|
$mymodule = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2017-01-26 05:20:08 +01:00
|
|
|
$php = <<<PHP
|
|
|
|
<?php
|
|
|
|
namespace SilverStripe\Framework\Core;
|
|
|
|
|
|
|
|
class MyClass extends Base implements SomeService {
|
|
|
|
public function getNewLines() {
|
|
|
|
return _t(
|
|
|
|
__CLASS__.'.NEWLINES',
|
|
|
|
'New Lines'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PHP;
|
|
|
|
$this->assertEquals(
|
|
|
|
[ 'SilverStripe\\Framework\\Core\\MyClass.NEWLINES' => "New Lines" ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule)
|
2017-01-26 05:20:08 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testNewlinesInEntityValues()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-03-14 03:20:51 +01:00
|
|
|
$mymodule = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2008-11-01 19:55:27 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$php = <<<PHP
|
2008-11-01 19:55:27 +01:00
|
|
|
_t(
|
|
|
|
'Test.NEWLINESINGLEQUOTE',
|
|
|
|
'Line 1
|
|
|
|
Line 2'
|
|
|
|
);
|
|
|
|
PHP;
|
2009-11-21 02:43:54 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$eol = PHP_EOL;
|
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.NEWLINESINGLEQUOTE' => "Line 1{$eol}Line 2" ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
2008-11-01 19:55:27 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$php = <<<PHP
|
2008-11-01 19:55:27 +01:00
|
|
|
_t(
|
|
|
|
'Test.NEWLINEDOUBLEQUOTE',
|
|
|
|
"Line 1
|
|
|
|
Line 2"
|
|
|
|
);
|
|
|
|
PHP;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[ 'Test.NEWLINEDOUBLEQUOTE' => "Line 1{$eol}Line 2" ],
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test extracting entities from the new _t method signature
|
|
|
|
*/
|
|
|
|
public function testCollectFromCodeNewSignature()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-01-25 04:35:13 +01:00
|
|
|
$c->setWarnOnEmptyDefault(false); // Disable warnings for tests
|
2017-03-14 03:20:51 +01:00
|
|
|
$mymodule = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$php = <<<PHP
|
2012-04-16 07:24:48 +02:00
|
|
|
_t('i18nTestModule.NEWMETHODSIG',"New _t method signature test");
|
2012-09-26 23:34:00 +02:00
|
|
|
_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"));
|
2017-01-25 04:35:13 +01:00
|
|
|
_t('i18nTestModule.INJECTIONS4', array("name"=>"Cat", "greeting"=>"meow", "goodbye"=>"meow"));
|
2013-05-05 02:19:31 +02:00
|
|
|
_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"]);
|
2017-01-25 04:35:13 +01:00
|
|
|
_t('i18nTestModule.INJECTIONS8', ["name"=>"Cat", "greeting"=>"meow", "goodbye"=>"meow"]);
|
|
|
|
_t('i18nTestModule.INJECTIONS9', "An item|{count} items", ['count' => 4], "Test Pluralisation");
|
2012-04-16 07:24:48 +02:00
|
|
|
PHP;
|
|
|
|
|
2017-03-14 03:20:51 +01:00
|
|
|
$collectedTranslatables = $c->collectFromCode($php, null, $mymodule);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2017-01-18 04:58:48 +01:00
|
|
|
$expectedArray = [
|
|
|
|
'i18nTestModule.INJECTIONS2' => "Hello {name} {greeting}. But it is late, {goodbye}",
|
2017-01-25 04:35:13 +01:00
|
|
|
'i18nTestModule.INJECTIONS3' => [
|
|
|
|
'default' => "Hello {name} {greeting}. But it is late, {goodbye}",
|
|
|
|
'comment' => 'New context (this should be ignored)'
|
|
|
|
],
|
2017-01-18 04:58:48 +01:00
|
|
|
'i18nTestModule.INJECTIONS6' => "Hello {name} {greeting}. But it is late, {goodbye}",
|
2017-01-25 04:35:13 +01:00
|
|
|
'i18nTestModule.INJECTIONS7' => [
|
|
|
|
'default' => "Hello {name} {greeting}. But it is late, {goodbye}",
|
|
|
|
'comment' => "New context (this should be ignored)",
|
|
|
|
],
|
|
|
|
'i18nTestModule.INJECTIONS9' => [
|
|
|
|
'one' => 'An item',
|
|
|
|
'other' => '{count} items',
|
|
|
|
'comment' => 'Test Pluralisation',
|
|
|
|
],
|
2017-01-18 04:58:48 +01:00
|
|
|
'i18nTestModule.NEWMETHODSIG' => "New _t method signature test",
|
|
|
|
];
|
|
|
|
$this->assertEquals($expectedArray, $collectedTranslatables);
|
|
|
|
|
2017-01-25 04:35:13 +01:00
|
|
|
// Test warning is raised on empty default
|
2017-01-18 04:58:48 +01:00
|
|
|
$this->setExpectedException(
|
|
|
|
PHPUnit_Framework_Error_Notice::class,
|
|
|
|
'Missing localisation default for key i18nTestModule.INJECTIONS4'
|
|
|
|
);
|
|
|
|
$php = <<<PHP
|
|
|
|
_t('i18nTestModule.INJECTIONS4', array("name"=>"Cat", "greeting"=>"meow", "goodbye"=>"meow"));
|
|
|
|
PHP;
|
2017-01-25 04:35:13 +01:00
|
|
|
$c->setWarnOnEmptyDefault(true);
|
2017-03-14 03:20:51 +01:00
|
|
|
$c->collectFromCode($php, null, $mymodule);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
2017-01-18 04:58:48 +01:00
|
|
|
public function testUncollectableCode()
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-03-14 03:20:51 +01:00
|
|
|
$mymodule = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2017-01-18 04:58:48 +01:00
|
|
|
|
|
|
|
$php = <<<PHP
|
|
|
|
_t(static::class.'.KEY1', 'Default');
|
|
|
|
_t(self::class.'.KEY2', 'Default');
|
|
|
|
_t(__CLASS__.'.KEY3', 'Default');
|
|
|
|
_t('Collectable.KEY4', 'Default');
|
|
|
|
PHP;
|
|
|
|
|
2017-03-14 03:20:51 +01:00
|
|
|
$collectedTranslatables = $c->collectFromCode($php, null, $mymodule);
|
2017-01-18 04:58:48 +01:00
|
|
|
|
|
|
|
// Only one item is collectable
|
|
|
|
$expectedArray = [ 'Collectable.KEY4' => 'Default' ];
|
|
|
|
$this->assertEquals($expectedArray, $collectedTranslatables);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollectFromIncludedTemplates()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-01-25 04:35:13 +01:00
|
|
|
$c->setWarnOnEmptyDefault(false); // Disable warnings for tests
|
2017-03-14 03:20:51 +01:00
|
|
|
$mymodule = ModuleLoader::instance()->getManifest()->getModule('i18ntestmodule');
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$templateFilePath = $this->alternateBasePath . '/i18ntestmodule/templates/Layout/i18nTestModule.ss';
|
|
|
|
$html = file_get_contents($templateFilePath);
|
2017-03-14 03:20:51 +01:00
|
|
|
$matches = $c->collectFromTemplate($html, $templateFilePath, $mymodule);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2017-03-14 03:20:51 +01:00
|
|
|
$this->assertArrayHasKey('i18nTestModule.ss.LAYOUTTEMPLATENONAMESPACE', $matches);
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
'Layout Template no namespace',
|
2017-03-14 03:20:51 +01:00
|
|
|
$matches['i18nTestModule.ss.LAYOUTTEMPLATENONAMESPACE']
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
2017-03-14 03:20:51 +01:00
|
|
|
$this->assertArrayHasKey('i18nTestModule.ss.SPRINTFNONAMESPACE', $matches);
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
'My replacement no namespace: %s',
|
2017-03-14 03:20:51 +01:00
|
|
|
$matches['i18nTestModule.ss.SPRINTFNONAMESPACE']
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
$this->assertArrayHasKey('i18nTestModule.LAYOUTTEMPLATE', $matches);
|
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
'Layout Template',
|
|
|
|
$matches['i18nTestModule.LAYOUTTEMPLATE']
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
$this->assertArrayHasKey('i18nTestModule.SPRINTFNAMESPACE', $matches);
|
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
'My replacement: %s',
|
|
|
|
$matches['i18nTestModule.SPRINTFNAMESPACE']
|
2016-12-16 05:34:21 +01: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollectMergesWithExisting()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-01-25 04:35:13 +01:00
|
|
|
$c->setWarnOnEmptyDefault(false);
|
2017-01-18 04:58:48 +01:00
|
|
|
$c->setWriter(new YamlWriter());
|
2016-12-16 05:34:21 +01:00
|
|
|
$c->basePath = $this->alternateBasePath;
|
|
|
|
$c->baseSavePath = $this->alternateBaseSavePath;
|
|
|
|
|
|
|
|
$entitiesByModule = $c->collect(null, true /* merge */);
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
'i18nTestModule.ENTITY',
|
|
|
|
$entitiesByModule['i18ntestmodule'],
|
|
|
|
'Retains existing entities'
|
|
|
|
);
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
'i18nTestModule.NEWENTITY',
|
|
|
|
$entitiesByModule['i18ntestmodule'],
|
|
|
|
'Adds new entities'
|
|
|
|
);
|
2017-01-18 04:58:48 +01:00
|
|
|
|
|
|
|
// Test cross-module strings are set correctly
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
'i18nProviderClass.OTHER_MODULE',
|
|
|
|
$entitiesByModule['i18ntestmodule']
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2017-01-25 04:35:13 +01:00
|
|
|
[
|
|
|
|
'comment' => 'Test string in another module',
|
|
|
|
'default' => 'i18ntestmodule string defined in i18nothermodule',
|
|
|
|
],
|
2017-01-18 04:58:48 +01:00
|
|
|
$entitiesByModule['i18ntestmodule']['i18nProviderClass.OTHER_MODULE']
|
|
|
|
);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollectFromFilesystemAndWriteMasterTables()
|
|
|
|
{
|
|
|
|
i18n::set_locale('en_US'); //set the locale to the US locale expected in the asserts
|
|
|
|
i18n::config()->update('default_locale', 'en_US');
|
2017-01-25 04:35:13 +01:00
|
|
|
i18n::config()->update('missing_default_warning', false);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-01-25 04:35:13 +01:00
|
|
|
$c->setWarnOnEmptyDefault(false);
|
2017-01-18 04:58:48 +01:00
|
|
|
$c->setWriter(new YamlWriter());
|
2016-12-16 05:34:21 +01:00
|
|
|
$c->basePath = $this->alternateBasePath;
|
|
|
|
$c->baseSavePath = $this->alternateBaseSavePath;
|
|
|
|
|
|
|
|
$c->run();
|
|
|
|
|
|
|
|
// i18ntestmodule
|
|
|
|
$moduleLangFile = "{$this->alternateBaseSavePath}/i18ntestmodule/lang/" . $c->getDefaultLocale() . '.yml';
|
|
|
|
$this->assertTrue(
|
|
|
|
file_exists($moduleLangFile),
|
|
|
|
'Master language file can be written to modules /lang folder'
|
|
|
|
);
|
|
|
|
|
|
|
|
$moduleLangFileContent = file_get_contents($moduleLangFile);
|
|
|
|
$this->assertContains(
|
|
|
|
" ADDITION: Addition\n",
|
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
" ENTITY: 'Entity with \"Double Quotes\"'\n",
|
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
" MAINTEMPLATE: 'Main Template'\n",
|
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
" OTHERENTITY: 'Other Entity'\n",
|
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
" WITHNAMESPACE: 'Include Entity with Namespace'\n",
|
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
" NONAMESPACE: 'Include Entity without Namespace'\n",
|
|
|
|
$moduleLangFileContent
|
|
|
|
);
|
|
|
|
|
|
|
|
// i18nothermodule
|
|
|
|
$otherModuleLangFile = "{$this->alternateBaseSavePath}/i18nothermodule/lang/" . $c->getDefaultLocale() . '.yml';
|
|
|
|
$this->assertTrue(
|
|
|
|
file_exists($otherModuleLangFile),
|
|
|
|
'Master language file can be written to modules /lang folder'
|
|
|
|
);
|
|
|
|
$otherModuleLangFileContent = file_get_contents($otherModuleLangFile);
|
|
|
|
$this->assertContains(
|
|
|
|
" ENTITY: 'Other Module Entity'\n",
|
|
|
|
$otherModuleLangFileContent
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
" MAINTEMPLATE: 'Main Template Other Module'\n",
|
|
|
|
$otherModuleLangFileContent
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCollectFromEntityProvidersInCustomObject()
|
|
|
|
{
|
2017-01-18 04:58:48 +01:00
|
|
|
// note: Disable _fakewebroot manifest for this test
|
|
|
|
$this->popManifests();
|
2016-12-16 05:34:21 +01:00
|
|
|
|
2017-01-18 04:58:48 +01:00
|
|
|
$c = i18nTextCollector::create();
|
2017-01-25 04:35:13 +01:00
|
|
|
|
|
|
|
// Collect from MyObject.php
|
2016-12-16 05:34:21 +01:00
|
|
|
$filePath = __DIR__ . '/i18nTest/MyObject.php';
|
|
|
|
$matches = $c->collectFromEntityProviders($filePath);
|
|
|
|
$this->assertEquals(
|
2017-01-18 04:58:48 +01:00
|
|
|
[
|
|
|
|
'SilverStripe\Admin\LeftAndMain.OTHER_TITLE' => [
|
|
|
|
'default' => 'Other title',
|
|
|
|
'module' => 'admin',
|
|
|
|
],
|
|
|
|
'SilverStripe\i18n\Tests\i18nTest\MyObject.PLURALNAME' => 'My Objects',
|
|
|
|
'SilverStripe\i18n\Tests\i18nTest\MyObject.PLURALS' => [
|
|
|
|
'one' => 'A My Object',
|
|
|
|
'other' => '{count} My Objects',
|
|
|
|
],
|
|
|
|
'SilverStripe\i18n\Tests\i18nTest\MyObject.SINGULARNAME' => 'My Object',
|
|
|
|
],
|
|
|
|
$matches
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-25 04:35:13 +01:00
|
|
|
public function testCollectFromEntityProvidersInWebRoot()
|
|
|
|
{
|
|
|
|
// Collect from i18nProviderClass
|
|
|
|
$c = i18nTextCollector::create();
|
|
|
|
$c->setWarnOnEmptyDefault(false);
|
|
|
|
$c->setWriter(new YamlWriter());
|
|
|
|
$c->basePath = $this->alternateBasePath;
|
|
|
|
$c->baseSavePath = $this->alternateBaseSavePath;
|
|
|
|
$entitiesByModule = $c->collect(null, false);
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
'comment' => 'Plural forms for the test class',
|
|
|
|
'one' => 'A class',
|
|
|
|
'other' => '{count} classes',
|
|
|
|
],
|
|
|
|
$entitiesByModule['i18nothermodule']['i18nProviderClass.PLURALS']
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'My Provider Class',
|
|
|
|
$entitiesByModule['i18nothermodule']['i18nProviderClass.TITLE']
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
'comment' => 'Test string in another module',
|
|
|
|
'default' => 'i18ntestmodule string defined in i18nothermodule',
|
|
|
|
],
|
|
|
|
$entitiesByModule['i18ntestmodule']['i18nProviderClass.OTHER_MODULE']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* Test that duplicate keys are resolved to the appropriate modules
|
|
|
|
*/
|
|
|
|
public function testResolveDuplicates()
|
|
|
|
{
|
|
|
|
$collector = new Collector();
|
|
|
|
|
|
|
|
// Dummy data as collected
|
2017-01-18 04:58:48 +01:00
|
|
|
$data1 = [
|
|
|
|
'i18ntestmodule' => [
|
|
|
|
'i18nTestModule.PLURALNAME' => 'Data Objects',
|
|
|
|
'i18nTestModule.SINGULARNAME' => 'Data Object',
|
|
|
|
],
|
|
|
|
'mymodule' => [
|
|
|
|
'i18nTestModule.PLURALNAME' => 'Ignored String',
|
|
|
|
'i18nTestModule.STREETNAME' => 'Shortland Street',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$expected = [
|
|
|
|
'i18ntestmodule' => [
|
|
|
|
'i18nTestModule.PLURALNAME' => 'Data Objects',
|
|
|
|
'i18nTestModule.SINGULARNAME' => 'Data Object',
|
|
|
|
],
|
|
|
|
'mymodule' => [
|
|
|
|
// Removed PLURALNAME because this key doesn't exist in i18ntestmodule strings
|
|
|
|
'i18nTestModule.STREETNAME' => 'Shortland Street'
|
|
|
|
]
|
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$resolved = $collector->resolveDuplicateConflicts_Test($data1);
|
|
|
|
$this->assertEquals($expected, $resolved);
|
|
|
|
|
|
|
|
// Test getConflicts
|
2017-01-18 04:58:48 +01:00
|
|
|
$data2 = [
|
|
|
|
'module1' => [
|
|
|
|
'i18ntestmodule.ONE' => 'One',
|
|
|
|
'i18ntestmodule.TWO' => 'Two',
|
|
|
|
'i18ntestmodule.THREE' => 'Three',
|
|
|
|
],
|
|
|
|
'module2' => [
|
|
|
|
'i18ntestmodule.THREE' => 'Three',
|
|
|
|
],
|
|
|
|
'module3' => [
|
|
|
|
'i18ntestmodule.TWO' => 'Two',
|
|
|
|
'i18ntestmodule.THREE' => 'Three',
|
|
|
|
],
|
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
$conflictsA = $collector->getConflicts_Test($data2);
|
|
|
|
sort($conflictsA);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('i18ntestmodule.THREE', 'i18ntestmodule.TWO'),
|
|
|
|
$conflictsA
|
|
|
|
);
|
|
|
|
|
|
|
|
// Removing module3 should remove a conflict
|
|
|
|
unset($data2['module3']);
|
|
|
|
$conflictsB = $collector->getConflicts_Test($data2);
|
|
|
|
$this->assertEquals(
|
|
|
|
array('i18ntestmodule.THREE'),
|
|
|
|
$conflictsB
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test ability for textcollector to detect modules
|
|
|
|
*/
|
|
|
|
public function testModuleDetection()
|
|
|
|
{
|
|
|
|
$collector = new Collector();
|
2017-03-14 03:20:51 +01:00
|
|
|
$modules = ModuleLoader::instance()->getManifest()->getModules();
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'i18nnonstandardmodule',
|
|
|
|
'i18ntestmodule',
|
2017-03-14 03:20:51 +01:00
|
|
|
'i18nothermodule'
|
2016-12-16 05:34:21 +01:00
|
|
|
),
|
2017-03-14 03:20:51 +01:00
|
|
|
array_keys($modules)
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals('i18ntestmodule', $collector->findModuleForClass_Test('i18nTestNamespacedClass'));
|
|
|
|
$this->assertEquals(
|
|
|
|
'i18ntestmodule',
|
|
|
|
$collector->findModuleForClass_Test('i18nTest\\i18nTestNamespacedClass')
|
|
|
|
);
|
|
|
|
$this->assertEquals('i18ntestmodule', $collector->findModuleForClass_Test('i18nTestSubModule'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that text collector can detect module file lists properly
|
|
|
|
*/
|
|
|
|
public function testModuleFileList()
|
|
|
|
{
|
|
|
|
$collector = new Collector();
|
|
|
|
$collector->basePath = $this->alternateBasePath;
|
|
|
|
$collector->baseSavePath = $this->alternateBaseSavePath;
|
|
|
|
|
|
|
|
// 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(7, 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);
|
|
|
|
$this->assertArrayHasKey("{$testRoot}/code/subfolder/i18nTestNamespacedClass.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);
|
|
|
|
|
|
|
|
// Standard modules with code in odd places should only have code in those directories detected
|
|
|
|
$otherFiles = $collector->getFileListForModule_Test('i18nothermodule');
|
|
|
|
$otherRoot = $this->alternateBasePath . '/i18nothermodule';
|
2017-01-18 04:58:48 +01:00
|
|
|
$this->assertEquals(4, count($otherFiles));
|
2016-12-16 05:34:21 +01:00
|
|
|
// Only detect well-behaved files
|
|
|
|
$this->assertArrayHasKey("{$otherRoot}/code/i18nOtherModule.php", $otherFiles);
|
2017-01-18 04:58:48 +01:00
|
|
|
$this->assertArrayHasKey("{$otherRoot}/code/i18nProviderClass.php", $otherFiles);
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertArrayHasKey("{$otherRoot}/code/i18nTestModuleDecorator.php", $otherFiles);
|
|
|
|
$this->assertArrayHasKey("{$otherRoot}/templates/i18nOtherModule.ss", $otherFiles);
|
|
|
|
}
|
2015-07-05 06:53:21 +02:00
|
|
|
}
|