init
This commit is contained in:
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Test\Integrity\App\Language;
|
||||
|
||||
use Magento\Framework\App\Language\Config;
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class CircularDependencyTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Config[][]
|
||||
*/
|
||||
private $packs;
|
||||
|
||||
/**
|
||||
* Test circular dependencies between languages
|
||||
*/
|
||||
public function testCircularDependencies()
|
||||
{
|
||||
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
|
||||
$componentRegistrar = new ComponentRegistrar();
|
||||
$declaredLanguages = $componentRegistrar->getPaths(ComponentRegistrar::LANGUAGE);
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$domFactoryMock = $this->createMock(\Magento\Framework\Config\DomFactory::class);
|
||||
$domFactoryMock->expects($this->any())
|
||||
->method('createDom')
|
||||
->willReturnCallback(
|
||||
function ($arguments) use ($validationStateMock) {
|
||||
return new \Magento\Framework\Config\Dom(
|
||||
$arguments['xml'],
|
||||
$validationStateMock,
|
||||
[],
|
||||
null,
|
||||
$arguments['schemaFile']
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$packs = [];
|
||||
foreach ($declaredLanguages as $language) {
|
||||
$languageConfig = $objectManager->getObject(
|
||||
\Magento\Framework\App\Language\Config::class,
|
||||
[
|
||||
'source' => file_get_contents($language . '/language.xml'),
|
||||
'domFactory' => $domFactoryMock
|
||||
]
|
||||
);
|
||||
$this->packs[$languageConfig->getVendor()][$languageConfig->getPackage()] = $languageConfig;
|
||||
$packs[] = $languageConfig;
|
||||
}
|
||||
|
||||
/** @var $languageConfig Config */
|
||||
foreach ($packs as $languageConfig) {
|
||||
$languages = [];
|
||||
/** @var $config Config */
|
||||
foreach ($this->collectCircularInheritance($languageConfig) as $config) {
|
||||
$languages[] = $config->getVendor() . '/' . $config->getPackage();
|
||||
}
|
||||
if (!empty($languages)) {
|
||||
$this->fail("Circular dependency detected:\n" . implode(' -> ', $languages));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $languageConfig
|
||||
* @param array $languageList
|
||||
* @param bool $isCircular
|
||||
* @return array|null
|
||||
*/
|
||||
private function collectCircularInheritance(Config $languageConfig, &$languageList = [], &$isCircular = false)
|
||||
{
|
||||
$packKey = implode('|', [$languageConfig->getVendor(), $languageConfig->getPackage()]);
|
||||
if (isset($languageList[$packKey])) {
|
||||
$isCircular = true;
|
||||
} else {
|
||||
$languageList[$packKey] = $languageConfig;
|
||||
foreach ($languageConfig->getUses() as $reuse) {
|
||||
if (isset($this->packs[$reuse['vendor']][$reuse['package']])) {
|
||||
$this->collectCircularInheritance(
|
||||
$this->packs[$reuse['vendor']][$reuse['package']],
|
||||
$languageList,
|
||||
$isCircular
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $isCircular ? $languageList : [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Test\Integrity\App\Language;
|
||||
|
||||
class ConfigTest extends \Magento\TestFramework\Integrity\AbstractConfig
|
||||
{
|
||||
public function testSchemaUsingInvalidXml($expectedErrors = null)
|
||||
{
|
||||
$expectedErrors = [
|
||||
"Element 'code': [facet 'pattern'] The value 'e_GB' is not accepted by the pattern",
|
||||
"Element 'code': 'e_GB' is not a valid value of the atomic type 'codeType'",
|
||||
"Element 'vendor': [facet 'pattern'] The value 'Magento1' is not accepted by the pattern",
|
||||
"Element 'vendor': 'Magento1' is not a valid value of the atomic type",
|
||||
"Element 'sort_odrer': This element is not expected. Expected is",
|
||||
];
|
||||
parent::testSchemaUsingInvalidXml($expectedErrors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the XSD file to be used to validate the XML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getXsd()
|
||||
{
|
||||
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
|
||||
return $urnResolver->getRealPath('urn:magento:framework:App/Language/package.xsd');
|
||||
}
|
||||
|
||||
/**
|
||||
* The location of a single valid complete xml file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getKnownValidXml()
|
||||
{
|
||||
return __DIR__ . '/_files/known_valid.xml';
|
||||
}
|
||||
|
||||
/**
|
||||
* The location of a single known invalid complete xml file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getKnownInvalidXml()
|
||||
{
|
||||
return __DIR__ . '/_files/known_invalid.xml';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getKnownValidPartialXml()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getFileXsd()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getKnownInvalidPartialXml()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _getXmlName()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\App\Language;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
use Magento\Framework\Filesystem\Driver\File;
|
||||
|
||||
class TranslationFiles extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\File\Csv
|
||||
*/
|
||||
protected $csvParser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->csvParser = new \Magento\Framework\File\Csv(new File());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLocalePlacePath()
|
||||
{
|
||||
$pathToSource = BP;
|
||||
$places = [];
|
||||
$componentRegistrar = new ComponentRegistrar();
|
||||
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $modulePath) {
|
||||
$places[basename($modulePath)] = ['placePath' => $modulePath];
|
||||
}
|
||||
foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $themePath) {
|
||||
$placeName = basename(dirname(dirname($themePath))) . '_' . basename($themePath);
|
||||
$places[$placeName] = ['placePath' => $themePath];
|
||||
}
|
||||
$places['lib_web'] = ['placePath' => "{$pathToSource}/lib/web"];
|
||||
return $places;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $modulePath
|
||||
* @return string[] Array csv files array[$locale]$pathToCsvFile]
|
||||
*/
|
||||
protected function getCsvFiles($modulePath)
|
||||
{
|
||||
$files = [];
|
||||
foreach (glob("{$modulePath}/i18n/*.csv") as $file) {
|
||||
$locale = str_replace('.csv', '', basename($file));
|
||||
$files[$locale] = $file;
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $baseLocaleData
|
||||
* @param array $localeData
|
||||
* @return array
|
||||
*/
|
||||
protected function comparePhrase($baseLocaleData, $localeData)
|
||||
{
|
||||
$missing = array_diff_key($baseLocaleData, $localeData);
|
||||
$extra = array_diff_key($localeData, $baseLocaleData);
|
||||
|
||||
$failures = [];
|
||||
if (!empty($missing)) {
|
||||
$failures['missing'] = array_keys($missing);
|
||||
}
|
||||
if (!empty($extra)) {
|
||||
$failures['extra'] = array_keys($extra);
|
||||
}
|
||||
return $failures;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[][][] $failures Array errors in format $failures[$locale][$errorType][$message]
|
||||
* @param string $message
|
||||
* @return string
|
||||
*/
|
||||
protected function printMessage($failures, $message = '')
|
||||
{
|
||||
$message .= PHP_EOL;
|
||||
foreach ($failures as $locale => $localeErrors) {
|
||||
$message .= $locale . PHP_EOL;
|
||||
foreach ($localeErrors as $typeError => $error) {
|
||||
$message .= PHP_EOL . "##########" . PHP_EOL . ucfirst($typeError) . ':' . PHP_EOL;
|
||||
foreach ($error as $phrase) {
|
||||
$message .= '"' . $phrase . '","' . $phrase . '"' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\App\Language;
|
||||
|
||||
use Magento\Framework\App\Utility\Files;
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
use Magento\Setup\Module\I18n\Dictionary\Options\ResolverFactory;
|
||||
use Magento\Setup\Module\I18n\Locale;
|
||||
use Magento\Setup\Module\I18n\Pack\Writer\File\Csv;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class TranslationFilesTest extends TranslationFiles
|
||||
{
|
||||
/**
|
||||
* Context
|
||||
*
|
||||
* @var \Magento\Setup\Module\I18n\Context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* Test default locale
|
||||
*
|
||||
* Check that all translation phrases in code are present in the locale files
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $phrases
|
||||
*
|
||||
* @dataProvider defaultLocaleDataProvider
|
||||
*/
|
||||
public function testDefaultLocale($file, $phrases)
|
||||
{
|
||||
$this->markTestSkipped('MAGETWO-26083');
|
||||
$failures = $this->comparePhrase($phrases, $this->csvParser->getDataPairs($file));
|
||||
$this->assertEmpty(
|
||||
$failures,
|
||||
$this->printMessage([$file => $failures])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function defaultLocaleDataProvider()
|
||||
{
|
||||
$parser = $this->prepareParser();
|
||||
|
||||
$optionResolverFactory = new ResolverFactory();
|
||||
$optionResolver = $optionResolverFactory->create(BP, true);
|
||||
|
||||
$parser->parse($optionResolver->getOptions());
|
||||
|
||||
$defaultLocale = [];
|
||||
foreach ($parser->getPhrases() as $key => $phrase) {
|
||||
if (!$phrase->getContextType() || !$phrase->getContextValue()) {
|
||||
throw new \RuntimeException(sprintf('Missed context in row #%d.', $key + 1));
|
||||
}
|
||||
foreach ($phrase->getContextValue() as $context) {
|
||||
$phraseText = $this->eliminateSpecialChars($phrase->getPhrase());
|
||||
$phraseTranslation = $this->eliminateSpecialChars($phrase->getTranslation());
|
||||
$file = $this->buildFilePath($phrase, $context);
|
||||
$defaultLocale[$file]['file'] = $file;
|
||||
$defaultLocale[$file]['phrases'][$phraseText] = $phraseTranslation;
|
||||
}
|
||||
}
|
||||
return $defaultLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Setup\Module\I18n\Dictionary\Phrase $phrase
|
||||
* @param array $context
|
||||
* @return string
|
||||
*/
|
||||
protected function buildFilePath($phrase, $context)
|
||||
{
|
||||
$path = $this->getContext()->buildPathToLocaleDirectoryByContext($phrase->getContextType(), $context);
|
||||
return $path . Locale::DEFAULT_SYSTEM_LOCALE . '.' . Csv::FILE_EXTENSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Setup\Module\I18n\Context
|
||||
*/
|
||||
protected function getContext()
|
||||
{
|
||||
if ($this->context === null) {
|
||||
$this->context = new \Magento\Setup\Module\I18n\Context(new ComponentRegistrar());
|
||||
}
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Setup\Module\I18n\Parser\Contextual
|
||||
*/
|
||||
protected function prepareParser()
|
||||
{
|
||||
$filesCollector = new \Magento\Setup\Module\I18n\FilesCollector();
|
||||
|
||||
$phraseCollector = new \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector(
|
||||
new \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer()
|
||||
);
|
||||
$adapters = [
|
||||
'php' => new \Magento\Setup\Module\I18n\Parser\Adapter\Php($phraseCollector),
|
||||
'js' => new \Magento\Setup\Module\I18n\Parser\Adapter\Js(),
|
||||
'xml' => new \Magento\Setup\Module\I18n\Parser\Adapter\Xml(),
|
||||
'html' => new \Magento\Setup\Module\I18n\Parser\Adapter\Html(),
|
||||
];
|
||||
|
||||
$parserContextual = new \Magento\Setup\Module\I18n\Parser\Contextual(
|
||||
$filesCollector,
|
||||
new \Magento\Setup\Module\I18n\Factory(),
|
||||
new \Magento\Setup\Module\I18n\Context(new ComponentRegistrar())
|
||||
);
|
||||
foreach ($adapters as $type => $adapter) {
|
||||
$parserContextual->addAdapter($type, $adapter);
|
||||
}
|
||||
|
||||
return $parserContextual;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
protected function eliminateSpecialChars($text)
|
||||
{
|
||||
return preg_replace(['/\\\\\'/', '/\\\\\\\\/'], ['\'', '\\'], $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test placeholders in translations.
|
||||
* Compares count numeric placeholders in keys and translates.
|
||||
*
|
||||
* @param string $placePath
|
||||
* @dataProvider getLocalePlacePath
|
||||
*/
|
||||
public function testPhrasePlaceHolders($placePath)
|
||||
{
|
||||
$this->markTestSkipped('MAGETWO-26083');
|
||||
$files = $this->getCsvFiles($placePath);
|
||||
|
||||
$failures = [];
|
||||
foreach ($files as $locale => $file) {
|
||||
$fileData = $this->csvParser->getDataPairs($file);
|
||||
foreach ($fileData as $key => $translate) {
|
||||
preg_match_all('/%(\d+)/', $key, $keyMatches);
|
||||
preg_match_all('/%(\d+)/', $translate, $translateMatches);
|
||||
if (count(array_unique($keyMatches[1])) != count(array_unique($translateMatches[1]))) {
|
||||
$failures[$locale][$key][] = $translate;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assertEmpty(
|
||||
$failures,
|
||||
$this->printMessage(
|
||||
$failures,
|
||||
'Found discrepancy between keys and translations in count of numeric placeholders'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>e_GB</code>
|
||||
<vendor>Magento1</vendor>
|
||||
<sort_odrer>100</sort_odrer>
|
||||
<use code="en_GB"/>
|
||||
</language>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_GB</code>
|
||||
<vendor>Magento</vendor>
|
||||
<package>en_GB</package>
|
||||
<sort_order>100</sort_order>
|
||||
<use vendor="oxford-university" package="en_us"/>
|
||||
<use vendor="oxford-university" package="en_gb"/>
|
||||
</language>
|
||||
Reference in New Issue
Block a user