This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,235 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Test\GraphQl;
use Exception;
use Magento\Framework\App\Utility\Files;
use Magento\TestFramework\CodingStandard\Tool\CodeSniffer;
use Magento\TestFramework\CodingStandard\Tool\CodeSniffer\Wrapper;
use Magento\Test\Php\LiveCodeTest as PHPCodeTest;
use PHPUnit\Framework\TestCase;
/**
* Set of tests for static code style
*/
class LiveCodeTest extends TestCase
{
private const FILE_EXTENSION = 'graphqls';
/**
* @var string
*/
private static $reportDir = '';
/**
* @var string
*/
private static $changeCheckDir = '';
/**
* @var mixed
*/
private static mixed $frontendUIComponent;
/**
* Setup basics for all tests
*/
public static function setUpBeforeClass(): void
{
self::$reportDir = BP . '/dev/tests/static/report';
if (!is_dir(self::$reportDir)) {
mkdir(self::$reportDir, 0770);
}
self::$changeCheckDir = BP . '/app/code/Magento';
}
/**
* Test GraphQL schema files code style using phpcs
*/
public function testCodeStyle(): void
{
$reportFile = self::$reportDir . '/graphql_phpcs_report.txt';
$codeSniffer = new CodeSniffer('Magento', $reportFile, new Wrapper());
$codeSniffer->setExtensions([self::FILE_EXTENSION]);
$result = $codeSniffer->run(PHPCodeTest::getWhitelist([self::FILE_EXTENSION]));
$report = file_exists($reportFile) ? file_get_contents($reportFile) : '';
$this->assertEquals(
0,
$result,
"PHP Code Sniffer detected {$result} violation(s): " . PHP_EOL . $report
);
}
/**
* Test if there is corresponding GraphQL module change for each magento core modules
*
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function testModulesRequireGraphQLChange(): void
{
$this->markTestSkipped('AC-9497 written incorrectly');
$modulesRequireGraphQLChange = self::getModulesRequiringGraphQLChange();
$graphQlModules = implode(", ", $modulesRequireGraphQLChange);
$this->assertEmpty(
$modulesRequireGraphQLChange,
"The view layer changes have been detected in the " .
str_replace("GraphQl", "", $graphQlModules) . " module. " .
"The " . $graphQlModules ." module is expected to be updated to reflect these changes. " .
"The test failure can be ignored if the changes can not be covered with GraphQL API."
);
}
/**
* returns a array with the list of graphql modules which require changes
*
* @return array
* @throws Exception
*/
private static function getModulesRequiringGraphQLChange(): array
{
$whitelistFiles = PHPCodeTest::getWhitelist(
['php', 'graphqls'],
'',
'',
'/_files/whitelist/graphql.txt'
);
$fileList = self::filterFiles($whitelistFiles);
$updatedGraphQlModules = [];
$requireGraphQLChanges = [];
foreach ($fileList as $whitelistFile) {
$moduleName = self::getModuleName($whitelistFile);
if (!$moduleName) {
continue;
}
$isGraphQlModule = str_ends_with($moduleName, 'GraphQl');
if (!in_array($moduleName, $updatedGraphQlModules) && $isGraphQlModule) {
$updatedGraphQlModules[] = $moduleName;
continue;
}
if (!in_array($moduleName, $requireGraphQLChanges) && self::isViewLayerClass($whitelistFile, $moduleName)) {
$requireGraphQLChanges[] = $moduleName . "GraphQl";
}
}
return array_diff($requireGraphQLChanges, $updatedGraphQlModules);
}
/**
* Returns the module name of the file from the path
*
* @param string $filePath
* @return string
*/
private static function getModuleName(string $filePath): string
{
$fileName = substr($filePath, strlen(self::$changeCheckDir));
$pathParts = explode('/', $fileName);
return $pathParts[1] ?? '';
}
/**
* Return true if the class is a data provider for the frontend
*
* @param string $filePath
* @param string $moduleName
* @return bool
*/
private static function isViewLayerClass(string $filePath, string $moduleName): bool
{
$className = self::getClassNameWithNamespace($filePath);
$adminChange = str_contains(strtolower($className), 'adminhtml');
if ($className && !$adminChange && self::isFrontendUIComponent($moduleName, $className)) {
return true;
}
return false;
}
/**
* Returns the files namespace using regular expression
*
* @param string $filePath
* @return string
*/
private static function getClassNameWithNamespace(string $filePath): string
{
$className = str_replace('.php', '', basename($filePath));
if (preg_match('#^namespace\s+(.+?);$#sm', file_get_contents($filePath), $m)) {
return ($m[1] && $className) ? $m[1] . "\\" . $className : '';
}
return '';
}
/**
* Check if the class is a frontend data provider
*
* @param string $moduleName
* @param string $className
* @return bool
*/
private static function isFrontendUIComponent(string $moduleName, string $className): bool
{
if (!isset(self::$frontendUIComponent[$moduleName])) {
$files = glob(BP . '/app/code/Magento/'.$moduleName.'/view/frontend/*/*.xml');
if (is_array($files)) {
$uIComponentClasses = [];
foreach ($files as $filename) {
$uIComponentClasses[] = simplexml_load_file($filename)->xpath('//@class');
}
self::$frontendUIComponent[$moduleName] = self::filterUiComponents(
array_unique(array_merge([], ...$uIComponentClasses)),
$moduleName
);
}
}
return in_array($className, self::$frontendUIComponent[$moduleName]);
}
/**
* Filter the array of classes to return only the classes in this module
*
* @param array $uIComponentClasses
* @param string $moduleName
* @return array
*/
private static function filterUiComponents(array $uIComponentClasses, string $moduleName): array
{
$frontendUIComponent = [];
foreach ($uIComponentClasses as $dataProvider) {
$dataProviderClass = ltrim((string)$dataProvider->class, '\\');
if (str_starts_with($dataProviderClass, 'Magento\\' . $moduleName)) {
$frontendUIComponent[] = $dataProviderClass;
}
}
return $frontendUIComponent;
}
/**
* Skip files not requiring graphql side changes
*
* @param array $fileList
* @return array
* @throws Exception
*/
private static function filterFiles(array $fileList): array
{
$denyListFiles = Files::init()->readLists(__DIR__ . '/_files/denylist/*.txt');
$filter = function ($value) use ($denyListFiles) {
return !in_array($value, $denyListFiles);
};
return array_filter($fileList, $filter);
}
}
@@ -0,0 +1 @@
app/code/Magento/Csp/Block/Sri/Hashes.php
@@ -0,0 +1,79 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Html;
use Magento\Framework\App\Utility\Files;
use Magento\TestFramework\CodingStandard\Tool\CodeSniffer;
use Magento\Test\Php\LiveCodeTest as PHPCodeTest;
use Magento\TestFramework\CodingStandard\Tool\CodeSniffer\Wrapper;
use PHPUnit\Framework\TestCase;
/**
* Set of tests for static code style
*/
class LiveCodeTest extends TestCase
{
private const FILE_EXTENSION = 'html';
/**
* @var string
*/
private static $reportDir = '';
/**
* Setup basics for all tests
*
* @return void
*/
public static function setUpBeforeClass(): void
{
self::$reportDir = BP . '/dev/tests/static/report';
if (!is_dir(self::$reportDir)) {
mkdir(self::$reportDir, 0770);
}
}
/**
* Run the magento specific coding standards on the code
*
* @return void
*/
public function testCodeStyle(): void
{
$reportFile = self::$reportDir . '/html_report.txt';
$codeSniffer = new CodeSniffer('Magento', $reportFile, new Wrapper());
$codeSniffer->setExtensions([self::FILE_EXTENSION]);
$fileList = $this->isFullScan() ? array_column(Files::init()->getStaticHtmlFiles(), '0')
: PHPCodeTest::getWhitelist([self::FILE_EXTENSION], __DIR__, __DIR__);
$result = $codeSniffer->run($fileList);
$report = file_exists($reportFile) ? file_get_contents($reportFile) : '';
$this->assertEquals(
0,
$result,
"PHP Code Sniffer detected {$result} violation(s): " . PHP_EOL . $report
);
}
/**
* Returns whether a full scan was requested.
*
* This can be set in the `phpunit.xml` used to run these test cases, by setting the constant
* `TESTCODESTYLE_IS_FULL_SCAN` to `1`, e.g.:
* ```xml
* <php>
* <!-- TESTCODESTYLE_IS_FULL_SCAN - specify if full scan should be performed for test code style test -->
* <const name="TESTCODESTYLE_IS_FULL_SCAN" value="0"/>
* </php>
* ```
*
* @return bool
*/
private function isFullScan(): bool
{
return defined('TESTCODESTYLE_IS_FULL_SCAN') && TESTCODESTYLE_IS_FULL_SCAN === '1';
}
}
@@ -0,0 +1,2 @@
# Format: <componentType=module|library|theme|language|*> <componentName> <globPattern> or simply <globPattern>
* * /
@@ -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;
}
}
@@ -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'
)
);
}
}
@@ -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>
@@ -0,0 +1,80 @@
<?php
/**
* Scan source code for incorrect or undeclared modules dependencies
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity;
use Magento\Framework\App\Utility\Files;
use Magento\Setup\Module\Dependency\Circular;
class CircularDependencyTest extends \PHPUnit\Framework\TestCase
{
/**
* Modules dependencies map
*
* @var array
*/
protected $moduleDependencies = [];
/**
* Circular dependencies
*
* @var array
*/
protected $circularModuleDependencies = [];
protected function setUp(): void
{
$this->buildModulesDependencies();
$this->buildCircularModulesDependencies();
}
/**
* Build modules dependencies
*/
protected function buildModulesDependencies()
{
$configFiles = Files::init()->getConfigFiles('module.xml', [], false);
foreach ($configFiles as $configFile) {
preg_match('#/([^/]+?/[^/]+?)/etc/module\.xml$#', $configFile, $moduleName);
$moduleName = str_replace('/', '_', $moduleName[1]);
$config = simplexml_load_file($configFile);
$result = $config->xpath("/config/module/depends/module") ?: [];
foreach ($result as $node) {
/** @var \SimpleXMLElement $node */
$this->moduleDependencies[$moduleName][] = (string) $node['name'];
}
}
}
/**
* Build circular modules dependencies
*/
protected function buildCircularModulesDependencies()
{
$this->circularModuleDependencies = (new Circular())->buildCircularDependencies($this->moduleDependencies);
}
/**
* Check Magento modules structure for circular dependencies
*/
public function testCircularDependencies()
{
$this->markTestSkipped('Skipped before circular dependencies will be fixed MAGETWO-10938');
if ($this->circularModuleDependencies) {
$result = '';
foreach ($this->circularModuleDependencies as $module => $chains) {
$result .= $module . ' dependencies:' . PHP_EOL;
foreach ($chains as $chain) {
$result .= 'Chain : ' . implode('->', $chain) . PHP_EOL;
}
$result .= PHP_EOL;
}
$this->fail('Circular dependencies:' . PHP_EOL . $result);
}
}
}
@@ -0,0 +1,687 @@
<?php
/**
* Scan source code for references to classes and see if they indeed exist
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity;
use Magento\Framework\App\Utility\Classes;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\App\Utility\Files;
/**
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class ClassesTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ComponentRegistrar
*/
private $componentRegistrar;
/**
* List of already found classes to avoid checking them over and over again
*
* @var array
*/
private $existingClasses = [];
/**
* @var array
*/
private static $excludeKeywords = ["String", "Array", "Boolean", "Element"];
/**
* @var array|null
*/
private $excludeReference = null;
/**
* Set Up
*/
protected function setUp(): void
{
$this->componentRegistrar = new ComponentRegistrar();
}
public function testPhpFiles()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $file
*/
function ($file) {
$contents = file_get_contents($file);
$classes = Classes::getAllMatches(
$contents,
'/
# ::getResourceModel ::getBlockSingleton ::getModel ::getSingleton
\:\:get(?:ResourceModel | BlockSingleton | Model | Singleton)?\(\s*[\'"]([a-z\d\\\\]+)[\'"]\s*[\),]
# various methods, first argument
| \->(?:initReport | addBlock | createBlock
| setAttributeModel | setBackendModel | setFrontendModel | setSourceModel | setModel
)\(\s*\'([a-z\d\\\\]+)\'\s*[\),]
# various methods, second argument
| \->add(?:ProductConfigurationHelper | OptionsRenderCfg)\(.+?,\s*\'([a-z\d\\\\]+)\'\s*[\),]
# \Mage::helper ->helper
| (?:Mage\:\:|\->)helper\(\s*\'([a-z\d\\\\]+)\'\s*\)
# misc
| function\s_getCollectionClass\(\)\s+{\s+return\s+[\'"]([a-z\d\\\\]+)[\'"]
| \'resource_model\'\s*=>\s*[\'"]([a-z\d\\\\]+)[\'"]
| (?:_parentResourceModelName | _checkoutType | _apiType)\s*=\s*\'([a-z\d\\\\]+)\'
| \'renderer\'\s*=>\s*\'([a-z\d\\\\]+)\'
/ix'
);
// without modifier "i". Starting from capital letter is a significant characteristic of a class name
Classes::getAllMatches(
$contents,
'/(?:\-> | parent\:\:)(?:_init | setType)\(\s*
\'([A-Z][a-z\d][A-Za-z\d\\\\]+)\'(?:,\s*\'([A-Z][a-z\d][A-Za-z\d\\\\]+)\')
\s*\)/x',
$classes
);
$this->collectResourceHelpersPhp($contents, $classes);
$this->assertClassesExist($classes, $file);
},
Files::init()->getPhpFiles(
Files::INCLUDE_APP_CODE
| Files::INCLUDE_PUB_CODE
| Files::INCLUDE_LIBS
| Files::INCLUDE_TEMPLATES
| Files::AS_DATA_SET
| Files::INCLUDE_NON_CLASSES
)
);
}
/**
* Special case: collect resource helper references in PHP-code
*
* @param string $contents
* @param array &$classes
* @return void
*/
private function collectResourceHelpersPhp(string $contents, array &$classes): void
{
$regex = '/(?:\:\:|\->)getResourceHelper\(\s*\'([a-z\d\\\\]+)\'\s*\)/ix';
$matches = Classes::getAllMatches($contents, $regex);
foreach ($matches as $moduleName) {
$classes[] = "{$moduleName}\\Model\\ResourceModel\\Helper\\Mysql4";
}
}
public function testConfigFiles()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $path
*/
function ($path) {
$classes = Classes::collectClassesInConfig(simplexml_load_file($path));
$this->assertClassesExist($classes, $path);
},
Files::init()->getMainConfigFiles()
);
}
public function testLayoutFiles()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $path
*/
function ($path) {
$xml = simplexml_load_file($path);
$classes = Classes::getXmlNodeValues(
$xml,
'/layout//*[contains(text(), "\\\\Block\\\\") or contains(text(),
"\\\\Model\\\\") or contains(text(), "\\\\Helper\\\\")]'
);
foreach (Classes::getXmlAttributeValues(
$xml,
'/layout//@helper',
'helper'
) as $class) {
$classes[] = Classes::getCallbackClass($class);
}
foreach (Classes::getXmlAttributeValues(
$xml,
'/layout//@module',
'module'
) as $module) {
$classes[] = str_replace('_', '\\', "{$module}_Helper_Data");
}
$classes = array_merge($classes, Classes::collectLayoutClasses($xml));
$this->assertClassesExist(array_unique($classes), $path);
},
Files::init()->getLayoutFiles()
);
}
/**
* Check whether specified classes correspond to a file according PSR-0 standard
*
* Cyclomatic complexity is because of temporary marking test as incomplete
* Suppressing "unused variable" because of the "catch" block
*
* @param array $classes
* @param string $path
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
private function assertClassesExist(array $classes, string $path): void
{
if (!$classes) {
return;
}
$badClasses = [];
$badUsages = [];
foreach ($classes as $class) {
$class = trim($class, '\\');
try {
if (strrchr($class, '\\') === false && !Classes::isVirtual($class)) {
$badUsages[] = $class;
continue;
} else {
$this->assertTrue(
isset(
$this->existingClasses[$class]
) || Files::init()->classFileExists(
$class
) || Classes::isVirtual(
$class
) || Classes::isAutogenerated(
$class
)
);
}
$this->existingClasses[$class] = 1;
} catch (\PHPUnit\Framework\AssertionFailedError $e) {
$badClasses[] = '\\' . $class;
}
}
if ($badClasses) {
$this->fail("Files not found for following usages in {$path}:\n" . implode("\n", $badClasses));
}
if ($badUsages) {
$this->fail("Bad usages of classes in {$path}: \n" . implode("\n", $badUsages));
}
}
public function testClassNamespaces()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* Assert PHP classes have valid formal namespaces according to file locations
*
* @param array $file
*/
function ($file) {
$relativePath = str_replace(BP . "/", "", $file);
// exceptions made for fixture files from tests
if (strpos($relativePath, '/_files/') !== false) {
return;
}
$contents = file_get_contents($file);
$classPattern = '/^(abstract\s)?class\s[A-Z][^\s\/]+/m';
$classNameMatch = [];
$className = null;
// if no class declaration found for $file, then skip this file
if (preg_match($classPattern, $contents, $classNameMatch) == 0) {
return;
}
$classParts = explode(' ', $classNameMatch[0]);
$className = array_pop($classParts);
$this->assertClassNamespace($file, $relativePath, $contents, $className);
},
Files::init()->getPhpFiles()
);
}
/**
* Assert PHP classes have valid formal namespaces according to file locations
*
*
* @param string $file
* @param string $relativePath
* @param string $contents
* @param string $className
* @return void
*/
private function assertClassNamespace(string $file, string $relativePath, string $contents, string $className): void
{
$namespacePattern = '/(Magento|Zend)\/[a-zA-Z]+[^\.]+/';
$formalPattern = '/^namespace\s[a-zA-Z]+(\\\\[a-zA-Z0-9]+)*/m';
$namespaceMatch = [];
$formalNamespaceArray = [];
$namespaceFolders = null;
// if no namespace pattern found according to the path of the file, skip the file
if (preg_match($namespacePattern, $relativePath, $namespaceMatch) == 0) {
return;
}
$namespaceFolders = $namespaceMatch[0];
$classParts = explode('/', $namespaceFolders);
array_pop($classParts);
$expectedNamespace = implode('\\', $classParts);
if (preg_match($formalPattern, $contents, $formalNamespaceArray) != 0) {
$foundNamespace = substr($formalNamespaceArray[0], 10);
$foundNamespace = str_replace('\\', '/', $foundNamespace);
$foundNamespace .= '/' . $className;
if ($namespaceFolders != null && $foundNamespace != null) {
$this->assertEquals(
$namespaceFolders,
$foundNamespace,
"Location of {$file} does not match formal namespace: {$expectedNamespace}\n"
);
}
} else {
$this->fail("Missing expected namespace \"{$expectedNamespace}\" for file: {$file}");
}
}
public function testClassReferences()
{
$this->markTestSkipped("To be fixed in MC-33329. The test is not working properly "
. "after excluded logic was fixed. Previously it was ignoring all files.");
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $file
*/
function ($file) {
$relativePath = str_replace(BP, "", $file);
// Due to the examples given with the regex patterns, we skip this test file itself
if (preg_match(
'/\/dev\/tests\/static\/testsuite\/Magento\/Test\/Integrity\/ClassesTest.php$/',
$relativePath
)) {
return;
}
$contents = file_get_contents($file);
$formalPattern = '/^namespace\s[a-zA-Z]+(\\\\[a-zA-Z0-9]+)*/m';
$formalNamespaceArray = [];
// Skip the file if the class is not defined using formal namespace
if (preg_match($formalPattern, $contents, $formalNamespaceArray) == 0) {
return;
}
$namespacePath = str_replace('\\', '/', substr($formalNamespaceArray[0], 10));
// Instantiation of new object, for example: "return new Foo();"
$newObjectPattern = '/^' .
'.*new\s(?<venderClass>\\\\Magento(?:\\\\[a-zA-Z0-9_]+)+)\(.*\)' .
'|.*new\s(?<badClass>[A-Z][a-zA-Z0-9]+[a-zA-Z0-9_\\\\]*)\(.*\)\;' .
'|use [A-Z][a-zA-Z0-9_\\\\]+ as (?<aliasClass>[A-Z][a-zA-Z0-9]+)' .
'/m';
$result1 = [];
preg_match_all($newObjectPattern, $contents, $result1);
// Static function/variable, for example: "Foo::someStaticFunction();"
$staticCallPattern = '/^' .
'((?!Magento).)*(?<venderClass>\\\\Magento(?:\\\\[a-zA-Z0-9_]+)+)\:\:.*\;' .
'|[^\\\\^a-z^A-Z^0-9^_^:](?<badClass>[A-Z][a-zA-Z0-9_]+)\:\:.*\;' .
'|use [A-Z][a-zA-Z0-9_\\\\]+ as (?<aliasClass>[A-Z][a-zA-Z0-9]+)' .
'/m';
$result2 = [];
preg_match_all($staticCallPattern, $contents, $result2);
// Annotation, for example: "* @return \Magento\Foo\Bar" or "* @throws Exception" or "* @return Foo"
$annotationPattern = '/^' .
'[\s]*\*\s\@(?:return|throws)\s(?<venderClass>\\\\Magento(?:\\\\[a-zA-Z0-9_]+)+)' .
'|[\s]*\*\s\@return\s(?<badClass>[A-Z][a-zA-Z0-9_\\\\]+)' .
'|[\s]*\*\s\@throws\s(?<exception>[A-Z][a-zA-Z0-9_\\\\]+)' .
'|use [A-Z][a-zA-Z0-9_\\\\]+ as (?<aliasClass>[A-Z][a-zA-Z0-9]+)' .
'/m';
$result3 = [];
preg_match_all($annotationPattern, $contents, $result3);
$vendorClasses = array_unique(
array_merge_recursive($result1['venderClass'], $result2['venderClass'], $result3['venderClass'])
);
$badClasses = array_unique(
array_merge_recursive($result1['badClass'], $result2['badClass'], $result3['badClass'])
);
$aliasClasses = array_unique(
array_merge_recursive($result1['aliasClass'], $result2['aliasClass'], $result3['aliasClass'])
);
$vendorClasses = array_filter($vendorClasses, 'strlen');
$vendorClasses = $this->excludedReferenceFilter($vendorClasses);
if (!empty($vendorClasses)) {
$this->assertClassesExist($vendorClasses, $file);
}
if (!empty($result3['exception']) && $result3['exception'][0] != "") {
$badClasses = array_merge($badClasses, array_filter($result3['exception'], 'strlen'));
}
$badClasses = array_filter($badClasses, 'strlen');
if (empty($badClasses)) {
return;
}
$aliasClasses = array_filter($aliasClasses, 'strlen');
if (!empty($aliasClasses)) {
$badClasses = $this->handleAliasClasses($aliasClasses, $badClasses);
}
$badClasses = $this->excludedReferenceFilter($badClasses);
$badClasses = $this->removeSpecialCases($badClasses, $file, $contents, $namespacePath);
$this->assertClassReferences($badClasses, $file);
},
Files::init()->getPhpFiles()
);
}
/**
* Remove alias class name references that have been identified as 'bad'.
*
* @param array $aliasClasses
* @param array $badClasses
* @return array
*/
private function handleAliasClasses(array $aliasClasses, array $badClasses): array
{
foreach ($aliasClasses as $aliasClass) {
foreach ($badClasses as $badClass) {
if (strpos($badClass, $aliasClass) === 0) {
unset($badClasses[array_search($badClass, $badClasses)]);
}
}
}
return $badClasses;
}
/**
* This function is to remove legacy code usages according to _files/blacklist/reference.txt
*
* @param array $classes
* @return array
*/
private function excludedReferenceFilter(array $classes): array
{
// exceptions made for the files from the exclusion
$excludeClasses = $this->getExcludedReferences();
foreach ($classes as $class) {
if (in_array($class, $excludeClasses)) {
unset($classes[array_search($class, $classes)]);
}
}
return $classes;
}
/**
* Returns array of class names from black list.
*
* @return array
*/
private function getExcludedReferences(): array
{
if (!isset($this->excludeReference)) {
$this->excludeReference = file(
__DIR__ . '/_files/blacklist/reference.txt',
FILE_IGNORE_NEW_LINES
);
}
return $this->excludeReference;
}
/**
* This function is to remove special cases (if any) from the list of found bad classes
*
* @param array $badClasses
* @param string $file
* @param string $contents
* @param string $namespacePath
* @return array
*/
private function removeSpecialCases(array $badClasses, string $file, string $contents, string $namespacePath): array
{
foreach ($badClasses as $badClass) {
// Remove valid usages of Magento modules from the list
// for example: 'Magento_Sales::actions_edit'
if (preg_match('/^[A-Z][a-z]+_[A-Z0-9][a-z0-9]+$/', $badClass)) {
$moduleDir = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $badClass);
if ($moduleDir !== null) {
unset($badClasses[array_search($badClass, $badClasses)]);
continue;
}
}
// Remove usage of key words such as "Array", "String", and "Boolean"
if (in_array($badClass, self::$excludeKeywords)) {
unset($badClasses[array_search($badClass, $badClasses)]);
continue;
}
$classParts = explode('/', $file);
$className = array_pop($classParts);
// Remove usage of the class itself from the list
if ($badClass . '.php' == $className) {
unset($badClasses[array_search($badClass, $badClasses)]);
continue;
}
if ($this->removeSpecialCasesNonFullyQualifiedClassNames($namespacePath, $badClasses, $badClass)) {
continue;
}
$referenceFile = implode('/', $classParts) . '/' . str_replace('\\', '/', $badClass) . '.php';
if (file_exists($referenceFile)) {
unset($badClasses[array_search($badClass, $badClasses)]);
continue;
}
// Remove usage of classes that have been declared as "use" or "include"
// Also deals with case like: "use \Laminas\Code\Scanner\FileScanner, Magento\Tools\Di\Compiler\Log\Log;"
// (continued) where there is a comma separating two different classes.
if (preg_match('/use\s.*[\\n]?.*' . str_replace('\\', '\\\\', $badClass) . '[\,\;]/', $contents)) {
unset($badClasses[array_search($badClass, $badClasses)]);
continue;
}
}
return $badClasses;
}
/**
* Helper class for removeSpecialCases to remove classes that do not use fully-qualified class names
*
* @param string $namespacePath
* @param array $badClasses
* @param string $badClass
* @return bool
* @throws \Exception
*/
private function removeSpecialCasesNonFullyQualifiedClassNames($namespacePath, &$badClasses, $badClass)
{
$namespaceParts = explode('/', $namespacePath);
$moduleDir = null;
if (isset($namespaceParts[1])) {
$moduleName = array_shift($namespaceParts) . '_' . array_shift($namespaceParts);
$moduleDir = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
}
if ($moduleDir) {
$fullPath = $moduleDir . '/' . implode('/', $namespaceParts) . '/' .
str_replace('\\', '/', $badClass) . '.php';
if (file_exists($fullPath)) {
unset($badClasses[array_search($badClass, $badClasses)]);
return true;
}
}
$fullPath = $this->getLibraryDirByPath($namespacePath, $badClass);
if ($fullPath && file_exists($fullPath)) {
unset($badClasses[array_search($badClass, $badClasses)]);
return true;
} else {
return $this->removeSpecialCasesForAllOthers($namespacePath, $badClass, $badClasses);
}
}
/**
* Get path to the file in the library based on namespace path
*
* @param string $namespacePath
* @param string $badClass
* @return null|string
*/
private function getLibraryDirByPath(string $namespacePath, string $badClass)
{
$libraryDir = null;
$fullPath = null;
$namespaceParts = explode('/', $namespacePath);
if (isset($namespaceParts[1]) && $namespaceParts[1]) {
$vendor = array_shift($namespaceParts);
$lib = array_shift($namespaceParts);
if ($lib == 'framework') {
$subLib = $namespaceParts[0];
$subLib = strtolower(preg_replace('/(.)([A-Z])/', "$1-$2", $subLib));
$libraryName = $vendor . '/' . $lib . '-' . $subLib;
$libraryDir = $this->componentRegistrar->getPath(
ComponentRegistrar::LIBRARY,
strtolower($libraryName)
);
if ($libraryDir) {
array_shift($namespaceParts);
} else {
$libraryName = $vendor . '/' . $lib;
$libraryDir = $this->componentRegistrar->getPath(
ComponentRegistrar::LIBRARY,
strtolower($libraryName)
);
}
} else {
$lib = strtolower(preg_replace('/(.)([A-Z])/', "$1-$2", $lib));
$libraryName = $vendor . '/' . $lib;
$libraryDir = $this->componentRegistrar->getPath(
ComponentRegistrar::LIBRARY,
strtolower($libraryName)
);
}
}
if ($libraryDir) {
$fullPath = $libraryDir . '/' . implode('/', $namespaceParts) . '/' .
str_replace('\\', '/', $badClass) . '.php';
}
return $fullPath;
}
/**
* @param string $namespacePath
* @param string $badClass
* @param array $badClasses
* @return bool
*/
private function removeSpecialCasesForAllOthers(string $namespacePath, string $badClass, array &$badClasses): bool
{
// Remove usage of classes that do NOT using fully-qualified class names (possibly under same namespace)
$directories = [
BP . '/dev/tools/',
BP . '/dev/tests/api-functional/framework/',
BP . '/dev/tests/integration/framework/',
BP . '/dev/tests/integration/framework/tests/unit/testsuite/',
BP . '/dev/tests/integration/testsuite/',
BP . '/dev/tests/integration/testsuite/Magento/Test/Integrity/',
BP . '/dev/tests/static/framework/',
BP . '/dev/tests/static/testsuite/',
BP . '/setup/src/',
];
$libraryPaths = $this->componentRegistrar->getPaths(ComponentRegistrar::LIBRARY);
$directories = array_merge($directories, $libraryPaths);
// Full list of directories where there may be namespace classes
foreach ($directories as $directory) {
$fullPath = $directory . $namespacePath . '/' . str_replace('\\', '/', $badClass) . '.php';
if (file_exists($fullPath)) {
unset($badClasses[array_search($badClass, $badClasses)]);
return true;
}
}
return false;
}
/**
* Assert any found class name resolves into a file name and corresponds to an existing file
*
* @param array $badClasses
* @param string $file
* @return void
*/
private function assertClassReferences(array $badClasses, string $file): void
{
if (empty($badClasses)) {
return;
}
$this->fail("Incorrect namespace usage(s) found in file {$file}:\n" . implode("\n", $badClasses));
}
public function testCoversAnnotation()
{
$files = Files::init();
$errors = [];
$filesToTest = $files->getPhpFiles(Files::INCLUDE_TESTS);
if (($key = array_search(str_replace('\\', '/', __FILE__), $filesToTest)) !== false) {
unset($filesToTest[$key]);
}
foreach ($filesToTest as $file) {
$code = file_get_contents($file);
if (preg_match('/@covers(DefaultClass)?\s+([\w\\\\]+)(::([\w\\\\]+))?/', $code, $matches)) {
if ($this->isNonexistentEntityCovered($matches)) {
$errors[] = $file . ': ' . $matches[0];
}
}
}
if ($errors) {
$this->fail(
'Nonexistent classes/methods were found in @covers annotations: ' . PHP_EOL . implode(PHP_EOL, $errors)
);
}
}
/**
* @param array $matches
* @return bool
*/
private function isNonexistentEntityCovered($matches)
{
return !empty($matches[2]) && !class_exists($matches[2])
|| !empty($matches[4]) && !method_exists($matches[2], $matches[4]);
}
}
@@ -0,0 +1,130 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity;
/**
* A test that enforces composer.lock is up to date with composer.json
*/
class ComposerLockTest extends \PHPUnit\Framework\TestCase
{
/**
* @return string
*/
public function testLockFileExists()
{
$lockFilePath = BP . '/composer.lock';
$this->assertLockFileExists($lockFilePath);
return $lockFilePath;
}
/**
* @depends testLockFileExists
* @param string $lockFilePath
* @return string
*/
public function testLockFileReadable($lockFilePath)
{
$this->assertLockFileReadable($lockFilePath);
return $lockFilePath;
}
/**
* @depends testLockFileReadable
* @param string $lockFilePath
* @return string
*/
public function testLockFileContainsJson($lockFilePath)
{
$lockFileContent = file_get_contents($lockFilePath);
$this->assertLockFileContainsValidJson($lockFileContent);
return $lockFileContent;
}
/**
* @depends testLockFileContainsJson
* @param string $lockFileContent
*/
public function testUpToDate($lockFileContent)
{
$lockData = json_decode($lockFileContent, true);
$composerFilePath = BP . '/composer.json';
$this->assertLockDataRelevantToComposerFile($lockData, $composerFilePath);
}
/**
* @param string $lockFilePath
*/
private function assertLockFileExists($lockFilePath)
{
$this->assertFileExists($lockFilePath, 'composer.lock file does not exist');
}
/**
* @param string $lockFilePath
*/
private function assertLockFileReadable($lockFilePath)
{
if (!is_readable($lockFilePath)) {
$this->fail('composer.lock file is not readable');
}
}
/**
* @param string $lockFileContent
*/
private function assertLockFileContainsValidJson($lockFileContent)
{
$this->assertJson($lockFileContent, 'composer.lock file does not contains valid json');
}
/**
* @param array $lockData
* @param string $composerFilePath
*/
private function assertLockDataRelevantToComposerFile(array $lockData, $composerFilePath)
{
if (isset($lockData['content-hash'])) {
$this->assertLockDataRelevantToMeaningfulComposerConfig($lockData, $composerFilePath);
} else if (isset($lockData['hash'])) {
$this->assertLockDataRelevantToFullComposerConfig($lockData, $composerFilePath);
} else {
$this->fail('composer.lock does not linked to composer.json data');
}
}
/**
* @param array $lockData
* @param string $composerFilePath
*/
private function assertLockDataRelevantToMeaningfulComposerConfig(array $lockData, $composerFilePath)
{
$contentHashCalculator = 'Composer\Package\Locker::getContentHash';
if (!is_callable($contentHashCalculator)) {
$this->markTestSkipped('Unable to check composer.lock file by content hash');
}
$composerContentHash = call_user_func($contentHashCalculator, file_get_contents($composerFilePath));
$this->assertSame(
$composerContentHash,
$lockData['content-hash'],
'composer.lock file is not up to date (composer.json file was modified)'
);
}
/**
* @param array $lockData
* @param string $composerFilePath
*/
private function assertLockDataRelevantToFullComposerConfig(array $lockData, $composerFilePath)
{
$composerFileHash = hash_file('md5', $composerFilePath);
$this->assertSame(
$composerFileHash,
$lockData['hash'],
'composer.lock file is not up to date (composer.json file was modified)'
);
}
}
@@ -0,0 +1,558 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity;
use Magento\Framework\App\Bootstrap;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Composer\MagentoComponent;
/**
* A test that enforces validity of composer.json files and any other conventions in Magento components
*/
class ComposerTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string
*/
private static $root;
/**
* @var \stdClass
*/
private static $rootJson;
/**
* @var array
*/
private static $dependencies;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private static $objectManager;
/**
* @var string[]
*/
private static $rootComposerModuleBlacklist = [];
/**
* @var string[]
*/
private static $moduleNameBlacklist;
/**
* @var string
*/
private static $magentoFrameworkLibraryName = 'magento/framework';
public static function setUpBeforeClass(): void
{
self::$root = BP;
self::$rootJson = json_decode(file_get_contents(self::$root . '/composer.json'), true);
self::$dependencies = [];
self::$objectManager = Bootstrap::create(BP, $_SERVER)->getObjectManager();
// A block can be whitelisted and thus not be required to be public
self::$rootComposerModuleBlacklist = self::getBlacklist(
__DIR__ . '/_files/blacklist/composer_root_modules*.txt'
);
self::$moduleNameBlacklist = self::getBlacklist(__DIR__ . '/_files/blacklist/composer_module_names*.txt');
}
/**
* Return aggregated blacklist
*
* @param string $pattern
* @return string[]
*/
public static function getBlacklist(string $pattern)
{
$blacklist = [];
foreach (glob($pattern) as $list) {
$blacklist[] = file($list, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}
return array_merge([], ...$blacklist);
}
public function testValidComposerJson()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $dir
* @param string $packageType
*/
function ($dir, $packageType) {
$file = $dir . '/composer.json';
$this->assertFileExists($file);
$this->validateComposerJsonFile($dir);
$contents = file_get_contents($file);
$json = json_decode($contents);
$this->assertCodingStyle($contents);
$this->assertMagentoConventions($dir, $packageType, $json);
},
$this->validateComposerJsonDataProvider()
);
}
/**
* @return array
*/
public function validateComposerJsonDataProvider()
{
$root = BP;
$componentRegistrar = new ComponentRegistrar();
$result = [];
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $dir) {
$result[$dir] = [$dir, 'magento2-module'];
}
foreach ($componentRegistrar->getPaths(ComponentRegistrar::LANGUAGE) as $dir) {
$result[$dir] = [$dir, 'magento2-language'];
}
foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $dir) {
$result[$dir] = [$dir, 'magento2-theme'];
}
foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $dir) {
$result[$dir] = [$dir, 'magento2-library'];
}
$result[$root] = [$root, 'project'];
return $result;
}
/**
* Validate a composer.json under the given path
*
* @param string $path path to composer.json
*/
private function validateComposerJsonFile($path)
{
/** @var \Magento\Framework\Composer\MagentoComposerApplicationFactory $appFactory */
$appFactory = self::$objectManager->get(\Magento\Framework\Composer\MagentoComposerApplicationFactory::class);
$app = $appFactory->create();
try {
$app->runComposerCommand(['command' => 'validate'], $path);
} catch (\RuntimeException $exception) {
$this->fail($exception->getMessage());
}
}
/**
* Some of coding style conventions
*
* @param string $contents
*/
private function assertCodingStyle($contents)
{
$this->assertDoesNotMatchRegularExpression(
'/" :\s*["{]/',
$contents,
'Coding style: there should be no space before colon.'
);
$this->assertDoesNotMatchRegularExpression(
'/":["{]/',
$contents,
'Coding style: a space is necessary after colon.'
);
}
/**
* Enforce Magento-specific conventions to a composer.json file
*
* @param string $dir
* @param string $packageType
* @param \StdClass $json
* @throws \InvalidArgumentException
*/
private function assertMagentoConventions($dir, $packageType, \StdClass $json)
{
$this->assertObjectHasProperty('name', $json);
$this->assertObjectHasProperty('license', $json);
$this->assertObjectHasProperty('type', $json);
$this->assertObjectHasProperty('require', $json);
$this->assertEquals($packageType, $json->type);
if ($packageType !== 'project') {
self::$dependencies[] = $json->name;
$this->assertAutoloadRegistrar($json, $dir);
$this->assertNoMap($json);
}
switch ($packageType) {
case 'magento2-module':
$xml = simplexml_load_file("$dir/etc/module.xml");
if ($this->isVendorMagento($json->name)) {
$this->assertConsistentModuleName($xml, $json->name);
}
$this->assertDependsOnPhp($json->require);
$this->assertPhpVersionInSync($json->name, $json->require->php);
$this->assertDependsOnFramework($json->require);
$this->assertRequireInSync($json);
$this->assertAutoload($json);
$this->assertNoVersionSpecified($json);
break;
case 'magento2-language':
$this->assertMatchesRegularExpression(
'/^magento\/language\-[a-z]{2}_([a-z]{4}_)?[a-z]{2}$/',
$json->name
);
$this->assertDependsOnFramework($json->require);
$this->assertRequireInSync($json);
$this->assertNoVersionSpecified($json);
break;
case 'magento2-theme':
$this->assertMatchesRegularExpression(
'/^magento\/theme-(?:adminhtml|frontend)(\-[a-z0-9_]+)+$/',
$json->name
);
$this->assertDependsOnPhp($json->require);
$this->assertPhpVersionInSync($json->name, $json->require->php);
$this->assertDependsOnFramework($json->require);
$this->assertRequireInSync($json);
$this->assertNoVersionSpecified($json);
break;
case 'magento2-library':
$this->assertDependsOnPhp($json->require);
$this->assertMatchesRegularExpression('/^magento\/framework*/', $json->name);
$this->assertPhpVersionInSync($json->name, $json->require->php);
$this->assertRequireInSync($json);
$this->assertAutoload($json);
$this->assertNoVersionSpecified($json);
break;
case 'project':
$this->checkProject();
$this->assertNoVersionSpecified($json);
break;
default:
throw new \InvalidArgumentException("Unknown package type {$packageType}");
}
}
/**
* Checks if package vendor is Magento.
*
* @param string $packageName
* @return bool
*/
private function isVendorMagento(string $packageName): bool
{
return strpos($packageName, 'magento/') === 0;
}
/**
* Assert that component registrar is autoloaded in composer json
*
* @param \StdClass $json
* @param string $dir
*/
private function assertAutoloadRegistrar(\StdClass $json, $dir)
{
$error = 'There must be an "autoload->files" node in composer.json of each Magento component.';
$this->assertObjectHasProperty('autoload', $json, $error);
$this->assertObjectHasProperty('files', $json->autoload, $error);
$this->assertTrue(in_array("registration.php", $json->autoload->files), $error);
$this->assertFileExists("$dir/registration.php");
}
/**
* Version must not be specified in the root and package composer JSON files in Git.
*
* All versions are added by tools during release publication by version setter tool.
*
* @param \StdClass $json
*/
private function assertNoVersionSpecified(\StdClass $json)
{
if (!in_array($json->name, self::$rootComposerModuleBlacklist)) {
$errorMessage = 'Version must not be specified in the root and package composer JSON files in Git';
$this->assertObjectNotHasProperty('version', $json, $errorMessage);
}
}
/**
* Assert that there is PSR-4 autoload in composer json
*
* @param \StdClass $json
*/
private function assertAutoload(\StdClass $json)
{
$errorMessage = 'There must be an "autoload->psr-4" section in composer.json of each Magento component.';
$this->assertObjectHasProperty('autoload', $json, $errorMessage);
$this->assertObjectHasProperty('psr-4', $json->autoload, $errorMessage);
}
/**
* Assert that there is map in specified composer json
*
* @param \StdClass $json
*/
private function assertNoMap(\StdClass $json)
{
$error = 'There is no "extra->map" node in composer.json of each Magento component.';
$this->assertObjectNotHasProperty('extra', $json, $error);
}
/**
* Enforce package naming conventions for modules
*
* @param \SimpleXMLElement $xml
* @param string $packageName
*/
private function assertConsistentModuleName(\SimpleXMLElement $xml, $packageName)
{
if (!in_array($packageName, self::$moduleNameBlacklist)) {
$moduleName = (string)$xml->module->attributes()->name;
$expectedPackageName = $this->convertModuleToPackageName($moduleName);
$this->assertEquals(
$expectedPackageName,
$packageName,
"For the module '{$moduleName}', the expected package name is '{$expectedPackageName}'"
);
}
}
/**
* Make sure a component depends on php version
*
* @param \StdClass $json
*/
private function assertDependsOnPhp(\StdClass $json)
{
$this->assertObjectHasProperty('php', $json, 'This component is expected to depend on certain PHP version(s)');
}
/**
* Make sure a component depends on magento/framework component
*
* @param \StdClass $json
*/
private function assertDependsOnFramework(\StdClass $json)
{
$this->assertObjectHasProperty(
self::$magentoFrameworkLibraryName,
$json,
'This component is expected to depend on ' . self::$magentoFrameworkLibraryName
);
}
/**
* Assert that PHP versions in root composer.json and Magento component's composer.json are not out of sync
*
* @param string $name
* @param string $phpVersion
*/
private function assertPhpVersionInSync($name, $phpVersion)
{
if (isset(self::$rootJson['require']['php'])) {
$composerVersionsPattern = '{\s*\|\|?\s*}';
$rootPhpVersions = preg_split($composerVersionsPattern, self::$rootJson['require']['php']);
$modulePhpVersions = preg_split($composerVersionsPattern, $phpVersion);
$this->assertEmpty(
array_diff($rootPhpVersions, $modulePhpVersions),
"PHP version {$phpVersion} in component {$name} is inconsistent with version "
. self::$rootJson['require']['php'] . ' in root composer.json'
);
}
}
/**
* Make sure requirements of components are reflected in root composer.json
*
* @param \StdClass $json
* @return void
*/
private function assertRequireInSync(\StdClass $json)
{
if (preg_match('/magento\/project-*/', self::$rootJson['name']) == 1) {
return;
}
if (!in_array($json->name, self::$rootComposerModuleBlacklist) && isset($json->require)) {
$this->checkPackageInRootComposer($json);
}
}
/**
* Check if package is reflected in root composer.json
*
* @param \StdClass $json
* @return void
*/
private function checkPackageInRootComposer(\StdClass $json)
{
$name = $json->name;
$errors = [];
foreach (array_keys((array)$json->require) as $depName) {
if ($depName == 'magento/magento-composer-installer') {
// Magento Composer Installer is not needed for already existing components
continue;
}
if (!isset(self::$rootJson['require-dev'][$depName]) && !isset(self::$rootJson['require'][$depName])
&& !isset(self::$rootJson['replace'][$depName])) {
$errors[] = "'$name' depends on '$depName'";
}
}
if (!empty($errors)) {
$this->fail(
"The following dependencies are missing in root 'composer.json',"
. " while declared in child components.\n"
. "Consider adding them to 'require-dev' section (if needed for child components only),"
. " to 'replace' section (if they are present in the project),"
. " to 'require' section (if needed for the skeleton).\n"
. join("\n", $errors)
);
}
}
/**
* Convert a fully qualified module name to a composer package name according to conventions
*
* @param string $moduleName
* @return string
*/
private function convertModuleToPackageName($moduleName)
{
list($vendor, $name) = explode('_', $moduleName, 2);
$package = 'module';
foreach (preg_split('/([A-Z\d][a-z]*)/', $name, -1, PREG_SPLIT_DELIM_CAPTURE) as $chunk) {
$package .= $chunk ? "-{$chunk}" : '';
}
return strtolower("{$vendor}/{$package}");
}
public function testComponentPathsInRoot()
{
if (!isset(self::$rootJson['extra']) || !isset(self::$rootJson['extra']['component_paths'])) {
$this->markTestSkipped("The root composer.json file doesn't mention any extra component paths information");
}
$this->assertArrayHasKey(
'replace',
self::$rootJson,
"If there are any component paths specified, then they must be reflected in 'replace' section"
);
$flat = $this->getFlatPathsInfo(self::$rootJson['extra']['component_paths']);
foreach ($flat as $item) {
list($component, $path) = $item;
$this->assertFileExists(
self::$root . '/' . $path,
"Missing or invalid component path: {$component} -> {$path}"
);
$this->assertArrayHasKey(
$component,
self::$rootJson['replace'],
"The {$component} is specified in 'extra->component_paths', but missing in 'replace' section"
);
}
foreach (array_keys(self::$rootJson['replace']) as $replace) {
if (!MagentoComponent::matchMagentoComponent($replace)) {
$this->assertArrayHasKey(
$replace,
self::$rootJson['extra']['component_paths'],
"The {$replace} is specified in 'replace', but missing in 'extra->component_paths' section"
);
}
}
}
/**
* @param array $info
* @return array
* @throws \Exception
*/
private function getFlatPathsInfo(array $info)
{
$flat = [];
foreach ($info as $key => $element) {
if (is_string($element)) {
$flat[] = [$key, $element];
} elseif (is_array($element)) {
foreach ($element as $path) {
$flat[] = [$key, $path];
}
} else {
throw new \Exception("Unexpected element 'in extra->component_paths' section");
}
}
return $flat;
}
/**
* @return void
*/
private function checkProject()
{
sort(self::$dependencies);
$dependenciesListed = [];
if (strpos(self::$rootJson['name'], 'magento/project-') !== 0) {
$this->assertArrayHasKey(
'replace',
(array)self::$rootJson,
'No "replace" section found in root composer.json'
);
foreach (array_keys((array)self::$rootJson['replace']) as $key) {
if (MagentoComponent::matchMagentoComponent($key)) {
$dependenciesListed[] = $key;
}
}
sort($dependenciesListed);
$nonDeclaredDependencies = array_diff(
self::$dependencies,
$dependenciesListed,
self::$rootComposerModuleBlacklist
);
$nonexistentDependencies = array_diff($dependenciesListed, self::$dependencies);
$this->assertEmpty(
$nonDeclaredDependencies,
'Following dependencies are not declared in the root composer.json: '
. join(', ', $nonDeclaredDependencies)
);
$this->assertEmpty(
$nonexistentDependencies,
'Following dependencies declared in the root composer.json do not exist: '
. join(', ', $nonexistentDependencies)
);
}
}
/**
* Check the correspondence between the root composer file and magento/framework composer file.
*/
public function testConsistencyOfDeclarationsInComposerFiles()
{
if (strpos(self::$rootJson['name'], 'magento/project-') !== false) {
// The Dependency test is skipped for vendor/magento build
self::markTestSkipped(
'The build is running for composer installation. Consistency test for composer files is skipped.'
);
}
$componentRegistrar = new ComponentRegistrar();
$magentoFrameworkLibraryDir =
$componentRegistrar->getPath(ComponentRegistrar::LIBRARY, self::$magentoFrameworkLibraryName);
$magentoFrameworkComposerFile =
json_decode(
file_get_contents($magentoFrameworkLibraryDir . DIRECTORY_SEPARATOR . 'composer.json'),
true
);
$inconsistentDependencies = [];
foreach ($magentoFrameworkComposerFile['require'] as $dependency => $constraint) {
if (isset(self::$rootJson['require'][$dependency])
&& self::$rootJson['require'][$dependency] !== $constraint
) {
$inconsistentDependencies[] = $dependency;
}
}
$this->assertEmpty(
$inconsistentDependencies,
'There is a discrepancy between the declared versions of the following modules in "'
. self::$magentoFrameworkLibraryName . '" and the root composer.json: '
. implode(', ', $inconsistentDependencies)
);
}
}
@@ -0,0 +1,65 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity;
use Magento\Framework\App\Utility\Classes;
class ConfigTest extends \PHPUnit\Framework\TestCase
{
public function testPaymentMethods()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* Verify whether all payment methods are declared in appropriate modules
*/
function ($configFile, $moduleName) {
$config = simplexml_load_file($configFile);
$nodes = $config->xpath('/config/default/payment/*/model') ?: [];
$formalModuleName = str_replace('_', '\\', $moduleName);
foreach ($nodes as $node) {
if (!Classes::isVirtual((string)$node)) {
$this->assertStringStartsWith(
$formalModuleName . '\Model\\',
(string)$node,
"'{$node}' payment method is declared in '{$configFile}' module, " .
"but doesn't belong to '{$moduleName}' module"
);
}
}
},
$this->paymentMethodsDataProvider()
);
}
public function paymentMethodsDataProvider()
{
$data = [];
foreach ($this->_getConfigFilesPerModule() as $configFile => $moduleName) {
$data[] = [$configFile, $moduleName];
}
return $data;
}
/**
* Get list of configuration files associated with modules
*
* @return array
*/
protected function _getConfigFilesPerModule()
{
$data = [];
$componentRegistrar = new \Magento\Framework\Component\ComponentRegistrar();
$modulesPaths = $componentRegistrar->getPaths(\Magento\Framework\Component\ComponentRegistrar::MODULE);
foreach ($modulesPaths as $moduleName => $path) {
if (file_exists($configFile = $path . '/etc/config.xml')) {
$data[$configFile] = $moduleName;
}
}
return $data;
}
}
@@ -0,0 +1,138 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Test\Integrity\DBSchema;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Setup\Declaration\Schema\Config\Converter;
use PHPUnit\Framework\TestCase;
/**
* Test for finding database tables missing primary key
*/
class PrimaryKeyTest extends TestCase
{
/**
* Check missing database tables' primary key
*
* @throws LocalizedException
*/
public function testMissingPrimaryKey()
{
$exemptionList = $this->getExemptionList();
$tablesSchemaDeclaration = $this->getDbSchemaDeclarations()['table'];
$exemptionList = array_intersect(array_keys($tablesSchemaDeclaration), $exemptionList);
foreach ($exemptionList as $exemptionTableName) {
unset($tablesSchemaDeclaration[$exemptionTableName]);
}
$errorMessage = '';
$failedTableCtr = 0;
foreach ($tablesSchemaDeclaration as $tableName => $tableSchemaDeclaration) {
if (!$this->hasPrimaryKey($tableSchemaDeclaration)) {
$message = '';
if (!empty($tableSchemaDeclaration['modules'])) {
$message = "It is declared in the following modules: \n" . implode(
"\t\n",
$tableSchemaDeclaration['modules']
);
}
$errorMessage .= 'Table ' . $tableName . ' does not have primary key. ' . $message . "\n";
$failedTableCtr ++;
}
}
if (!empty($errorMessage)) {
$errorMessage .= "\n\nTotal " . $failedTableCtr . " tables failed";
$this->fail($errorMessage);
}
}
/**
* Check table schema and verify if the table has primary key defined.
*
* @param array $tableSchemaDeclaration
* @return bool
*/
private function hasPrimaryKey(array $tableSchemaDeclaration): bool
{
if (isset($tableSchemaDeclaration['constraint'])) {
foreach ($tableSchemaDeclaration['constraint'] as $constraint) {
if ($constraint['type'] == 'primary') {
return true;
}
}
}
return false;
}
/**
* Get database schema declarations from file.
*
* @param string $filePath
* @return array
*/
private function getDbSchemaDeclarationByFile(string $filePath): array
{
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($filePath));
return (new Converter())->convert($dom);
}
/**
* Get database schema declarations for whole application
*
* @return array
* @throws LocalizedException
*/
private function getDbSchemaDeclarations(): array
{
$declarations = [];
foreach (Files::init()->getDbSchemaFiles() as $filePath) {
$filePath = reset($filePath);
preg_match('#/(\w+/\w+)/etc/db_schema.xml#', $filePath, $result);
$moduleName = str_replace('/', '_', $result[1]);
$moduleDeclaration = $this->getDbSchemaDeclarationByFile($filePath);
foreach ($moduleDeclaration['table'] as $tableName => $tableDeclaration) {
if (!isset($tableDeclaration['modules'])) {
$tableDeclaration['modules'] = [];
}
array_push($tableDeclaration['modules'], $moduleName);
$moduleDeclaration = array_replace_recursive(
$moduleDeclaration,
[
'table' => [
$tableName => $tableDeclaration,
]
]
);
}
$declarations = array_merge_recursive($declarations, $moduleDeclaration);
}
return $declarations;
}
/**
* Return primary key exemption tables list
*
* @return string[]
*/
private function getExemptionList(): array
{
$exemptionListFiles = str_replace(
'\\',
'/',
realpath(__DIR__) . '/_files/primary_key_exemption_list*.txt'
);
$exemptionList = [];
foreach (glob($exemptionListFiles) as $fileName) {
$exemptionList[] = file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}
return array_merge([], ...$exemptionList);
}
}
@@ -0,0 +1,152 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Test\Integrity;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\Utility\AggregateInvoker;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Exception\LocalizedException;
use Magento\Test\Integrity\Dependency\DeclarativeSchemaDependencyProvider;
use Magento\TestFramework\Inspection\Exception as InspectionException;
use PHPUnit\Framework\TestCase;
/**
* Class DeclarativeDependencyTest
* Test for undeclared dependencies in declarative schema
*/
class DeclarativeDependencyTest extends TestCase
{
/**
* @var DeclarativeSchemaDependencyProvider
*/
private $dependencyProvider;
/**
* Sets up data
*
* @throws InspectionException
*/
protected function setUp(): void
{
$root = BP;
$rootJson = $this->readJsonFile($root . '/composer.json', true);
if (preg_match('/magento\/project-*/', $rootJson['name']) == 1) {
// The Dependency test is skipped for vendor/magento build
self::markTestSkipped(
'MAGETWO-43654: The build is running from vendor/magento. DependencyTest is skipped.'
);
}
$objectManager = ObjectManager::getInstance();
$this->dependencyProvider = $objectManager->create(DeclarativeSchemaDependencyProvider::class);
}
/**
* @throws LocalizedException
*/
public function testUndeclaredDependencies()
{
$invoker = new AggregateInvoker($this);
$invoker(
/**
* Check undeclared modules dependencies for specified file
*
* @param string $fileType
* @param string $file
*/
function ($file) {
$componentRegistrar = new ComponentRegistrar();
$foundModuleName = '';
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $moduleDir) {
if (strpos($file, $moduleDir . '/') !== false) {
$foundModuleName = str_replace('_', '\\', $moduleName);
break;
}
}
if (empty($foundModuleName)) {
return;
}
$undeclaredDependency = $this->dependencyProvider->getUndeclaredModuleDependencies($foundModuleName);
$result = [];
foreach ($undeclaredDependency as $name => $modules) {
$modules = array_unique($modules);
$result[] = $this->getErrorMessage($name) . "\n" . implode("\t\n", $modules) . "\n";
}
if (!empty($result)) {
$this->fail(
'Module ' . $moduleName . ' has undeclared dependencies: ' . "\n" . implode("\t\n", $result)
);
}
},
$this->prepareFiles(Files::init()->getDbSchemaFiles())
);
}
/**
* Convert file list to data provider structure.
*
* @param string[] $files
* @return array
*/
private function prepareFiles(array $files): array
{
$result = [];
foreach ($files as $relativePath => $file) {
$absolutePath = reset($file);
$result[$relativePath] = [$absolutePath];
}
return $result;
}
/**
* Retrieve error message for dependency.
*
* @param string $id
* @return string
*/
private function getErrorMessage(string $id): string
{
$decodedId = DeclarativeSchemaDependencyProvider::decodeDependencyId($id);
$entityType = $decodedId['entityType'];
if ($entityType === DeclarativeSchemaDependencyProvider::SCHEMA_ENTITY_TABLE) {
$message = sprintf(
'Table %s has undeclared dependency on one of the following modules:',
$decodedId['tableName']
);
} else {
$message = sprintf(
'%s %s from %s table has undeclared dependency on one of the following modules:',
ucfirst($entityType),
$decodedId['entityName'],
$decodedId['tableName']
);
}
return $message;
}
/**
* Read data from json file.
*
* @param string $file
* @return mixed
* @throws InspectionException
*/
private function readJsonFile(string $file, bool $asArray = false)
{
$decodedJson = json_decode(file_get_contents($file), $asArray);
if (null == $decodedJson) {
throw new InspectionException("Invalid Json: $file");
}
return $decodedJson;
}
}
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Dependency;
/**
* Converter of webapi.xml content into array format.
*/
class Converter implements \Magento\Framework\Config\ConverterInterface
{
/**#@+
* Array keys for config internal representation.
*/
private const KEY_URL = 'url';
private const KEY_CLASS = 'class';
private const KEY_METHOD = 'method';
private const KEY_ROUTE = 'route';
private const KEY_ROUTES = 'routes';
private const KEY_SERVICE = 'service';
/**#@-*/
/**
* @inheritdoc
*/
public function convert($source)
{
$result = [];
/** @var \DOMNodeList $routes */
$routes = $source->getElementsByTagName(self::KEY_ROUTE);
/** @var \DOMElement $route */
foreach ($routes as $route) {
if ($route->nodeType != XML_ELEMENT_NODE) {
continue;
}
/** @var \DOMElement $service */
$service = $route->getElementsByTagName(self::KEY_SERVICE)->item(0);
$serviceClass = $service->attributes->getNamedItem(self::KEY_CLASS)->nodeValue;
$serviceMethod = $service->attributes->getNamedItem(self::KEY_METHOD)->nodeValue;
$url = trim($route->attributes->getNamedItem(self::KEY_URL)->nodeValue);
$method = $route->attributes->getNamedItem(self::KEY_METHOD)->nodeValue;
// We could handle merging here by checking if the route already exists
$result[self::KEY_ROUTES][$url][$method] = [
self::KEY_SERVICE => [
self::KEY_CLASS => $serviceClass,
self::KEY_SERVICE => $serviceMethod,
],
];
}
return $result;
}
}
@@ -0,0 +1,595 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Test\Integrity\Dependency;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Setup\Declaration\Schema\Config\Converter;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Inspection\Exception as InspectionException;
/**
* Provide information on the dependency between the modules according to the declarative schema.
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class DeclarativeSchemaDependencyProvider
{
/**
* Declarative name for table entity of the declarative schema.
*/
public const SCHEMA_ENTITY_TABLE = 'table';
/**
* Declarative name for column entity of the declarative schema.
*/
public const SCHEMA_ENTITY_COLUMN = 'column';
/**
* Declarative name for constraint entity of the declarative schema.
*/
public const SCHEMA_ENTITY_CONSTRAINT = 'constraint';
/**
* Declarative name for index entity of the declarative schema.
*/
public const SCHEMA_ENTITY_INDEX = 'index';
/**
* @var array
*/
private $dbSchemaDeclaration = [];
/**
* @var array
*/
private $moduleSchemaFileMapping = [];
/**
* @var DependencyProvider
*/
private $dependencyProvider;
/**
* @param DependencyProvider $dependencyProvider
*/
public function __construct(DependencyProvider $dependencyProvider)
{
$this->dependencyProvider = $dependencyProvider;
}
/**
* Provide declared dependencies between modules based on the declarative schema configuration.
*
* @param string $moduleName
* @return array
* @throws \Exception
*/
public function getDeclaredExistingModuleDependencies(string $moduleName): array
{
$dependencies = $this->getDependenciesFromFiles($this->getSchemaFileNameByModuleName($moduleName));
$dependencies = $this->filterSelfDependency($moduleName, $dependencies);
$declared = $this->dependencyProvider->getDeclaredDependencies(
$moduleName,
DependencyProvider::TYPE_HARD,
DependencyProvider::MAP_TYPE_DECLARED
);
$existingDeclared = [];
foreach ($dependencies as $dependency) {
$checkResult = array_intersect($declared, $dependency);
if ($checkResult) {
$existingDeclared[] = array_values($checkResult);
}
}
return array_unique(array_merge([], ...$existingDeclared));
}
/**
* Provide undeclared dependencies between modules based on the declarative schema configuration.
*
* [
* $dependencyId => [$module1, $module2, $module3 ...],
* ...
* ]
*
* @param string $moduleName
* @return array
* @throws \Exception
*/
public function getUndeclaredModuleDependencies(string $moduleName): array
{
$dependencies = $this->getDependenciesFromFiles($this->getSchemaFileNameByModuleName($moduleName));
$dependencies = $this->filterSelfDependency($moduleName, $dependencies);
return $this->collectDependencies($moduleName, $dependencies);
}
/**
* Provide schema file name by module name.
*
* @param string $module
* @return string
* @throws LocalizedException
*/
private function getSchemaFileNameByModuleName(string $module): string
{
if (empty($this->moduleSchemaFileMapping)) {
$componentRegistrar = new ComponentRegistrar();
foreach (array_values(Files::init()->getDbSchemaFiles()) as $filePath) {
$filePath = reset($filePath);
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $moduleDir) {
if (strpos($filePath, $moduleDir . '/') !== false) {
$foundModuleName = str_replace('_', '\\', $moduleName);
$this->moduleSchemaFileMapping[$foundModuleName] = $filePath;
break;
}
}
}
}
return $this->moduleSchemaFileMapping[$module] ?? '';
}
/**
* Remove self dependencies.
*
* @param string $moduleName
* @param array $dependencies
* @return array
*/
private function filterSelfDependency(string $moduleName, array $dependencies): array
{
foreach ($dependencies as $id => $modules) {
$decodedId = self::decodeDependencyId($id);
$entityType = $decodedId['entityType'];
if ($entityType === self::SCHEMA_ENTITY_TABLE || $entityType === "column") {
if (array_search($moduleName, $modules) !== false) {
unset($dependencies[$id]);
}
} else {
$dependencies[$id] = $this->filterComplexDependency($moduleName, $modules);
}
}
return array_filter($dependencies);
}
/**
* Remove already declared dependencies.
*
* @param string $moduleName
* @param array $modules
* @return array
*/
private function filterComplexDependency(string $moduleName, array $modules): array
{
$resultDependencies = [];
if (!is_array(reset($modules))) {
if (array_search($moduleName, $modules) === false) {
$resultDependencies = $modules;
}
} else {
foreach ($modules as $dependencySet) {
if (array_search($moduleName, $dependencySet) === false) {
$resultDependencies[] = $dependencySet;
}
}
$resultDependencies = array_merge([], ...$resultDependencies);
}
return array_values(array_unique($resultDependencies));
}
/**
* Retrieve declarative schema declaration.
*
* @return array
* @throws LocalizedException
*/
private function getDeclarativeSchema(): array
{
if ($this->dbSchemaDeclaration) {
return $this->dbSchemaDeclaration;
}
$entityTypes = [self::SCHEMA_ENTITY_COLUMN, self::SCHEMA_ENTITY_CONSTRAINT, self::SCHEMA_ENTITY_INDEX];
$declaration = [];
foreach (Files::init()->getDbSchemaFiles() as $filePath) {
$filePath = reset($filePath);
preg_match('#app/code/(\w+/\w+)#', $filePath, $result);
$moduleName = str_replace('/', '\\', $result[1]);
$moduleDeclaration = $this->getDbSchemaDeclaration($filePath);
foreach ($moduleDeclaration[self::SCHEMA_ENTITY_TABLE] as $tableName => $tableDeclaration) {
if (!isset($tableDeclaration['modules'])) {
$tableDeclaration['modules'] = [];
}
array_push($tableDeclaration['modules'], $moduleName);
$moduleDeclaration = array_replace_recursive(
$moduleDeclaration,
[self::SCHEMA_ENTITY_TABLE => [
$tableName => $tableDeclaration,
]
]
);
foreach ($entityTypes as $entityType) {
if (!isset($tableDeclaration[$entityType])) {
continue;
}
$moduleDeclaration = array_replace_recursive(
$moduleDeclaration,
[self::SCHEMA_ENTITY_TABLE => [
$tableName => $this->addModuleAssigment($tableDeclaration, $entityType, $moduleName)
]
]
);
}
}
$declaration = array_merge_recursive($declaration, $moduleDeclaration);
}
$this->dbSchemaDeclaration = $declaration;
return $this->dbSchemaDeclaration;
}
/**
* Get declared dependencies.
*
* @param string $tableName
* @param string $entityType
* @param null|string $entityName
* @return array
* @throws LocalizedException
*/
private function resolveEntityDependencies(string $tableName, string $entityType, ?string $entityName = null): array
{
switch ($entityType) {
case self::SCHEMA_ENTITY_COLUMN:
case self::SCHEMA_ENTITY_CONSTRAINT:
case self::SCHEMA_ENTITY_INDEX:
return $this->getDeclarativeSchema()
[self::SCHEMA_ENTITY_TABLE][$tableName][$entityType][$entityName]['modules'];
case self::SCHEMA_ENTITY_TABLE:
return $this->getDeclarativeSchema()[self::SCHEMA_ENTITY_TABLE][$tableName]['modules'];
default:
return [];
}
}
/**
* @param string $filePath
* @return array
*/
private function getDbSchemaDeclaration(string $filePath): array
{
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($filePath));
return (new Converter())->convert($dom);
}
/**
* Add dependency on the current module.
*
* @param array $tableDeclaration
* @param string $entityType
* @param string $moduleName
* @return array
*/
private function addModuleAssigment(
array $tableDeclaration,
string $entityType,
string $moduleName
): array {
$declarationWithAssigment = [];
foreach ($tableDeclaration[$entityType] as $entityName => $entityDeclaration) {
if (!isset($entityDeclaration['modules'])) {
$entityDeclaration['modules'] = [];
}
if (!$this->isEntityDisabled($entityDeclaration)) {
array_push($entityDeclaration['modules'], $moduleName);
}
$declarationWithAssigment[$entityType][$entityName] = $entityDeclaration;
}
return $declarationWithAssigment;
}
/**
* Retrieve dependencies from files.
*
* @param string $file
* @return string[]
* @throws \Exception
*/
private function getDependenciesFromFiles($file)
{
if (!$file) {
return [];
}
$moduleDbSchema = $this->getDbSchemaDeclaration($file);
$dependencies = array_merge_recursive(
$this->getDisabledDependencies($moduleDbSchema),
$this->getConstraintDependencies($moduleDbSchema),
$this->getIndexDependencies($moduleDbSchema)
);
return $dependencies;
}
/**
* Retrieve dependencies for disabled entities.
*
* @param array $moduleDeclaration
* @return array
* @throws LocalizedException
*/
private function getDisabledDependencies(array $moduleDeclaration): array
{
$disabledDependencies = [];
$entityTypes = [self::SCHEMA_ENTITY_COLUMN, self::SCHEMA_ENTITY_CONSTRAINT, self::SCHEMA_ENTITY_INDEX];
foreach ($moduleDeclaration[self::SCHEMA_ENTITY_TABLE] as $tableName => $tableDeclaration) {
foreach ($entityTypes as $entityType) {
if (!isset($tableDeclaration[$entityType])) {
continue;
}
foreach ($tableDeclaration[$entityType] as $entityName => $entityDeclaration) {
if ($this->isEntityDisabled($entityDeclaration)) {
$dependencyIdentifier = $this->getDependencyId($tableName, $entityType, $entityName);
$disabledDependencies[$dependencyIdentifier] =
$this->resolveEntityDependencies($tableName, $entityType, $entityName);
}
}
}
if ($this->isEntityDisabled($tableDeclaration)) {
$disabledDependencies[$this->getDependencyId($tableName)] =
$this->resolveEntityDependencies($tableName, self::SCHEMA_ENTITY_TABLE);
}
}
return $disabledDependencies;
}
/**
* Retrieve dependencies for foreign entities.
*
* @param array $constraintDeclaration
* @return array
* @throws \Exception
*/
private function getFKDependencies(array $constraintDeclaration): array
{
$referenceDependencyIdentifier =
$this->getDependencyId(
$constraintDeclaration['referenceTable'],
self::SCHEMA_ENTITY_CONSTRAINT,
$constraintDeclaration['referenceId']
);
$dependencyIdentifier =
$this->getDependencyId(
$constraintDeclaration[self::SCHEMA_ENTITY_TABLE],
self::SCHEMA_ENTITY_CONSTRAINT,
$constraintDeclaration['referenceId']
);
$constraintDependencies = [];
$constraintDependencies[$referenceDependencyIdentifier] =
$this->resolveEntityDependencies(
$constraintDeclaration['referenceTable'],
self::SCHEMA_ENTITY_COLUMN,
$constraintDeclaration['referenceColumn']
);
$constraintDependencies[$dependencyIdentifier] =
$this->resolveEntityDependencies(
$constraintDeclaration[self::SCHEMA_ENTITY_TABLE],
self::SCHEMA_ENTITY_COLUMN,
$constraintDeclaration[self::SCHEMA_ENTITY_COLUMN]
);
return $constraintDependencies;
}
/**
* Retrieve dependencies for constraint entities.
*
* @param array $moduleDeclaration
* @return array
* @throws \Exception
*/
private function getConstraintDependencies(array $moduleDeclaration): array
{
$constraintDependencies = [];
foreach ($moduleDeclaration[self::SCHEMA_ENTITY_TABLE] as $tableName => $tableDeclaration) {
if (empty($tableDeclaration[self::SCHEMA_ENTITY_CONSTRAINT])) {
continue;
}
foreach ($tableDeclaration[self::SCHEMA_ENTITY_CONSTRAINT] as $constraintName => $constraintDeclaration) {
if ($this->isEntityDisabled($constraintDeclaration)) {
continue;
}
$dependencyIdentifier =
$this->getDependencyId($tableName, self::SCHEMA_ENTITY_CONSTRAINT, $constraintName);
switch ($constraintDeclaration['type']) {
case 'foreign':
//phpcs:ignore Magento2.Performance.ForeachArrayMerge
$constraintDependencies = array_merge(
$constraintDependencies,
$this->getFKDependencies($constraintDeclaration)
);
break;
case 'primary':
case 'unique':
$constraintDependencies[$dependencyIdentifier] = $this->getComplexDependency(
$tableName,
$constraintDeclaration
);
}
}
}
return $constraintDependencies;
}
/**
* Calculate complex dependency.
*
* @param string $tableName
* @param array $entityDeclaration
* @return array
* @throws LocalizedException
*/
private function getComplexDependency(string $tableName, array $entityDeclaration): array
{
$complexDependency = [];
if (empty($entityDeclaration[self::SCHEMA_ENTITY_COLUMN])) {
return $complexDependency;
}
if (!is_array($entityDeclaration[self::SCHEMA_ENTITY_COLUMN])) {
$entityDeclaration[self::SCHEMA_ENTITY_COLUMN] = [$entityDeclaration[self::SCHEMA_ENTITY_COLUMN]];
}
foreach (array_keys($entityDeclaration[self::SCHEMA_ENTITY_COLUMN]) as $columnName) {
$complexDependency[] =
$this->resolveEntityDependencies($tableName, self::SCHEMA_ENTITY_COLUMN, $columnName);
}
return array_values($complexDependency);
}
/**
* Retrieve dependencies for index entities.
*
* @param array $moduleDeclaration
* @return array
* @throws LocalizedException
*/
private function getIndexDependencies(array $moduleDeclaration): array
{
$indexDependencies = [];
foreach ($moduleDeclaration[self::SCHEMA_ENTITY_TABLE] as $tableName => $tableDeclaration) {
if (empty($tableDeclaration[self::SCHEMA_ENTITY_INDEX])) {
continue;
}
foreach ($tableDeclaration[self::SCHEMA_ENTITY_INDEX] as $indexName => $indexDeclaration) {
if ($this->isEntityDisabled($indexDeclaration)) {
continue;
}
$dependencyIdentifier =
$this->getDependencyId($tableName, self::SCHEMA_ENTITY_INDEX, $indexName);
$indexDependencies[$dependencyIdentifier] =
$this->getComplexDependency($tableName, $indexDeclaration);
}
}
return $indexDependencies;
}
/**
* Check status of the entity declaration.
*
* @param array $entityDeclaration
* @return bool
*/
private function isEntityDisabled(array $entityDeclaration): bool
{
return isset($entityDeclaration['disabled']) && $entityDeclaration['disabled'] == true;
}
/**
* Retrieve dependency id.
*
* @param string $tableName
* @param string $entityType
* @param null|string $entityName
* @return string
*/
private function getDependencyId(
string $tableName,
string $entityType = self::SCHEMA_ENTITY_TABLE,
?string $entityName = null
) {
return implode('___', [$tableName, $entityType, $entityName ?: $tableName]);
}
/**
* Retrieve dependency parameters from dependency id.
*
* @param string $id
* @return array
*/
public static function decodeDependencyId(string $id): array
{
$decodedValues = explode('___', $id);
$result = [
'tableName' => $decodedValues[0],
'entityType' => $decodedValues[1],
'entityName' => $decodedValues[2],
];
return $result;
}
/**
* Collect module dependencies.
*
* @param $currentModuleName
* @param array $dependencies
* @return array
* @throws InspectionException
* @throws LocalizedException
*/
private function collectDependencies($currentModuleName, $dependencies = []): array
{
if (empty($dependencies)) {
return [];
}
foreach ($dependencies as $dependencyName => $dependency) {
$this->collectDependency($dependencyName, $dependency, $currentModuleName);
}
return $this->dependencyProvider->getDeclaredDependencies(
$currentModuleName,
DependencyProvider::TYPE_HARD,
DependencyProvider::MAP_TYPE_FOUND
);
}
/**
* Collect a module dependency.
*
* @param string $dependencyName
* @param array $dependency
* @param string $currentModule
* @throws LocalizedException
* @throws InspectionException
*/
private function collectDependency(
string $dependencyName,
array $dependency,
string $currentModule
) {
$declared = $this->dependencyProvider->getDeclaredDependencies(
$currentModule,
DependencyProvider::TYPE_HARD,
DependencyProvider::MAP_TYPE_DECLARED
);
$checkResult = array_intersect($declared, $dependency);
if (empty($checkResult)) {
$this->dependencyProvider->addDependencies(
$currentModule,
DependencyProvider::TYPE_HARD,
DependencyProvider::MAP_TYPE_FOUND,
[
$dependencyName => $dependency,
]
);
}
}
}
@@ -0,0 +1,221 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Test\Integrity\Dependency;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Config\Composer\Package;
use Magento\TestFramework\Inspection\Exception as InspectionException;
class DependencyProvider
{
/**
* Types of dependency between modules.
*/
public const TYPE_HARD = 'hard';
/**
* The identifier of dependency for mapping.
*/
public const MAP_TYPE_DECLARED = 'declared';
/**
* The identifier of dependency for mapping.
*/
public const MAP_TYPE_FOUND = 'found';
/**
* @var array
*/
private $mapDependencies = [];
/**
* @var array
*/
private $packageModuleMapping = [];
/**
* @var bool
*/
private $isInited = false;
/**
* Add dependency map items.
*
* @param $module
* @param $type
* @param $mapType
* @param $dependencies
* @throws LocalizedException
* @throws InspectionException
*/
public function addDependencies(string $module, string $type, string $mapType, array $dependencies)
{
if (!$this->isInited) {
$this->initDeclaredDependencies();
}
$this->mapDependencies[$module][$type][$mapType] = array_merge_recursive(
$this->getDeclaredDependencies($module, $type, $mapType),
$dependencies
);
}
/**
* Retrieve array of dependency items.
*
* @param $module
* @param $type
* @param $mapType
* @return array
* @throws LocalizedException
* @throws InspectionException
*/
public function getDeclaredDependencies(string $module, string $type, string $mapType): array
{
if (!$this->isInited) {
$this->initDeclaredDependencies();
}
return $this->mapDependencies[$module][$type][$mapType] ?? [];
}
/**
* Initialise map of dependencies.
*
* @throws InspectionException
* @throws LocalizedException
*/
private function initDeclaredDependencies()
{
$this->isInited = true;
if (empty($this->mapDependencies)) {
$jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false);
foreach ($jsonFiles as $file) {
$json = new Package($this->readJsonFile($file));
$moduleName = $this->convertModuleName($json->get('name'));
$require = array_keys((array)$json->get('require'));
$this->presetDependencies($moduleName, $require, self::TYPE_HARD);
}
}
}
/**
* Add dependencies to dependency list.
*
* @param string $moduleName
* @param array $packageNames
* @param string $type
*
* @return void
* @throws InspectionException
* @throws LocalizedException
*/
private function presetDependencies(string $moduleName, array $packageNames, string $type): void
{
$packageNames = array_filter($packageNames, function ($packageName) {
return $this->getModuleName($packageName) ||
0 === strpos($packageName, 'magento/') && 'magento/magento-composer-installer' != $packageName;
});
foreach ($packageNames as $packageName) {
$this->addDependencies(
$moduleName,
$type,
self::MAP_TYPE_DECLARED,
[$this->convertModuleName($packageName)]
);
}
}
/**
* @param string $jsonName
* @return string
* @throws InspectionException
* @throws LocalizedException
*/
private function convertModuleName(string $jsonName): string
{
$moduleName = $this->getModuleName($jsonName);
if ($moduleName) {
return $moduleName;
}
if (strpos($jsonName, 'magento/magento') !== false
|| strpos($jsonName, 'magento/framework') !== false
) {
$moduleName = str_replace('/', "\t", $jsonName);
$moduleName = str_replace('framework-', "Framework\t", $moduleName);
$moduleName = str_replace('-', ' ', $moduleName);
$moduleName = ucwords($moduleName);
$moduleName = str_replace("\t", '\\', $moduleName);
$moduleName = str_replace(' ', '', $moduleName);
} else {
$moduleName = $jsonName;
}
return $moduleName;
}
/**
* Read data from json file.
*
* @param string $file
* @return mixed
* @throws InspectionException
*/
private function readJsonFile(string $file, bool $asArray = false)
{
$decodedJson = json_decode(file_get_contents($file), $asArray);
if (null == $decodedJson) {
throw new InspectionException("Invalid Json: $file");
}
return $decodedJson;
}
/**
* Retrieve Magento style module name.
*
* @param string $packageName
* @return null|string
* @throws InspectionException
* @throws LocalizedException
*/
private function getModuleName(string $packageName): ?string
{
return $this->getPackageModuleMapping()[$packageName] ?? null;
}
/**
* Returns package name on module name mapping.
*
* @return array
* @throws InspectionException
* @throws LocalizedException
*/
private function getPackageModuleMapping(): array
{
if (!$this->packageModuleMapping) {
$jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false);
$packageModuleMapping = [];
foreach ($jsonFiles as $file) {
$moduleXml = simplexml_load_file(dirname($file) . '/etc/module.xml');
$moduleName = str_replace('_', '\\', (string)$moduleXml->module->attributes()->name);
$composerJson = $this->readJsonFile($file);
$packageName = $composerJson->name;
$packageModuleMapping[$packageName] = $moduleName;
}
$this->packageModuleMapping = $packageModuleMapping;
}
return $this->packageModuleMapping;
}
}
@@ -0,0 +1,160 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Test\Integrity\Dependency;
use Magento\Framework\GraphQlSchemaStitching\GraphQlReader;
use Magento\Framework\GraphQlSchemaStitching\GraphQlReader\TypeReaderComposite;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Inspection\Exception as InspectionException;
/**
* Provide information on the dependency between the modules according to the GraphQL schema.
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class GraphQlSchemaDependencyProvider
{
/**
* @var array
*/
private $parsedSchema = [];
/**
* @var DependencyProvider
*/
private $dependencyProvider;
/**
* @param DependencyProvider $dependencyProvider
*/
public function __construct(DependencyProvider $dependencyProvider)
{
$this->dependencyProvider = $dependencyProvider;
}
/**
* Provide declared dependencies between modules based on the declarative schema configuration.
*
* @param string $moduleName
* @return array
* @throws LocalizedException
* @throws InspectionException
*/
public function getDeclaredExistingModuleDependencies(string $moduleName): array
{
$dependencies = $this->getDependenciesFromSchema($moduleName);
$declared = $this->dependencyProvider->getDeclaredDependencies(
$moduleName,
DependencyProvider::TYPE_HARD,
DependencyProvider::MAP_TYPE_DECLARED
);
return array_unique(array_values(array_intersect($declared, $dependencies)));
}
/**
* Provide undeclared dependencies between modules based on the declarative schema configuration.
*
* [
* $dependencyId => [$module1, $module2, $module3 ...],
* ...
* ]
*
* @param string $moduleName
* @return array
* @throws InspectionException
* @throws LocalizedException
*/
public function getUndeclaredModuleDependencies(string $moduleName): array
{
$dependencies = $this->getDependenciesFromSchema($moduleName);
return $this->collectDependencies($moduleName, $dependencies);
}
/**
* Get parsed GraphQl schema
*
* @return array
*/
private function getGraphQlSchemaDeclaration(): array
{
if (!$this->parsedSchema) {
$objectManager = ObjectManager::getInstance();
$typeReader = $objectManager->create(TypeReaderComposite::class);
$reader = $objectManager->create(GraphQlReader::class, ['typeReader' => $typeReader]);
$this->parsedSchema = $reader->read();
}
return $this->parsedSchema;
}
/**
* Get dependencies from GraphQl schema
*
* @param string $moduleName
* @return array
*/
private function getDependenciesFromSchema(string $moduleName): array
{
$schema = $this->getGraphQlSchemaDeclaration();
$dependencies = [];
foreach ($schema as $type) {
if (isset($type['module']) && $type['module'] === $moduleName && isset($type['implements'])) {
$interfaces = array_keys($type['implements']);
foreach ($interfaces as $interface) {
$dependOnModule = $schema[$interface]['module'];
if ($dependOnModule !== $moduleName) {
$dependencies[] = $dependOnModule;
}
}
}
}
return array_unique($dependencies);
}
/**
* Collect module dependencies.
*
* @param string $currentModuleName
* @param array $dependencies
* @return array
* @throws InspectionException
* @throws LocalizedException
*/
private function collectDependencies(string $currentModuleName, array $dependencies = []): array
{
if (empty($dependencies)) {
return [];
}
$declared = $this->dependencyProvider->getDeclaredDependencies(
$currentModuleName,
DependencyProvider::TYPE_HARD,
DependencyProvider::MAP_TYPE_DECLARED
);
$checkResult = array_intersect($declared, $dependencies);
if (empty($checkResult)) {
$this->dependencyProvider->addDependencies(
$currentModuleName,
DependencyProvider::TYPE_HARD,
DependencyProvider::MAP_TYPE_FOUND,
[$currentModuleName => $dependencies]
);
}
return $this->dependencyProvider->getDeclaredDependencies(
$currentModuleName,
DependencyProvider::TYPE_HARD,
DependencyProvider::MAP_TYPE_FOUND
);
}
}
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Dependency;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Config\SchemaLocatorInterface;
class SchemaLocator implements SchemaLocatorInterface
{
/**
* @var string
*/
private $schema;
/**
* @var string
*/
private $perFileSchema;
public function __construct(ComponentRegistrar $componentRegistrar)
{
$module_path = $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Webapi');
$this->schema = $module_path . '/etc/webapi_merged.xsd';
$this->perFileSchema = $module_path . '/etc/webapi.xsd';
}
/**
* Return webapi_merged.xsd path
*
* @return string
*/
public function getSchema()
{
return $this->schema;
}
/**
* Return webapi.xsd path
*
* @return string
*/
public function getPerFileSchema()
{
return $this->perFileSchema;
}
}
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Dependency;
use Magento\Framework\Component\ComponentRegistrar;
/**
* Collects all webapi.xml files
*/
class WebapiFileResolver implements \Magento\Framework\Config\FileResolverInterface
{
/**
* @var ComponentRegistrar
*/
private $componentRegistrar;
/**
* @var string[]
*/
private $webapiXmlPaths;
public function __construct(ComponentRegistrar $componentRegistrar)
{
$this->componentRegistrar = $componentRegistrar;
}
/**
* @inheritDoc
*/
public function get($filename, $scope)
{
if (!$this->webapiXmlPaths) {
$paths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
$webapiXmlPaths = [];
foreach ($paths as $path) {
$path = $path . '/etc/webapi.xml';
if (file_exists($path)) {
$webapiXmlPaths[$path] = file_get_contents($path);
}
}
$this->webapiXmlPaths = $webapiXmlPaths;
}
return $this->webapiXmlPaths;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,418 @@
<?php
/**
* Compiler test. Check compilation of DI definitions and code generation
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Di;
use Magento\Framework\Api\Code\Generator\Mapper;
use Magento\Framework\Api\Code\Generator\SearchResults;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Interception\Code\InterfaceValidator;
use Magento\Framework\ObjectManager\Code\Generator\Converter;
use Magento\Framework\ObjectManager\Code\Generator\Factory;
use Magento\Framework\ObjectManager\Code\Generator\Repository;
use Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceGenerator;
use Magento\Framework\Api\Code\Generator\ExtensionAttributesGenerator;
use Magento\Framework\App\Utility\Files;
use Magento\TestFramework\Integrity\PluginValidator;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CompilerTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string
*/
protected $_command;
/**
* @var \Magento\Framework\Shell
*/
protected $_shell;
/**
* @var string
*/
protected $_generationDir;
/**
* @var string
*/
protected $_compilationDir;
/**
* @var \Magento\Framework\ObjectManager\Config\Mapper\Dom()
*/
protected $_mapper;
/**
* @var \Magento\Framework\Code\Validator
*/
protected $_validator;
/**
* Class arguments reader
*
* @var PluginValidator
*/
protected $pluginValidator;
/**
* @var string[]|null
*/
private $pluginBlacklist;
protected function setUp(): void
{
$this->_shell = new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer());
$basePath = BP;
$basePath = str_replace('\\', '/', $basePath);
$directoryList = new DirectoryList($basePath);
$this->_generationDir = $directoryList->getPath(DirectoryList::GENERATED_CODE);
$this->_compilationDir = $directoryList->getPath(DirectoryList::GENERATED_METADATA);
$this->_command = 'php ' . $basePath . '/bin/magento setup:di:compile';
$booleanUtils = new \Magento\Framework\Stdlib\BooleanUtils();
$constInterpreter = new \Magento\Framework\Data\Argument\Interpreter\Constant();
$argumentInterpreter = new \Magento\Framework\Data\Argument\Interpreter\Composite(
[
'boolean' => new \Magento\Framework\Data\Argument\Interpreter\Boolean($booleanUtils),
'string' => new \Magento\Framework\Data\Argument\Interpreter\BaseStringUtils($booleanUtils),
'number' => new \Magento\Framework\Data\Argument\Interpreter\Number(),
'null' => new \Magento\Framework\Data\Argument\Interpreter\NullType(),
'object' => new \Magento\Framework\Data\Argument\Interpreter\DataObject($booleanUtils),
'const' => $constInterpreter,
'init_parameter' => new \Magento\Framework\App\Arguments\ArgumentInterpreter($constInterpreter),
],
\Magento\Framework\ObjectManager\Config\Reader\Dom::TYPE_ATTRIBUTE
);
// Add interpreters that reference the composite
$argumentInterpreter->addInterpreter(
'array',
new \Magento\Framework\Data\Argument\Interpreter\ArrayType($argumentInterpreter)
);
$this->_mapper = new \Magento\Framework\ObjectManager\Config\Mapper\Dom(
$argumentInterpreter,
$booleanUtils,
new \Magento\Framework\ObjectManager\Config\Mapper\ArgumentParser()
);
$this->_validator = new \Magento\Framework\Code\Validator();
$this->_validator->add(new \Magento\Framework\Code\Validator\ConstructorIntegrity());
$this->_validator->add(new \Magento\Framework\Code\Validator\TypeDuplication());
$this->_validator->add(new \Magento\Framework\Code\Validator\ArgumentSequence());
$this->_validator->add(new \Magento\Framework\Code\Validator\ConstructorArgumentTypes());
$this->pluginValidator = new PluginValidator(new InterfaceValidator());
}
/**
* Return plugin blacklist class names
*
* @return string[]
*/
private function getPluginBlacklist(): array
{
if ($this->pluginBlacklist === null) {
$blacklistFiles = str_replace(
'\\',
'/',
realpath(__DIR__) . '/../_files/blacklist/compiler_plugins*.txt'
);
$blacklistItems = [];
foreach (glob($blacklistFiles) as $fileName) {
$blacklistItems[] = file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}
$blacklistItems = array_merge([], ...$blacklistItems);
$this->pluginBlacklist = $blacklistItems;
}
return $this->pluginBlacklist;
}
/**
* Validate DI config file
*
* @param string $file
*/
protected function _validateFile($file)
{
$dom = new \DOMDocument();
$dom->load($file);
$data = $this->_mapper->convert($dom);
foreach ($data as $instanceName => $parameters) {
if (!isset($parameters['parameters']) || empty($parameters['parameters'])) {
continue;
}
if (\Magento\Framework\App\Utility\Classes::isVirtual($instanceName)) {
$instanceName = \Magento\Framework\App\Utility\Classes::resolveVirtualType($instanceName);
}
if (!$this->_classExistsAsReal($instanceName)) {
continue;
}
$reflectionClass = new \ReflectionClass($instanceName);
$constructor = $reflectionClass->getConstructor();
if (!$constructor) {
$this->fail('Class ' . $instanceName . ' does not have __constructor');
}
$parameters = $parameters['parameters'];
$classParameters = $constructor->getParameters();
foreach ($classParameters as $classParameter) {
$parameterName = $classParameter->getName();
if (array_key_exists($parameterName, $parameters)) {
unset($parameters[$parameterName]);
}
}
$message = 'Configuration of ' . $instanceName . ' contains data for non-existed parameters: ' . implode(
', ',
array_keys($parameters)
);
$this->assertEmpty($parameters, $message);
}
}
/**
* Checks if class is a real one or generated Factory
* @param string $instanceName class name
* @throws \PHPUnit\Framework\AssertionFailedError
* @return bool
*/
protected function _classExistsAsReal($instanceName)
{
if (class_exists($instanceName)) {
return true;
}
// check for generated factory
if (substr($instanceName, -7) == 'Factory' && class_exists(substr($instanceName, 0, -7))) {
return false;
}
$this->fail('Detected configuration of non existed class: ' . $instanceName);
}
/**
* Get php classes list
*
* @return array
*/
protected function _phpClassesDataProvider()
{
$generationPath = str_replace('/', '\\', $this->_generationDir);
$files = Files::init()->getPhpFiles(Files::INCLUDE_APP_CODE | Files::INCLUDE_LIBS);
$patterns = ['/' . preg_quote($generationPath) . '/',];
$replacements = [''];
$componentRegistrar = new ComponentRegistrar();
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $modulePath) {
$patterns[] = '/' . preg_quote(str_replace('/', '\\', $modulePath)) . '/';
$replacements[] = '\\' . str_replace('_', '\\', $moduleName);
}
foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $libPath) {
$patterns[] = '/' . preg_quote(str_replace('/', '\\', $libPath)) . '/';
$replacements[] = '\\Magento\\Framework';
}
/** Convert file names into class name format */
$classes = [];
foreach ($files as $file) {
$file = str_replace('/', '\\', $file);
$filePath = preg_replace($patterns, $replacements, $file);
$className = substr($filePath, 0, -4);
if (class_exists($className, false)) {
$file = str_replace('\\', DIRECTORY_SEPARATOR, $file);
$classes[$file] = $className;
}
}
/** Build class inheritance hierarchy */
$output = [];
$allowedFiles = array_keys($classes);
foreach ($classes as $class) {
if (!in_array($class, $output)) {
$output[] = $this->_buildInheritanceHierarchyTree($class, $allowedFiles);
}
}
$output = array_unique(array_merge([], ...$output));
/** Convert data into data provider format */
$outputClasses = [];
foreach ($output as $className) {
$outputClasses[] = [$className];
}
return $outputClasses;
}
/**
* Build inheritance hierarchy tree
*
* @param string $className
* @param array $allowedFiles
* @return array
*/
protected function _buildInheritanceHierarchyTree($className, array $allowedFiles)
{
$output = [];
if (0 !== strpos($className, '\\')) {
$className = '\\' . $className;
}
$class = new \ReflectionClass($className);
$parent = $class->getParentClass();
$file = false;
if ($parent) {
$file = str_replace('\\', DIRECTORY_SEPARATOR, $parent->getFileName());
}
/** Prevent analysis of non Magento classes */
if ($parent && in_array($file, $allowedFiles)) {
$output = array_merge(
$this->_buildInheritanceHierarchyTree($parent->getName(), $allowedFiles),
[$className],
$output
);
} else {
$output[] = $className;
}
return array_unique($output);
}
/**
* Validate class
*
* @param string $className
*/
protected function _validateClass($className)
{
try {
$this->_validator->validate($className);
} catch (\Magento\Framework\Exception\ValidatorException $exceptions) {
$this->fail($exceptions->getMessage());
} catch (\ReflectionException $exceptions) {
$this->fail($exceptions->getMessage());
}
}
/**
* Validate DI configuration
*/
public function testConfigurationOfInstanceParameters()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
function ($file) {
$this->_validateFile($file);
},
Files::init()->getDiConfigs(true)
);
}
/**
* Validate constructor integrity
*/
public function testConstructorIntegrity()
{
$generatorIo = new \Magento\Framework\Code\Generator\Io(
new \Magento\Framework\Filesystem\Driver\File(),
$this->_generationDir
);
$generator = new \Magento\Framework\Code\Generator(
$generatorIo,
[
Factory::ENTITY_TYPE => \Magento\Framework\ObjectManager\Code\Generator\Factory::class,
Repository::ENTITY_TYPE => \Magento\Framework\ObjectManager\Code\Generator\Repository::class,
Converter::ENTITY_TYPE => \Magento\Framework\ObjectManager\Code\Generator\Converter::class,
Mapper::ENTITY_TYPE => \Magento\Framework\Api\Code\Generator\Mapper::class,
SearchResults::ENTITY_TYPE => \Magento\Framework\Api\Code\Generator\SearchResults::class,
ExtensionAttributesInterfaceGenerator::ENTITY_TYPE =>
\Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceGenerator::class,
ExtensionAttributesGenerator::ENTITY_TYPE =>
\Magento\Framework\Api\Code\Generator\ExtensionAttributesGenerator::class
]
);
$generationAutoloader = new \Magento\Framework\Code\Generator\Autoloader($generator);
spl_autoload_register([$generationAutoloader, 'load']);
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
function ($className) {
$this->_validateClass($className);
},
$this->_phpClassesDataProvider()
);
spl_autoload_unregister([$generationAutoloader, 'load']);
}
/**
* Test consistency of plugin interfaces
*/
public function testPluginInterfaces()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
function ($plugin, $type) {
$this->validatePlugins($plugin, $type);
},
$this->pluginDataProvider()
);
}
/**
* Validate plugin interface
*
* @param string $plugin
* @param string $type
*/
protected function validatePlugins($plugin, $type)
{
try {
$module = \Magento\Framework\App\Utility\Classes::getClassModuleName($type);
if (Files::init()->isModuleExists($module)) {
$this->pluginValidator->validate($plugin, $type);
}
} catch (\Magento\Framework\Exception\ValidatorException $exception) {
$this->fail($exception->getMessage());
}
}
/**
* Get application plugins
*
* @return array
* @throws \Exception
*/
protected function pluginDataProvider()
{
$files = Files::init()->getDiConfigs();
$plugins = [];
foreach ($files as $file) {
$dom = new \DOMDocument();
$dom->load($file);
$xpath = new \DOMXPath($dom);
$pluginList = $xpath->query('//config/type/plugin');
foreach ($pluginList as $node) {
/** @var $node \DOMNode */
$type = $node->parentNode->attributes->getNamedItem('name')->nodeValue;
$type = \Magento\Framework\App\Utility\Classes::resolveVirtualType($type);
if ($node->attributes->getNamedItem('type')) {
$plugin = $node->attributes->getNamedItem('type')->nodeValue;
if (!in_array($plugin, $this->getPluginBlacklist())) {
$plugin = \Magento\Framework\App\Utility\Classes::resolveVirtualType($plugin);
$plugins[] = [$plugin, $type];
}
}
}
}
return $plugins;
}
}
@@ -0,0 +1,136 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Test\Integrity;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\Utility\AggregateInvoker;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Exception\LocalizedException;
use Magento\Test\Integrity\Dependency\GraphQlSchemaDependencyProvider;
use Magento\TestFramework\Inspection\Exception as InspectionException;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;
class GraphQlDependencyTest extends TestCase
{
/**
* @var GraphQlSchemaDependencyProvider
*/
private $dependencyProvider;
/**
* Sets up data
*
* @throws InspectionException
*/
protected function setUp(): void
{
$root = BP;
$rootJson = $this->readJsonFile($root . '/composer.json', true);
if (preg_match('/magento\/project-*/', $rootJson['name']) == 1) {
// The Dependency test is skipped for vendor/magento build
self::markTestSkipped(
'MAGETWO-43654: The build is running from vendor/magento. DependencyTest is skipped.'
);
}
$objectManager = ObjectManager::getInstance();
$this->dependencyProvider = $objectManager->create(GraphQlSchemaDependencyProvider::class);
}
/**
* @throws LocalizedException
*/
public function testUndeclaredDependencies()
{
$invoker = new AggregateInvoker($this);
$invoker(
/**
* Check undeclared modules dependencies for specified file
*
* @param string $fileType
* @param string $file
* @throws LocalizedException
* @throws InspectionException
* @throws AssertionFailedError
*/
function ($file) {
$componentRegistrar = new ComponentRegistrar();
$foundModuleName = '';
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $moduleDir) {
if (strpos($file, $moduleDir . '/') !== false) {
$foundModuleName = str_replace('_', '\\', $moduleName);
break;
}
}
if (empty($foundModuleName)) {
return;
}
$undeclaredDependency = $this->dependencyProvider->getUndeclaredModuleDependencies($foundModuleName);
$result = [];
foreach ($undeclaredDependency as $name => $modules) {
$modules = array_unique($modules);
$result[] = $this->getErrorMessage($name) . "\n" . implode("\t\n", $modules) . "\n";
}
if (!empty($result)) {
$this->fail(
'Module ' . $moduleName . ' has undeclared dependencies: ' . "\n" . implode("\t\n", $result)
);
}
},
$this->prepareFiles(Files::init()->getDbSchemaFiles('schema.graphqls'))
);
}
/**
* Convert file list to data provider structure.
*
* @param string[] $files
* @return array
*/
private function prepareFiles(array $files): array
{
$result = [];
foreach ($files as $relativePath => $file) {
$absolutePath = reset($file);
$result[$relativePath] = [$absolutePath];
}
return $result;
}
/**
* Retrieve error message for dependency.
*
* @param string $id
* @return string
*/
private function getErrorMessage(string $id): string
{
return sprintf('%s has undeclared dependency on one of the following modules:', $id);
}
/**
* Read data from json file.
*
* @param string $file
* @return mixed
* @throws InspectionException
*/
private function readJsonFile(string $file, bool $asArray = false)
{
$decodedJson = json_decode(file_get_contents($file), $asArray);
if (null == $decodedJson) {
throw new InspectionException("Invalid Json: $file");
}
return $decodedJson;
}
}
@@ -0,0 +1,36 @@
<?php
/**
* Test block names exists
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Layout;
class BlockNamesTest extends \PHPUnit\Framework\TestCase
{
public function testBlocksHasName()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* Test validate that blocks without name doesn't exist in layout file
*
* @param string $layoutFile
*/
function ($layoutFile) {
$dom = new \DOMDocument();
$dom->load($layoutFile);
$xpath = new \DOMXpath($dom);
$count = $xpath->query('//block[not(@name)]')->length;
if ($count) {
$this->fail('Following file contains ' . $count . ' blocks without name. ' .
'File Path:' . "\n" . $layoutFile);
}
},
\Magento\Framework\App\Utility\Files::init()->getLayoutFiles()
);
}
}
@@ -0,0 +1,113 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Layout;
use Magento\Framework\App\Utility\Files;
class BlocksTest extends \PHPUnit\Framework\TestCase
{
/**
* @var array
*/
protected static $_containerAliases = [];
/**
* @var array
*/
protected static $_blockAliases = [];
/**
* Collect declarations of containers per layout file that have aliases
*/
public static function setUpBeforeClass(): void
{
foreach (Files::init()->getLayoutFiles([], false) as $file) {
$xml = simplexml_load_file($file);
$elements = $xml->xpath('/layout//*[self::container or self::block]') ?: [];
/** @var $node \SimpleXMLElement */
foreach ($elements as $node) {
$alias = (string)$node['as'];
if (empty($alias)) {
$alias = (string)$node['name'];
}
if ($node->getName() == 'container') {
self::$_containerAliases[$alias]['files'][] = $file;
self::$_containerAliases[$alias]['names'][] = (string)$node['name'];
} else {
self::$_blockAliases[$alias]['files'][] = $file;
self::$_blockAliases[$alias]['names'][] = (string)$node['name'];
}
}
}
}
public function testBlocksNotContainers()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* Check that containers are not used as blocks in templates
*
* @param string $alias
* @param string $file
* @throws \Exception|PHPUnit\Framework\ExpectationFailedException
*/
function ($alias, $file) {
if (isset(self::$_containerAliases[$alias])) {
if (!isset(self::$_blockAliases[$alias])) {
$this->fail(
"Element with alias '{$alias}' is used as a block in file '{$file}' " .
"via getChildBlock() method," .
" while '{$alias}' alias is declared as a container in file(s): " .
join(
', ',
self::$_containerAliases[$alias]['files']
)
);
} else {
$this->markTestSkipped(
"Element with alias '{$alias}' is used as a block in file '{$file}' " .
"via getChildBlock() method." .
" It's impossible to determine explicitly whether the element is a block or a container, " .
"as it is declared as a container in file(s): " .
join(
', ',
self::$_containerAliases[$alias]['files']
) . " and as a block in file(s): " . join(
', ',
self::$_blockAliases[$alias]['files']
)
);
}
}
},
$this->getChildBlockDataProvider()
);
}
/**
* @return array
*/
public function getChildBlockDataProvider()
{
$result = [];
$collectedFiles = Files::init()->getPhpFiles(
Files::INCLUDE_APP_CODE
| Files::INCLUDE_TEMPLATES
| Files::INCLUDE_NON_CLASSES
);
foreach ($collectedFiles as $file) {
$aliases = \Magento\Framework\App\Utility\Classes::getAllMatches(
file_get_contents($file),
'/\->getChildBlock\(\'([^\']+)\'\)/x'
);
foreach ($aliases as $alias) {
$result[$file] = [$alias, $file];
}
}
return $result;
}
}
@@ -0,0 +1,97 @@
<?php
/**
* Test format of layout files
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Layout;
class HandlesTest extends \PHPUnit\Framework\TestCase
{
/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function testHandleDeclarations()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* Test dependencies between handle attributes that is out of coverage by XSD
*
* @param string $layoutFile
*/
function ($layoutFile) {
$issues = [];
$node = simplexml_load_file($layoutFile);
$label = $node['label'];
$designAbstraction = $node['design_abstraction'];
if (!$label) {
if ($designAbstraction) {
$issues[] = 'Attribute "design_abstraction" is defined, but "label" is not';
}
}
if ($issues) {
$this->fail("Issues found in handle declaration:\n" . implode("\n", $issues) . "\n");
}
},
\Magento\Framework\App\Utility\Files::init()->getLayoutFiles()
);
}
public function testContainerDeclarations()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* Test dependencies between container attributes that is out of coverage by XSD
*
* @param string $layoutFile
*/
function ($layoutFile) {
$issues = [];
$xml = simplexml_load_file($layoutFile);
$containers = $xml->xpath('/layout//container') ?: [];
/** @var \SimpleXMLElement $node */
foreach ($containers as $node) {
if (!isset($node['htmlTag']) && (isset($node['htmlId']) || isset($node['htmlClass']))) {
$issues[] = $node->asXML();
}
}
if ($issues) {
$this->fail(
'The following containers declare attribute "htmlId" and/or "htmlClass", but not "htmlTag":' .
"\n" .
implode(
"\n",
$issues
) . "\n"
);
}
},
\Magento\Framework\App\Utility\Files::init()->getLayoutFiles()
);
}
public function testHeadBlockUsage()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* Test validate that head block doesn't exist in layout
*
* @param string $layoutFile
*/
function ($layoutFile) {
$dom = new \DOMDocument();
$dom->load($layoutFile);
$xpath = new \DOMXpath($dom);
if ($xpath->query("//*[@name='head']")->length) {
$this->fail('Following file contains deprecated head block. File Path:' . "\n" . $layoutFile);
}
},
\Magento\Framework\App\Utility\Files::init()->getLayoutFiles()
);
}
}
@@ -0,0 +1,108 @@
<?php
/**
* Test layout declaration and usage of block elements
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Layout;
use Magento\Framework\App\Utility\Files;
class TemplatesTest extends \PHPUnit\Framework\TestCase
{
/**
* @var array
*/
protected static $templates = [];
/**
* @var array
*/
protected static $blockVirtualTypes = [];
/**
* Collect declarations of containers per layout file that have aliases
*/
public static function setUpBeforeClass(): void
{
$count = 0;
self::getBlockVirtualTypesWithDifferentModule();
foreach (Files::init()->getLayoutFiles([], false) as $file) {
$xml = simplexml_load_file($file);
$blocks = $xml->xpath('//block[@template]') ?: [];
$fileTemplates = [];
foreach ($blocks as $block) {
$fileTemplates[] = ['class' => (string)$block['class'], 'file' => (string)$block['template']];
}
if (!empty($fileTemplates)) {
self::$templates[$file] = $fileTemplates;
$count += count($fileTemplates);
}
}
}
/**
* Test that references to template files follows canonical format.
*
* path/to/template.phtml Format is prohibited.
* @return void
*/
public function testTemplateFollowsCanonicalName()
{
$errors = [];
$warnings = [];
foreach (self::$templates as $file => $templates) {
foreach ($templates as $templatePair) {
if (!preg_match('/[A-Za-z0-9]_[A-Za-z0-9]+\:\:[A-Za-z0-9\\_\-\.]+/', $templatePair['file'])) {
if (!isset($errors[$file])) {
$errors[$file] = [];
}
$errors[$file][] = $templatePair['file'];
} else {
if (isset(self::$blockVirtualTypes[$templatePair['class']])) {
$warnings[$file][] = $templatePair;
}
}
}
}
if (count($errors) > 0) {
$message = 'Failed to assert that the template reference follows the canonical format '
. 'Vendor' . '_' . 'Module::path/to/template.phtml. Following files haven\'t pass verification:'
. PHP_EOL;
foreach ($errors as $file => $wrongTemplates) {
$message .= $file . ':' . PHP_EOL;
$message .= '- ' . implode(PHP_EOL . '- ', $wrongTemplates) . PHP_EOL;
}
$this->fail($message);
}
}
/**
* Initialize array with the Virtual types for blocks
*
* Contains just those occurrences where base type and virtual type are located in different modules
*/
private static function getBlockVirtualTypesWithDifferentModule()
{
$virtual = \Magento\Framework\App\Utility\Classes::getVirtualClasses();
foreach ($virtual as $className => $resolvedName) {
if (strpos($resolvedName, 'Block') !== false) {
$matches = [];
preg_match('/([A-Za-z0-9]+\\\\[A-Za-z0-9]+).*/', $className, $matches);
if (count($matches) > 1) {
$oldModule = $matches[1];
} else {
$oldModule = $className;
}
$matches = [];
preg_match('/([A-Za-z0-9]+\\\\[A-Za-z0-9]+).*/', $resolvedName, $matches);
$newModule = $matches[1];
if ($oldModule != $newModule) {
self::$blockVirtualTypes[$className] = $resolvedName;
}
}
}
}
}
@@ -0,0 +1,87 @@
<?php
/**
* Test declarations of handles in theme layout updates
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Layout;
class ThemeHandlesTest extends \PHPUnit\Framework\TestCase
{
/**
* @var array|null
*/
protected $_baseFrontendHandles = null;
public function testIsDesignHandleDeclaredInCode()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* Check that all handles declared in a theme layout are declared in base layouts
*
* @param string $handleName
*/
function ($handleName) {
$this->assertContains(
$handleName,
$this->_getBaseFrontendHandles(),
"Handle '{$handleName}' is not declared in any module.'"
);
},
$this->designHandlesDataProvider()
);
}
/**
* @return array
*/
public function designHandlesDataProvider()
{
$files = \Magento\Framework\App\Utility\Files::init()->getLayoutFiles(
['include_code' => false, 'area' => 'frontend'],
false
);
$handles = $this->_extractLayoutHandles($files);
$result = [];
foreach ($handles as $handleName) {
$result[$handleName] = [$handleName];
}
return $result;
}
/**
* Return layout handles that are declared in the base layouts for frontend
*
* @return array
*/
protected function _getBaseFrontendHandles()
{
if ($this->_baseFrontendHandles === null) {
$files = \Magento\Framework\App\Utility\Files::init()->getLayoutFiles(
['include_design' => false, 'area' => 'frontend'],
false
);
$this->_baseFrontendHandles = $this->_extractLayoutHandles($files);
}
return $this->_baseFrontendHandles;
}
/**
* Retrieve the list of unique layout handle names from the layout files
*
* @param array $files
* @return array
*/
protected function _extractLayoutHandles(array $files)
{
$result = [];
foreach ($files as $filename) {
$handleName = basename($filename, '.xml');
$result[] = $handleName;
}
$result = array_unique($result);
return $result;
}
}
@@ -0,0 +1,184 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Library;
use Laminas\Code\Reflection\ClassReflection;
use Laminas\Code\Reflection\Exception\InvalidArgumentException;
use Magento\Framework\App\Utility\AggregateInvoker;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Setup\Module\Di\Code\Reader\FileClassScanner;
use Magento\TestFramework\Integrity\Library\Injectable;
use Magento\TestFramework\Integrity\Library\PhpParser\ParserFactory;
use Magento\TestFramework\Integrity\Library\PhpParser\Tokens;
use PHPUnit\Framework\TestCase;
/**
* Test check if Magento library components contain incorrect dependencies to application layer
*
*/
class DependencyTest extends TestCase
{
/**
* Collect errors
*
* @var array
*/
protected $errors = [];
/**
* Allowed sub namespaces
*
* @return array
*/
protected function getAllowedNamespaces()
{
return [
'Framework',
'SomeModule',
'ModuleName',
'Setup\Console\CommandList',
'Setup\Console\CompilerPreparation',
'Setup\Model\ObjectManagerProvider',
'Setup\Mvc\Bootstrap\InitParamListener',
'Store\Model\ScopeInterface',
'Store\Model\StoreManagerInterface',
'Directory\Model\CurrencyFactory',
'PageCache\Model\Cache\Type',
'Backup\Model\ResourceModel\Db',
'Backend\Block\Widget\Button',
'Ui\Component\Container',
'SalesRule\Model\Rule',
'SalesRule\Api\Data\RuleInterface',
'SalesRule\Model\Rule\Interceptor',
'SalesRule\Model\Rule\Proxy',
'Theme\Model\View\Design'
];
}
public function testCheckDependencies(): void
{
$invoker = new AggregateInvoker($this);
$invoker(
/**
* @param string $file
*/
function ($file) {
$this->errors = [];
$componentRegistrar = new ComponentRegistrar();
$reflectedFilePath = $this->getFilePath($file);
$tokens = new Tokens(file_get_contents($reflectedFilePath), new ParserFactory());
$tokens->parseContent();
$fileScanner = new FileClassScanner($file);
$className = $fileScanner->getClassName();
if ($className) { // could be not a class but just a php-file
$class = new ClassReflection($className);
$classUses = (new Injectable())->getDependencies($class);
} else {
$classUses = [];
}
$dependencies = array_merge(
$classUses,
$tokens->getDependencies()
);
$allowedNamespaces = str_replace('\\', '\\\\', implode('|', $this->getAllowedNamespaces()));
$pattern = '#Magento\\\\(?!' . $allowedNamespaces . ').*#';
foreach ($dependencies as $dependency) {
$dependencyPaths = explode('\\', $dependency);
$dependencyPaths = array_slice($dependencyPaths, 2);
$dependencyPath = implode('\\', $dependencyPaths);
$libraryPaths = $componentRegistrar->getPaths(ComponentRegistrar::LIBRARY);
foreach ($libraryPaths as $libraryPath) {
$filePath = str_replace('\\', '/', $libraryPath . '/' . $dependencyPath . '.php');
if (preg_match($pattern, $dependency) && !file_exists($filePath)) {
$this->errors[basename($reflectedFilePath)][] = $dependency;
}
}
}
if (!empty($this->errors)) {
$this->fail($this->getFailMessage());
}
},
$this->libraryDataProvider()
);
}
/**
* copied from laminas-code 3.5.1
*
* @param string $filename
*
* @return string
*/
private function getFilePath(string $filename): string
{
if (($fileRealPath = realpath($filename)) === false) {
$fileRealPath = stream_resolve_include_path($filename);
}
if (! $fileRealPath) {
throw new InvalidArgumentException(sprintf(
'No file for %s was found.',
$filename
));
}
return $fileRealPath;
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->errors = [];
}
/**
* Prepare failed message
*
* @return string
*/
protected function getFailMessage()
{
$failMessage = '';
foreach ($this->errors as $class => $dependencies) {
$failMessage .= $class . ' depends for non-library ' . (count($dependencies) > 1 ? 'classes ' : 'class ');
foreach ($dependencies as $dependency) {
$failMessage .= $dependency . ' ';
}
$failMessage = trim($failMessage) . PHP_EOL;
}
return $failMessage;
}
/**
* Contains all library files
*
* @return array
*/
public function libraryDataProvider()
{
// @TODO: remove this code when class Magento\Framework\Data\Collection will fixed
$componentRegistrar = new ComponentRegistrar();
include_once $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework')
. '/Option/ArrayInterface.php';
$blackList = Files::init()->readLists(__DIR__ . '/_files/blacklist*.txt');
$dataProvider = Files::init()->getPhpFiles(Files::INCLUDE_LIBS | Files::AS_DATA_SET);
foreach ($dataProvider as $key => $data) {
if (in_array($data[0], $blackList)) {
unset($dataProvider[$key]);
} else {
include_once $data[0];
}
}
return $dataProvider;
}
}
@@ -0,0 +1,74 @@
library magento/framework Data/Collection/Filesystem.php
library magento/framework Data/Form/Element/Radio.php
library magento/framework Data/Form/Element/Label.php
library magento/framework Data/Form/Element/AbstractElement.php
library magento/framework Data/Form/Element/File.php
library magento/framework Data/Form/Element/Checkbox.php
library magento/framework Data/Form/Element/Checkboxes.php
library magento/framework Data/Form/Element/Password.php
library magento/framework Data/Form/Element/Column.php
library magento/framework Data/Form/Element/Gallery.php
library magento/framework Data/Form/Element/Obscure.php
library magento/framework Data/Form/Element/Multiline.php
library magento/framework Data/Form/Element/Radios.php
library magento/framework Data/Form/Element/Submit.php
library magento/framework Data/Form/Element/Note.php
library magento/framework Data/Form/Element/Image.php
library magento/framework Data/Form/Element/Text.php
library magento/framework Data/Form/Element/Time.php
library magento/framework Data/Form/Element/Button.php
library magento/framework Data/Form/Element/Editor.php
library magento/framework Data/Form/Element/Hidden.php
library magento/framework Data/Form/Element/Reset.php
library magento/framework Data/Form/Element/Link.php
library magento/framework Data/Form/Element/Editablemultiselect.php
library magento/framework Data/Form/Element/Multiselect.php
library magento/framework Data/Form/Element/Fieldset.php
library magento/framework Data/Form/Element/Select.php
library magento/framework Data/Form/Element/Textarea.php
library magento/framework Data/Form/Element/Imagefile.php
library magento/framework Data/Form/Element/Imagefile.php
library magento/framework Data/Form/Element/Date.php
library magento/framework Data/Form/AbstractForm.php
library magento/framework Data/Collection.php
library magento/framework Data/Form.php
library magento/framework Data/Form/FormKey.php
library magento/framework Exception/AuthenticationException.php
library magento/framework Exception/AuthorizationException.php
library magento/framework Exception/InputException.php
library magento/framework Exception/NoSuchEntityException.php
library magento/framework View/Context.php
library magento/framework View/Element/Js/Cookie.php
library magento/framework View/Element/Html/Calendar.php
library magento/framework View/Element/Html/Link/Current.php
library magento/framework View/Element/Messages.php
library magento/framework View/Element/AbstractBlock.php
library magento/framework View/Element/Template.php
library magento/framework View/Element/Context.php
library magento/framework View/Element/Template/Context.php
library magento/framework View/Element/Redirect.php
library magento/framework Event/Invoker/InvokerDefault.php
library magento/framework Phrase/Renderer/Translate.php
library magento/framework Backup/Snapshot.php
library magento/framework Oauth/Exception.php
library magento/framework App/Helper/AbstractHelper.php
library magento/framework App/Helper/Context.php
library magento/framework View/DesignLoader.php
library magento/framework View/Page/Config.php
library magento/framework View/Page/Title.php
library magento/framework Session/SidResolverInterface.php
library magento/framework Filesystem/Driver/Http.php
library magento/framework Url/ScopeResolver.php
library magento/framework Url/SecurityInfo.php
library magento/framework Url/RouteParamsResolver.php
library magento/framework View/Url/Config.php
library magento/framework View/Asset/Config.php
library magento/framework Locale/Format.php
@@ -0,0 +1,260 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Backend;
use Magento\TestFramework\Utility\ChangedFiles;
use Magento\Framework\App\Utility\Files;
use Magento\Backend\App\AbstractAction;
class ControllerAclTest extends \PHPUnit\Framework\TestCase
{
/**
* Default function for checking accessibility of the ACL resource.
*/
const ACL_FUNC_NAME = '_isAllowed';
/**
* Name of the const. that contains ACL resource path.
*/
const ACL_CONST_NAME = 'ADMIN_RESOURCE';
/**
* Default value from the AbstractResource.
*/
const DEFAULT_BACKEND_RESOURCE = 'Magento_Backend::admin';
/**
* Several backend controllers should be accessible always, and can't be closed by ACL.
*
* @var array
*/
private $whiteListedBackendControllers = [];
/**
* List of ACL resources collected from acl.xml files.
*
* @var null|array
*/
private $aclResources;
/**
* Set up before test execution.
*/
protected function setUp(): void
{
$whitelistedClasses = [];
$path = sprintf('%s/_files/controller_acl_test_whitelist_*.txt', __DIR__);
foreach (glob($path) as $listFile) {
$whitelistedClasses = array_merge(
$whitelistedClasses,
file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
);
}
foreach ($whitelistedClasses as $item) {
if (substr($item, 0, 1) === '#') {
continue;
}
$this->whiteListedBackendControllers[$item] = 1;
}
}
/**
* Test ACL in the admin area by various assertions.
*/
public function testAcl()
{
$errorMessages = [];
$pathMask = sprintf('%s/../../../_files/changed_files*', __DIR__, DIRECTORY_SEPARATOR);
$changedFiles = ChangedFiles::getPhpFiles($pathMask);
foreach ($changedFiles as $line) {
$relativeFilePath = $line[0];
// we don't have to check tests,
if ($this->isItTest($relativeFilePath)) {
continue;
}
$controllerPath = $this->getControllerPath($relativeFilePath);
if (!$controllerPath) {
continue;
}
$controllerClass = $this->getClassByFilePath($controllerPath);
// skip whitelisted controllers.
if (isset($this->whiteListedBackendControllers[$controllerClass->getName()])) {
continue;
}
// we don't have to check abstract classes.
if ($controllerClass->isAbstract()) {
continue;
}
$className = $controllerClass->getName();
if (!$this->isClassExtendsBackendClass($controllerClass)) {
$inheritanceMessage = "Backend controller $className have to inherit " . AbstractAction::class;
$errorMessages[] = $inheritanceMessage;
continue;
}
$isAclRedefinedInTheChildClass = $this->isConstantOverwritten($controllerClass)
|| $this->isMethodOverwritten($controllerClass);
if (!$isAclRedefinedInTheChildClass) {
$errorMessages[] = "Backend controller $className have to overwrite _isAllowed method or "
. 'ADMIN_RESOURCE constant';
}
$errorMessages = array_merge($errorMessages, $this->collectAclErrorsInTheXml($controllerClass));
}
sort($errorMessages);
$this->assertEmpty($errorMessages, implode("\n", $errorMessages));
}
/**
* Collect possible errors for the ACL that exists in the php code but doesn't exists in the XML code.
*
* @param \ReflectionClass $class
* @return array
*/
private function collectAclErrorsInTheXml(\ReflectionClass $class)
{
$errorMessages = [];
$className = $class->getName();
$method = $class->getMethod(self::ACL_FUNC_NAME);
$codeLines = file($method->getFileName());
$length = $method->getEndLine() - $method->getStartLine();
$start = $method->getStartLine();
$codeOfTheMethod = implode(' ', array_slice($codeLines, $start, $length));
preg_match('~["\']Magento_.*?::.*?["\']~', $codeOfTheMethod, $matches);
$aclResources = $this->getAclResources();
foreach ($matches as $resource) {
$resourceUnquoted = str_replace(['"', "'"], ['', ''], $resource);
if (!isset($aclResources[$resourceUnquoted])) {
$errorMessages[] = "ACL $resource exists in $className but doesn't exists in the acl.xml file";
}
}
return $errorMessages;
}
/**
* Collect all available ACL resources from acl.xml files.
*
* @return array
*/
private function getAclResources()
{
if ($this->aclResources !== null) {
return $this->aclResources;
}
$aclFiles = Files::init()->getConfigFiles('acl.xml', []);
$xmlResources = [];
array_map(function ($file) use (&$xmlResources) {
$config = simplexml_load_file($file[0]);
$nodes = $config->xpath('.//resource/@id') ?: [];
foreach ($nodes as $node) {
$xmlResources[(string)$node] = $node;
}
}, $aclFiles);
$this->aclResources = $xmlResources;
return $this->aclResources;
}
/**
* Is ADMIN_RESOURCE constant was overwritten in the child class.
*
* @param \ReflectionClass $class
* @return bool
*/
private function isConstantOverwritten(\ReflectionClass $class)
{
// check that controller overwrites default ACL to some specific
if ($class->getConstant(self::ACL_CONST_NAME) !== self::DEFAULT_BACKEND_RESOURCE) {
return true;
}
return false;
}
/**
* Is _isAllowed method was overwritten in the child class.
*
* @param \ReflectionClass $class
* @return bool
*/
private function isMethodOverwritten(\ReflectionClass $class)
{
// check that controller overwrites default ACL to some specific (at least we check that it was overwritten).
$method = $class->getMethod(self::ACL_FUNC_NAME);
try {
$method->getPrototype();
return true;
} catch (\ReflectionException $e) {
return false;
}
}
/**
* Is controller extends Magento\Backend\App\AbstractAction.
*
* @param \ReflectionClass $class
* @return bool
*/
private function isClassExtendsBackendClass(\ReflectionClass $class)
{
while ($parentClass = $class->getParentClass()) {
if (AbstractAction::class === $parentClass->getName()) {
return true;
}
$class = $parentClass;
}
return false;
}
/**
* Check is file looks like a test.
*
* @param string $relativeFilePath
* @return bool
*/
private function isItTest($relativeFilePath)
{
$isTest = (preg_match('~.*?(/dev/tests/|/Test/Unit/).*?\.php$~', $relativeFilePath) === 1);
return $isTest;
}
/**
* Get c
*
* @param string $relativeFilePath
* @return string
*/
private function getControllerPath($relativeFilePath)
{
if (preg_match('~(Magento\/[^\/]+\/Controller\/Adminhtml\/.*)\.php~', $relativeFilePath, $matches)) {
if (count($matches) === 2) {
$partPath = $matches[1];
return $partPath;
}
}
return '';
}
/**
* Try to get reflection for a admin html controller class by it path.
*
* @param string $controllerPath
* @return \ReflectionClass
*/
private function getClassByFilePath($controllerPath)
{
$className = str_replace('/', '\\', $controllerPath);
try {
$reflectionClass = new \ReflectionClass($className);
} catch (\ReflectionException $e) {
$reflectionClass = new \ReflectionClass(new \stdClass());
}
return $reflectionClass;
}
}
@@ -0,0 +1,32 @@
<?php
/**
* Find "backend/system.xml" files and validate them
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Backend;
class SystemConfigTest extends \PHPUnit\Framework\TestCase
{
public function testSchema()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $configFile
*/
function ($configFile) {
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($configFile));
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
$schema = $urnResolver->getRealPath('urn:magento:module:Magento_Config:etc/system_file.xsd');
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
if ($errors) {
$this->fail('XML-file has validation errors:' . PHP_EOL . implode(PHP_EOL . PHP_EOL, $errors));
}
},
\Magento\Framework\App\Utility\Files::init()->getConfigFiles('adminhtml/system.xml', [])
);
}
}
@@ -0,0 +1,35 @@
Magento\Security\Controller\Adminhtml\Session\Activity
Magento\Security\Controller\Adminhtml\Session\LogoutAll
Magento\Backend\Controller\Adminhtml\Denied
Magento\Backend\Controller\Adminhtml\Noroute\Index
Magento\Directory\Controller\Adminhtml\Json\CountryRegion
Magento\Tax\Controller\Adminhtml\Rule\AjaxLoadRates
# List of classes that locates in controllers folder but don't inherit base admin controller MAGETWO-70433.
Magento\Bundle\Controller\Adminhtml\Product\Initialization\Helper\Plugin\Bundle
Magento\CatalogUrlRewrite\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper
Magento\Catalog\Controller\Adminhtml\Product\Builder
Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper
Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\HandlerFactory
Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\Plugin\Handler\Composite
Magento\Catalog\Controller\Adminhtml\Product\Initialization\StockDataFilter
Magento\Cms\Controller\Adminhtml\Page\PostDataProcessor
Magento\Config\Controller\Adminhtml\System\ConfigSectionChecker
Magento\ConfigurableProduct\Controller\Adminhtml\Product\Builder\Plugin
Magento\ConfigurableProduct\Controller\Adminhtml\Product\Initialization\Helper\Plugin\Configurable
Magento\ConfigurableProduct\Controller\Adminhtml\Product\Initialization\Helper\Plugin\UpdateConfigurations
Magento\Downloadable\Controller\Adminhtml\Product\Initialization\Helper\Plugin\Downloadable
Magento\Paypal\Controller\Adminhtml\Transparent\RequestSecureToken
Magento\Paypal\Controller\Adminhtml\Transparent\Response
Magento\Paypal\Controller\Adminhtml\Transparent\Redirect
Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader
Magento\Search\Controller\Adminhtml\Synonyms\ResultPageBuilder
Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader
Magento\Swatches\Controller\Adminhtml\Product\Attribute\Plugin\Save
Magento\Ui\Controller\Adminhtml\Export\GridToCsv
Magento\Ui\Controller\Adminhtml\Export\GridToXml
Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\AttributeFilter
Magento\Inventory\Controller\Adminhtml\Source\SourceCarrierDataProcessor
Magento\Inventory\Controller\Adminhtml\Source\SourceHydrator
Magento\Inventory\Controller\Adminhtml\Stock\StockSaveProcessor
Magento\Inventory\Controller\Adminhtml\Stock\StockSourceLinkProcessor
Magento\InventoryCatalogAdminUi\Controller\Adminhtml\Bulk\BulkPageProcessor
@@ -0,0 +1,110 @@
<?php
/**
* Find "fieldset.xml" files and validate them
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Core\Model\Fieldset;
class FieldsetConfigTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Framework\Config\Dom\UrnResolver */
protected $urnResolver;
protected function setUp(): void
{
$this->urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
}
public function testXmlFiles()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $configFile
*/
function ($configFile) {
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($configFile));
$schema = $this->urnResolver->getRealPath(
'urn:magento:framework:DataObject/etc/fieldset_file.xsd'
);
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
if ($errors) {
$this->fail(
'XML-file ' . $configFile . ' has validation errors:' . PHP_EOL . implode(
PHP_EOL . PHP_EOL,
$errors
)
);
}
},
\Magento\Framework\App\Utility\Files::init()->getConfigFiles('fieldset.xml', [], true)
);
}
public function testSchemaUsingValidXml()
{
$xmlFile = __DIR__ . '/_files/fieldset.xml';
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
$schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset.xsd');
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
if ($errors) {
$this->fail(
'There is a problem with the schema. A known good XML file failed validation: ' . PHP_EOL . implode(
PHP_EOL . PHP_EOL,
$errors
)
);
}
}
public function testSchemaUsingInvalidXml()
{
if (!function_exists('libxml_set_external_entity_loader')) {
$this->markTestSkipped('Skipped due to MAGETWO-45033');
}
$xmlFile = __DIR__ . '/_files/invalid_fieldset.xml';
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
$schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset.xsd');
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
if (!$errors) {
$this->fail('There is a problem with the schema. A known bad XML file passed validation');
}
}
public function testFileSchemaUsingValidXml()
{
$xmlFile = __DIR__ . '/_files/fieldset_file.xml';
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
$schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset_file.xsd');
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
if ($errors) {
$this->fail(
'There is a problem with the schema. A known good XML file failed validation: ' . PHP_EOL . implode(
PHP_EOL . PHP_EOL,
$errors
)
);
}
}
public function testFileSchemaUsingInvalidXml()
{
if (!function_exists('libxml_set_external_entity_loader')) {
$this->markTestSkipped('Skipped due to MAGETWO-45033');
}
$xmlFile = __DIR__ . '/_files/invalid_fieldset.xml';
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
$schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset_file.xsd');
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
if (!$errors) {
$this->fail('There is a problem with the schema. A known bad XML file passed validation');
}
}
}
@@ -0,0 +1,881 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="sales_copy_order">
<field name="customer_email">
<aspect name="to_edit" />
</field>
<field name="customer_group_id">
<aspect name="to_edit" />
</field>
</fieldset>
<fieldset id="sales_copy_order_billing_address">
<field name="prefix">
<aspect name="to_order" />
</field>
<field name="firstname">
<aspect name="to_order" />
</field>
<field name="middlename">
<aspect name="to_order" />
</field>
<field name="lastname">
<aspect name="to_order" />
</field>
<field name="suffix">
<aspect name="to_order" />
</field>
<field name="customer_address_id">
<aspect name="to_order" />
</field>
<field name="company">
<aspect name="to_order" />
</field>
<field name="street">
<aspect name="to_order" />
</field>
<field name="city">
<aspect name="to_order" />
</field>
<field name="region">
<aspect name="to_order" />
</field>
<field name="postcode">
<aspect name="to_order" />
</field>
<field name="country_id">
<aspect name="to_order" />
</field>
<field name="telephone">
<aspect name="to_order" />
</field>
<field name="fax">
<aspect name="to_order" />
</field>
<field name="region_id">
<aspect name="to_order" />
</field>
</fieldset>
<fieldset id="sales_copy_order_shipping_address">
<field name="prefix">
<aspect name="to_order" />
</field>
<field name="firstname">
<aspect name="to_order" />
</field>
<field name="middlename">
<aspect name="to_order" />
</field>
<field name="lastname">
<aspect name="to_order" />
</field>
<field name="suffix">
<aspect name="to_order" />
</field>
<field name="customer_address_id">
<aspect name="to_order" />
</field>
<field name="company">
<aspect name="to_order" />
</field>
<field name="street">
<aspect name="to_order" />
</field>
<field name="city">
<aspect name="to_order" />
</field>
<field name="region">
<aspect name="to_order" />
</field>
<field name="postcode">
<aspect name="to_order" />
</field>
<field name="country_id">
<aspect name="to_order" />
</field>
<field name="telephone">
<aspect name="to_order" />
</field>
<field name="fax">
<aspect name="to_order" />
</field>
<field name="region_id">
<aspect name="to_order" />
</field>
</fieldset>
<fieldset id="sales_convert_quote">
<field name="remote_ip">
<aspect name="to_order" />
</field>
<field name="x_forwarded_for">
<aspect name="to_order" />
</field>
<field name="customer_id">
<aspect name="to_order" />
</field>
<field name="customer_email">
<aspect name="to_order" />
</field>
<field name="customer_prefix">
<aspect name="to_order" />
</field>
<field name="customer_firstname">
<aspect name="to_order" />
</field>
<field name="customer_middlename">
<aspect name="to_order" />
</field>
<field name="customer_lastname">
<aspect name="to_order" />
</field>
<field name="customer_suffix">
<aspect name="to_order" />
</field>
<field name="customer_group_id">
<aspect name="to_order" />
</field>
<field name="customer_tax_class_id">
<aspect name="to_order" />
</field>
<field name="customer_note">
<aspect name="to_order" />
</field>
<field name="customer_note_notify">
<aspect name="to_order" />
</field>
<field name="customer_is_guest">
<aspect name="to_order" />
</field>
<field name="customer_dob">
<aspect name="to_order" />
</field>
<field name="customer_taxvat">
<aspect name="to_order" />
</field>
<field name="customer_gender">
<aspect name="to_order" />
</field>
<field name="base_grand_total">
<aspect name="to_order" targetField="quote_base_grand_total" />
</field>
<field name="global_currency_code">
<aspect name="to_order" />
</field>
<field name="base_currency_code">
<aspect name="to_order" />
</field>
<field name="store_currency_code">
<aspect name="to_order" />
</field>
<field name="quote_currency_code">
<aspect name="to_order" targetField="order_currency_code" />
</field>
<field name="store_to_base_rate">
<aspect name="to_order" />
</field>
<field name="store_to_quote_rate">
<aspect name="to_order" targetField="store_to_order_rate" />
</field>
<field name="base_to_global_rate">
<aspect name="to_order" />
</field>
<field name="base_to_quote_rate">
<aspect name="to_order" targetField="base_to_order_rate" />
</field>
<field name="coupon_code">
<aspect name="to_order" />
</field>
<field name="is_virtual">
<aspect name="to_order" />
</field>
<field name="is_multi_payment">
<aspect name="to_order" />
</field>
<field name="applied_rule_ids">
<aspect name="to_order" />
</field>
<field name="items_qty">
<aspect name="to_order" targetField="total_qty_ordered" />
</field>
</fieldset>
<fieldset id="sales_convert_quote_address">
<field name="weight">
<aspect name="to_order" />
</field>
<field name="shipping_method">
<aspect name="to_order" />
</field>
<field name="shipping_description">
<aspect name="to_order" />
</field>
<field name="shipping_rate">
<aspect name="to_order" />
</field>
<field name="subtotal">
<aspect name="to_order" />
</field>
<field name="tax_amount">
<aspect name="to_order" />
</field>
<field name="tax_string">
<aspect name="to_order" />
</field>
<field name="discount_amount">
<aspect name="to_order" />
</field>
<field name="shipping_amount">
<aspect name="to_order" />
</field>
<field name="shipping_incl_tax">
<aspect name="to_order" />
</field>
<field name="shipping_tax_amount">
<aspect name="to_order" />
</field>
<field name="custbalance_amount">
<aspect name="to_order" />
</field>
<field name="grand_total">
<aspect name="to_order" />
</field>
<field name="base_subtotal">
<aspect name="to_order" />
</field>
<field name="base_tax_amount">
<aspect name="to_order" />
</field>
<field name="base_discount_amount">
<aspect name="to_order" />
</field>
<field name="base_shipping_amount">
<aspect name="to_order" />
</field>
<field name="base_shipping_incl_tax">
<aspect name="to_order" />
</field>
<field name="base_shipping_tax_amount">
<aspect name="to_order" />
</field>
<field name="base_custbalance_amount">
<aspect name="to_order" />
</field>
<field name="base_grand_total">
<aspect name="to_order" />
</field>
<field name="discount_tax_compensation_amount">
<aspect name="to_order" />
</field>
<field name="base_discount_tax_compensation_amount">
<aspect name="to_order" />
</field>
<field name="shipping_discount_tax_compensation_amount">
<aspect name="to_order" />
</field>
<field name="base_shipping_discount_tax_compensation_amount">
<aspect name="to_order" />
</field>
<field name="prefix">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="firstname">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="middlename">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="lastname">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="suffix">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="company">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="street_full">
<aspect name="to_order_address" targetField="street" />
</field>
<field name="street">
<aspect name="to_customer_address" />
</field>
<field name="city">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="region">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="region_id">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="postcode">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="country_id">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="telephone">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="fax">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
<field name="email">
<aspect name="to_order_address" />
<aspect name="to_customer_address" />
</field>
</fieldset>
<fieldset id="sales_convert_quote_payment">
<field name="method">
<aspect name="to_order_payment" />
</field>
<field name="additional_data">
<aspect name="to_order_payment" />
</field>
<field name="additional_information">
<aspect name="to_order_payment" />
</field>
<field name="po_number">
<aspect name="to_order_payment" />
</field>
<field name="cc_type">
<aspect name="to_order_payment" />
</field>
<field name="cc_number_enc">
<aspect name="to_order_payment" />
</field>
<field name="cc_last_4">
<aspect name="to_order_payment" />
</field>
<field name="cc_owner">
<aspect name="to_order_payment" />
</field>
<field name="cc_exp_month">
<aspect name="to_order_payment" />
</field>
<field name="cc_exp_year">
<aspect name="to_order_payment" />
</field>
<field name="cc_number">
<aspect name="to_order_payment" />
</field>
<field name="cc_cid">
<aspect name="to_order_payment" />
</field>
<field name="cc_ss_issue">
<aspect name="to_order_payment" />
</field>
<field name="cc_ss_start_month">
<aspect name="to_order_payment" />
</field>
<field name="cc_ss_start_year">
<aspect name="to_order_payment" />
</field>
</fieldset>
<fieldset id="quote_convert_item">
<field name="sku">
<aspect name="to_order_item" />
</field>
<field name="name">
<aspect name="to_order_item" />
</field>
<field name="description">
<aspect name="to_order_item" />
</field>
<field name="weight">
<aspect name="to_order_item" />
</field>
<field name="is_qty_decimal">
<aspect name="to_order_item" />
</field>
<field name="qty">
<aspect name="to_order_item" targetField="qty_ordered" />
</field>
<field name="is_virtual">
<aspect name="to_order_item" />
</field>
<field name="original_price">
<aspect name="to_order_item" />
</field>
<field name="applied_rule_ids">
<aspect name="to_order_item" />
</field>
<field name="additional_data">
<aspect name="to_order_item" />
</field>
<field name="calculation_price">
<aspect name="to_order_item" targetField="price" />
</field>
<field name="base_calculation_price">
<aspect name="to_order_item" targetField="base_price" />
</field>
<field name="tax_percent">
<aspect name="to_order_item" />
</field>
<field name="tax_amount">
<aspect name="to_order_item" />
</field>
<field name="tax_before_discount">
<aspect name="to_order_item" />
</field>
<field name="base_tax_before_discount">
<aspect name="to_order_item" />
</field>
<field name="tax_string">
<aspect name="to_order_item" />
</field>
<field name="row_weight">
<aspect name="to_order_item" />
</field>
<field name="row_total">
<aspect name="to_order_item" />
</field>
<field name="base_original_price">
<aspect name="to_order_item" />
</field>
<field name="base_tax_amount">
<aspect name="to_order_item" />
</field>
<field name="base_row_total">
<aspect name="to_order_item" />
</field>
<field name="discount_percent">
<aspect name="to_order_item_discount" />
</field>
<field name="discount_amount">
<aspect name="to_order_item_discount" />
</field>
<field name="base_discount_amount">
<aspect name="to_order_item_discount" />
</field>
<field name="base_cost">
<aspect name="to_order_item" />
</field>
<field name="store_id">
<aspect name="to_order_item" />
</field>
<field name="discount_tax_compensation_amount">
<aspect name="to_order_item" />
</field>
<field name="base_discount_tax_compensation_amount">
<aspect name="to_order_item" />
</field>
<field name="free_shipping">
<aspect name="to_order_item" />
</field>
</fieldset>
<fieldset id="sales_convert_order">
<field name="customer_id">
<aspect name="to_quote" />
</field>
<field name="customer_email">
<aspect name="to_quote" />
</field>
<field name="customer_group_id">
<aspect name="to_quote" />
</field>
<field name="customer_tax_class_id">
<aspect name="to_quote" />
</field>
<field name="customer_taxvat">
<aspect name="to_quote" />
</field>
<field name="customer_note">
<aspect name="to_quote" />
</field>
<field name="customer_note_notify">
<aspect name="to_quote" />
</field>
<field name="customer_is_guest">
<aspect name="to_quote" />
</field>
<field name="global_currency_code">
<aspect name="to_quote" />
<aspect name="to_invoice" />
<aspect name="to_shipment" />
<aspect name="to_cm" />
</field>
<field name="base_currency_code">
<aspect name="to_quote" />
<aspect name="to_invoice" />
<aspect name="to_shipment" />
<aspect name="to_cm" />
</field>
<field name="store_currency_code">
<aspect name="to_quote" />
<aspect name="to_invoice" />
<aspect name="to_shipment" />
<aspect name="to_cm" />
</field>
<field name="order_currency_code">
<aspect name="to_quote" targetField="quote_currency_code" />
<aspect name="to_invoice" />
<aspect name="to_shipment" />
<aspect name="to_cm" />
</field>
<field name="store_to_base_rate">
<aspect name="to_quote" />
<aspect name="to_invoice" />
<aspect name="to_shipment" />
<aspect name="to_cm" />
</field>
<field name="store_to_order_rate">
<aspect name="to_quote" targetField="store_to_quote_rate" />
<aspect name="to_invoice" />
<aspect name="to_shipment" />
<aspect name="to_cm" />
</field>
<field name="base_to_global_rate">
<aspect name="to_quote" />
<aspect name="to_invoice" />
<aspect name="to_shipment" />
<aspect name="to_cm" />
</field>
<field name="base_to_order_rate">
<aspect name="to_quote" targetField="base_to_quote_rate" />
<aspect name="to_invoice" />
<aspect name="to_shipment" />
<aspect name="to_cm" />
</field>
<field name="grand_total">
<aspect name="to_quote" />
<aspect name="to_quote_address_shipping" />
</field>
<field name="base_grand_total">
<aspect name="to_quote" />
<aspect name="to_quote_address_shipping" />
</field>
<field name="coupon_code">
<aspect name="to_quote" />
</field>
<field name="applied_rule_ids">
<aspect name="to_quote" />
</field>
<field name="weight">
<aspect name="to_quote_address_shipping" />
</field>
<field name="shipping_method">
<aspect name="to_quote_address_shipping" />
</field>
<field name="shipping_description">
<aspect name="to_quote_address_shipping" />
</field>
<field name="shipping_rate">
<aspect name="to_quote_address_shipping" />
</field>
<field name="subtotal">
<aspect name="to_quote_address_shipping" />
</field>
<field name="tax_amount">
<aspect name="to_quote_address_shipping" />
</field>
<field name="tax_string">
<aspect name="to_quote_address_shipping" />
</field>
<field name="discount_amount">
<aspect name="to_quote_address_shipping" />
</field>
<field name="shipping_amount">
<aspect name="to_quote_address_shipping" />
</field>
<field name="shipping_incl_tax">
<aspect name="to_quote_address_shipping" />
</field>
<field name="custbalance_amount">
<aspect name="to_quote_address_shipping" />
</field>
<field name="base_subtotal">
<aspect name="to_quote_address_shipping" />
</field>
<field name="base_tax_amount">
<aspect name="to_quote_address_shipping" />
</field>
<field name="base_discount_amount">
<aspect name="to_quote_address_shipping" />
</field>
<field name="base_shipping_amount">
<aspect name="to_quote_address_shipping" />
</field>
<field name="base_shipping_incl_tax">
<aspect name="to_quote_address_shipping" />
</field>
<field name="base_custbalance_amount">
<aspect name="to_quote_address_shipping" />
</field>
<field name="shipping_tax_amount">
<aspect name="to_cm" />
</field>
<field name="base_shipping_tax_amount">
<aspect name="to_cm" />
</field>
</fieldset>
<fieldset id="sales_convert_order_address">
<field name="prefix">
<aspect name="to_quote_address" />
</field>
<field name="firstname">
<aspect name="to_quote_address" />
</field>
<field name="middlename">
<aspect name="to_quote_address" />
</field>
<field name="lastname">
<aspect name="to_quote_address" />
</field>
<field name="suffix">
<aspect name="to_quote_address" />
</field>
<field name="company">
<aspect name="to_quote_address" />
</field>
<field name="street_full">
<aspect name="to_quote_address" targetField="street" />
</field>
<field name="city">
<aspect name="to_quote_address" />
</field>
<field name="region">
<aspect name="to_quote_address" />
</field>
<field name="region_id">
<aspect name="to_quote_address" />
</field>
<field name="postcode">
<aspect name="to_quote_address" />
</field>
<field name="country_id">
<aspect name="to_quote_address" />
</field>
<field name="telephone">
<aspect name="to_quote_address" />
</field>
<field name="fax">
<aspect name="to_quote_address" />
</field>
</fieldset>
<fieldset id="sales_convert_order_payment">
<field name="method">
<aspect name="to_quote_payment" />
</field>
<field name="additional_data">
<aspect name="to_quote_payment" />
</field>
<field name="additional_information">
<aspect name="to_quote_payment" />
</field>
<field name="po_number">
<aspect name="to_quote_payment" />
</field>
<field name="cc_type">
<aspect name="to_quote_payment" />
</field>
<field name="cc_number_enc">
<aspect name="to_quote_payment" />
</field>
<field name="cc_last_4">
<aspect name="to_quote_payment" />
</field>
<field name="cc_owner">
<aspect name="to_quote_payment" />
</field>
<field name="cc_exp_month">
<aspect name="to_quote_payment" />
</field>
<field name="cc_exp_year">
<aspect name="to_quote_payment" />
</field>
<field name="cc_ss_issue">
<aspect name="to_quote_payment" />
</field>
<field name="cc_ss_start_month">
<aspect name="to_quote_payment" />
</field>
<field name="cc_ss_start_year">
<aspect name="to_quote_payment" />
</field>
</fieldset>
<fieldset id="sales_convert_order_item">
<field name="sku">
<aspect name="to_quote_item" />
<aspect name="to_invoice_item" />
<aspect name="to_shipment_item" />
<aspect name="to_cm_item" />
</field>
<field name="name">
<aspect name="to_quote_item" />
<aspect name="to_invoice_item" />
<aspect name="to_shipment_item" />
<aspect name="to_cm_item" />
</field>
<field name="description">
<aspect name="to_quote_item" />
<aspect name="to_invoice_item" />
<aspect name="to_shipment_item" />
<aspect name="to_cm_item" />
</field>
<field name="weight">
<aspect name="to_quote_item" />
<aspect name="to_shipment_item" />
</field>
<field name="price">
<aspect name="to_quote_item" targetField="custom_price" />
<aspect name="to_invoice_item" />
<aspect name="to_shipment_item" />
<aspect name="to_cm_item" />
</field>
<field name="discount_percent">
<aspect name="to_quote_item_discount" />
</field>
<field name="discount_amount">
<aspect name="to_quote_item_discount" />
</field>
<field name="tax_percent">
<aspect name="to_quote_item" />
</field>
<field name="tax_string">
<aspect name="to_quote_item" />
</field>
<field name="tax_amount">
<aspect name="to_quote_item" />
</field>
<field name="row_weight">
<aspect name="to_quote_item" />
</field>
<field name="row_total">
<aspect name="to_quote_item" />
</field>
<field name="applied_rule_ids">
<aspect name="to_quote_item" />
</field>
<field name="base_discount_amount">
<aspect name="to_quote_item_discount" />
</field>
<field name="base_tax_amount">
<aspect name="to_quote_item" />
</field>
<field name="base_row_total">
<aspect name="to_quote_item" />
</field>
<field name="base_price">
<aspect name="to_invoice_item" targetField="base_price" />
<aspect name="to_shipment_item" />
<aspect name="to_cm_item" />
</field>
<field name="base_cost">
<aspect name="to_invoice_item" />
<aspect name="to_cm_item" />
<aspect name="to_quote_item" />
</field>
<field name="free_shipping">
<aspect name="to_quote_item" />
</field>
</fieldset>
<fieldset id="customer_account">
<field name="id">
<aspect name="to_quote" targetField="customer_id" />
</field>
<field name="email">
<aspect name="to_quote" targetField="customer_email" />
</field>
<field name="prefix">
<aspect name="to_quote" targetField="customer_prefix" />
</field>
<field name="firstname">
<aspect name="to_quote" targetField="customer_firstname" />
</field>
<field name="middlename">
<aspect name="to_quote" targetField="customer_middlename" />
</field>
<field name="lastname">
<aspect name="to_quote" targetField="customer_lastname" />
</field>
<field name="suffix">
<aspect name="to_quote" targetField="customer_suffix" />
</field>
<field name="group_id">
<aspect name="to_quote" targetField="customer_group_id" />
</field>
<field name="tax_class_id">
<aspect name="to_quote" targetField="customer_tax_class_id" />
</field>
<field name="taxvat">
<aspect name="to_quote" targetField="customer_taxvat" />
</field>
<field name="dob">
<aspect name="to_quote" targetField="customer_dob" />
</field>
<field name="gender">
<aspect name="to_quote" targetField="customer_gender" />
</field>
</fieldset>
<fieldset id="customer_address">
<field name="id">
<aspect name="to_quote_address" targetField="customer_address_id" />
</field>
<field name="parent_id">
<aspect name="to_quote_address" targetField="customer_id" />
</field>
<field name="prefix">
<aspect name="to_quote_address" />
</field>
<field name="firstname">
<aspect name="to_quote_address" />
</field>
<field name="middlename">
<aspect name="to_quote_address" />
</field>
<field name="lastname">
<aspect name="to_quote_address" />
</field>
<field name="suffix">
<aspect name="to_quote_address" />
</field>
<field name="company">
<aspect name="to_quote_address" />
</field>
<field name="street_full">
<aspect name="to_quote_address" targetField="street" />
</field>
<field name="city">
<aspect name="to_quote_address" />
</field>
<field name="region">
<aspect name="to_quote_address" />
</field>
<field name="region_id">
<aspect name="to_quote_address" />
</field>
<field name="postcode">
<aspect name="to_quote_address" />
</field>
<field name="country_id">
<aspect name="to_quote_address" />
</field>
<field name="telephone">
<aspect name="to_quote_address" />
</field>
<field name="fax">
<aspect name="to_quote_address" />
</field>
</fieldset>
</scope>
</config>
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset_file.xsd">
<scope id="global">
<fieldset id="sales_copy_order">
<field name="customer_email">
<aspect name="to_edit_or_not_to_edit" />
</field>
</fieldset>
<fieldset id="customer_address">
</fieldset>
</scope>
</config>
@@ -0,0 +1,882 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset_file.xsd">
<global>
<fieldsets>
<sales_copy_order>
<customer_email>
<to_edit>*</to_edit>
</customer_email>
<customer_group_id>
<to_edit>*</to_edit>
</customer_group_id>
</sales_copy_order>
<sales_copy_order_billing_address>
<prefix>
<to_order>*</to_order>
</prefix>
<firstname>
<to_order>*</to_order>
</firstname>
<middlename>
<to_order>*</to_order>
</middlename>
<lastname>
<to_order>*</to_order>
</lastname>
<suffix>
<to_order>*</to_order>
</suffix>
<customer_address_id>
<to_order>*</to_order>
</customer_address_id>
<company>
<to_order>*</to_order>
</company>
<street>
<to_order>*</to_order>
</street>
<city>
<to_order>*</to_order>
</city>
<region>
<to_order>*</to_order>
</region>
<postcode>
<to_order>*</to_order>
</postcode>
<country_id>
<to_order>*</to_order>
</country_id>
<telephone>
<to_order>*</to_order>
</telephone>
<fax>
<to_order>*</to_order>
</fax>
<region_id>
<to_order>*</to_order>
</region_id>
</sales_copy_order_billing_address>
<sales_copy_order_shipping_address>
<prefix>
<to_order>*</to_order>
</prefix>
<firstname>
<to_order>*</to_order>
</firstname>
<middlename>
<to_order>*</to_order>
</middlename>
<lastname>
<to_order>*</to_order>
</lastname>
<suffix>
<to_order>*</to_order>
</suffix>
<customer_address_id>
<to_order>*</to_order>
</customer_address_id>
<company>
<to_order>*</to_order>
</company>
<street>
<to_order>*</to_order>
</street>
<city>
<to_order>*</to_order>
</city>
<region>
<to_order>*</to_order>
</region>
<postcode>
<to_order>*</to_order>
</postcode>
<country_id>
<to_order>*</to_order>
</country_id>
<telephone>
<to_order>*</to_order>
</telephone>
<fax>
<to_order>*</to_order>
</fax>
<region_id>
<to_order>*</to_order>
</region_id>
</sales_copy_order_shipping_address>
<sales_convert_quote>
<remote_ip>
<to_order>*</to_order>
</remote_ip>
<x_forwarded_for>
<to_order>*</to_order>
</x_forwarded_for>
<customer_id>
<to_order>*</to_order>
</customer_id>
<customer_email>
<to_order>*</to_order>
</customer_email>
<customer_prefix>
<to_order>*</to_order>
</customer_prefix>
<customer_firstname>
<to_order>*</to_order>
</customer_firstname>
<customer_middlename>
<to_order>*</to_order>
</customer_middlename>
<customer_lastname>
<to_order>*</to_order>
</customer_lastname>
<customer_suffix>
<to_order>*</to_order>
</customer_suffix>
<customer_group_id>
<to_order>*</to_order>
</customer_group_id>
<customer_tax_class_id>
<to_order>*</to_order>
</customer_tax_class_id>
<customer_note>
<to_order>*</to_order>
</customer_note>
<customer_note_notify>
<to_order>*</to_order>
</customer_note_notify>
<customer_is_guest>
<to_order>*</to_order>
</customer_is_guest>
<customer_dob>
<to_order>*</to_order>
</customer_dob>
<customer_taxvat>
<to_order>*</to_order>
</customer_taxvat>
<customer_gender>
<to_order>*</to_order>
</customer_gender>
<base_grand_total>
<to_order>quote_base_grand_total</to_order>
</base_grand_total>
<global_currency_code>
<to_order>*</to_order>
</global_currency_code>
<base_currency_code>
<to_order>*</to_order>
</base_currency_code>
<store_currency_code>
<to_order>*</to_order>
</store_currency_code>
<quote_currency_code>
<to_order>order_currency_code</to_order>
</quote_currency_code>
<store_to_base_rate>
<to_order>*</to_order>
</store_to_base_rate>
<store_to_quote_rate>
<to_order>store_to_order_rate</to_order>
</store_to_quote_rate>
<base_to_global_rate>
<to_order>*</to_order>
</base_to_global_rate>
<base_to_quote_rate>
<to_order>base_to_order_rate</to_order>
</base_to_quote_rate>
<coupon_code>
<to_order>*</to_order>
</coupon_code>
<is_virtual>
<to_order>*</to_order>
</is_virtual>
<is_multi_payment>
<to_order>*</to_order>
</is_multi_payment>
<applied_rule_ids>
<to_order>*</to_order>
</applied_rule_ids>
<items_qty>
<to_order>total_qty_ordered</to_order>
</items_qty>
</sales_convert_quote>
<sales_convert_quote_address>
<weight>
<to_order>*</to_order>
</weight>
<shipping_method>
<to_order>*</to_order>
</shipping_method>
<shipping_description>
<to_order>*</to_order>
</shipping_description>
<shipping_rate>
<to_order>*</to_order>
</shipping_rate>
<subtotal>
<to_order>*</to_order>
</subtotal>
<tax_amount>
<to_order>*</to_order>
</tax_amount>
<tax_string>
<to_order>*</to_order>
</tax_string>
<discount_amount>
<to_order>*</to_order>
</discount_amount>
<shipping_amount>
<to_order>*</to_order>
</shipping_amount>
<shipping_incl_tax>
<to_order>*</to_order>
</shipping_incl_tax>
<shipping_tax_amount>
<to_order>*</to_order>
</shipping_tax_amount>
<custbalance_amount>
<to_order>*</to_order>
</custbalance_amount>
<grand_total>
<to_order>*</to_order>
</grand_total>
<base_subtotal>
<to_order>*</to_order>
</base_subtotal>
<base_tax_amount>
<to_order>*</to_order>
</base_tax_amount>
<base_discount_amount>
<to_order>*</to_order>
</base_discount_amount>
<base_shipping_amount>
<to_order>*</to_order>
</base_shipping_amount>
<base_shipping_incl_tax>
<to_order>*</to_order>
</base_shipping_incl_tax>
<base_shipping_tax_amount>
<to_order>*</to_order>
</base_shipping_tax_amount>
<base_custbalance_amount>
<to_order>*</to_order>
</base_custbalance_amount>
<base_grand_total>
<to_order>*</to_order>
</base_grand_total>
<discount_tax_compensation_amount>
<to_order>*</to_order>
</discount_tax_compensation_amount>
<base_discount_tax_compensation_amount>
<to_order>*</to_order>
</base_discount_tax_compensation_amount>
<shipping_discount_tax_compensation_amount>
<to_order>*</to_order>
</shipping_discount_tax_compensation_amount>
<base_shipping_discount_tax_compensation_amount>
<to_order>*</to_order>
</base_shipping_discount_tax_compensation_amount>
<prefix>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</prefix>
<firstname>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</firstname>
<middlename>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</middlename>
<lastname>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</lastname>
<suffix>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</suffix>
<company>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</company>
<street_full>
<to_order_address>street</to_order_address>
</street_full>
<street>
<to_customer_address>*</to_customer_address>
</street>
<city>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</city>
<region>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</region>
<region_id>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</region_id>
<postcode>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</postcode>
<country_id>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</country_id>
<telephone>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</telephone>
<fax>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</fax>
<email>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</email>
</sales_convert_quote_address>
<sales_convert_quote_payment>
<method>
<to_order_payment>*</to_order_payment>
</method>
<additional_data>
<to_order_payment>*</to_order_payment>
</additional_data>
<additional_information>
<to_order_payment>*</to_order_payment>
</additional_information>
<po_number>
<to_order_payment>*</to_order_payment>
</po_number>
<cc_type>
<to_order_payment>*</to_order_payment>
</cc_type>
<cc_number_enc>
<to_order_payment>*</to_order_payment>
</cc_number_enc>
<cc_last_4>
<to_order_payment>*</to_order_payment>
</cc_last_4>
<cc_owner>
<to_order_payment>*</to_order_payment>
</cc_owner>
<cc_exp_month>
<to_order_payment>*</to_order_payment>
</cc_exp_month>
<cc_exp_year>
<to_order_payment>*</to_order_payment>
</cc_exp_year>
<cc_number>
<to_order_payment>*</to_order_payment>
</cc_number>
<cc_cid>
<to_order_payment>*</to_order_payment>
</cc_cid>
<cc_ss_issue>
<to_order_payment>*</to_order_payment>
</cc_ss_issue>
<cc_ss_start_month>
<to_order_payment>*</to_order_payment>
</cc_ss_start_month>
<cc_ss_start_year>
<to_order_payment>*</to_order_payment>
</cc_ss_start_year>
</sales_convert_quote_payment>
<sales_convert_quote_item>
<sku>
<to_order_item>*</to_order_item>
</sku>
<name>
<to_order_item>*</to_order_item>
</name>
<description>
<to_order_item>*</to_order_item>
</description>
<weight>
<to_order_item>*</to_order_item>
</weight>
<is_qty_decimal>
<to_order_item>*</to_order_item>
</is_qty_decimal>
<qty>
<to_order_item>qty_ordered</to_order_item>
</qty>
<is_virtual>
<to_order_item>*</to_order_item>
</is_virtual>
<original_price>
<to_order_item>*</to_order_item>
</original_price>
<applied_rule_ids>
<to_order_item>*</to_order_item>
</applied_rule_ids>
<additional_data>
<to_order_item>*</to_order_item>
</additional_data>
<calculation_price>
<to_order_item>price</to_order_item>
</calculation_price>
<base_calculation_price>
<to_order_item>base_price</to_order_item>
</base_calculation_price>
<tax_percent>
<to_order_item>*</to_order_item>
</tax_percent>
<tax_amount>
<to_order_item>*</to_order_item>
</tax_amount>
<tax_before_discount>
<to_order_item>*</to_order_item>
</tax_before_discount>
<base_tax_before_discount>
<to_order_item>*</to_order_item>
</base_tax_before_discount>
<tax_string>
<to_order_item>*</to_order_item>
</tax_string>
<row_weight>
<to_order_item>*</to_order_item>
</row_weight>
<row_total>
<to_order_item>*</to_order_item>
</row_total>
<base_original_price>
<to_order_item>*</to_order_item>
</base_original_price>
<base_tax_amount>
<to_order_item>*</to_order_item>
</base_tax_amount>
<base_row_total>
<to_order_item>*</to_order_item>
</base_row_total>
<discount_percent>
<to_order_item_discount>*</to_order_item_discount>
</discount_percent>
<discount_amount>
<to_order_item_discount>*</to_order_item_discount>
</discount_amount>
<base_discount_amount>
<to_order_item_discount>*</to_order_item_discount>
</base_discount_amount>
<base_cost>
<to_order_item>*</to_order_item>
</base_cost>
<store_id>
<to_order_item>*</to_order_item>
</store_id>
<discount_tax_compensation_amount>
<to_order_item>*</to_order_item>
</discount_tax_compensation_amount>
<base_discount_tax_compensation_amount>
<to_order_item>*</to_order_item>
</base_discount_tax_compensation_amount>
<free_shipping>
<to_order_item>*</to_order_item>
</free_shipping>
</sales_convert_quote_item>
<sales_convert_order>
<customer_id>
<to_quote>*</to_quote>
</customer_id>
<customer_email>
<to_quote>*</to_quote>
</customer_email>
<customer_group_id>
<to_quote>*</to_quote>
</customer_group_id>
<customer_tax_class_id>
<to_quote>*</to_quote>
</customer_tax_class_id>
<customer_taxvat>
<to_quote>*</to_quote>
</customer_taxvat>
<customer_note>
<to_quote>*</to_quote>
</customer_note>
<customer_note_notify>
<to_quote>*</to_quote>
</customer_note_notify>
<customer_is_guest>
<to_quote>*</to_quote>
</customer_is_guest>
<global_currency_code>
<to_quote>*</to_quote>
<to_invoice>*</to_invoice>
<to_shipment>*</to_shipment>
<to_cm>*</to_cm>
</global_currency_code>
<base_currency_code>
<to_quote>*</to_quote>
<to_invoice>*</to_invoice>
<to_shipment>*</to_shipment>
<to_cm>*</to_cm>
</base_currency_code>
<store_currency_code>
<to_quote>*</to_quote>
<to_invoice>*</to_invoice>
<to_shipment>*</to_shipment>
<to_cm>*</to_cm>
</store_currency_code>
<order_currency_code>
<to_quote>quote_currency_code</to_quote>
<to_invoice>*</to_invoice>
<to_shipment>*</to_shipment>
<to_cm>*</to_cm>
</order_currency_code>
<store_to_base_rate>
<to_quote>*</to_quote>
<to_invoice>*</to_invoice>
<to_shipment>*</to_shipment>
<to_cm>*</to_cm>
</store_to_base_rate>
<store_to_order_rate>
<to_quote>store_to_quote_rate</to_quote>
<to_invoice>*</to_invoice>
<to_shipment>*</to_shipment>
<to_cm>*</to_cm>
</store_to_order_rate>
<base_to_global_rate>
<to_quote>*</to_quote>
<to_invoice>*</to_invoice>
<to_shipment>*</to_shipment>
<to_cm>*</to_cm>
</base_to_global_rate>
<base_to_order_rate>
<to_quote>base_to_quote_rate</to_quote>
<to_invoice>*</to_invoice>
<to_shipment>*</to_shipment>
<to_cm>*</to_cm>
</base_to_order_rate>
<grand_total>
<to_quote>*</to_quote>
<to_quote_address_shipping>*</to_quote_address_shipping>
</grand_total>
<base_grand_total>
<to_quote>*</to_quote>
<to_quote_address_shipping>*</to_quote_address_shipping>
</base_grand_total>
<coupon_code>
<to_quote>*</to_quote>
</coupon_code>
<applied_rule_ids>
<to_quote>*</to_quote>
</applied_rule_ids>
<weight>
<to_quote_address_shipping>*</to_quote_address_shipping>
</weight>
<shipping_method>
<to_quote_address_shipping>*</to_quote_address_shipping>
</shipping_method>
<shipping_description>
<to_quote_address_shipping>*</to_quote_address_shipping>
</shipping_description>
<shipping_rate>
<to_quote_address_shipping>*</to_quote_address_shipping>
</shipping_rate>
<subtotal>
<to_quote_address_shipping>*</to_quote_address_shipping>
</subtotal>
<tax_amount>
<to_quote_address_shipping>*</to_quote_address_shipping>
</tax_amount>
<tax_string>
<to_quote_address_shipping>*</to_quote_address_shipping>
</tax_string>
<discount_amount>
<to_quote_address_shipping>*</to_quote_address_shipping>
</discount_amount>
<shipping_amount>
<to_quote_address_shipping>*</to_quote_address_shipping>
</shipping_amount>
<shipping_incl_tax>
<to_quote_address_shipping>*</to_quote_address_shipping>
</shipping_incl_tax>
<custbalance_amount>
<to_quote_address_shipping>*</to_quote_address_shipping>
</custbalance_amount>
<base_subtotal>
<to_quote_address_shipping>*</to_quote_address_shipping>
</base_subtotal>
<base_tax_amount>
<to_quote_address_shipping>*</to_quote_address_shipping>
</base_tax_amount>
<base_discount_amount>
<to_quote_address_shipping>*</to_quote_address_shipping>
</base_discount_amount>
<base_shipping_amount>
<to_quote_address_shipping>*</to_quote_address_shipping>
</base_shipping_amount>
<base_shipping_incl_tax>
<to_quote_address_shipping>*</to_quote_address_shipping>
</base_shipping_incl_tax>
<base_custbalance_amount>
<to_quote_address_shipping>*</to_quote_address_shipping>
</base_custbalance_amount>
<shipping_tax_amount>
<to_cm>*</to_cm>
</shipping_tax_amount>
<base_shipping_tax_amount>
<to_cm>*</to_cm>
</base_shipping_tax_amount>
</sales_convert_order>
<sales_convert_order_address>
<prefix>
<to_quote_address>*</to_quote_address>
</prefix>
<firstname>
<to_quote_address>*</to_quote_address>
</firstname>
<middlename>
<to_quote_address>*</to_quote_address>
</middlename>
<lastname>
<to_quote_address>*</to_quote_address>
</lastname>
<suffix>
<to_quote_address>*</to_quote_address>
</suffix>
<company>
<to_quote_address>*</to_quote_address>
</company>
<street_full>
<to_quote_address>street</to_quote_address>
</street_full>
<city>
<to_quote_address>*</to_quote_address>
</city>
<region>
<to_quote_address>*</to_quote_address>
</region>
<region_id>
<to_quote_address>*</to_quote_address>
</region_id>
<postcode>
<to_quote_address>*</to_quote_address>
</postcode>
<country_id>
<to_quote_address>*</to_quote_address>
</country_id>
<telephone>
<to_quote_address>*</to_quote_address>
</telephone>
<fax>
<to_quote_address>*</to_quote_address>
</fax>
</sales_convert_order_address>
<sales_convert_order_payment>
<method>
<to_quote_payment>*</to_quote_payment>
</method>
<additional_data>
<to_quote_payment>*</to_quote_payment>
</additional_data>
<additional_information>
<to_quote_payment>*</to_quote_payment>
</additional_information>
<po_number>
<to_quote_payment>*</to_quote_payment>
</po_number>
<cc_type>
<to_quote_payment>*</to_quote_payment>
</cc_type>
<cc_number_enc>
<to_quote_payment>*</to_quote_payment>
</cc_number_enc>
<cc_last_4>
<to_quote_payment>*</to_quote_payment>
</cc_last_4>
<cc_owner>
<to_quote_payment>*</to_quote_payment>
</cc_owner>
<cc_exp_month>
<to_quote_payment>*</to_quote_payment>
</cc_exp_month>
<cc_exp_year>
<to_quote_payment>*</to_quote_payment>
</cc_exp_year>
<cc_ss_issue>
<to_quote_payment>*</to_quote_payment>
</cc_ss_issue>
<cc_ss_start_month>
<to_quote_payment>*</to_quote_payment>
</cc_ss_start_month>
<cc_ss_start_year>
<to_quote_payment>*</to_quote_payment>
</cc_ss_start_year>
</sales_convert_order_payment>
<sales_convert_order_item>
<sku>
<to_quote_item>*</to_quote_item>
<to_invoice_item>*</to_invoice_item>
<to_shipment_item>*</to_shipment_item>
<to_cm_item>*</to_cm_item>
</sku>
<name>
<to_quote_item>*</to_quote_item>
<to_invoice_item>*</to_invoice_item>
<to_shipment_item>*</to_shipment_item>
<to_cm_item>*</to_cm_item>
</name>
<description>
<to_quote_item>*</to_quote_item>
<to_invoice_item>*</to_invoice_item>
<to_shipment_item>*</to_shipment_item>
<to_cm_item>*</to_cm_item>
</description>
<weight>
<to_quote_item>*</to_quote_item>
<to_shipment_item>*</to_shipment_item>
</weight>
<price>
<to_quote_item>custom_price</to_quote_item>
<to_invoice_item>*</to_invoice_item>
<to_shipment_item>*</to_shipment_item>
<to_cm_item>*</to_cm_item>
</price>
<discount_percent>
<to_quote_item_discount>*</to_quote_item_discount>
</discount_percent>
<discount_amount>
<to_quote_item_discount>*</to_quote_item_discount>
</discount_amount>
<tax_percent>
<to_quote_item>*</to_quote_item>
</tax_percent>
<tax_string>
<to_quote_item>*</to_quote_item>
</tax_string>
<tax_amount>
<to_quote_item>*</to_quote_item>
</tax_amount>
<row_weight>
<to_quote_item>*</to_quote_item>
</row_weight>
<row_total>
<to_quote_item>*</to_quote_item>
</row_total>
<applied_rule_ids>
<to_quote_item>*</to_quote_item>
</applied_rule_ids>
<base_discount_amount>
<to_quote_item_discount>*</to_quote_item_discount>
</base_discount_amount>
<base_tax_amount>
<to_quote_item>*</to_quote_item>
</base_tax_amount>
<base_row_total>
<to_quote_item>*</to_quote_item>
</base_row_total>
<base_price>
<to_invoice_item>base_price</to_invoice_item>
<to_shipment_item>*</to_shipment_item>
<to_cm_item>*</to_cm_item>
</base_price>
<base_cost>
<to_invoice_item>*</to_invoice_item>
<to_cm_item>*</to_cm_item>
<to_quote_item>*</to_quote_item>
</base_cost>
<free_shipping>
<to_quote_item>*</to_quote_item>
</free_shipping>
</sales_convert_order_item>
<customer_account>
<id>
<to_quote>customer_id</to_quote>
</id>
<email>
<to_quote>customer_email</to_quote>
</email>
<prefix>
<to_quote>customer_prefix</to_quote>
</prefix>
<firstname>
<to_quote>customer_firstname</to_quote>
</firstname>
<middlename>
<to_quote>customer_middlename</to_quote>
</middlename>
<lastname>
<to_quote>customer_lastname</to_quote>
</lastname>
<suffix>
<to_quote>customer_suffix</to_quote>
</suffix>
<group_id>
<to_quote>customer_group_id</to_quote>
</group_id>
<tax_class_id>
<to_quote>customer_tax_class_id</to_quote>
</tax_class_id>
<taxvat>
<to_quote>customer_taxvat</to_quote>
</taxvat>
<dob>
<to_quote>customer_dob</to_quote>
</dob>
<gender>
<to_quote>customer_gender</to_quote>
</gender>
</customer_account>
<customer_address>
<id>
<to_quote_address>customer_address_id</to_quote_address>
</id>
<parent_id>
<to_quote_address>customer_id</to_quote_address>
</parent_id>
<prefix>
<to_quote_address>*</to_quote_address>
</prefix>
<firstname>
<to_quote_address>*</to_quote_address>
</firstname>
<middlename>
<to_quote_address>*</to_quote_address>
</middlename>
<lastname>
<to_quote_address>*</to_quote_address>
</lastname>
<suffix>
<to_quote_address>*</to_quote_address>
</suffix>
<company>
<to_quote_address>*</to_quote_address>
</company>
<street_full>
<to_quote_address>street</to_quote_address>
</street_full>
<city>
<to_quote_address>*</to_quote_address>
</city>
<region>
<to_quote_address>*</to_quote_address>
</region>
<region_id>
<to_quote_address>*</to_quote_address>
</region_id>
<postcode>
<to_quote_address>*</to_quote_address>
</postcode>
<country_id>
<to_quote_address>*</to_quote_address>
</country_id>
<telephone>
<to_quote_address>*</to_quote_address>
</telephone>
<fax>
<to_quote_address>*</to_quote_address>
</fax>
</customer_address>
</fieldsets>
</global>
</config>
@@ -0,0 +1,269 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Framework\Api;
use Laminas\Code\Reflection\ClassReflection;
use Magento\Framework\App\Utility\Files;
use Magento\Setup\Module\Di\Code\Reader\FileClassScanner;
/**
* Check interfaces inherited from \Magento\Framework\Api\ExtensibleDataInterface.
*
* Ensure that all interfaces inherited from \Magento\Framework\Api\ExtensibleDataInterface
* override getExtensionAttributes() method and have correct return type specified.
*/
class ExtensibleInterfacesTest extends \PHPUnit\Framework\TestCase
{
const EXTENSIBLE_DATA_INTERFACE = \Magento\Framework\Api\ExtensibleDataInterface::class;
/**
* Check return types of getExtensionAttributes() methods.
*/
public function testGetSetExtensionAttributes()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $filename
*/
function ($filename) {
$errors = [];
$fileContent = file_get_contents($filename);
$pattern = '/'
. str_replace('\\', '\\\\', self::EXTENSIBLE_DATA_INTERFACE)
. '/';
$extendsFromExtensibleDataInterface = preg_match($pattern, $fileContent);
$namespacePattern = '/namespace ([\w\\\\]+).*interface ([\w\\\\]+)/s';
if ($extendsFromExtensibleDataInterface
&& preg_match($namespacePattern, $fileContent, $matches)
) {
$namespace = $matches[1];
$interfaceName = $matches[2];
$fullInterfaceName = '\\' . $namespace . '\\' . $interfaceName;
$interfaceReflection = new \ReflectionClass($fullInterfaceName);
if ($interfaceReflection->isSubclassOf(self::EXTENSIBLE_DATA_INTERFACE)) {
$interfaceName = '\\' . $interfaceReflection->getName();
$extensionClassName = substr($interfaceName, 0, -strlen('Interface')) . 'Extension';
$extensionInterfaceName = $extensionClassName . 'Interface';
/** Check getExtensionAttributes method */
$errors = $this->checkGetExtensionAttributes(
$interfaceReflection,
$extensionInterfaceName,
$fullInterfaceName
);
/** Check setExtensionAttributes method */
$errors = array_merge(
$errors,
$this->checkSetExtensionAttributes(
$interfaceReflection,
$extensionInterfaceName,
$fullInterfaceName
)
);
}
}
$this->assertEmpty(
$errors,
"Error validating $filename\n" . print_r($errors, true)
);
},
$this->getInterfacesFiles()
);
}
/**
* Check getExtensionAttributes methods
*
* @param \ReflectionClass $interfaceReflection
* @param string $extensionInterfaceName
* @param string $fullInterfaceName
* @return array
*/
private function checkGetExtensionAttributes(
\ReflectionClass $interfaceReflection,
$extensionInterfaceName,
$fullInterfaceName
) {
$errors = [];
try {
$methodReflection = $interfaceReflection->getMethod('getExtensionAttributes');
/** Ensure that proper return type of getExtensionAttributes() method is specified */
$methodDocBlock = $methodReflection->getDocComment();
$pattern = "/@return\s+" . str_replace('\\', '\\\\', $extensionInterfaceName) . "/";
if (!preg_match($pattern, $methodDocBlock)) {
$errors[] =
"'{$fullInterfaceName}::getExtensionAttributes()' must be declared "
. "with a return type of '{$extensionInterfaceName}'.";
}
} catch (\ReflectionException $e) {
$errors[] = "The following method should be declared in "
. "'{$extensionInterfaceName}'. '{$extensionInterfaceName}' must be specified as"
. " a return type for '{$fullInterfaceName}::getExtensionAttributes()'";
}
return $errors;
}
/**
* Check setExtensionAttributes methods
*
* @param \ReflectionClass $interfaceReflection
* @param string $extensionInterfaceName
* @param string $fullInterfaceName
* @return array
*/
private function checkSetExtensionAttributes(
\ReflectionClass $interfaceReflection,
$extensionInterfaceName,
$fullInterfaceName
) {
$errors = [];
try {
$methodReflection = $interfaceReflection->getMethod('setExtensionAttributes');
/** Ensure that proper argument type for setExtensionAttributes() method is specified */
$methodParameters = $methodReflection->getParameters();
if (empty($methodParameters)) {
$errors[] = "'{$extensionInterfaceName}' must be specified as the parameter type "
. "in '{$fullInterfaceName}::setExtensionAttributes()'.";
} else {
// Get the parameter name via a regular expression capture because the class may
// not exist which causes a fatal error
preg_match('/\[\s\<\w+?>\s([?]?[\w\\\]+)/s', $methodParameters[0]->__toString(), $matches);
$isCorrectParameter = false;
if (isset($matches[1])
&& ('\\' . ltrim($matches[1], '?')) === $extensionInterfaceName) {
$isCorrectParameter = true;
}
if (!$isCorrectParameter) {
$errors[] = "'{$extensionInterfaceName}' must be specified as the parameter type "
. "in '{$fullInterfaceName}::setExtensionAttributes()'.";
}
}
} catch (\ReflectionException $e) {
$errors[] = "'{$fullInterfaceName}::setExtensionAttributes()' must be declared "
. "with a '{$extensionInterfaceName}' parameter type.";
}
return $errors;
}
/**
* Ensure that all classes extended from extensible classes implement getter and setter for extension attributes.
*/
public function testExtensibleClassesWithMissingInterface() //phpcs:ignore Generic.Metrics.NestingLevel
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $filename
*/
function ($filename) {
$errors = [];
$fileContent = file_get_contents($filename);
$extensibleClassPattern = 'class [^\{]+extends[^\{]+AbstractExtensible';
$abstractExtensibleClassPattern = 'abstract ' . $extensibleClassPattern;
if (preg_match('/' . $extensibleClassPattern . '/', $fileContent) &&
!preg_match('/' . $abstractExtensibleClassPattern . '/', $fileContent)
) {
$fileClassScanner = new FileClassScanner($filename);
$classReflection = new ClassReflection($fileClassScanner->getClassName());
if ($classReflection->isSubclassOf(self::EXTENSIBLE_DATA_INTERFACE)) {
$methodsToCheck = ['setExtensionAttributes', 'getExtensionAttributes'];
foreach ($methodsToCheck as $methodName) {
try {
$classReflection->getMethod($methodName);
} catch (\ReflectionException $e) {
$className = $classReflection->getName();
$errors[] = "'{$className}::{$methodName}()' must be declared or "
. "'{$className}' should not be inherited from extensible class.";
}
}
}
}
$this->assertEmpty(
$errors,
"Error validating $filename\n" . print_r($errors, true)
);
},
$this->getPhpFiles()
);
}
/**
* Retrieve a list of all interfaces declared in the Magento application and Magento library.
*
* @return array
*/
public function getInterfacesFiles()
{
$codeInterfaceFiles = $this->getFiles(BP . '/app', '*Interface.php');
$libInterfaceFiles = $this->getFiles(BP . '/lib/Magento', '*Interface.php');
$interfaces = [];
$filesToCheck = $this->blacklistFilter(array_merge($codeInterfaceFiles, $libInterfaceFiles));
foreach ($filesToCheck as $file) {
$interfaces[substr($file, strlen(BP))] = [$file];
}
return $interfaces;
}
/**
* Retrieve a list of all php files declared in the Magento application and Magento library.
*
* @return array
*/
public function getPhpFiles()
{
$codeFiles = $this->getFiles(BP . '/app', '*.php');
$libFiles = $this->getFiles(BP . '/lib/Magento', '*.php');
$phpFiles = [];
$filesToCheck = $this->blacklistFilter(array_merge($codeFiles, $libFiles));
foreach ($filesToCheck as $file) {
$phpFiles[substr($file, strlen(BP))] = [$file];
}
return $phpFiles;
}
/**
* Retrieve all files in a directory that correspond to the given pattern
*
* @param string $dir
* @param string $pattern
* @return array
*/
protected function getFiles($dir, $pattern)
{
$files = [glob($dir . '/' . $pattern, GLOB_NOSORT)];
foreach (glob($dir . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $newDir) {
$files[] = $this->getFiles($newDir, $pattern);
}
return array_merge([], ...$files);
}
/**
* Filter blacklisted files out of an array
*
* @param array $preFilter
* @return array
*/
protected function blacklistFilter($preFilter)
{
$postFilter = [];
$blacklist = Files::init()->readLists(__DIR__ . '/_files/ExtensibleInterfacesTest/blacklist*');
foreach ($preFilter as $file) {
if (!in_array($file, $blacklist)) {
$postFilter[] = $file;
}
}
return $postFilter;
}
}
@@ -0,0 +1,5 @@
module Magento_Payment Model/Info.php
module Magento_Customer Model/Address/AbstractAddress.php
library magento/framework MessageQueue/Rpc/Publisher.php
module Magento_GraphQl Model/Query/ContextInterface.php
module Magento_LoginAsCustomerApi Api/Data/AuthenticationDataInterface.php
@@ -0,0 +1,89 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);
namespace Magento\Test\Integrity\Magento\Framework\Cache;
use Magento\Framework\Config\Dom\UrnResolver;
use Magento\Framework\TestFramework\Unit\Utility\XsdValidator;
use PHPUnit\Framework\TestCase;
/**
* Unit test of the cache configuration
*/
class ConfigTest extends TestCase
{
/**
* Path to xsd schema file
* @var string
*/
private $xsdSchema;
/**
* @var UrnResolver
*/
private $urnResolver;
/**
* @var XsdValidator
*/
private $xsdValidator;
/**
* Setup environment for test
*/
protected function setUp(): void
{
if (!function_exists('libxml_set_external_entity_loader')) {
$this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
}
$this->urnResolver = new UrnResolver();
$this->xsdSchema = $this->urnResolver->getRealPath(
'urn:magento:framework:Cache/etc/cache.xsd'
);
$this->xsdValidator = new XsdValidator();
}
/**
* Tests invalid configurations
*
* @param string $xmlString
* @param array $expectedError
* @dataProvider schemaCorrectlyIdentifiesInvalidXmlDataProvider
*/
public function testSchemaCorrectlyIdentifiesInvalidXml(
string $xmlString,
array $expectedError
): void {
$actualError = $this->xsdValidator->validate(
$this->xsdSchema,
$xmlString
);
$this->assertEquals($expectedError, $actualError);
}
/**
* Tests valid configurations
*/
public function testSchemaCorrectlyIdentifiesValidXml(): void
{
$xmlString = file_get_contents(__DIR__ . '/_files/valid_cache_config.xml');
$actualResult = $this->xsdValidator->validate(
$this->xsdSchema,
$xmlString
);
$this->assertEmpty($actualResult);
}
/**
* Data provider with invalid xml array according to cache.xsd
*/
public function schemaCorrectlyIdentifiesInvalidXmlDataProvider(): array
{
return include __DIR__ . '/_files/invalidCacheConfigXmlArray.php';
}
}
@@ -0,0 +1,74 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
return [
'without_type_handle' => [
'<?xml version="1.0"?><config></config>',
["Element 'config': Missing child element(s). Expected is ( type ).\n" .
"Line: 1\nThe xml was: \n0:<?xml version=\"1.0\"?>\n1:<config/>\n2:\n"],
],
'cache_config_with_notallowed_attribute' => [
'<?xml version="1.0"?><config>' .
'<type name="test" translate="label,description" instance="Class\Name" notallowed="some value">' .
'<label>Test</label><description>Test</description></type></config>',
["Element 'type', attribute 'notallowed': The attribute 'notallowed' is not allowed.\nLine: 1\n" .
"The xml was: \n0:<?xml version=\"1.0\"?>\n1:<config><type name=\"test\" translate=\"label,description\" " .
"instance=\"Class\\Name\" notallowed=\"some value\"><label>Test</label><description>Test</description>" .
"</type></config>\n2:\n"],
],
'cache_config_without_name_attribute' => [
'<?xml version="1.0"?><config><type translate="label,description" instance="Class\Name">' .
'<label>Test</label><description>Test</description></type></config>',
["Element 'type': The attribute 'name' is required but missing.\n" .
"Line: 1\nThe xml was: \n0:<?xml version=\"1.0\"?>\n1:<config>" .
"<type translate=\"label,description\" instance=\"Class\\Name\"><label>Test</label>" .
"<description>Test</description></type></config>\n2:\n"],
],
'cache_config_without_instance_attribute' => [
'<?xml version="1.0"?><config><type name="test" translate="label,description">' .
'<label>Test</label><description>Test</description></type></config>',
["Element 'type': The attribute 'instance' is required but missing.\n" .
"Line: 1\nThe xml was: \n0:<?xml version=\"1.0\"?>\n1:<config>" .
"<type name=\"test\" translate=\"label,description\"><label>Test</label><description>Test</description>" .
"</type></config>\n2:\n"],
],
'cache_config_without_label_element' => [
'<?xml version="1.0"?><config><type name="test" translate="label,description" instance="Class\Name">' .
'<description>Test</description></type></config>',
["Element 'type': Missing child element(s). Expected is ( label ).\n" .
"Line: 1\nThe xml was: \n0:<?xml version=\"1.0\"?>\n" .
"1:<config><type name=\"test\" translate=\"label,description\" instance=\"Class\\Name\">" .
"<description>Test</description></type></config>\n2:\n"],
],
'cache_config_without_description_element' => [
'<?xml version="1.0"?><config><type name="test" translate="label,description" instance="Class\Name">' .
'<label>Test</label></type></config>',
["Element 'type': Missing child element(s). Expected is ( description ).\n" .
"Line: 1\nThe xml was: \n0:<?xml version=\"1.0\"?>\n" .
"1:<config><type name=\"test\" translate=\"label,description\" instance=\"Class\\Name\">" .
"<label>Test</label></type></config>\n2:\n"],
],
'cache_config_without_child_elements' => [
'<?xml version="1.0"?><config><type name="test" translate="label,description" instance="Class\Name">' .
'</type></config>',
["Element 'type': Missing child element(s). Expected is one of ( label, description ).\n" .
"Line: 1\nThe xml was: \n0:<?xml version=\"1.0\"?>\n" .
"1:<config><type name=\"test\" translate=\"label,description\" instance=\"Class\\Name\"/></config>\n2:\n"],
],
'cache_config_cache_name_not_unique' => [
'<?xml version="1.0"?><config><type name="test" translate="label,description" instance="Class\Name1">' .
'<label>Test1</label><description>Test1</description></type>' .
'<type name="test" translate="label,description" instance="Class\Name2">' .
'<label>Test2</label><description>Test2</description></type></config>',
[
"Element 'type': Duplicate key-sequence ['test'] in unique identity-constraint 'uniqueCacheName'.\n" .
"Line: 1\nThe xml was: \n0:<?xml version=\"1.0\"?>\n" .
"1:<config><type name=\"test\" translate=\"label,description\" instance=\"Class\\Name1\">" .
"<label>Test1</label><description>Test1</description></type><type name=\"test\" " .
"translate=\"label,description\" instance=\"Class\\Name2\">" .
"<label>Test2</label><description>Test2</description></type></config>\n2:\n"
],
],
];
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Cache/etc/cache.xsd">
<type name="type_name_1" translate="label,description" instance="Instance1\Class\Name">
<label>Type1</label>
<description>Type1</description>
</type>
<type name="type_name_2" translate="label,description" instance="Instance2\Class\Name">
<label>Type2</label>
<description>Type2</description>
</type>
</config>
@@ -0,0 +1,135 @@
<?php
/**
* Test search_request.xsd and xml files.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Framework\Search;
class RequestConfigTest extends \Magento\TestFramework\Integrity\AbstractConfig
{
/** @var \Magento\Framework\Config\Dom\UrnResolver */
protected $urnResolver;
protected function setUp(): void
{
$this->urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
}
/**
* Returns the name of the XSD file to be used to validate the XML
*
* @return string
*/
protected function _getXsd()
{
return $this->urnResolver->getRealPath('urn:magento:framework:Search/etc/search_request_merged.xsd');
}
/**
* Returns the name of the XSD file to be used to validate partial XML
*
* @return string
*/
protected function _getFileXsd()
{
return $this->urnResolver->getRealPath('urn:magento:framework:Search/etc/search_request.xsd');
}
/**
* The location of a single valid complete xml file
*
* @return string
*/
protected function _getKnownValidXml()
{
return __DIR__ . '/_files/request/valid.xml';
}
/**
* The location of a single known invalid complete xml file
*
* @return string
*/
protected function _getKnownInvalidXml()
{
return __DIR__ . '/_files/request/invalid.xml';
}
/**
* The location of a single known valid partial xml file
*
* @return string
*/
protected function _getKnownValidPartialXml()
{
return __DIR__ . '/_files/request/valid_partial.xml';
}
/**
* @param null $expectedErrors
*/
public function testSchemaUsingInvalidXml($expectedErrors = null)
{
$expectedErrors = array_filter(
explode(
"\n",
"
No match found for key-sequence ['suggested_search_container'] of keyref 'requestQueryReference'.
Element 'queryReference': No match found for key-sequence ['fulltext_search_query4'] of keyref 'queryReference'.
"
)
);
parent::testSchemaUsingInvalidXml($expectedErrors);
}
/**
* @param null $expectedErrors
*/
public function testFileSchemaUsingInvalidXml($expectedErrors = null)
{
$expectedErrors = array_filter(
explode(
"\n",
"
Element 'dimensions': Missing child element(s). Expected is ( dimension ).
Element 'queryReference': The attribute 'clause' is required but missing.
Element 'queryReference': The attribute 'ref' is required but missing.
Element 'filterReference': The attribute 'clause' is required but missing.
Element 'filterReference': The attribute 'ref' is required but missing.
Element 'filter': The attribute 'field' is required but missing.
Element 'metric', attribute 'type': [facet 'enumeration'] " .
"The value 'sumasdasd' is not an element of the set {'sum', 'count', 'min', 'max', 'avg'}.
Element 'metric', attribute 'type': 'sumasdasd' is not a valid value of the local atomic type.
Element 'bucket': Missing child element(s). Expected is one of ( metrics, ranges )."
)
);
parent::testFileSchemaUsingInvalidXml($expectedErrors);
}
/**
* Returns the name of the xml files to validate
*
* @return string
*/
protected function _getXmlName()
{
return 'search_request.xml';
}
/**
* The location of a single known invalid partial xml file
*
* @return string
*/
protected function _getKnownInvalidPartialXml()
{
return __DIR__ . '/_files/request/invalid_partial.xml';
}
public function testSchemaUsingValidXml()
{
parent::testSchemaUsingValidXml();
}
}
@@ -0,0 +1,115 @@
<?php
/**
* Test search_request.xsd and xml files.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Framework\Search;
class SearchEngineConfigTest extends \Magento\TestFramework\Integrity\AbstractConfig
{
/** @var \Magento\Framework\Config\Dom\UrnResolver */
protected $urnResolver;
protected function setUp(): void
{
$this->urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
}
/**
* Returns the name of the XSD file to be used to validate the XML
*
* @return string
*/
protected function _getXsd()
{
return $this->urnResolver->getRealPath('urn:magento:framework:Search/etc/search_engine.xsd');
}
/**
* Returns the name of the XSD file to be used to validate partial XML
*
* @return string
*/
protected function _getFileXsd()
{
return $this->urnResolver->getRealPath('urn:magento:framework:Search/etc/search_engine.xsd');
}
/**
* The location of a single valid complete xml file
*
* @return string
*/
protected function _getKnownValidXml()
{
return __DIR__ . '/_files/search_engine/valid.xml';
}
/**
* The location of a single known invalid complete xml file
*
* @return string
*/
protected function _getKnownInvalidXml()
{
return __DIR__ . '/_files/search_engine/invalid.xml';
}
/**
* The location of a single known valid partial xml file
*
* @return string
*/
protected function _getKnownValidPartialXml()
{
return null;
}
/**
* @param null $expectedErrors
*/
public function testSchemaUsingInvalidXml($expectedErrors = null)
{
$expectedErrors = array_filter(
explode(
"\n",
"
Element 'feature': The attribute 'support' is required but missing.
Element 'wrong': This element is not expected. Expected is ( feature ).
Element 'feature': The attribute 'name' is required but missing.
Element 'engine', attribute 'wrong': The attribute 'wrong' is not allowed.
Element 'engine': The attribute 'name' is required but missing.
Element 'feature', attribute 'support': 'wrong' is not a valid value of the atomic type 'xs:boolean'.
"
)
);
parent::testSchemaUsingInvalidXml($expectedErrors);
}
/**
* Returns the name of the xml files to validate
*
* @return string
*/
protected function _getXmlName()
{
return 'search_engine.xml';
}
/**
* The location of a single known invalid partial xml file
*
* @return string
*/
protected function _getKnownInvalidPartialXml()
{
return null;
}
public function testSchemaUsingValidXml()
{
parent::testSchemaUsingValidXml();
}
}
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">
<request query="suggested_search_container" index="product">
<queries>
<query xsi:type="boolQuery" name="suggested_search_container_dd" boost="2">
<queryReference clause="not" ref="fulltext_search_query4" />
</query>
</queries>
<from>10</from>
<size>10</size>
</request>
</requests>
@@ -0,0 +1,51 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">
<request query="sugested_search_container" index="product">
<dimensions>
</dimensions>
<queries>
<query xsi:type="boolQuery" name="sugested_search_container" boost="2">
<queryReference clause="not" ref="fulltext_search_query"/>
</query>
<query xsi:type="boolQuery" name="suggested_search_container_dd" boost="2">
<queryReference clause="not" ref="fulltext_search_query"/>
</query>
<query xsi:type="matchQuery" value="$fulltext_search_query$" name="fulltext_search_query" boost="5">
<match field="title"/>
<match field="description"/>
</query>
<query xsi:type="filteredQuery" name="promoted_documents_boost">
<queryReference/>
</query>
<query xsi:type="filteredQuery" name="promoted_documents_boost2">
<filterReference/>
</query>
</queries>
<filters>
<filter xsi:type="termFilter" name="promoted_documents_boost" value="$promoted_documents_boost$"/>
<filter xsi:type="rangeFilter" field="promoted" name="price_name" from="10" to="100"/>
<filter xsi:type="boolFilter" name="price_name1">
<filterReference clause="must" ref="price_name"/>
<filterReference clause="must" ref="price_name"/>
</filter>
<filter xsi:type="termFilter" name="promoted_boost" field="promoted" value="1"/>
<filter xsi:type="rangeFilter" field="promoted" name="price" from="10" to="100"/>
</filters>
<aggregations>
<bucket xsi:type="termBucket" name="category_bucket" field="category">
</bucket>
<bucket xsi:type="rangeBucket" name="price_bucket" field="price">
<metrics>
<metric type="sumasdasd"/>
</metrics>
</bucket>
</aggregations>
</request>
</requests>
@@ -0,0 +1,101 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">
<request query="sugegsted_search_container_1" index="product_1">
<dimensions>
<dimension name="scope" value="default"/>
</dimensions>
<queries>
<query xsi:type="boolQuery" name="sugegsted_search_container_1" boost="2">
<queryReference clause="must" ref="fulltext_search_query"/>
<queryReference clause="should" ref="promoted_documents_boost"/>
<queryReference clause="not" ref="query_reference"/>
</query>
<query xsi:type="matchQuery" name="fulltext_search_query" value="$fulltext_search_query$" boost="5">
<match field="title"/>
<match field="description"/>
</query>
<query xsi:type="filteredQuery" name="promoted_documents_boost">
<queryReference clause="must" ref="fulltext_search_query"/>
</query>
<query xsi:type="filteredQuery" name="query_reference">
<filterReference clause="must" ref="price"/>
</query>
</queries>
<filters>
<filter xsi:type="termFilter" name="promoted_documents_boost" field="promoted" value="1"/>
<filter xsi:type="rangeFilter" field="promoted" name="price_name" from="10" to="100"/>
<filter xsi:type="boolFilter" name="price_name_bool">
<filterReference clause="must" ref="promoted_boost"/>
<filterReference clause="should" ref="promoted_documents_boost"/>
<filterReference clause="not" ref="price_name"/>
</filter>
<filter xsi:type="termFilter" name="promoted_boost" field="promoted" value="1"/>
<filter xsi:type="rangeFilter" field="promoted" name="price" from="10" to="100"/>
</filters>
<aggregations>
<bucket xsi:type="termBucket" name="category_bucket" field="category">
<metrics>
<metric type="sum"/>
<metric type="count"/>
<metric type="min"/>
<metric type="max"/>
</metrics>
</bucket>
<bucket xsi:type="rangeBucket" name="price_bucket" field="price">
<metrics>
<metric type="sum"/>
<metric type="count"/>
<metric type="min"/>
<metric type="max"/>
</metrics>
<ranges>
<range from="" to="50"/>
<range from="50" to="100"/>
<range from="100" to=""/>
</ranges>
</bucket>
</aggregations>
<from>10</from>
<size>10</size>
</request>
<request query="sugegsted_search_container_2" index="product_2">
<queries>
<query xsi:type="boolQuery" name="sugegsted_search_container_2" boost="2">
<queryReference clause="not" ref="fulltext_search_query_c_2"/>
</query>
<query xsi:type="matchQuery" value="$fulltext_search$" name="fulltext_search_query_c_2" boost="5">
<match field="title"/>
<match field="description"/>
</query>
</queries>
<filters>
<filter xsi:type="rangeFilter" field="promoted" name="price_filter" from="10" to="100"/>
</filters>
<aggregations>
<bucket xsi:type="termBucket" name="category_bucket" field="category">
<metrics>
<metric type="sum"/>
</metrics>
</bucket>
<bucket xsi:type="rangeBucket" name="price_bucket" field="price">
<metrics>
<metric type="sum"/>
</metrics>
<ranges>
<range from="" to="50"/>
</ranges>
</bucket>
</aggregations>
<from>0</from>
<size>10</size>
</request>
</requests>
@@ -0,0 +1,71 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">
<request query="sugested_search_container_1" index="product_1">
<queries>
<query xsi:type="boolQuery" name="sugested_search_container" boost="2">
<queryReference clause="must" ref="fulltext_search_query" />
<queryReference clause="should" ref="suggested_search_container_dd" />
</query>
<query xsi:type="boolQuery" name="suggested_search_container_dd" boost="2">
<queryReference clause="not" ref="fulltext_search_query" />
</query>
<query xsi:type="matchQuery" value="$fulltext_search_query$" name="fulltext_search_query" boost="5">
<match field="title" />
<match field="description" />
</query>
<query xsi:type="filteredQuery" name="promoted_documents_boost">
<queryReference clause="must" ref="fulltext_search_query" />
</query>
<query xsi:type="filteredQuery" name="promoted_documents_boost2">
<filterReference clause="must" ref="promoted_documents_filter" />
</query>
</queries>
<filters>
<filter xsi:type="termFilter" name="promoted_documents_filter" field="promoted" value="1" />
<filter xsi:type="rangeFilter" field="promoted" name="price_name" from="10" to="100" />
<filter xsi:type="boolFilter" name="price_name1">
<filterReference clause="must" ref="promoted_boost" />
<filterReference clause="must" ref="price" />
<filterReference clause="must" ref="promoted_documents_filter" />
</filter>
<filter xsi:type="termFilter" name="promoted_boost" field="promoted" value="1" />
<filter xsi:type="rangeFilter" field="promoted" name="price" from="10" to="100" />
</filters>
<aggregations>
<bucket xsi:type="termBucket" name="category_bucket" field="category">
<metrics>
<metric type="sum" />
<metric type="count" />
<metric type="min" />
<metric type="max" />
</metrics>
</bucket>
<bucket xsi:type="rangeBucket" name="price_bucket" field="price">
<metrics>
<metric type="sum" />
<metric type="count" />
<metric type="min" />
<metric type="max" />
</metrics>
<ranges>
<range from="" to="50" />
<range from="50" to="100" />
<range from="100" to="" />
</ranges>
</bucket>
<bucket xsi:type="dynamicBucket" method="dynamic1" name="dynamic_price" field="price" />
</aggregations>
<from>10</from>
<size>10</size>
</request>
</requests>
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<engines xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_engine.xsd">
<engine name="engine1">
<feature name="feature1"/>
<wrong name="feature2" support="1" />
</engine>
<engine name="engine2">
<feature support="1" />
</engine>
<engine wrong="engine3">
<feature name="feature1" support="wrong" />
<feature name="feature2" support="0" />
</engine>
</engines>
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<engines xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_engine.xsd">
<engine name="engine1">
<feature name="feature1" support="true" />
<feature name="feature2" support="1" />
</engine>
<engine name="engine2">
<feature name="feature1" support="1" />
<feature name="feature2" support="false" />
</engine>
<engine name="engine3">
<feature name="feature1" support="0" />
<feature name="feature2" support="0" />
</engine>
</engines>
@@ -0,0 +1,92 @@
<?php
/**
* Test indexer.xsd and xml files.
*
* Find "indexer.xml" files in code tree and validate them. Also verify schema fails on an invalid xml and
* passes on a valid xml.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Indexer;
class ConfigTest extends \Magento\TestFramework\Integrity\AbstractConfig
{
/** @var \Magento\Framework\Config\Dom\UrnResolver */
protected $urnResolver;
protected function setUp(): void
{
$this->urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
}
/**
* Returns the name of the XSD file to be used to validate the XML
*
* @return string
*/
protected function _getXsd()
{
return $this->urnResolver->getRealPath('urn:magento:framework:Indexer/etc/indexer_merged.xsd');
}
/**
* The location of a single valid complete xml file
*
* @return string
*/
protected function _getKnownValidXml()
{
return __DIR__ . '/_files/valid.xml';
}
/**
* The location of a single known invalid complete xml file
*
* @return string
*/
protected function _getKnownInvalidXml()
{
return __DIR__ . '/_files/invalid.xml';
}
/**
* The location of a single known valid partial xml file
*
* @return string
*/
protected function _getKnownValidPartialXml()
{
return __DIR__ . '/_files/valid_partial.xml';
}
/**
* The location of a single known invalid partial xml file
*
* @return string
*/
protected function _getKnownInvalidPartialXml()
{
return null;
}
/**
* Returns the name of the XSD file to be used to validate partial XML
*
* @return string
*/
protected function _getFileXsd()
{
return $this->urnResolver->getRealPath('urn:magento:framework:Indexer/etc/indexer.xsd');
}
/**
* Returns the name of the xml files to validate
*
* @return string
*/
protected function _getXmlName()
{
return '/lib/internal/Magento/Framework/Indexer/etc/indexer.xml';
}
}
@@ -0,0 +1,87 @@
<?xml version="1.0"?>
<!--
/**
* This file contains errors that will fail schema validation.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer_merged.xsd">
<indexer id="indexer_0" view_id="catalogsearch_fulltext" class="NotAClass">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">Invalid provider attribute value</description>
</indexer>
<indexer id="indexer_0" view_id="catalogsearch_fulltext" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">Duplicate indexer id</description>
</indexer>
<indexer id="indexer_10" view_id="catalogsearch_fulltext_10" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">Duplicate 'view_id' in indexer declaration</description>
</indexer>
<indexer id="indexer_11" view_id="catalogsearch_fulltext_11" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">Empty fields</description>
<fieldset source="Collection" provider="Magento\Framework\Search\Index\Fieldset\Default" name="default"/>
</indexer>
<indexer id="indexer_1" view_id="catalogsearch_fulltext_1" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">Invalid handler attribute value</description>
<fieldset source="Collection" provider="Magento\Framework\Search\Index\Fieldset\Default" name="default">
<field name="visibility" handler="Magento\Framework\Search\Index\Field\Handler\Class" xsi:type="filterable" dataType="int" />
</fieldset>
</indexer>
<indexer id="indexer_2" view_id="catalogsearch_fulltext_2" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">Duplicate field declaration</description>
<fieldset source="Collection" provider="Magento\Framework\Search\Index\Fieldset\Default" name="default">
<field name="visibility" handler="defaultHandler" xsi:type="filterable" dataType="int" />
<field name="visibility" handler="defaultHandler">
<filter class="Magento\Framework\Search\Index\Filter\StopWordsFilter"/>
</field>
</fieldset>
</indexer>
<indexer id="indexer_3" view_id="catalogsearch_fulltext_3" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">Invalid source attribute value</description>
<fieldset source="Collection" provider="Magento\Framework\Search\Index\Fieldset\Default" name="default">
<field name="visibility" handler="defaultHandler"/>
</fieldset>
</indexer>
<indexer id="indexer_4" view_id="catalogsearch_fulltext_4" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">Invalid field handler attribute value</description>
<fieldset source="Collection" provider="Magento\Framework\Search\Index\Fieldset\Default" name="default">
<field name="visibility" handler="handler" xsi:type="filterable" dataType="int"/>
</fieldset>
</indexer>
<indexer id="indexer_5" view_id="catalogsearch_fulltext_5" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">Invalid field type</description>
<fieldset source="Collection" provider="Magento\Framework\Search\Index\Fieldset\Default" name="default">
<field name="visibility" handler="defaultHandler" xsi:type="any"/>
</fieldset>
</indexer>
<indexer id="indexer_6" view_id="catalogsearch_fulltext_6" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">No dataType attribute for 'filterable' type field</description>
<fieldset source="Collection" provider="Magento\Framework\Search\Index\Fieldset\Default" name="default">
<field name="visibility" handler="defaultHandler" xsi:type="filterable"/>
</fieldset>
</indexer>
<indexer id="indexer_12" view_id="catalogsearch_fulltext_12" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">Invalid field dataType attribute value</description>
<fieldset source="Collection" provider="Magento\Framework\Search\Index\Fieldset\Default" name="default">
<field name="visibility" handler="defaultHandler" xsi:type="filterable" dataType="string"/>
</fieldset>
</indexer>
<indexer id="indexer_13" view_id="catalogsearch_fulltext_13" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration</title>
<description translate="true">No dataType attribute for 'filterable' type field</description>
<fieldset source="Collection" provider="Magento\Framework\Search\Index\Fieldset\Default" name="default">
<field name="visibility" handler="defaultHandler" xsi:type="filterable"/>
</fieldset>
</indexer>
</config>
@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer_merged.xsd">
<indexer id="indexer_1" view_id="catalogsearch_fulltext" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration 1</title>
<description translate="true">Test Indexer Declaration 1</description>
<fieldset name="default" source="Magento\Framework\Search\Index\ResourceModel" provider="Magento\Framework\Search\Index\Fieldset\Default">
<field name="title" handler="Magento\Framework\Search\Index\Handler">
<filter class="Magento\Framework\Search\Index\Filter\StopWordsFilter"/>
</field>
<field name="description" handler="default" xsi:type="searchable">
<filter class="Magento\Framework\Search\Index\Filter\LowercaseFilter"/>
</field>
<field name="visibility" handler="default" xsi:type="filterable" dataType="int" />
</fieldset>
<fieldset name="related" source="Magento\Framework\Search\Index\ResourceModel" provider="Magento\Framework\Search\Index\Fieldset\Default">
<reference fieldset="default" from="main_id" to="current_id" />
<field name="description_2" handler="default" xsi:type="searchable">
<filter class="Magento\Framework\Search\Index\Filter\LowercaseFilter"/>
</field>
</fieldset>
<structure class="Magento\Framework\Search\Index\Structure"/>
<saveHandler class="Magento\Framework\Search\Index\SaveHandler"/>
</indexer>
<indexer id="indexer_2" view_id="catalogsearch_fulltext_2" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration 1</title>
<description translate="true">Test Indexer Declaration 1</description>
<fieldset name="default" source="Magento\Framework\Search\Index\ResourceModel" provider="Magento\Framework\Search\Index\Fieldset\Default">
<field name="title" handler="Magento\Framework\Search\Index\Handler">
<filter class="Magento\Framework\Search\Index\Filter\StopWordsFilter"/>
</field>
<field name="description" handler="default" xsi:type="searchable">
<filter class="Magento\Framework\Search\Index\Filter\LowercaseFilter"/>
</field>
<field name="visibility" handler="default" xsi:type="filterable" dataType="int" />
</fieldset>
<structure class="Magento\Framework\Search\Index\Structure"/>
<saveHandler class="Magento\Framework\Search\Index\SaveHandler"/>
</indexer>
</config>
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
<indexer id="indexer_1" view_id="catalogsearch_fulltext" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Test Indexer Declaration 1</title>
<description translate="true">Test Indexer Declaration 1</description>
<fieldset name="default" source="Magento\Framework\Search\Index\ResourceModel" provider="Magento\Framework\Search\Index\Fieldset\Default">
<field name="title" handler="Magento\Framework\Search\Index\Handler">
<filter class="Magento\Framework\Search\Index\Filter\StopWordsFilter"/>
</field>
<field name="description" handler="default" xsi:type="searchable">
<filter class="Magento\Framework\Search\Index\Filter\LowercaseFilter"/>
</field>
<field name="visibility" handler="default" xsi:type="filterable" dataType="int" />
</fieldset>
<fieldset name="related" provider="Magento\Framework\Search\Index\Fieldset\Default">
<reference fieldset="default" from="main_id" to="current_id" />
<field name="description_2" handler="default" xsi:type="searchable">
<filter class="Magento\Framework\Search\Index\Filter\LowercaseFilter"/>
</field>
</fieldset>
<structure class="Magento\Framework\Search\Index\Structure"/>
<saveHandler class="Magento\Framework\Search\Index\SaveHandler"/>
</indexer>
</config>
@@ -0,0 +1,96 @@
<?php
/**
* Validates that payment groups referenced from store configuration matches the groups declared in payment.xml
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Payment\Config;
class ReferentialTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string[] $usedGroups all payment groups used in store configuration
*/
protected static $_usedGroups = [];
/** @var string[] $_registeredGroups all registered payment groups */
protected static $_registeredGroups = [];
public static function setUpBeforeClass(): void
{
self::_populateUsedGroups();
self::_populateRegisteredGroups();
}
/**
* Gathers all payment groups used in store configuration
*/
private static function _populateUsedGroups()
{
/**
* @var string[] $configFiles
*/
$configFiles = \Magento\Framework\App\Utility\Files::init()->getConfigFiles('config.xml', [], false);
/**
* @var string $file
*/
foreach ($configFiles as $file) {
/**
* @var \DOMDocument $dom
*/
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($file));
$xpath = new \DOMXPath($dom);
foreach ($xpath->query('/config/*/payment/*/group') as $group) {
if (!in_array($group->nodeValue, self::$_usedGroups)) {
self::$_usedGroups[] = $group->nodeValue;
}
}
}
}
/**
* Gathers all registered payment groups
*/
private static function _populateRegisteredGroups()
{
/**
* @var string[] $configFiles
*/
$configFiles = \Magento\Framework\App\Utility\Files::init()->getConfigFiles('payment.xml', [], false);
/**
* @var string $file
*/
foreach ($configFiles as $file) {
/**
* @var \DOMDocument $dom
*/
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($file));
$xpath = new \DOMXPath($dom);
foreach ($xpath->query('/payment/groups/group') as $group) {
$id = $group->attributes->getNamedItem('id')->nodeValue;
if (!in_array($id, self::$_registeredGroups)) {
self::$_registeredGroups[] = $id;
}
}
}
}
public function testGroupsExists()
{
$missing = array_diff(self::$_usedGroups, self::$_registeredGroups);
if (!empty($missing)) {
$message = sprintf(
"The groups, referenced in store configuration for the payment, " .
"don't correspond to any payment group declared in payment.xml: %s",
implode(', ', $missing)
);
$this->fail($message);
}
}
}
@@ -0,0 +1,119 @@
<?php
/**
* Find "payment.xml" files and validate them
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Payment\Model;
class ConfigTest extends \Magento\TestFramework\Integrity\AbstractConfig
{
/** @var \Magento\Framework\Config\Dom\UrnResolver */
protected $urnResolver;
protected function setUp(): void
{
$this->urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
}
public function testSchemaUsingInvalidXml($expectedErrors = null)
{
$expectedErrors = [
"Element 'type': The attribute 'id' is required but missing.",
"Element 'type': Missing child element(s). Expected is ( label ).",
"Element 'group': The attribute 'id' is required but missing.",
"Element 'group': Missing child element(s). Expected is ( label ).",
];
parent::testSchemaUsingInvalidXml($expectedErrors);
}
public function testFileSchemaUsingInvalidXml($expectedErrors = null)
{
$expectedErrors = [
"Element 'type': The attribute 'id' is required but missing.",
"Element 'type': The attribute 'id' is required but missing.",
"Element 'group': The attribute 'id' is required but missing.",
];
parent::testFileSchemaUsingInvalidXml($expectedErrors);
}
public function testSchemaUsingPartialXml($expectedErrors = null)
{
$expectedErrors = [
"Element 'type': The attribute 'order' is required but missing.",
"Element 'type': Missing child element(s). Expected is ( label ).",
];
parent::testSchemaUsingPartialXml($expectedErrors);
}
/**
* Returns the name of the xml files to validate
*
* @return string
*/
protected function _getXmlName()
{
return 'payment.xml';
}
/**
* The location of a single valid complete xml file
*
* @return string
*/
protected function _getKnownValidXml()
{
return __DIR__ . '/_files/payment.xml';
}
/**
* The location of a single known invalid complete xml file
*
* @return string
*/
protected function _getKnownInvalidXml()
{
return __DIR__ . '/_files/invalid_payment.xml';
}
/**
* The location of a single known valid partial xml file
*
* @return string
*/
protected function _getKnownValidPartialXml()
{
return __DIR__ . '/_files/payment_partial.xml';
}
/**
* The location of a single known invalid partial xml file
*
* @return string
*/
protected function _getKnownInvalidPartialXml()
{
return __DIR__ . '/_files/invalid_payment_partial.xml';
}
/**
* Returns the name of the XSD file to be used to validate the XSD
*
* @return string
*/
protected function _getXsd()
{
return $this->urnResolver->getRealPath('urn:magento:module:Magento_Payment:etc/payment.xsd');
}
/**
* Returns the name of the XSD file to be used to validate partial XML
*
* @return string
*/
protected function _getFileXsd()
{
return $this->urnResolver->getRealPath('urn:magento:module:Magento_Payment:etc/payment_file.xsd');
}
}
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<payment>
<credit_cards>
<type order="0">
<label>ABC Credit Card Company</label>
</type>
<type id="XYZ" order="10"/>
</credit_cards>
<groups>
<group>
<label>Other Payment Methods</label>
</group>
<group id="other"/>
</groups>
</payment>
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<payment>
<credit_cards>
<type order="0">
<label>ABC Credit Card Company</label>
</type>
<type order="10">
<label>ABC Credit Card Company</label>
</type>
</credit_cards>
<groups>
<group>
<label>Other Payment Methods</label>
</group>
</groups>
</payment>
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<payment>
<credit_cards>
<type id="ABC" order="0">
<label>ABC Credit Card Company</label>
</type>
<type id="XYZ" order="10">
<label>ABC Credit Card Company</label>
</type>
</credit_cards>
<groups>
<group id="other">
<label>Other Payment Methods</label>
</group>
</groups>
</payment>
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<payment>
<credit_cards>
<type id="ABC" order="0">
<label>ABC Credit Card Company</label>
</type>
<type id="XYZ">
</type>
</credit_cards>
<groups>
<group id="none">
<label>Group Label</label>
</group>
</groups>
</payment>
@@ -0,0 +1,109 @@
<?php
/**
* Test persistent.xsd and xml files.
*
* Find "persistent.xml" files in code tree and validate them. Also verify schema fails on an invalid xml and
* passes on a valid xml.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Persistent;
class ConfigTest extends \Magento\TestFramework\Integrity\AbstractConfig
{
/**
* 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:module:Magento_Persistent:etc/persistent.xsd');
}
/**
* The location of a single valid complete xml file
*
* @return string
*/
protected function _getKnownValidXml()
{
return __DIR__ . '/_files/valid_persistent.xml';
}
/**
* The location of a single known invalid complete xml file
*
* @return string
*/
protected function _getKnownInvalidXml()
{
return __DIR__ . '/_files/invalid_persistent.xml';
}
/**
* The location of a single known valid partial xml file
*
* @return string
*/
protected function _getKnownValidPartialXml()
{
return '';
}
/**
* Returns the name of the XSD file to be used to validate partial XML
*
* @return string
*/
protected function _getFileXsd()
{
return '';
}
/**
* The location of a single known invalid partial xml file
*
* @return string
*/
protected function _getKnownInvalidPartialXml()
{
return '';
}
/**
* Returns the name of the xml files to validate
*
* @return string
*/
protected function _getXmlName()
{
return 'persistent.xml';
}
public function testFileSchemaUsingInvalidXml($expectedErrors = null)
{
$this->markTestSkipped('persistent.xml does not have a partial schema');
}
public function testSchemaUsingPartialXml($expectedErrors = null)
{
$this->markTestSkipped('persistent.xml does not have a partial schema');
}
public function testFileSchemaUsingPartialXml()
{
$this->markTestSkipped('persistent.xml does not have a partial schema');
}
public function testSchemaUsingInvalidXml($expectedErrors = null)
{
$expectedErrors = [
"Element 'welcome': This element is not expected.",
"Element 'models': This element is not expected.",
];
parent::testSchemaUsingInvalidXml($expectedErrors);
}
}
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<!--
/**
* This file contains errors that will fail schema validation.
*
* The welcome and models nodes will be unexpected - this is the old version of persistent.xml.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Persistent:etc/persistent.xsd">
<instances>
<blocks>
<welcome>
<name_in_layout>header</name_in_layout>
<class>Magento\Persistent\Model\Observer</class>
<method>emulateWelcomeBlock</method>
<block_type>Magento\Theme\Block\Html\Header</block_type>
</welcome>
<top_links>
<name_in_layout>top.links</name_in_layout>
<class>Magento\Persistent\Model\Observer</class>
<method>emulateTopLinks</method>
<block_type>Magento\Theme\Block\Template\Links</block_type>
</top_links>
</blocks>
<models />
<collections />
</instances>
</config>
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Persistent:etc/persistent.xsd">
<instances>
<blocks>
<reference id="welcome">
<name_in_layout>header</name_in_layout>
<class>Magento\Persistent\Model\Observer</class>
<method>emulateWelcomeBlock</method>
<block_type>Magento\Theme\Block\Html\Header</block_type>
</reference>
<reference id="top_links">
<name_in_layout>top.links</name_in_layout>
<class>Magento\Persistent\Model\Observer</class>
<method>emulateTopLinks</method>
<block_type>Magento\Theme\Block\Template\Links</block_type>
</reference>
</blocks>
</instances>
</config>
@@ -0,0 +1,118 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Webapi\Model;
use Magento\TestFramework\Integrity\AbstractConfig;
/**
* Find webapi xml files and validate them
*/
class ConfigTest extends AbstractConfig
{
/**
* @inheritdoc
*/
public function testSchemaUsingInvalidXml($expectedErrors = null)
{
// @codingStandardsIgnoreStart
$expectedErrors = [
"Element 'route', attribute 'method': [facet 'enumeration'] The value 'PATCH' is not an element of the set {'GET', 'PUT', 'POST', 'DELETE'}.",
"Element 'route', attribute 'method': 'PATCH' is not a valid value of the local atomic type.",
"Element 'service': The attribute 'method' is required but missing.",
"Element 'route': Missing child element(s). Expected is ( service ).",
"Element 'route': Missing child element(s). Expected is ( resources ).",
];
// @codingStandardsIgnoreEnd
parent::testSchemaUsingInvalidXml($expectedErrors);
}
/**
* @inheritdoc
*/
public function testFileSchemaUsingInvalidXml($expectedErrors = null)
{
// @codingStandardsIgnoreStart
$expectedErrors = [
"Element 'route', attribute 'method': [facet 'enumeration'] The value 'PATCH' is not an element of the set {'GET', 'PUT', 'POST', 'DELETE'}.",
"Element 'route', attribute 'method': 'PATCH' is not a valid value of the local atomic type.",
"Element 'service': The attribute 'method' is required but missing.",
];
// @codingStandardsIgnoreEnd
parent::testFileSchemaUsingInvalidXml($expectedErrors);
}
/**
* Returns the name of the xml files to validate
*
* @return string
*/
protected function _getXmlName()
{
return 'webapi.xml';
}
/**
* The location of a single valid complete xml file
*
* @return string
*/
protected function _getKnownValidXml()
{
return __DIR__ . '/_files/webapi.xml';
}
/**
* The location of a single known invalid complete xml file
*
* @return string
*/
protected function _getKnownInvalidXml()
{
return __DIR__ . '/_files/invalid_webapi.xml';
}
/**
* The location of a single known valid partial xml file
*
* @return string
*/
protected function _getKnownValidPartialXml()
{
return __DIR__ . '/_files/partial_webapi.xml';
}
/**
* The location of a single known invalid partial xml file
*
* @return string
*/
protected function _getKnownInvalidPartialXml()
{
return __DIR__ . '/_files/partial_invalid_webapi.xml';
}
/**
* Returns the name of the XSD file to be used to validate the XSD
*
* @return string
*/
protected function _getXsd()
{
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
return $urnResolver->getRealPath('urn:magento:module:Magento_Webapi:etc/webapi_merged.xsd');
}
/**
* Returns the name of the XSD file to be used to validate partial XML
*
* @return string
*/
protected function _getFileXsd()
{
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
return $urnResolver->getRealPath('urn:magento:module:Magento_Webapi:etc/webapi.xsd');
}
}
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/customer/me" method="PATCH">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" />
<resources>
<resource ref="a resource" />
</resources>
<data>
</data>
</route>
<route url="/V1/customers" method="POST"/>
<route url="/V1/customers" method="PUT">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="foo" />
</route>
</routes>
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/customer/me" method="PATCH">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" />
<resources>
<resource ref="a resource" />
</resources>
<data>
</data>
</route>
<route url="/V1/customers" method="POST"/>
<route url="/V1/customers" method="PUT">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="foo" />
</route>
</routes>
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/customers/me" method="GET">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="getById" />
<resources>
<resource ref="Magento_Customer::customer_self" />
</resources>
<data>
<parameter name="id" force="true">null</parameter>
</data>
</route>
<route url="/V1/customers/me" method="PUT" secure="true">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="save" />
<resources>
<resource ref="Magento_Customer::customer_self" />
</resources>
<data>
<parameter name="id">null</parameter>
</data>
</route>
<route url="/V1/customers" method="POST">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="save" />
<resources>
<resource ref="Magento_Customer::manage" />
</resources>
</route>
<route url="/V1/customers/:id" method="GET">
<resources>
<resource ref="Magento_Customer::read" />
</resources>
</route>
</routes>
@@ -0,0 +1,40 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/customers/me" method="GET">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="getById" />
<resources>
<resource ref="Magento_Customer::customer_self" />
</resources>
<data>
<parameter name="id" force="true">null</parameter>
</data>
</route>
<route url="/V1/customers/me" method="PUT" secure="true">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="save" />
<resources>
<resource ref="Magento_Customer::customer_self" />
</resources>
<data>
<parameter name="id">null</parameter>
</data>
</route>
<route url="/V1/customers" method="POST">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="save" />
<resources>
<resource ref="Magento_Customer::manage" />
</resources>
</route>
<route url="/V1/customers/:id" method="GET">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="getById" />
<resources>
<resource ref="Magento_Customer::read" />
</resources>
</route>
</routes>
@@ -0,0 +1,112 @@
<?php
/**
* Find "widget.xml" files and validate them
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Magento\Widget;
class WidgetConfigTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Framework\Config\Dom\UrnResolver */
protected $urnResolver;
protected function setUp(): void
{
$this->urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
}
public function testXmlFiles()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $configFile
*/
function ($configFile) {
$schema = $this->urnResolver->getRealPath('urn:magento:module:Magento_Widget:etc/widget.xsd');
$this->_validateFileExpectSuccess($configFile, $schema);
},
array_merge(
\Magento\Framework\App\Utility\Files::init()->getConfigFiles('widget.xml'),
\Magento\Framework\App\Utility\Files::init()->getLayoutConfigFiles('widget.xml')
)
);
}
public function testSchemaUsingValidXml()
{
$xmlFile = __DIR__ . '/_files/widget.xml';
$schema = $this->urnResolver->getRealPath('urn:magento:module:Magento_Widget:etc/widget.xsd');
$this->_validateFileExpectSuccess($xmlFile, $schema);
}
public function testSchemaUsingInvalidXml()
{
if (!function_exists('libxml_set_external_entity_loader')) {
$this->markTestSkipped('Skipped due to MAGETWO-45033');
}
$xmlFile = __DIR__ . '/_files/invalid_widget.xml';
$schema = $this->urnResolver->getRealPath('urn:magento:module:Magento_Widget:etc/widget.xsd');
$this->_validateFileExpectFailure($xmlFile, $schema);
}
public function testFileSchemaUsingXml()
{
$xmlFile = __DIR__ . '/_files/widget_file.xml';
$schema = $this->urnResolver->getRealPath('urn:magento:module:Magento_Widget:etc/widget_file.xsd');
$this->_validateFileExpectSuccess($xmlFile, $schema);
}
public function testFileSchemaUsingInvalidXml()
{
if (!function_exists('libxml_set_external_entity_loader')) {
$this->markTestSkipped('Skipped due to MAGETWO-45033');
}
$xmlFile = __DIR__ . '/_files/invalid_widget.xml';
$schema = $this->urnResolver->getRealPath('urn:magento:module:Magento_Widget:etc/widget_file.xsd');
$this->_validateFileExpectFailure($xmlFile, $schema);
}
/**
* Run schema validation against an xml file with a provided schema.
*
* This helper expects the validation to pass and will fail a test if any errors are found.
*
* @param $xmlFile string a known good xml file.
* @param $schemaFile string schema that should find no errors in the known good xml file.
*/
protected function _validateFileExpectFailure($xmlFile, $schemaFile)
{
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schemaFile);
if (!$errors) {
$this->fail('There is a problem with the schema. A known bad XML file passed validation');
}
}
/**
* Run schema validation against a known bad xml file with a provided schema.
*
* This helper expects the validation to fail and will fail a test if no errors are found.
*
* @param $xmlFile string a known bad xml file.
* @param $schemaFile string schema that should find errors in the known bad xml file.
*/
protected function _validateFileExpectSuccess($xmlFile, $schemaFile)
{
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schemaFile);
if ($errors) {
$this->fail(
'There is a problem with the schema. A known good XML file failed validation: ' . PHP_EOL . implode(
PHP_EOL . PHP_EOL,
$errors
)
);
}
}
}
@@ -0,0 +1,141 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
<widget id="new_products" class="Magento\Catalog\Block\Product\Widget\NewWidget" module="Magento_Catalog" is_email_compatible="true"
placeholder_image="Magento_Catalog::images/product_widget_new.png" translate="label description">
<label>Catalog New Products List</label>
<description>List of Products that are set as New</description>
<parameter name="display_type" type="select" required="true" visible="true" translate="label description">
<label>Display Type</label>
<description>All products - recently added products, New products - products marked as new</description>
<option name="default" value="all_products" selected="true" translate="label">
<label>All products</label>
</option>
<option name="item" value="new_products" translate="label">
<label>New products</label>
</option>
</parameter>
<parameter name="show_pager" type="select" visible="true" source_model="Magento\Config\Model\Config\Source\Yesno"
translate="label" >
<label>Display Page Control</label>
</parameter>
<parameter name="products_per_page" type="text" required="true" visible="true" translate="label">
<label>Number of Products per Page</label>
<value>5</value>
<depends>
<parameter name="show_pager" value="1"/>
</depends>
</parameter>
<parameter name="products_count" type="text" required="true" visible="true" translate="label">
<label>Number of Products to Display</label>
<value>10</value>
</parameter>
<parameter name="template" type="select" required="true" visible="true" translate="label">
<label>Template</label>
<option name="default" value="product/widget/new/content/new_grid.phtml" selected="true" translate="label">
<label>New Products Grid Template</label>
</option>
<option name="list" value="product/widget/new/content/new_list.phtml" translate="label">
<label>New Products List Template</label>
</option>
<option name="list_default" value="product/widget/new/column/new_default_list.phtml" translate="label">
<label>New Products Images and Names Template</label>
</option>
<option name="list_names" value="product/widget/new/column/new_names_list.phtml" translate="label">
<label>New Products Names Only Template</label>
</option>
<option name="list_images" value="product/widget/new/column/new_images_list.phtml" translate="label">
<label>New Products Images Only Template</label>
</option>
</parameter>
<parameter name="cache_lifetime" type="text" visible="true" translate="label description">
<label>Cache Lifetime (Seconds)</label>
<description>86400 by default, if not set. To refresh instantly, clear the Blocks HTML Output cache.</description>
</parameter>
<container name="left">
<template name="default" value="list_default"/>
<template name="names_only" value="list_names"/>
<template name="images_only" value="list_images"/>
</container>
<container name="content">
<template name="grid" value="default"/>
<template name="list" value="list"/>
</container>
<container name="right">
<template name="default" value="list_default"/>
<template name="names_only" value="list_names"/>
<template name="images_only" value="list_images"/>
</container>
</widget>
<widget id="catalog_product_link" class="Magento\Catalog\Block\Product\Widget\Link" module="Magento_Catalog" is_email_compatible="true"
placeholder_image="Magento_Catalog::images/product_widget_link.png" translate="label description">
<label>Catalog Product Link</label>
<description>Link to a Specified Product</description>
<parameter name="id_path" type="block" visible="true" required="true" sort_order="10" translate="label">
<label>Product</label>
<block class="Magento\Backend\Block\Catalog\Product\Widget\Chooser">
<data>
<item name="button" type="array">
<item name="open" type="string">Select Product...</item>
</item>
</data>
</block>
</parameter>
<parameter name="anchor_text" type="text" visible="true" translate="label description">
<label>Anchor Custom Text</label>
<description>If empty, we'll use the product name here.</description>
</parameter>
<parameter name="title" type="text" visible="true" translate="label">
<label>Anchor Custom Title</label>
</parameter>
<parameter name="template" type="select" visible="true" translate="label" >
<label>Template</label>
<option name="default" value="product/widget/link/link_block.phtml" selected="true" translate="label">
<label>Product Link Block Template</label>
</option>
<option name="link_inline" value="product/widget/link/link_inline.phtml" translate="label">
<label>Product Link Inline Template</label>
</option>
</parameter>
</widget>
<widget id="catalog_category_link" class="Magento\Catalog\Block\Category\Widget\Link" module="Magento_Catalog" is_email_compatible="true"
placeholder_image="Magento_Catalog::images/category_widget_link.png" translate="label description">
<label>Catalog Category Link</label>
<description>Link to a Specified Category</description>
<parameter name="id_path" type="block" visible="true" required="true" sort_order="10" translate="label">
<label>Category</label>
<block class="Magento\Backend\Block\Catalog\Category\Widget\Chooser">
<data>
<item name="button" type="array">
<item name="open" type="string">Select Category...</item>
</item>
</data>
</block>
</parameter>
<parameter name="anchor_text" type="text" visible="true" translate="label description">
<label>Anchor Custom Text</label>
<description>If empty, we'll use the category name here.</description>
</parameter>
<parameter name="title" type="text" visible="true" translate="label">
<label>Anchor Custom Title</label>
</parameter>
<parameter name="template" type="select" visible="true" translate="label">
<label>Template</label>
<option name="default" value="category/widget/link/link_block.phtml" selected="true" translate="label">
<label>Category Link Block Template</label>
</option>
<option name="link_inline" value="category/widget/link/link_inline.phtml" translate="label">
<label>Category Link Inline Template</label>
</option>
</parameter>
</widget>
</widgets>
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
<widget id="sales_widget_guestform" class="Magento\Sales\Block\Widget\Guest\Form" is_email_compatible="true" >
<label translate="true">Orders and Returns</label>
<description translate="true">Orders and Returns Search Form</description>
<parameters>
<parameter name="title" xsi:type="text" visible="false">
<label translate="true">Anchor Custom Title</label>
</parameter>
<parameter name="template" xsi:type="select" visible="false">
<options>
<option name="default" value="hierarchy/widget/link/link_block.phtml" selected="true">
<label translate="true">CMS Page Link Block Template</label>
</option>
<option name="link_inline" value="hierarchy/widget/link/link_inline.phtml">
<label translate="true">CMS Page Link Inline Template</label>
</option>
</options>
</parameter>
<parameter name="link_display" xsi:type="select" visible="true" sort_order="10"
source_model="Magento\Config\Model\Config\Source\Yesno">
<label translate="true">Display a Link to Loading a Spreadsheet</label>
<description translate="true">Defines whether a link to My Account</description>
</parameter>
<parameter name="link_text" xsi:type="text" required="true" visible="true" sort_order="20">
<label translate="true">Link Text</label>
<description translate="true">The text of the link to the My Account &amp;gt; Order by SKU page</description>
<depends>
<parameter name="link_display" value="1" />
</depends>
<value translate="true">Load a list of SKUs</value>
</parameter>
<parameter name="id_path" xsi:type="block" visible="true" required="true" sort_order="10">
<label translate="true">Product</label>
<block class="Magento\Backend\Block\Catalog\Product\Widget\Chooser">
<data>
<item name="button" xsi:type="array">
<item name="open" xsi:type="string">Select Product...</item>
</item>
</data>
</block>
</parameter>
</parameters>
<containers>
<container name="left">
<template name="default" value="default_template" />
</container>
<container name="right">
<template name="default" value="default_template" />
</container>
</containers>
</widget>
</widgets>
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget_file.xsd">
<widget id="sales_widget_guestform">
<parameters>
<parameter name="test" xsi:type="select">
<depends>
<parameter name="test" value="1"/>
</depends>
</parameter>
</parameters>
</widget>
<widget id="the_id">
</widget>
</widgets>
@@ -0,0 +1,119 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity;
use Magento\Framework\App\Utility\Files;
use Magento\Tax\Observer\GetPriceConfigurationObserver;
/**
* PAY ATTENTION: Current implementation does not support of virtual types
*/
class ObserverImplementationTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string
*/
public const OBSERVER_INTERFACE = \Magento\Framework\Event\ObserverInterface::class;
/**
* @var array
*/
protected static $observerClasses = [];
public static function setUpBeforeClass(): void
{
self::$observerClasses = array_merge(
self::getObserverClasses('{*/events.xml,events.xml}', '//observer')
);
}
public function testObserverInterfaceImplementation()
{
$errors = [];
foreach (self::$observerClasses as $observerClass) {
if (!is_subclass_of($observerClass, self::OBSERVER_INTERFACE)) {
$errors[] = $observerClass;
}
}
if ($errors) {
$errors = array_unique($errors);
sort($errors);
$this->fail(
sprintf(
'%d of observers which not implement \Magento\Framework\Event\ObserverInterface: %s',
count($errors),
"\n" . implode("\n", $errors)
)
);
}
}
public function testObserverHasNoExtraPublicMethods()
{
$errors = [];
foreach (self::$observerClasses as $observerClass) {
$reflection = (new \ReflectionClass($observerClass));
$publicMethodsCount = 0;
$maxCountMethod = $reflection->getConstructor() ? 2 : 1;
$publicMethods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($publicMethods as $publicMethod) {
if (!str_starts_with($publicMethod->getName(), '_')) {
$publicMethodsCount++;
}
}
if ($publicMethodsCount > $maxCountMethod) {
$errors[] = $observerClass;
}
}
if ($errors) {
$errors = array_unique($errors);
sort($errors);
$this->fail(
sprintf(
'%d of observers have extra public methods: %s',
count($errors),
implode("\n", $errors)
)
);
}
}
/**
* @param string $fileNamePattern
* @param string $xpath
* @return array
*/
protected static function getObserverClasses($fileNamePattern, $xpath)
{
$observerClasses = [];
foreach (Files::init()->getConfigFiles($fileNamePattern, [], false) as $configFile) {
foreach (simplexml_load_file($configFile)->xpath($xpath) as $observer) {
$className = (string)$observer->attributes()->instance;
// $className may be empty in cases like this <observer name="observer_name" disabled="true" />
if ($className) {
$observerClasses[] = trim((string)$observer->attributes()->instance, '\\');
}
}
}
$blacklistFiles = str_replace('\\', '/', realpath(__DIR__)) . '/_files/blacklist/observers*.txt';
$blacklistExceptions = [];
foreach (glob($blacklistFiles) as $fileName) {
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
$blacklistExceptions = array_merge(
$blacklistExceptions,
file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
);
}
return array_diff(
array_unique($observerClasses),
$blacklistExceptions
);
}
}
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Test\Integrity;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\TestFramework\Fixture\DataFixtureInterface;
use Magento\TestFramework\Utility\AddedFiles;
use Magento\TestFramework\Utility\ClassNameExtractor;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionException;
/**
* Static test for legacy data fixtures
*/
class ParameterizedFixtureTest extends TestCase
{
/**
* Validates parameterized data fixtures location
*
* @return void
*/
public function testLocation(): void
{
$classNameExtractor = new ClassNameExtractor();
$files = AddedFiles::getAddedFilesList(__DIR__ . '/..');
$errors = [];
foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) !== 'php' || !file_exists($file)) {
continue;
}
$path = str_replace(BP . '/', '', $file);
$errorMessage = "Parameterized data fixture $path MUST be placed in {{ModuleAppDir}}/Test/Fixture folder";
$class = $classNameExtractor->getNameWithNamespace(file_get_contents($file));
if ($class) {
try {
$classReflection = new ReflectionClass($class);
if (!$classReflection->isSubclassOf(DataFixtureInterface::class)) {
continue;
}
} catch (ReflectionException $exception) {
continue;
}
if (!$this->isFileLocatedInModuleDirectory($file)) {
$errors[] = $errorMessage;
}
}
}
if (!empty($errors)) {
$this->fail(implode(PHP_EOL, $errors));
}
}
/**
* @param string $file
* @return bool
*/
private function isFileLocatedInModuleDirectory(string $file): bool
{
$componentRegistrar = new ComponentRegistrar();
$found = false;
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) {
if ($file === $moduleDir . '/Test/Fixture/' . basename($file)) {
$found = true;
break;
}
}
return $found;
}
}
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Abstract class for phrase testing
*/
namespace Magento\Test\Integrity\Phrase;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Setup\Module\I18n\FilesCollector;
class AbstractTestCase extends \PHPUnit\Framework\TestCase
{
/**
* @param array $phrase
* @return string
*/
protected function _createPhraseError($phrase)
{
return "\nPhrase: {$phrase['phrase']} \nFile: {$phrase['file']} \nLine: {$phrase['line']}";
}
/**
* @param array $phrase
* @return string
*/
protected function _createMissedPhraseError($phrase)
{
return "\nMissed Phrase: File: {$phrase['file']} \nLine: {$phrase['line']}";
}
/**
* @return \RegexIterator
*/
protected function _getFiles()
{
$filesCollector = new FilesCollector();
$componentRegistrar = new ComponentRegistrar();
$paths = array_merge(
$componentRegistrar->getPaths(ComponentRegistrar::MODULE),
$componentRegistrar->getPaths(ComponentRegistrar::LIBRARY)
);
return $filesCollector->getFiles(
$paths,
'/\.(php|phtml)$/'
);
}
}
@@ -0,0 +1,130 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Phrase;
use Magento\Framework\Component\ComponentRegistrar;
/**
* Scan source code for detects invocations of __() function or Phrase object, analyzes placeholders with arguments
* and see if they not equal
*/
class ArgumentsTest extends \Magento\Test\Integrity\Phrase\AbstractTestCase
{
/**
* @var \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector
*/
protected $_phraseCollector;
/**
* List of files that must be omitted
*
* @todo remove blacklist related logic when all files correspond to the standard
* @var array
*/
protected $blackList;
protected function setUp(): void
{
$this->_phraseCollector = new \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector(
new \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer(),
true,
\Magento\Framework\Phrase::class
);
$componentRegistrar = new ComponentRegistrar();
$this->blackList = [
// the file below is the only file where strings are translated without corresponding arguments
$componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Translation')
. '/Model/Js/DataProvider.php',
];
}
public function testArguments()
{
$incorrectNumberOfArgumentsErrors = [];
$missedPhraseErrors = [];
foreach ($this->_getFiles() as $file) {
if (in_array($file, $this->blackList)) {
continue;
}
$this->_phraseCollector->parse($file);
foreach ($this->_phraseCollector->getPhrases() as $phrase) {
$this->checkEmptyPhrases($phrase, $missedPhraseErrors);
$this->checkArgumentMismatch($phrase, $incorrectNumberOfArgumentsErrors);
}
}
$this->assertEmpty(
$missedPhraseErrors,
sprintf(
"\n%d missed phrases were discovered: \n%s",
count($missedPhraseErrors),
implode("\n\n", $missedPhraseErrors)
)
);
$this->assertEmpty(
$incorrectNumberOfArgumentsErrors,
sprintf(
"\n%d usages of inconsistency the number of arguments and placeholders were discovered: \n%s",
count($incorrectNumberOfArgumentsErrors),
implode("\n\n", $incorrectNumberOfArgumentsErrors)
)
);
}
/**
* Will check if phrase is empty
*
* @param $phrase
* @param $missedPhraseErrors
*/
private function checkEmptyPhrases($phrase, &$missedPhraseErrors)
{
if (empty(trim($phrase['phrase'], "'\"\t\n\r\0\x0B"))) {
$missedPhraseErrors[] = $this->_createMissedPhraseError($phrase);
}
}
/**
* Will check if the number of arguments does not match the number of placeholders
*
* @param $phrase
* @param $incorrectNumberOfArgumentsErrors
*/
private function checkArgumentMismatch($phrase, &$incorrectNumberOfArgumentsErrors)
{
if (preg_match_all('/%(\w+)/', $phrase['phrase'], $matches) || $phrase['arguments']) {
$placeholderCount = count(array_unique($matches[1]));
// count all occurrences of sprintf placeholders
preg_match_all('/%\b([sducoxXbgGeEfF])\b/', $phrase['phrase'], $sprintfMatches);
if (count($sprintfMatches[0]) > count(array_unique($sprintfMatches[0]))) {
$placeholderCount = $placeholderCount +
count($sprintfMatches[0]) - count(array_unique($sprintfMatches[0]));
}
// Check for zend placeholders %placeholder% and sprintf placeholders and remove from the count
if (preg_match_all(
'/%\b(([sducoxXbgGeEfF])\b|([A-Za-z]+)%)/',
$phrase['phrase'],
$placeHolders,
PREG_OFFSET_CAPTURE
)) {
foreach ($placeHolders[0] as $ph) {
// Check if char after placeholder is not a digit or letter
$charAfterPh = $phrase['phrase'][$ph[1] + strlen($ph[0])];
if (!preg_match('/[A-Za-z0-9]/', $charAfterPh)) {
$placeholderCount--;
}
}
}
if ($placeholderCount != $phrase['arguments']) {
$incorrectNumberOfArgumentsErrors[] = $this->_createPhraseError($phrase);
}
}
}
}
@@ -0,0 +1,47 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Scan source code for detects invocations of outdated __() method
*/
namespace Magento\Test\Integrity\Phrase\Legacy;
use Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer;
use Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\Translate\MethodCollector;
class SignatureTest extends \Magento\Test\Integrity\Phrase\AbstractTestCase
{
/**
* @var \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\Translate\MethodCollector
*/
protected $_phraseCollector;
protected function setUp(): void
{
$this->_phraseCollector = new MethodCollector(
new Tokenizer()
);
}
public function testSignature()
{
$errors = [];
foreach ($this->_getFiles() as $file) {
$this->_phraseCollector->parse($file);
foreach ($this->_phraseCollector->getPhrases() as $phrase) {
$errors[] = $this->_createPhraseError($phrase);
}
}
$this->assertEmpty(
$errors,
sprintf(
'%d usages of the old translation method call were discovered: %s',
count($errors),
implode("\n\n", $errors)
)
);
}
}
@@ -0,0 +1,303 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity;
use Exception;
use Magento\Framework\App\Utility\Files;
use Magento\Setup\Module\Di\Code\Reader\FileClassScanner;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionMethod;
/**
* Tests @api annotated code integrity
*/
class PublicCodeTest extends TestCase
{
/**
* List of simple return types that are used in docblocks.
* Used to check if type declared in a docblock of a method is a class or interface
*
* @var array
*/
private $simpleReturnTypes = [
'$this', 'void', 'string', 'int', 'bool', 'boolean', 'integer', 'null'
];
/**
* @var string[]|null
*/
private $blockWhitelist;
/**
* Return whitelist class names
*
* @return string[]
*/
private function getWhitelist(): array
{
if ($this->blockWhitelist === null) {
$whiteListFiles = str_replace(
'\\',
'/',
realpath(__DIR__) . '/_files/whitelist/public_code*.txt'
);
$whiteListItems = [];
foreach (glob($whiteListFiles) as $fileName) {
$whiteListItems[] = file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}
$this->blockWhitelist = array_merge([], ...$whiteListItems);
}
return $this->blockWhitelist;
}
/**
* Since blocks can be referenced from templates, they should be stable not to break theme customizations.
* So all blocks should be @api annotated. This test checks that all blocks declared in layout files are public
*
* @param $layoutFile
* @throws \ReflectionException
* @dataProvider layoutFilesDataProvider
*/
public function testAllBlocksReferencedInLayoutArePublic($layoutFile)
{
$nonPublishedBlocks = [];
$xml = simplexml_load_file($layoutFile);
$elements = $xml->xpath('//block | //referenceBlock') ?: [];
/** @var $node \SimpleXMLElement */
foreach ($elements as $node) {
$class = (string) $node['class'];
if ($class && \class_exists($class) && !in_array($class, $this->getWhitelist())) {
$reflection = (new ReflectionClass($class));
if (strpos($reflection->getDocComment(), '@api') === false) {
$nonPublishedBlocks[] = $class;
}
}
}
if (count($nonPublishedBlocks)) {
$this->fail(
"Layout file '$layoutFile' uses following blocks that are not marked with @api annotation:\n"
. implode(",\n", array_unique($nonPublishedBlocks))
);
}
}
/**
* Find all layout update files in magento modules and themes.
*
* @return array
* @throws Exception
*/
public function layoutFilesDataProvider()
{
return Files::init()->getLayoutFiles([], true);
}
/**
* We want to avoid situation when a type is marked public (@api annotated) but one of its methods
* returns or accepts the value of non-public type.
* This test walks through all public PHP types and makes sure that all their method arguments
* and return values are public types.
*
* @param string $class
* @throws \ReflectionException
* @dataProvider publicPHPTypesDataProvider
*/
public function testAllPHPClassesReferencedFromPublicClassesArePublic($class)
{
$nonPublishedClasses = [];
$reflection = new ReflectionClass($class);
$filter = ReflectionMethod::IS_PUBLIC;
if ($reflection->isAbstract()) {
$filter = $filter | ReflectionMethod::IS_PROTECTED;
}
$methods = $reflection->getMethods($filter);
foreach ($methods as $method) {
if ($method->isConstructor()) {
continue;
}
$nonPublishedClasses = $this->checkParameters($class, $method, $nonPublishedClasses);
/* Taking into account docblock return types since this code
is written on early php 7 when return types are not actively used */
$returnTypes = [];
if ($method->hasReturnType()) {
$methodReturnType = $method->getReturnType();
// For PHP 8.0 - ReflectionUnionType doesn't have isBuiltin method.
if (method_exists($methodReturnType, 'isBuiltin')
&& !$methodReturnType->isBuiltin()) {
$returnTypes = [trim($methodReturnType->getName(), '?[]')];
}
} else {
$returnTypes = $this->getReturnTypesFromDocComment($method->getDocComment());
}
$nonPublishedClasses = $this->checkReturnValues($class, $returnTypes, $nonPublishedClasses);
}
if (count($nonPublishedClasses)) {
$this->fail(
"Public type '" . $class . "' references following non-public types:\n"
. implode("\n", array_unique($nonPublishedClasses))
);
}
}
/**
* Retrieve list of all interfaces and classes in Magento codebase that are marked with @api annotation.
*
* @return array
* @throws Exception
*/
public function publicPHPTypesDataProvider(): array
{
$files = Files::init()->getPhpFiles(Files::INCLUDE_LIBS | Files::INCLUDE_APP_CODE);
$result = [];
foreach ($files as $file) {
$fileContents = \file_get_contents($file);
if (strpos($fileContents, '@api') !== false) {
$fileClassScanner = new FileClassScanner($file);
$className = $fileClassScanner->getClassName();
if (!in_array($className, $this->getWhitelist())
&& (class_exists($className) || interface_exists($className))
) {
$result[$className] = [$className];
}
}
}
return $result;
}
/**
* Check if a class is @api annotated
*
* @param ReflectionClass $class
*
* @return bool
*/
private function isPublished(ReflectionClass $class)
{
return strpos($class->getDocComment(), '@api') !== false;
}
/**
* Simplified check of class relation.
*
* @param string $classNameA
* @param string $classNameB
* @return bool
*/
private function areClassesFromSameVendor($classNameA, $classNameB)
{
$classNameA = ltrim($classNameA, '\\');
$classNameB = ltrim($classNameB, '\\');
$aVendor = substr($classNameA, 0, strpos($classNameA, '\\'));
$bVendor = substr($classNameB, 0, strpos($classNameB, '\\'));
return $aVendor === $bVendor;
}
/**
* Check if the class belongs to the list of classes generated by Magento on demand.
*
* We don't need to check @api annotation coverage for generated classes
*
* @param string $className
* @return bool
*/
private function isGenerated($className)
{
return substr($className, -18) === 'ExtensionInterface' || substr($className, -7) === 'Factory';
}
/**
* Retrieves list of method return types from method doc comment
*
* Introduced this method to abstract complexity of coping with types in "return" annotation
*
* @param string $docComment
* @return array
*/
private function getReturnTypesFromDocComment($docComment)
{
// TODO: add docblock namespace resolving using third-party library
if (preg_match('/@return (\S*)/', $docComment, $matches)) {
return array_map(
'trim',
explode('|', $matches[1])
);
} else {
return [];
}
}
/**
* Check method return values
*
* TODO: improve return type filtration
*
* @param string $class
* @param array $returnTypes
* @param array $nonPublishedClasses
* @return mixed
*/
private function checkReturnValues($class, array $returnTypes, array $nonPublishedClasses)
{
foreach ($returnTypes as $returnType) {
if (!in_array($returnType, $this->simpleReturnTypes)
&& !$this->isGenerated($returnType)
&& \class_exists($returnType)
) {
$returnTypeReflection = new ReflectionClass($returnType);
if (!$returnTypeReflection->isInternal()
&& $this->areClassesFromSameVendor($returnType, $class)
&& !$this->isPublished($returnTypeReflection)
) {
$nonPublishedClasses[$returnType] = $returnType;
}
}
}
return $nonPublishedClasses;
}
/**
* Check if all method parameters are public
*
* @param string $class
* @param ReflectionMethod $method
* @param array $nonPublishedClasses
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function checkParameters($class, ReflectionMethod $method, array $nonPublishedClasses)
{
/* Ignoring docblocks for argument types */
foreach ($method->getParameters() as $parameter) {
$parameterType = $parameter->getType();
if ($parameterType
&& method_exists($parameterType, 'isBuiltin')
&& !$parameterType->isBuiltin()
&& !$this->isGenerated($parameterType->getName())
) {
$parameterClass = new ReflectionClass($parameterType->getName());
/*
* We don't want to check integrity of @api coverage of classes
* that belong to different vendors, because it is too complicated.
* Example:
* If Magento class references non-@api annotated class from Zend,
* we don't want to fail test, because Zend is considered public by default,
* and we don't care if Zend classes are @api-annotated
*/
if ($parameterClass && !$parameterClass->isInternal()
&& $this->areClassesFromSameVendor($parameterClass->getName(), $class)
&& !$this->isPublished($parameterClass)
) {
$nonPublishedClasses[$parameterClass->getName()] = $parameterClass->getName();
}
}
}
return $nonPublishedClasses;
}
}
@@ -0,0 +1,93 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Test to ensure that readme file present in specified directories
*/
namespace Magento\Test\Integrity\Readme;
use Magento\Framework\App\Utility\Files;
class ReadmeTest extends \PHPUnit\Framework\TestCase
{
const README_FILENAME = 'README.md';
const BLACKLIST_FILES_PATTERN = '_files/blacklist/*.txt';
const SCAN_LIST_FILE = '_files/scan_list.txt';
/** @var array Blacklisted files and directories */
private $blacklist = [];
/** @var array */
private $scanList = [];
protected function setUp(): void
{
$this->blacklist = $this->getPaths(__DIR__ . '/' . self::BLACKLIST_FILES_PATTERN);
$this->scanList = $this->getPaths(__DIR__ . '/' . self::SCAN_LIST_FILE);
}
public function testReadmeFiles()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $dir
*/
function ($dir) {
$file = $dir . DIRECTORY_SEPARATOR . self::README_FILENAME;
$this->assertFileExists(
$file,
sprintf('File %s not found in %s', self::README_FILENAME, $dir)
);
},
$this->getDirectories()
);
}
/**
* @return array
*/
private function getDirectories()
{
$directories = [];
foreach ($this->scanList as $dir) {
if (!$this->isInBlacklist($dir)) {
$directories[][] = $dir;
}
}
return $directories;
}
/**
* @param $path
* @return bool
*/
private function isInBlacklist($path)
{
return in_array($path, $this->blacklist);
}
/**
* Get paths basing on the file with patterns
*
* @param string $patternsFile
* @return array
*/
private function getPaths($patternsFile)
{
$result = [];
$files = Files::init()->readLists($patternsFile);
foreach ($files as $file) {
if (is_dir($file)) {
$result[] = rtrim($file, '/');
}
}
return $result;
}
}
@@ -0,0 +1,36 @@
module Magento_CatalogImportExport /
module Magento_CatalogUrlRewrite /
module Magento_CmsUrlRewrite /
module Magento_ConfigurableImportExport /
module Magento_GroupedImportExport /
module Magento_Msrp /
module Magento_TaxImportExport /
module Magento_Translation /
library magento/framework Acl
library magento/framework Api
library magento/framework Authorization
library magento/framework Cache
library magento/framework Config
library magento/framework DB
library magento/framework DomDocument
library magento/framework Filter
library magento/framework HTTP
library magento/framework Interception
library magento/framework Json
library magento/framework Mail
library magento/framework Mview
library magento/framework Notification
library magento/framework Oauth
library magento/framework Parse
library magento/framework Pricing
library magento/framework Reflection
library magento/framework RequireJs
library magento/framework Search
library magento/framework Simplexml
library magento/framework System
library magento/framework Test
library magento/framework App/Utility
library magento/framework Url
library magento/framework Xml
library magento/framework XsltProcessor
library magento/framework /
@@ -0,0 +1,3 @@
module * /
library * /
library magento/framework */
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Test to ensure that readme file present in specified directories
*/
namespace Magento\Test\Integrity;
use Magento\Framework\App\Utility\Files;
use \Magento\Framework\App\Bootstrap;
class TestPlacementTest extends \PHPUnit\Framework\TestCase
{
/** @var array */
private $scanList = ['dev/tests/unit/testsuite/Magento'];
/**
* @var string Path to project root
*/
private $root;
protected function setUp(): void
{
$this->root = BP;
}
public function testUnitTestFilesPlacement()
{
$objectManager = Bootstrap::create(BP, $_SERVER)->getObjectManager();
/** @var \Magento\Framework\Data\Collection\Filesystem $filesystem */
$filesystem = $objectManager->get(\Magento\Framework\Data\Collection\Filesystem::class);
$filesystem->setCollectDirs(false)
->setCollectFiles(true)
->setCollectRecursively(true);
$targetsExist = false;
foreach ($this->scanList as $dir) {
if (realpath($this->root . DIRECTORY_SEPARATOR . $dir)) {
$filesystem->addTargetDir($this->root . DIRECTORY_SEPARATOR . $dir);
$targetsExist = true;
}
}
if ($targetsExist) {
$files = $filesystem->load()->toArray();
$fileList = [];
foreach ($files['items'] as $file) {
$fileList[] = $file['filename'];
}
$this->assertEquals(
0,
$files['totalRecords'],
"The following files have been found in obsolete test directories: \n"
. implode("\n", $fileList)
);
}
}
}
@@ -0,0 +1,131 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Integrity\Xml;
use Magento\Framework\Component\ComponentRegistrar;
class SchemaTest extends \PHPUnit\Framework\TestCase
{
public function testXmlFiles()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
/**
* @param string $filename
*/
function ($filename) {
$dom = new \DOMDocument();
$xmlFile = file_get_contents($filename);
$dom->loadXML($xmlFile);
$errors = libxml_get_errors();
libxml_clear_errors();
$this->assertEmpty($errors, print_r($errors, true));
$schemaLocations = [];
preg_match('/xsi:noNamespaceSchemaLocation=\s*"(urn:[^"]+)"/s', $xmlFile, $schemaLocations);
$this->assertCount(
2,
$schemaLocations,
'The XML file at ' . $filename . ' does not have a schema properly defined. It should '
. 'have a xsi:noNamespaceSchemaLocation attribute defined with a URN path. E.g. '
. 'xsi:noNamespaceSchemaLocation="urn:magento:framework:Relative_Path/something.xsd"'
);
try {
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schemaLocations[1]);
} catch (\Exception $exception) {
$errors = [$exception->getMessage()];
}
$this->assertEmpty(
$errors,
"Error validating $filename against {$schemaLocations[1]}\n" . print_r($errors, true)
);
},
$this->getXmlFiles()
);
}
public function getSchemas()
{
$componentRegistrar = new ComponentRegistrar();
$codeSchemas = [];
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $modulePath) {
$codeSchemas = array_merge($codeSchemas, $this->_getFiles($modulePath, '*.xsd'));
}
$libSchemas = [];
foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $libraryPath) {
$libSchemas = array_merge($libSchemas, $this->_getFiles($libraryPath, '*.xsd'));
}
return $this->_dataSet(array_merge($codeSchemas, $libSchemas));
}
public function getXmlFiles()
{
$componentRegistrar = new ComponentRegistrar();
$codeXml = [];
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $modulePath) {
$codeXml = array_merge($codeXml, $this->_getFiles($modulePath, '*.xml', '/.\/Test\/./'));
}
$this->_filterSpecialCases($codeXml);
$designXml = [];
foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $themePath) {
$designXml = array_merge($designXml, $this->_getFiles($themePath, '*.xml'));
}
$libXml = [];
foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $libraryPath) {
$libXml = array_merge($libXml, $this->_getFiles($libraryPath, '*.xml', '/.\/Test\/./'));
}
return $this->_dataSet(array_merge($codeXml, $designXml, $libXml));
}
protected function _getFiles($dir, $pattern, $skipDirPattern = '')
{
$files = glob($dir . '/' . $pattern, GLOB_NOSORT);
if (empty($skipDirPattern) || !preg_match($skipDirPattern, $dir)) {
foreach (glob($dir . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $newDir) {
$files = array_merge($files, $this->_getFiles($newDir, $pattern, $skipDirPattern));
}
}
return $files;
}
/**
* Files that are exempt from validation
*
* @param array &$files
*/
private function _filterSpecialCases(&$files)
{
$list = [
'#etc/countries.xml$#',
'#conf/schema.xml$#',
'#layout/swagger_index_index.xml$#',
'#Doc/etc/doc/vars.xml$#',
'#phpunit.xml$#',
'#etc/db_schema.xml$#',
'#Test/Mftf#',
];
foreach ($list as $pattern) {
foreach ($files as $key => $value) {
if (preg_match($pattern, $value)) {
unset($files[$key]);
}
}
}
}
protected function _dataSet($files)
{
$data = [];
foreach ($files as $file) {
$data[substr($file, strlen(BP))] = [$file];
}
return $data;
}
}
@@ -0,0 +1 @@
magento/module-aws-s3
@@ -0,0 +1,13 @@
\Magento\Framework\Exception\LocalizedException
\Magento\Framework\View\Asset\File\NotFoundException
\Magento\Framework\Config\Dom\ValidationException
\Magento\Framework\Search\Request\EmptyRequestDataException
\Magento\Framework\Search\Request\NonExistingRequestNameException
\Magento\Framework\DB\Adapter\ConnectionException
\Magento\Framework\DB\Adapter\DeadlockException
\Magento\Framework\DB\Adapter\LockWaitException
\Magento\Framework\DB\Adapter\DuplicateException
\Magento\Framework\DB\DataConverter\DataConversionException
\Magento\Framework\DB\FieldDataConversionException
\Magento\Catalog\Model\Product\Image\NotLoadInfoImageException
\Magento\Framework\MessageQueue\ConnectionLostException
@@ -0,0 +1,10 @@
<?php
/**
* Black list for the @see \Magento\Test\Integrity\DependencyTest::testExternalDependencies()
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
return [
'app/code/Magento/Paypal/Model/AbstractConfig.php' => ['Magento\Cart'],
];
@@ -0,0 +1,16 @@
SalesOrderIndexGridAsyncInsertObserver
SalesInvoiceIndexGridAsyncInsertObserver
SalesShipmentIndexGridAsyncInsertObserver
SalesCreditmemoIndexGridAsyncInsertObserver
SalesOrderIndexGridSyncInsert
SalesInvoiceIndexGridSyncInsert
SalesShipmentIndexGridSyncInsert
SalesCreditmemoIndexGridSyncInsert
SalesOrderIndexGridSyncRemove
SalesInvoiceIndexGridSyncRemove
SalesShipmentIndexGridSyncRemove
SalesCreditmemoIndexGridSyncRemove
SalesOrderSendEmailsObserver
SalesOrderInvoiceSendEmailsObserver
SalesOrderShipmentSendEmailsObserver
SalesOrderCreditmemoSendEmailsObserver
@@ -0,0 +1,127 @@
PEAR_PackageFile
Simple_Xml
PersistentCustomerSegmentation
RegionUpdater
Fixture_Module
TheCompoundNamespace_TheCompoundModule
Some_Module
Not_Existed_Class
CustomSelect
\Magento\SomeModule\Model\Element\Proxy
Map_Module
Module_One
Module_Two
Module_Name
Test
Local_Module
\Magento\Webapi\Controller\Soap\Security
Mage
Pear_Package_Parser_v2
PEAR_Config
PEAR_DependencyDB
PEAR_Frontend
PEAR_Command
Zend
PEAR_PackageFileManager2
PEAR
Magento\LibFirst
\Magento\SomeModule\Exception
TestSuite
DbTest
Model1
Model3
\Magento\TestModuleExtensionAttributes\Api\Data\FakeRegionInterface
\Magento\TestModuleExtensionAttributes\Api\Data\FakeAddressInterface
\Magento\TestModuleExtensionAttributes\Api\Data\FakeExtensibleOneInterface
\Magento\TestModuleExtensionAttributes\Api\Data\FakeExtensibleTwoInterface
\Magento\TestModuleExtensionAttributes\Api\Data\FakeAttributeMetadataInterface
\Magento\TestModuleExtensionAttributes\Api\Data\FakeCustomerInterface
\Magento\TestModuleExtensionAttributes\Model\Data\FakeRegion
\Magento\TestModuleExtensionAttributes\Model\Data\FakeAddress
\Magento\TestModuleExtensionAttributes\Model\Data\FakeAttributeMetadata
\Magento\TestModuleExtensionAttributes\Model\Data\FakeCustomer
\Magento\TestModuleExtensionAttributes\Model\Data\FakeExtensibleOne
\Magento\TestModuleExtensionAttributes\Model\Data\FakeExtensibleTwo
\Magento\Framework\Error\Processor
\Magento\TestModule3\Service\V1\Entity\Parameter
\Magento\TestModule3\Service\V1\Entity\ParameterBuilder
\Magento\TestModuleMSC\Api\Data\ItemInterface
\Magento\TestModuleGraphQlQuery\Api\Data\ItemInterface
\Magento\TestModule5\Service\V1\Entity\AllSoapAndRest
\Magento\TestModule5\Service\V2\Entity\AllSoapAndRest
\Magento\TestModule5\Service\V2\Entity\AllSoapAndRestBuilder
\Magento\TestModule1\Service\V1\Entity\Item
\Magento\TestModule1\Service\V1\Entity\ItemBuilder
\Magento\TestModule1\Service\V2\Entity\Item
\Magento\TestModule1\Service\V2\Entity\ItemBuilder
\Magento\TestModule2\Service\V1\Entity\Item
\Magento\TestModule2\Service\V1\Entity\ItemBuilder
\Magento\TestModule4\Service\V1\Entity\DataObjectResponse
\Magento\TestModule4\Service\V1\Entity\DataObjectRequest
\Magento\Mtf\ObjectManager
\Magento\Mtf\ObjectManager\Config\Mapper\Dom
\Magento\Mtf\Data\Argument\Interpreter\Constant
\Magento\Mtf\Data\Argument\Interpreter\Boolean
\Magento\Mtf\Data\Argument\Interpreter\StringType
\Magento\Mtf\Data\Argument\Interpreter\Number
\Magento\Mtf\Data\Argument\Interpreter\NullType
\Magento\Mtf\Data\Argument\Interpreter\ObjectType
\Magento\Mtf\Data\Argument\Interpreter\Argument
\Magento\Mtf\Data\Argument\Interpreter\ArrayType
\Magento\Mtf\Data\Argument\InterpreterInterface
\Magento\Mtf\Util\Generate\GenerateResult
\Magento\Mtf\Util\Generate\Repository\RepositoryResource
\Magento\Mtf\Client\Element
\Magento\Mtf\TestSuite\AppState
\Magento\Framework\A
\Magento\Framework\B
\Magento\Test\Di\Child
\Magento\Test\Di\DiInterface
\Magento\Test\Di\DiParent
\Magento\Test\Di\Aggregate\AggregateParent
\Magento\Test\Di\Child\A
\Magento\Test\Di\Aggregate\WithOptional
\Magento\Test\Di\Aggregate\Child
\Magento\Framework\App\Cache\TagPlugin
\Magento\Store\Model\Action\Plugin
DoubleColon
\Magento\Framework\App\Config\Data\TestBackendModel
\Magento\Framework\App\Config\Data\WrongBackendModel
\Magento\ModuleName\Model\ClassName
\Magento\Mtf\Config\DataInterface
\Magento\Sales\Test\TestStep
\Magento\Mtf\Config\TestRunner
\Magento\Composer\InfoCommand
\Magento\Composer\MagentoComposerApplication
\Magento\Composer\RequireUpdateDryRunCommand
\Magento\SomeModule\Model\One\Test
\Magento\SomeModule\Model\Two\Test
\Magento\SomeModule\Model\Three\Test
\Magento\SomeModule\Model\Four\Test
\Magento\SomeModule\Model\Five\Test
\Magento\SomeModule\Model\Six\Test
\Magento\Framework\DataObject_MyResult
\Magento\Framework\ObjectManager\Code\Generator\Sample\Repository
\Magento\Framework\ObjectManager\Code\Generator\SampleConverter
\Magento\Observer
\Magento\Framework\MessageQueue\Model\TestConsumer
\Magento\Framework\MessageQueue\Code\Generator\TInterface
\Magento\Framework\MessageQueue\Code\Generator\TSearchResultsInterface
\Magento\Catalog\Api\Data\Product
\Magento\Framework\ObjectManager\Code\Generator\Sample
\Magento\Framework\ObjectManager\Code\Generator\Sample
\Magento\Config\Block\Tooltip
\Magento\Framework\Model\Name
\Magento\Test\Di\WrappedClass
\Magento\Test\Di\WrappedClass\Logger
\Magento\TestModuleMessageQueueConfiguration\AsyncHandler
\Magento\TestModuleMessageQueueConfiguration\SyncHandler
\Magento\TestModuleAsyncAmqp\Model\AsyncTestData
\Magento\Mtf\Client\ElementInterface
BarFactory
PartialNamespace\BarFactory
Product\OptionFactory
Magento_Module
Magento_Framework
Magento_TestModule
Magento_Test
@@ -0,0 +1,13 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
* Black list for the @see \Magento\Test\Integrity\DependencyTest::testUndeclared()
*/
return [
'app/code/Magento/Paypal/Model/AbstractConfig.php' => ['Magento\Cart'],
'app/code/Magento/Customer/Controller/Adminhtml/Index/Cart.php' => ['Magento\Cart'],
'app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart.php' => ['Magento\Cart'],
'app/code/Magento/Customer/Controller/Adminhtml/Index/Carts.php' => ['Magento\Cart'],
];
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
return [
'Magento\Checkout' => [
'Magento\Security' => 'Magento\Security'
]
];
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
return [
'Magento\GraphQl' => [
'Magento\Webapi' => 'Magento\Webapi'
]
];
@@ -0,0 +1,10 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
return [
'privacy-policy-cookie-restriction-mode/index/index',
];
@@ -0,0 +1,13 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
return [
'Magento\Elasticsearch' => [
'Magento\Elasticsearch7',
'Magento\OpenSearch'
]
];
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
return [
// the following modules must be disabled when Live Search is used
// so core modules must not be dependent on them
'Magento\LiveSearch' => [
'Magento\Elasticsearch',
'Magento\Elasticsearch7',
'Magento\Elasticsearch8',
'Magento\OpenSearch'
],
];
@@ -0,0 +1 @@
Magento\LoginAsCustomerAssistance\Block\Adminhtml\NotAllowedPopup
@@ -0,0 +1,25 @@
app/code/Magento/Customer/view/frontend/web/js/zxcvbn.js
app/code/Magento/Swagger/view/frontend/web/swagger-ui/js/swagger-ui-bundle.min.js
app/code/Magento/Swagger/view/frontend/web/swagger-ui/js/swagger-ui-standalone-preset.js
app/code/Magento/Catalog/view/adminhtml/web/catalog/product/composite/configure.js
app/code/Magento/Rule/view/adminhtml/web/rules.js
app/code/Magento/Sales/view/adminhtml/web/order/create/giftmessage.js
app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js
app/code/Magento/Shipping/view/adminhtml/web/order/packaging.js
app/code/Magento/Swagger/view/frontend/web/swagger-ui/js/magento-swagger.js
app/code/Magento/AdminAdobeIms/view/adminhtml/web/js/loadicons.js
lib/web/mage/adminhtml/tools.js
lib/web/mage/adminhtml/varienLoader.js
lib/web/magnifier/magnifier.js
lib/web/magnifier/magnify.js
lib/web/varien/js.js
lib/web/prototype/**/*.js
// MINIFIED FILES
app/code/**/*.min.js
lib/web/legacy-build.min.js
lib/web/tiny_mce_6/**/*.js
lib/web/tiny_mce_6/***/*.js
// TEST
vendor/magento/magento-coding-standard/Magento2/Tests/Eslint/*

Some files were not shown because too many files have changed in this diff Show More