init
This commit is contained in:
+116
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Setup\Module\I18n\Dictionary;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
use Magento\Setup\Module\I18n\Dictionary\Generator;
|
||||
use Magento\Setup\Module\I18n\ServiceLocator;
|
||||
|
||||
class GeneratorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $testDir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $expectedDir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $outputFileName;
|
||||
|
||||
/**
|
||||
* @var \Magento\Setup\Module\I18n\Dictionary\Generator
|
||||
*/
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $backupRegistrar;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(\Magento\Framework\Component\ComponentRegistrar::class);
|
||||
$paths = $reflection->getProperty('paths');
|
||||
$paths->setAccessible(true);
|
||||
$this->backupRegistrar = $paths->getValue();
|
||||
$paths->setValue(null, ['module' => [], 'theme' => []]);
|
||||
$paths->setAccessible(false);
|
||||
|
||||
$this->testDir = realpath(__DIR__ . '/_files');
|
||||
$this->expectedDir = $this->testDir . '/expected';
|
||||
$this->source = $this->testDir . '/source';
|
||||
$this->outputFileName = $this->testDir . '/translate.csv';
|
||||
|
||||
// Register the test modules
|
||||
ComponentRegistrar::register(
|
||||
ComponentRegistrar::MODULE,
|
||||
'Magento_FirstModule',
|
||||
$this->source . '/app/code/Magento/FirstModule'
|
||||
);
|
||||
ComponentRegistrar::register(
|
||||
ComponentRegistrar::MODULE,
|
||||
'Magento_SecondModule',
|
||||
$this->source . '/app/code/Magento/SecondModule'
|
||||
);
|
||||
|
||||
// Register the test theme
|
||||
ComponentRegistrar::register(
|
||||
ComponentRegistrar::THEME,
|
||||
'adminhtml/default/backend',
|
||||
$this->source . '/app/design/adminhtml/default/backend'
|
||||
);
|
||||
|
||||
$this->generator = ServiceLocator::getDictionaryGenerator();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if (file_exists($this->outputFileName)) {
|
||||
unlink($this->outputFileName);
|
||||
}
|
||||
$property = new \ReflectionProperty(\Magento\Setup\Module\I18n\ServiceLocator::class, '_dictionaryGenerator');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue(null, null);
|
||||
$property->setAccessible(false);
|
||||
|
||||
$reflection = new \ReflectionClass(\Magento\Framework\Component\ComponentRegistrar::class);
|
||||
$paths = $reflection->getProperty('paths');
|
||||
$paths->setAccessible(true);
|
||||
$paths->setValue(null, $this->backupRegistrar);
|
||||
$paths->setAccessible(false);
|
||||
}
|
||||
|
||||
public function testGenerationWithoutContext()
|
||||
{
|
||||
$this->generator->generate($this->source, $this->outputFileName);
|
||||
|
||||
$this->assertFileEquals($this->expectedDir . '/without_context.csv', $this->outputFileName);
|
||||
}
|
||||
|
||||
public function testGenerationWithContext()
|
||||
{
|
||||
$this->generator->generate($this->source, $this->outputFileName, true);
|
||||
|
||||
$expected = explode(PHP_EOL, file_get_contents($this->expectedDir . '/with_context.csv'));
|
||||
$output = file_get_contents($this->outputFileName);
|
||||
foreach ($expected as $line) {
|
||||
if ($line) {
|
||||
$this->assertStringContainsString($line, $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
Helper,Helper,module,Magento_FirstModule
|
||||
Model,Model,module,Magento_FirstModule
|
||||
"Module template","Module template",module,Magento_FirstModule
|
||||
Model,Model,module,Magento_SecondModule
|
||||
"Theme template","Theme template",theme,adminhtml/default/backend
|
||||
"Module js","Module js",module,Magento_FirstModule
|
||||
"Lib js","Lib js",lib,lib/web/mage/file.js
|
||||
"Lib js","Lib js",lib,lib/web/varien/file.js
|
||||
"Module layout label","Module layout label",module,Magento_FirstModule
|
||||
"Module layout title","Module layout title",module,Magento_FirstModule
|
||||
"Theme layout label","Theme layout label",theme,adminhtml/default/backend
|
||||
"Theme layout title","Theme layout title",theme,adminhtml/default/backend
|
||||
|
+13
@@ -0,0 +1,13 @@
|
||||
Helper,Helper
|
||||
Model,Model
|
||||
"Module template","Module template"
|
||||
"Theme template","Theme template"
|
||||
"Model unused","Model unused"
|
||||
"Theme template unused","Theme template unused"
|
||||
"Module js","Module js"
|
||||
"Lib js","Lib js"
|
||||
"Lib js unused","Lib js unused"
|
||||
"Module layout label","Module layout label"
|
||||
"Module layout title","Module layout title"
|
||||
"Theme layout label","Theme layout label"
|
||||
"Theme layout title","Theme layout title"
|
||||
|
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\FirstModule\Helper;
|
||||
|
||||
class Helper
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
__('Helper');
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\FirstModule\Model;
|
||||
|
||||
class Model
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
__('Model');
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?xml version='1.0' encoding="utf-8" ?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
|
||||
<layout>
|
||||
<referenceBlock translate="description, label">
|
||||
<description>Module layout description</description>
|
||||
<label>Module layout label</label>
|
||||
<title translate="true">Module layout title</title>
|
||||
</referenceBlock>
|
||||
</layout>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
$.mage.__('Module js');
|
||||
});
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
?>
|
||||
<?php __('Module template');
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\SecondModule\Model;
|
||||
|
||||
class Model
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
__('Model');
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?xml version='1.0' encoding="utf-8" ?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
|
||||
<layout>
|
||||
<referenceBlock translate="description, label">
|
||||
<description>Theme layout description</description>
|
||||
<label>Theme layout label</label>
|
||||
<title translate="true">Theme layout title</title>
|
||||
</referenceBlock>
|
||||
</layout>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
?>
|
||||
<?php __('Theme template');
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
$.mage.__('Lib js')
|
||||
});
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
$.mage.__('Lib js')
|
||||
});
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\FirstModule\Model;
|
||||
|
||||
class Model
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
__('Model unused');
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
$.mage.__('Lib js unused')
|
||||
});
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
?>
|
||||
<?php __('Theme template unused');
|
||||
Reference in New Issue
Block a user