init
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
/**
|
||||
* AbstractMergedConfigTest can be used to test merging of config files
|
||||
*/
|
||||
abstract class AbstractMergedConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* attributes represent merging rules
|
||||
* copied from original namespace Magento\Framework\App\Route\Config;
|
||||
*
|
||||
* class Reader
|
||||
*
|
||||
* @returns array
|
||||
*/
|
||||
abstract protected function getIdAttributes();
|
||||
|
||||
/**
|
||||
* Path to tough XSD for merged file validation
|
||||
*
|
||||
* @returns string
|
||||
*/
|
||||
abstract protected function getMergedSchemaFile();
|
||||
|
||||
/**
|
||||
* Returns an array of config files to test
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getConfigFiles();
|
||||
|
||||
public function testMergedConfigFiles()
|
||||
{
|
||||
$invalidFiles = [];
|
||||
|
||||
$files = $this->getConfigFiles();
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(false);
|
||||
$mergedConfig = new \Magento\Framework\Config\Dom(
|
||||
'<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></config>',
|
||||
$validationStateMock,
|
||||
$this->getIdAttributes()
|
||||
);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$content = file_get_contents($file[0]);
|
||||
try {
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
new \Magento\Framework\Config\Dom($content, $validationStateMock, $this->getIdAttributes());
|
||||
//merge won't be performed if file is invalid because of exception thrown
|
||||
$mergedConfig->merge($content);
|
||||
} catch (\Magento\Framework\Config\Dom\ValidationException $e) {
|
||||
$invalidFiles[] = $file[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($invalidFiles)) {
|
||||
$this->fail('Found broken files: ' . implode("\n", $invalidFiles));
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
$mergedConfig->validate($this->getMergedSchemaFile(), $errors);
|
||||
if ($errors) {
|
||||
$this->fail('Merged routes config is invalid: ' . "\n" . implode("\n", $errors));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
class AclConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Configuration acl file list
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_fileList = [];
|
||||
|
||||
/**
|
||||
* Path to scheme file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_schemeFile;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
|
||||
$this->_schemeFile = $urnResolver->getRealPath('urn:magento:framework:Acl/etc/acl.xsd');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test each acl configuration file
|
||||
* @param string $file
|
||||
* @dataProvider aclConfigFileDataProvider
|
||||
*/
|
||||
public function testAclConfigFile($file)
|
||||
{
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$domConfig = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock);
|
||||
$result = $domConfig->validate($this->_schemeFile, $errors);
|
||||
$message = "Invalid XML-file: {$file}\n";
|
||||
foreach ($errors as $error) {
|
||||
$message .= "{$error}\n";
|
||||
}
|
||||
$this->assertTrue($result, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function aclConfigFileDataProvider()
|
||||
{
|
||||
return \Magento\Framework\App\Utility\Files::init()->getConfigFiles('acl.xml');
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Customer\Model\Context;
|
||||
|
||||
/**
|
||||
* This test ensures that all blocks have the appropriate constructor arguments that allow
|
||||
* them to be instantiated via the objectManager.
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class BlockInstantiationTest extends \Magento\TestFramework\TestCase\AbstractIntegrity
|
||||
{
|
||||
public function testBlockInstantiation()
|
||||
{
|
||||
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
|
||||
$invoker(
|
||||
function ($module, $class, $area) {
|
||||
$this->assertNotEmpty($module);
|
||||
$this->assertTrue(class_exists($class), "Block class: {$class}");
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\Config\ScopeInterface::class
|
||||
)->setCurrentScope(
|
||||
$area
|
||||
);
|
||||
$context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Http\Context::class
|
||||
);
|
||||
$context->setValue(Context::CONTEXT_AUTH, false, false);
|
||||
$context->setValue(
|
||||
Context::CONTEXT_GROUP,
|
||||
\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID,
|
||||
\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID
|
||||
);
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea($area);
|
||||
|
||||
try {
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create($class);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("Unable to instantiate '{$class}'", 0, $e);
|
||||
}
|
||||
},
|
||||
$this->allBlocksDataProvider()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function allBlocksDataProvider()
|
||||
{
|
||||
$blockClass = '';
|
||||
try {
|
||||
/** @var $website \Magento\Store\Model\Website */
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->setWebsiteId(
|
||||
0
|
||||
);
|
||||
|
||||
$enabledModules = $this->_getEnabledModules();
|
||||
$skipBlocks = $this->_getBlocksToSkip();
|
||||
$templateBlocks = [];
|
||||
$blockMods = \Magento\Framework\App\Utility\Classes::collectModuleClasses('Block');
|
||||
foreach ($blockMods as $blockClass => $module) {
|
||||
if (!isset($enabledModules[$module]) || isset($skipBlocks[$blockClass])) {
|
||||
continue;
|
||||
}
|
||||
$class = new \ReflectionClass($blockClass);
|
||||
if ($class->isAbstract() || !$class->isSubclassOf(\Magento\Framework\View\Element\Template::class)) {
|
||||
continue;
|
||||
}
|
||||
$templateBlocks = $this->_addBlock($module, $blockClass, $class, $templateBlocks);
|
||||
}
|
||||
asort($templateBlocks);
|
||||
return $templateBlocks;
|
||||
} catch (\Exception $e) {
|
||||
trigger_error(
|
||||
"Corrupted data provider. Last known block instantiation attempt: '{$blockClass}'." .
|
||||
" Exception: {$e}",
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads block classes, that should not be instantiated during the instantiation test
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _getBlocksToSkip()
|
||||
{
|
||||
$result = [];
|
||||
foreach (glob(__DIR__ . '/_files/skip_blocks*.php') as $file) {
|
||||
$blocks = include $file;
|
||||
$result = array_merge($result, $blocks);
|
||||
}
|
||||
return array_combine($result, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $module
|
||||
* @param $blockClass
|
||||
* @param $class
|
||||
* @param $templateBlocks
|
||||
* @return mixed
|
||||
*/
|
||||
private function _addBlock($module, $blockClass, $class, $templateBlocks)
|
||||
{
|
||||
$area = 'frontend';
|
||||
if ($module == 'Magento_Backend' || strpos(
|
||||
$blockClass,
|
||||
'\\Adminhtml\\'
|
||||
) !== false || strpos(
|
||||
$blockClass,
|
||||
'_Backend_'
|
||||
) !== false || $class->isSubclassOf(
|
||||
\Magento\Backend\Block\Template::class
|
||||
)
|
||||
) {
|
||||
$area = 'adminhtml';
|
||||
}
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\AreaList::class
|
||||
)->getArea(
|
||||
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
|
||||
)->load(
|
||||
\Magento\Framework\App\Area::PART_CONFIG
|
||||
);
|
||||
$templateBlocks[$module . ', ' . $blockClass . ', ' . $area] = [$module, $blockClass, $area];
|
||||
return $templateBlocks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
class CacheFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $area
|
||||
* @dataProvider cacheConfigDataProvider
|
||||
*/
|
||||
public function testCacheConfig($area)
|
||||
{
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->expects($this->any())->method('isValidationRequired')->willReturn(true);
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Framework\Cache\Config\Reader $reader */
|
||||
$reader = $objectManager->create(
|
||||
\Magento\Framework\Cache\Config\Reader::class,
|
||||
['validationState' => $validationStateMock]
|
||||
);
|
||||
try {
|
||||
$reader->read($area);
|
||||
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
|
||||
$this->fail($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function cacheConfigDataProvider()
|
||||
{
|
||||
return ['global' => ['global'], 'adminhtml' => ['adminhtml'], 'frontend' => ['frontend']];
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Test configuration of Online Shipping carriers
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Module\Dir;
|
||||
|
||||
class CarrierConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Config\Model\Config\Structure\Reader
|
||||
*/
|
||||
protected $_reader;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
|
||||
$schemaFile = $urnResolver->getRealPath('urn:magento:module:Magento_Config:etc/system.xsd');
|
||||
$this->_reader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Config\Model\Config\Structure\Reader::class,
|
||||
['perFileSchema' => $schemaFile, 'isValidated' => true]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that all source_models used in shipping are valid
|
||||
*/
|
||||
public function testValidateShippingSourceModels()
|
||||
{
|
||||
$config = $this->_reader->read('adminhtml');
|
||||
|
||||
$carriers = $config['config']['system']['sections']['carriers']['children'];
|
||||
foreach ($carriers as $carrier) {
|
||||
foreach ($carrier['children'] as $field) {
|
||||
if (isset($field['source_model'])) {
|
||||
$model = $field['source_model'];
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create($model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
class CrontabConfigFilesTest extends AbstractMergedConfigTest
|
||||
{
|
||||
/**
|
||||
* attributes represent merging rules
|
||||
* copied from original class \Magento\Framework\App\Route\Config\Reader
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected function getIdAttributes()
|
||||
{
|
||||
return ['/config/group' => 'id', '/config/group/job' => 'name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Path to tough XSD for merged file validation
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected function getMergedSchemaFile()
|
||||
{
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
return $objectManager->get(\Magento\Cron\Model\Config\SchemaLocator::class)->getSchema();
|
||||
}
|
||||
|
||||
protected function getConfigFiles()
|
||||
{
|
||||
return \Magento\Framework\App\Utility\Files::init()->getConfigFiles('crontab.xml');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class DiConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Primary DI configs from app/etc
|
||||
* @var array
|
||||
*/
|
||||
protected static $_primaryFiles = [];
|
||||
|
||||
/**
|
||||
* Global DI configs from all modules
|
||||
* @var array
|
||||
*/
|
||||
protected static $_moduleGlobalFiles = [];
|
||||
|
||||
/**
|
||||
* Area DI configs from all modules
|
||||
* @var array
|
||||
*/
|
||||
protected static $_moduleAreaFiles = [];
|
||||
|
||||
protected function _prepareFiles()
|
||||
{
|
||||
//init primary configs
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $filesystem \Magento\Framework\Filesystem */
|
||||
$filesystem = $objectManager->get(\Magento\Framework\Filesystem::class);
|
||||
$configDirectory = $filesystem->getDirectoryRead(DirectoryList::CONFIG);
|
||||
$fileIteratorFactory = $objectManager->get(\Magento\Framework\Config\FileIteratorFactory::class);
|
||||
$search = [];
|
||||
foreach ($configDirectory->search('{*/di.xml,di.xml}') as $path) {
|
||||
$search[] = $configDirectory->getAbsolutePath($path);
|
||||
}
|
||||
self::$_primaryFiles = $fileIteratorFactory->create($search);
|
||||
//init module global configs
|
||||
/** @var $modulesReader \Magento\Framework\Module\Dir\Reader */
|
||||
$modulesReader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\Module\Dir\Reader::class);
|
||||
self::$_moduleGlobalFiles = $modulesReader->getConfigurationFiles('di.xml');
|
||||
|
||||
//init module area configs
|
||||
$areas = ['adminhtml', 'frontend'];
|
||||
foreach ($areas as $area) {
|
||||
$moduleAreaFiles = $modulesReader->getConfigurationFiles($area . '/di.xml');
|
||||
self::$_moduleAreaFiles[$area] = $moduleAreaFiles;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath
|
||||
* @param string $xml
|
||||
* @throws \Exception
|
||||
* @dataProvider linearFilesProvider
|
||||
*/
|
||||
public function testDiConfigFileWithoutMerging($filePath, $xml)
|
||||
{
|
||||
/** @var \Magento\Framework\ObjectManager\Config\SchemaLocator $schemaLocator */
|
||||
$schemaLocator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\ObjectManager\Config\SchemaLocator::class
|
||||
);
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
$dom->loadXML($xml);
|
||||
|
||||
libxml_use_internal_errors(true);
|
||||
$result = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schemaLocator->getSchema());
|
||||
libxml_use_internal_errors(false);
|
||||
|
||||
if (!empty($result)) {
|
||||
$this->fail(
|
||||
'File ' . $filePath . ' has invalid xml structure. '
|
||||
. implode("\n", $result)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function linearFilesProvider()
|
||||
{
|
||||
if (empty(self::$_primaryFiles)) {
|
||||
$this->_prepareFiles();
|
||||
}
|
||||
|
||||
$common = array_merge(self::$_primaryFiles->toArray(), self::$_moduleGlobalFiles->toArray());
|
||||
|
||||
foreach (self::$_moduleAreaFiles as $files) {
|
||||
$common = array_merge($common, $files->toArray());
|
||||
}
|
||||
|
||||
$output = [];
|
||||
foreach ($common as $path => $content) {
|
||||
$output[] = [substr($path, strlen(BP)), $content];
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $files
|
||||
* @dataProvider mixedFilesProvider
|
||||
*/
|
||||
public function testMergedDiConfig(array $files)
|
||||
{
|
||||
$mapperMock = $this->createMock(\Magento\Framework\ObjectManager\Config\Mapper\Dom::class);
|
||||
$fileResolverMock = $this->getMockBuilder(\Magento\Framework\Config\FileResolverInterface::class)
|
||||
->setMethods(['read'])
|
||||
->getMockForAbstractClass();
|
||||
$fileResolverMock->expects($this->any())->method('read')->willReturn($files);
|
||||
$validationStateMock = $this->createPartialMock(
|
||||
\Magento\Framework\Config\ValidationStateInterface::class,
|
||||
['isValidationRequired']
|
||||
);
|
||||
$validationStateMock->expects($this->any())->method('isValidationRequired')->willReturn(true);
|
||||
|
||||
/** @var \Magento\Framework\ObjectManager\Config\SchemaLocator $schemaLocator */
|
||||
$schemaLocator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\ObjectManager\Config\SchemaLocator::class
|
||||
);
|
||||
|
||||
new \Magento\Framework\ObjectManager\Config\Reader\Dom(
|
||||
$fileResolverMock,
|
||||
$mapperMock,
|
||||
$schemaLocator,
|
||||
$validationStateMock
|
||||
);
|
||||
}
|
||||
|
||||
public function mixedFilesProvider()
|
||||
{
|
||||
if (empty(self::$_primaryFiles)) {
|
||||
$this->_prepareFiles();
|
||||
}
|
||||
foreach (self::$_primaryFiles->toArray() as $file) {
|
||||
$primaryFiles[] = [[$file]];
|
||||
}
|
||||
$primaryFiles['all primary config files'] = [self::$_primaryFiles->toArray()];
|
||||
|
||||
foreach (self::$_moduleGlobalFiles->toArray() as $file) {
|
||||
$moduleFiles[] = [[$file]];
|
||||
}
|
||||
$moduleFiles['all module global config files'] = [self::$_moduleGlobalFiles->toArray()];
|
||||
|
||||
$areaFiles = [];
|
||||
foreach (self::$_moduleAreaFiles as $area => $files) {
|
||||
foreach ($files->toArray() as $file) {
|
||||
$areaFiles[] = [[$file]];
|
||||
}
|
||||
$areaFiles["all {$area} config files"] = [self::$_moduleAreaFiles[$area]->toArray()];
|
||||
}
|
||||
|
||||
return $primaryFiles + $moduleFiles + $areaFiles;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class EavAttributesConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Eav\Model\Entity\Attribute\Config\Reader
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $moduleDirSearch \Magento\Framework\Component\DirSearch */
|
||||
$moduleDirSearch = $objectManager->get(\Magento\Framework\Component\DirSearch::class);
|
||||
$fileIteratorFactory = $objectManager->get(\Magento\Framework\Config\FileIteratorFactory::class);
|
||||
$xmlFiles = $fileIteratorFactory->create(
|
||||
$moduleDirSearch->collectFiles(ComponentRegistrar::MODULE, 'etc/{*/eav_attributes.xml,eav_attributes.xml}')
|
||||
);
|
||||
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->expects($this->any())->method('isValidationRequired')->willReturn(true);
|
||||
$fileResolverMock = $this->createMock(\Magento\Framework\Config\FileResolverInterface::class);
|
||||
$fileResolverMock->expects($this->any())->method('get')->willReturn($xmlFiles);
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->_model = $objectManager->create(
|
||||
\Magento\Eav\Model\Entity\Attribute\Config\Reader::class,
|
||||
['fileResolver' => $fileResolverMock, 'validationState' => $validationStateMock]
|
||||
);
|
||||
}
|
||||
|
||||
public function testImportXmlFiles()
|
||||
{
|
||||
$this->_model->read('global');
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
class EventConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_schemaFile;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_schemaFile = $objectManager->get(\Magento\Framework\Event\Config\SchemaLocator::class)->getSchema();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
* @dataProvider eventConfigFilesDataProvider
|
||||
*/
|
||||
public function testEventConfigFiles($file)
|
||||
{
|
||||
$errors = [];
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$dom = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock);
|
||||
$result = $dom->validate($this->_schemaFile, $errors);
|
||||
$message = "Invalid XML-file: {$file}\n";
|
||||
foreach ($errors as $error) {
|
||||
$message .= "{$error->message} Line: {$error->line}\n";
|
||||
}
|
||||
$this->assertTrue($result, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function eventConfigFilesDataProvider()
|
||||
{
|
||||
return \Magento\Framework\App\Utility\Files::init()->getConfigFiles('{*/events.xml,events.xml}');
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class ExportConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\ImportExport\Model\Export\Config\Reader
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $moduleDirSearch \Magento\Framework\Component\DirSearch */
|
||||
$moduleDirSearch = $objectManager->get(\Magento\Framework\Component\DirSearch::class);
|
||||
$fileIteratorFactory = $objectManager->get(\Magento\Framework\Config\FileIteratorFactory::class);
|
||||
$xmlFiles = $fileIteratorFactory->create(
|
||||
$moduleDirSearch->collectFiles(ComponentRegistrar::MODULE, 'etc/{*/export.xml,export.xml}')
|
||||
);
|
||||
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->expects($this->any())->method('isValidationRequired')->willReturn(true);
|
||||
$fileResolverMock = $this->createMock(\Magento\Framework\Config\FileResolverInterface::class);
|
||||
$fileResolverMock->expects($this->any())->method('get')->willReturn($xmlFiles);
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->_model = $objectManager->create(
|
||||
\Magento\ImportExport\Model\Export\Config\Reader::class,
|
||||
['fileResolver' => $fileResolverMock, 'validationState' => $validationStateMock]
|
||||
);
|
||||
}
|
||||
|
||||
public function testExportXmlFiles()
|
||||
{
|
||||
$this->_model->read('global');
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests that existing fieldset.xml files are valid to schema individually and merged.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class FieldsetConfigFilesTest extends \Magento\TestFramework\TestCase\AbstractConfigFiles
|
||||
{
|
||||
/**
|
||||
* Returns the reader class name that will be instantiated via ObjectManager
|
||||
*
|
||||
* @return string reader class name
|
||||
*/
|
||||
protected function _getReaderClassName()
|
||||
{
|
||||
return \Magento\Framework\DataObject\Copy\Config\Reader::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string that represents the path to the config file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getConfigFilePathGlob()
|
||||
{
|
||||
return 'etc/fieldset.xml';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an absolute path to the XSD file corresponding to the XML files specified in _getConfigFilePathGlob
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getXsdPath()
|
||||
{
|
||||
return $this->componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework')
|
||||
. '/DataObject/etc/fieldset_file.xsd';
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class ImportConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\ImportExport\Model\Import\Config\Reader
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $moduleDirSearch \Magento\Framework\Component\DirSearch */
|
||||
$moduleDirSearch = $objectManager->get(\Magento\Framework\Component\DirSearch::class);
|
||||
$fileIteratorFactory = $objectManager->get(\Magento\Framework\Config\FileIteratorFactory::class);
|
||||
$xmlFiles = $fileIteratorFactory->create(
|
||||
$moduleDirSearch->collectFiles(ComponentRegistrar::MODULE, 'etc/{*/import.xml,import.xml}')
|
||||
);
|
||||
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->expects($this->any())->method('isValidationRequired')->willReturn(true);
|
||||
$fileResolverMock = $this->createMock(\Magento\Framework\Config\FileResolverInterface::class);
|
||||
$fileResolverMock->expects($this->any())->method('get')->willReturn($xmlFiles);
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->_model = $objectManager->create(
|
||||
\Magento\ImportExport\Model\Import\Config\Reader::class,
|
||||
['fileResolver' => $fileResolverMock, 'validationState' => $validationStateMock]
|
||||
);
|
||||
}
|
||||
|
||||
public function testImportXmlFiles()
|
||||
{
|
||||
$this->_model->read('global');
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Filesystem;
|
||||
|
||||
class IndexerConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Configuration acl file list
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fileList = [];
|
||||
|
||||
/**
|
||||
* Path to scheme file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $schemaFile;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
|
||||
$this->schemaFile = $urnResolver->getRealPath('urn:magento:framework:Indexer/etc/indexer.xsd');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test each acl configuration file
|
||||
* @param string $file
|
||||
* @dataProvider indexerConfigFileDataProvider
|
||||
*/
|
||||
public function testIndexerConfigFile($file)
|
||||
{
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$domConfig = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock);
|
||||
$result = $domConfig->validate($this->schemaFile, $errors);
|
||||
$message = "Invalid XML-file: {$file}\n";
|
||||
foreach ($errors as $error) {
|
||||
$message .= "{$error}\n";
|
||||
}
|
||||
$this->assertTrue($result, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function indexerConfigFileDataProvider()
|
||||
{
|
||||
return \Magento\Framework\App\Utility\Files::init()->getConfigFiles('indexer.xml');
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
class LayoutConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Path to schema file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $schemaFile;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
|
||||
$this->schemaFile = $urnResolver->getRealPath('urn:magento:framework:View/Layout/etc/elements.xsd');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a valid layout XML file
|
||||
*/
|
||||
public function testValidLayoutXmlFile()
|
||||
{
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')->willReturn(true);
|
||||
$domConfig = new \Magento\Framework\Config\Dom(
|
||||
'<referenceBlock name="product.info.something" group="column_left"></referenceBlock>',
|
||||
$validationStateMock
|
||||
);
|
||||
$result = $domConfig->validate($this->schemaFile, $errors);
|
||||
$this->assertTrue($result);
|
||||
$this->assertEmpty($errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a layout XML file having an invalid tag element
|
||||
*/
|
||||
public function testBrokenLayoutXmlFile()
|
||||
{
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')->willReturn(true);
|
||||
$domConfig = new \Magento\Framework\Config\Dom(
|
||||
'<invalidElement name="some.name"></invalidElement>',
|
||||
$validationStateMock
|
||||
);
|
||||
$result = $domConfig->validate($this->schemaFile, $errors);
|
||||
$this->assertFalse($result);
|
||||
$this->assertNotEmpty($errors);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class LayoutFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\View\Layout\Argument\Parser
|
||||
*/
|
||||
protected $_argParser;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Data\Argument\InterpreterInterface
|
||||
*/
|
||||
protected $_argInterpreter;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_argParser = $objectManager->get(\Magento\Framework\View\Layout\Argument\Parser::class);
|
||||
$this->_argInterpreter = $objectManager->get('layoutArgumentGeneratorInterpreter');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $area
|
||||
* @param string $layoutFile
|
||||
* @dataProvider layoutArgumentsDataProvider
|
||||
*/
|
||||
public function testLayoutArguments($area, $layoutFile)
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea($area);
|
||||
$dom = new \DOMDocument();
|
||||
$dom->load($layoutFile);
|
||||
$xpath = new \DOMXPath($dom);
|
||||
$argumentNodes = $xpath->query('/layout//arguments/argument | /layout//action/argument');
|
||||
/** @var \DOMNode $argumentNode */
|
||||
foreach ($argumentNodes as $argumentNode) {
|
||||
try {
|
||||
$argumentData = $this->_argParser->parse($argumentNode);
|
||||
if ($this->isSkippedArgument($argumentData)) {
|
||||
continue;
|
||||
}
|
||||
$this->_argInterpreter->evaluate($argumentData);
|
||||
} catch (\Exception $e) {
|
||||
$this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function layoutArgumentsDataProvider()
|
||||
{
|
||||
$areas = ['adminhtml', 'frontend', 'email'];
|
||||
$data = [];
|
||||
foreach ($areas as $area) {
|
||||
$layoutFiles = \Magento\Framework\App\Utility\Files::init()->getLayoutFiles(['area' => $area], false);
|
||||
foreach ($layoutFiles as $layoutFile) {
|
||||
$data[substr($layoutFile, strlen(BP))] = [$area, $layoutFile];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an argument should be skipped, because it cannot be evaluated in the testing environment
|
||||
*
|
||||
* @param array $argumentData
|
||||
* @return bool
|
||||
*/
|
||||
protected function isSkippedArgument(array $argumentData)
|
||||
{
|
||||
// Do not take into account argument name, shared and parameters
|
||||
unset($argumentData['name'], $argumentData['param'], $argumentData['shared']);
|
||||
|
||||
$isUpdater = isset($argumentData['updater']);
|
||||
unset($argumentData['updater']);
|
||||
|
||||
// Arguments, evaluation of which causes a run-time error, because of unsafe assumptions to the environment
|
||||
$typeAttr = \Magento\Framework\View\Model\Layout\Merge::TYPE_ATTRIBUTE;
|
||||
$prCollection =
|
||||
\Magento\GroupedProduct\Model\ResourceModel\Product\Type\Grouped\AssociatedProductsCollection::class;
|
||||
$ignoredArguments = [
|
||||
[
|
||||
$typeAttr => 'object',
|
||||
'value' => $prCollection,
|
||||
],
|
||||
[$typeAttr => 'object', 'value' => \Magento\Wishlist\Model\ResourceModel\Item\Collection\Grid::class],
|
||||
[
|
||||
$typeAttr => 'object',
|
||||
'value' => \Magento\CustomerSegment\Model\ResourceModel\Segment\Report\Detail\Collection::class
|
||||
],
|
||||
[$typeAttr => 'options', 'model' => \Magento\Logging\Model\ResourceModel\Grid\ActionsGroup::class],
|
||||
[$typeAttr => 'options', 'model' => \Magento\Logging\Model\ResourceModel\Grid\Actions::class],
|
||||
];
|
||||
$isIgnoredArgument = in_array($argumentData, $ignoredArguments, true);
|
||||
|
||||
unset($argumentData[$typeAttr]);
|
||||
$hasValue = !empty($argumentData);
|
||||
|
||||
return $isIgnoredArgument || $isUpdater && !$hasValue;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular\Magento\Catalog;
|
||||
|
||||
class AttributeConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_schemaFile;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Model\Attribute\Config\SchemaLocator $schemaLocator */
|
||||
$schemaLocator = $objectManager->get(\Magento\Catalog\Model\Attribute\Config\SchemaLocator::class);
|
||||
$this->_schemaFile = $schemaLocator->getSchema();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
* @dataProvider fileFormatDataProvider
|
||||
*/
|
||||
public function testFileFormat($file)
|
||||
{
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$dom = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock);
|
||||
$result = $dom->validate($this->_schemaFile, $errors);
|
||||
$this->assertTrue($result, print_r($errors, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function fileFormatDataProvider()
|
||||
{
|
||||
return \Magento\Framework\App\Utility\Files::init()->getConfigFiles('catalog_attributes.xml');
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular\Magento\Customer;
|
||||
|
||||
class AddressFormatsFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_schemaFile;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Address\Config\SchemaLocator $schemaLocator */
|
||||
$schemaLocator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Customer\Model\Address\Config\SchemaLocator::class
|
||||
);
|
||||
$this->_schemaFile = $schemaLocator->getSchema();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
* @dataProvider fileFormatDataProvider
|
||||
*/
|
||||
public function testFileFormat($file)
|
||||
{
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$dom = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock);
|
||||
$result = $dom->validate($this->_schemaFile, $errors);
|
||||
$this->assertTrue($result, print_r($errors, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function fileFormatDataProvider()
|
||||
{
|
||||
return \Magento\Framework\App\Utility\Files::init()->getConfigFiles(
|
||||
'{*/address_formats.xml,address_formats.xml}'
|
||||
);
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular\Magento\Email;
|
||||
|
||||
class EmailTemplateConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test that email template configuration file matches the format
|
||||
*
|
||||
* @param string $file
|
||||
* @dataProvider fileFormatDataProvider
|
||||
*/
|
||||
public function testFileFormat($file)
|
||||
{
|
||||
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
|
||||
$schemaFile = $urnResolver->getRealPath('urn:magento:module:Magento_Email:etc/email_templates.xsd');
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$dom = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock);
|
||||
$result = $dom->validate($schemaFile, $errors);
|
||||
$this->assertTrue($result, print_r($errors, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function fileFormatDataProvider()
|
||||
{
|
||||
return \Magento\Framework\App\Utility\Files::init()->getConfigFiles('email_templates.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that email template configuration contains references to existing template files
|
||||
*
|
||||
* @param string $templateId
|
||||
* @dataProvider templateReferenceDataProvider
|
||||
*/
|
||||
public function testTemplateReference($templateId)
|
||||
{
|
||||
/** @var \Magento\Email\Model\Template\Config $emailConfig */
|
||||
$emailConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Email\Model\Template\Config::class
|
||||
);
|
||||
|
||||
$parts = $emailConfig->parseTemplateIdParts($templateId);
|
||||
$templateId = $parts['templateId'];
|
||||
|
||||
$designParams = [];
|
||||
$theme = $parts['theme'];
|
||||
if ($theme) {
|
||||
$designParams['theme'] = $theme;
|
||||
}
|
||||
|
||||
$templateFilename = $emailConfig->getTemplateFilename($templateId, $designParams);
|
||||
$this->assertFileExists($templateFilename, 'Email template file, specified in the configuration, must exist');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function templateReferenceDataProvider()
|
||||
{
|
||||
$data = [];
|
||||
/** @var \Magento\Email\Model\Template\Config $emailConfig */
|
||||
$emailConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Email\Model\Template\Config::class
|
||||
);
|
||||
foreach ($emailConfig->getAvailableTemplates() as $template) {
|
||||
$data[$template['value']] = [$template['value']];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that merged configuration of email templates matches the format
|
||||
*/
|
||||
public function testMergedFormat()
|
||||
{
|
||||
$validationState = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationState->expects($this->any())->method('isValidationRequired')->willReturn(true);
|
||||
/** @var \Magento\Email\Model\Template\Config\Reader $reader */
|
||||
$reader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Email\Model\Template\Config\Reader::class,
|
||||
['validationState' => $validationState]
|
||||
);
|
||||
try {
|
||||
$reader->read();
|
||||
} catch (\Exception $e) {
|
||||
$this->fail('Merged email templates configuration does not pass XSD validation: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular\Magento\Sales;
|
||||
|
||||
class PdfConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $file
|
||||
* @dataProvider fileFormatDataProvider
|
||||
*/
|
||||
public function testFileFormat($file)
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order\Pdf\Config\SchemaLocator $schemaLocator */
|
||||
$schemaLocator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Sales\Model\Order\Pdf\Config\SchemaLocator::class
|
||||
);
|
||||
$schemaFile = $schemaLocator->getPerFileSchema();
|
||||
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$dom = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock);
|
||||
$result = $dom->validate($schemaFile, $errors);
|
||||
$this->assertTrue($result, print_r($errors, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function fileFormatDataProvider()
|
||||
{
|
||||
return \Magento\Framework\App\Utility\Files::init()->getConfigFiles('pdf.xml');
|
||||
}
|
||||
|
||||
public function testMergedFormat()
|
||||
{
|
||||
$validationState = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationState->expects($this->any())->method('isValidationRequired')->willReturn(true);
|
||||
|
||||
/** @var \Magento\Sales\Model\Order\Pdf\Config\Reader $reader */
|
||||
$reader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\Order\Pdf\Config\Reader::class,
|
||||
['validationState' => $validationState]
|
||||
);
|
||||
try {
|
||||
$reader->read();
|
||||
} catch (\Exception $e) {
|
||||
$this->fail('Merged pdf.xml files do not pass XSD validation: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Module\Dir;
|
||||
|
||||
class MenuConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Model\Menu\Config\Reader
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
|
||||
$schemaFile = $urnResolver->getRealPath('urn:magento:module:Magento_Backend:etc/menu.xsd');
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Backend\Model\Menu\Config\Reader::class,
|
||||
['perFileSchema' => $schemaFile, 'isValidated' => true]
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidateMenuFiles()
|
||||
{
|
||||
$this->_model->read('adminhtml');
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
class MviewConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Configuration acl file list
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fileList = [];
|
||||
|
||||
/**
|
||||
* Path to scheme file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $schemaFile;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
|
||||
$this->schemaFile = $urnResolver->getRealPath('urn:magento:framework:Mview/etc/mview.xsd');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test each acl configuration file
|
||||
* @param string $file
|
||||
* @dataProvider mviewConfigFileDataProvider
|
||||
*/
|
||||
public function testIndexerConfigFile($file)
|
||||
{
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$domConfig = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock);
|
||||
$result = $domConfig->validate($this->schemaFile, $errors);
|
||||
$message = "Invalid XML-file: {$file}\n";
|
||||
foreach ($errors as $error) {
|
||||
$message .= "{$error}\n";
|
||||
}
|
||||
$this->assertTrue($result, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function mviewConfigFileDataProvider()
|
||||
{
|
||||
return \Magento\Framework\App\Utility\Files::init()->getConfigFiles('mview.xml');
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests that existing payment.xml files are valid to schema individually and merged.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class PaymentConfigFilesTest extends \Magento\TestFramework\TestCase\AbstractConfigFiles
|
||||
{
|
||||
/**
|
||||
* Returns the reader class name that will be instantiated via ObjectManager
|
||||
*
|
||||
* @return string reader class name
|
||||
*/
|
||||
protected function _getReaderClassName()
|
||||
{
|
||||
return \Magento\Payment\Model\Config\Reader::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string that represents the path to the config file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getConfigFilePathGlob()
|
||||
{
|
||||
return 'etc/payment.xml';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an absolute path to the XSD file corresponding to the XML files specified in _getConfigFilePathGlob
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getXsdPath()
|
||||
{
|
||||
return $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Payment')
|
||||
. '/etc/payment_file.xsd';
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class ProductOptionsConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\ProductOptions\Config\Reader
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
//init primary configs
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $moduleDirSearch \Magento\Framework\Component\DirSearch */
|
||||
$moduleDirSearch = $objectManager->get(\Magento\Framework\Component\DirSearch::class);
|
||||
$fileIteratorFactory = $objectManager->get(\Magento\Framework\Config\FileIteratorFactory::class);
|
||||
$xmlFiles = $fileIteratorFactory->create(
|
||||
$moduleDirSearch->collectFiles(
|
||||
ComponentRegistrar::MODULE,
|
||||
'etc/{*/product_options.xml,product_options.xml}'
|
||||
)
|
||||
);
|
||||
|
||||
$fileResolverMock = $this->createMock(\Magento\Framework\Config\FileResolverInterface::class);
|
||||
$fileResolverMock->expects($this->any())->method('get')->willReturn($xmlFiles);
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->expects($this->any())->method('isValidationRequired')->willReturn(true);
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_model = $objectManager->create(
|
||||
\Magento\Catalog\Model\ProductOptions\Config\Reader::class,
|
||||
['fileResolver' => $fileResolverMock, 'validationState' => $validationStateMock]
|
||||
);
|
||||
}
|
||||
|
||||
public function testProductOptionsXmlFiles()
|
||||
{
|
||||
$this->_model->read('global');
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class ProductTypesConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\ProductTypes\Config\Reader
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $moduleDirSearch \Magento\Framework\Component\DirSearch */
|
||||
$moduleDirSearch = $objectManager->get(\Magento\Framework\Component\DirSearch::class);
|
||||
$fileIteratorFactory = $objectManager->get(\Magento\Framework\Config\FileIteratorFactory::class);
|
||||
$xmlFiles = $fileIteratorFactory->create(
|
||||
$moduleDirSearch->collectFiles(ComponentRegistrar::MODULE, 'etc/{*/product_types.xml,product_types.xml}')
|
||||
);
|
||||
|
||||
$fileResolverMock = $this->createMock(\Magento\Framework\Config\FileResolverInterface::class);
|
||||
$fileResolverMock->expects($this->any())->method('get')->willReturn($xmlFiles);
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->expects($this->any())->method('isValidationRequired')->willReturn(true);
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_model = $objectManager->create(
|
||||
\Magento\Catalog\Model\ProductTypes\Config\Reader::class,
|
||||
['fileResolver' => $fileResolverMock, 'validationState' => $validationStateMock]
|
||||
);
|
||||
}
|
||||
|
||||
public function testProductTypesXmlFiles()
|
||||
{
|
||||
$this->_model->read('global');
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\App\DeploymentConfig;
|
||||
use Magento\Framework\App\ResourceConnection\Config\Reader;
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
use Magento\Framework\Component\DirSearch;
|
||||
use Magento\Framework\Config\FileIteratorFactory;
|
||||
use Magento\Framework\Config\FileResolverInterface;
|
||||
use Magento\Framework\Config\ValidationStateInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ResourcesConfigFilesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Reader
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var $moduleDirSearch DirSearch */
|
||||
$moduleDirSearch = $objectManager->get(DirSearch::class);
|
||||
$fileIteratorFactory = $objectManager->get(FileIteratorFactory::class);
|
||||
$xmlFiles = $fileIteratorFactory->create(
|
||||
$moduleDirSearch->collectFiles(ComponentRegistrar::MODULE, 'etc/{*/resources.xml,resources.xml}')
|
||||
);
|
||||
|
||||
$fileResolverMock = $this->createMock(FileResolverInterface::class);
|
||||
$fileResolverMock->expects($this->any())->method('get')->willReturn($xmlFiles);
|
||||
$validationStateMock = $this->createMock(ValidationStateInterface::class);
|
||||
$validationStateMock->expects($this->any())->method('isValidationRequired')->willReturn(true);
|
||||
$deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
|
||||
->disableOriginalConstructor()
|
||||
->disableOriginalClone()
|
||||
->disableArgumentCloning()
|
||||
->disallowMockingUnknownTypes()
|
||||
->addMethods(['getConfiguration'])
|
||||
->getMock();
|
||||
|
||||
$deploymentConfigMock->expects($this->any())->method('getConfiguration')->willReturn([]);
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->model = $objectManager->create(
|
||||
Reader::class,
|
||||
[
|
||||
'fileResolver' => $fileResolverMock,
|
||||
'validationState' => $validationStateMock,
|
||||
'deploymentConfig' => $deploymentConfigMock
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function testResourcesXmlFiles()
|
||||
{
|
||||
$this->model->read('global');
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class RouteConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Config\ValidationStateInterface
|
||||
*/
|
||||
|
||||
protected $validationStateMock;
|
||||
|
||||
/**
|
||||
* attributes represent merging rules
|
||||
* copied from original class \Magento\Framework\App\Route\Config\Reader
|
||||
* @var array
|
||||
*/
|
||||
protected $_idAttributes = [
|
||||
'/config/routers' => 'id',
|
||||
'/config/routers/route' => 'id',
|
||||
'/config/routers/route/module' => 'name',
|
||||
];
|
||||
|
||||
/**
|
||||
* Path to loose XSD for per file validation
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $schemaFile;
|
||||
|
||||
/**
|
||||
* Path to tough XSD for merged file validation
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mergedSchemaFile;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$this->validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
|
||||
$this->schemaFile = $urnResolver->getRealPath('urn:magento:framework:App/etc/routes.xsd');
|
||||
$this->mergedSchemaFile = $urnResolver->getRealPath('urn:magento:framework:App/etc/routes_merged.xsd');
|
||||
}
|
||||
|
||||
public function testRouteConfigsValidation()
|
||||
{
|
||||
$invalidFiles = [];
|
||||
|
||||
$componentRegistrar = new ComponentRegistrar();
|
||||
$files = [];
|
||||
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) {
|
||||
$mask = $moduleDir . '/etc/*/routes.xml';
|
||||
$files = array_merge($files, glob($mask));
|
||||
}
|
||||
$mergedConfig = new \Magento\Framework\Config\Dom(
|
||||
'<config><router/></config>',
|
||||
$this->validationStateMock,
|
||||
$this->_idAttributes
|
||||
);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$content = file_get_contents($file);
|
||||
try {
|
||||
new \Magento\Framework\Config\Dom(
|
||||
$content,
|
||||
$this->validationStateMock,
|
||||
$this->_idAttributes,
|
||||
null,
|
||||
$this->schemaFile
|
||||
);
|
||||
|
||||
//merge won't be performed if file is invalid because of exception thrown
|
||||
$mergedConfig->merge($content);
|
||||
} catch (\Magento\Framework\Config\Dom\ValidationException $e) {
|
||||
$invalidFiles[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($invalidFiles)) {
|
||||
$this->fail('Found broken files: ' . implode("\n", $invalidFiles));
|
||||
}
|
||||
|
||||
try {
|
||||
$errors = [];
|
||||
$mergedConfig->validate($this->mergedSchemaFile, $errors);
|
||||
} catch (\Exception $e) {
|
||||
$this->fail('Merged routes config is invalid: ' . "\n" . implode("\n", $errors));
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
class SalesConfigFilesTest extends AbstractMergedConfigTest
|
||||
{
|
||||
/**
|
||||
* attributes represent merging rules
|
||||
* copied from original namespace Magento\Framework\App\Route\Config;
|
||||
*
|
||||
* class Reader
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected function getIdAttributes()
|
||||
{
|
||||
return [
|
||||
'/config/section' => 'name',
|
||||
'/config/section/group' => 'name',
|
||||
'/config/section/group/item' => 'name',
|
||||
'/config/section/group/item/renderer' => 'name',
|
||||
'/config/order/available_product_type' => 'name',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Path to tough XSD for merged file validation
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected function getMergedSchemaFile()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
return $objectManager->get(\Magento\Sales\Model\Config\SchemaLocator::class)->getSchema();
|
||||
}
|
||||
|
||||
protected function getConfigFiles()
|
||||
{
|
||||
return \Magento\Framework\App\Utility\Files::init()->getConfigFiles('sales.xml');
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class SystemConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testConfiguration()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
// disable config caching to not pollute it
|
||||
/** @var $cacheState \Magento\Framework\App\Cache\StateInterface */
|
||||
$cacheState = $objectManager->get(\Magento\Framework\App\Cache\StateInterface::class);
|
||||
$cacheState->setEnabled(\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER, false);
|
||||
|
||||
/** @var \Magento\Framework\Filesystem $filesystem */
|
||||
$filesystem = $objectManager->get(\Magento\Framework\Filesystem::class);
|
||||
$modulesDir = $filesystem->getDirectoryRead(DirectoryList::ROOT);
|
||||
/** @var $moduleDirSearch \Magento\Framework\Component\DirSearch */
|
||||
$moduleDirSearch = $objectManager->get(\Magento\Framework\Component\DirSearch::class);
|
||||
$fileList = $moduleDirSearch
|
||||
->collectFiles(ComponentRegistrar::MODULE, 'etc/adminhtml/system.xml');
|
||||
$configMock = $this->createPartialMock(
|
||||
\Magento\Framework\Module\Dir\Reader::class,
|
||||
['getConfigurationFiles', 'getModuleDir']
|
||||
);
|
||||
$configMock->expects($this->any())->method('getConfigurationFiles')->willReturn($fileList);
|
||||
$configMock->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'getModuleDir'
|
||||
)->with(
|
||||
'etc',
|
||||
'Magento_Backend'
|
||||
)->willReturn(
|
||||
$modulesDir->getAbsolutePath() . '/app/code/Magento/Backend/etc'
|
||||
);
|
||||
try {
|
||||
$objectManager->create(
|
||||
\Magento\Config\Model\Config\Structure\Reader::class,
|
||||
['moduleReader' => $configMock, 'runtimeValidation' => true]
|
||||
);
|
||||
} catch (\Magento\Framework\Exception\LocalizedException $exp) {
|
||||
$this->fail($exp->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Customer\Model\Context;
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class TemplateFilesTest extends \Magento\TestFramework\TestCase\AbstractIntegrity
|
||||
{
|
||||
public function testAllTemplates()
|
||||
{
|
||||
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
|
||||
$invoker(
|
||||
function ($module, $template, $class, $area) {
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
)->setDefaultDesignTheme();
|
||||
// intentionally to make sure the module files will be requested
|
||||
$params = [
|
||||
'area' => $area,
|
||||
'themeModel' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Design\ThemeInterface::class
|
||||
),
|
||||
'module' => $module,
|
||||
];
|
||||
$file = \Magento\TestFramework\Helper\Bootstrap::getObjectmanager()->get(
|
||||
\Magento\Framework\View\FileSystem::class
|
||||
)->getTemplateFileName(
|
||||
$template,
|
||||
$params
|
||||
);
|
||||
$this->assertIsString($file, "Block class: {$class} {$template}");
|
||||
$this->assertFileExists($file, "Block class: {$class}");
|
||||
},
|
||||
$this->allTemplatesDataProvider()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function allTemplatesDataProvider()
|
||||
{
|
||||
$blockClass = '';
|
||||
try {
|
||||
/** @var $website \Magento\Store\Model\Website */
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->setWebsiteId(
|
||||
0
|
||||
);
|
||||
|
||||
$templates = [];
|
||||
$skippedBlocks = $this->_getBlocksToSkip();
|
||||
foreach (\Magento\Framework\App\Utility\Classes::collectModuleClasses('Block') as $blockClass => $module) {
|
||||
if (!in_array($module, $this->_getEnabledModules()) || in_array($blockClass, $skippedBlocks)) {
|
||||
continue;
|
||||
}
|
||||
$class = new \ReflectionClass($blockClass);
|
||||
if ($class->isAbstract() || !$class->isSubclassOf(\Magento\Framework\View\Element\Template::class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$area = 'frontend';
|
||||
if ($module == 'Magento_Backend' || strpos(
|
||||
$blockClass,
|
||||
'\\Adminhtml\\'
|
||||
) !== false || strpos(
|
||||
$blockClass,
|
||||
'\\Backend\\'
|
||||
) !== false || $class->isSubclassOf(
|
||||
\Magento\Backend\Block\Template::class
|
||||
)
|
||||
) {
|
||||
$area = 'adminhtml';
|
||||
}
|
||||
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\AreaList::class
|
||||
)->getArea(
|
||||
$area
|
||||
)->load(
|
||||
\Magento\Framework\App\Area::PART_CONFIG
|
||||
);
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\Config\ScopeInterface::class
|
||||
)->setCurrentScope(
|
||||
$area
|
||||
);
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\State::class
|
||||
)->setAreaCode(
|
||||
$area
|
||||
);
|
||||
$context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Http\Context::class
|
||||
);
|
||||
$context->setValue(Context::CONTEXT_AUTH, false, false);
|
||||
$context->setValue(
|
||||
Context::CONTEXT_GROUP,
|
||||
\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID,
|
||||
\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID
|
||||
);
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create($blockClass);
|
||||
$template = $block->getTemplate();
|
||||
if ($template) {
|
||||
$templates[$module . ', ' . $template . ', ' . $blockClass . ', ' . $area] = [
|
||||
$module,
|
||||
$template,
|
||||
$blockClass,
|
||||
$area,
|
||||
];
|
||||
}
|
||||
}
|
||||
return $templates;
|
||||
} catch (\Exception $e) {
|
||||
trigger_error(
|
||||
"Corrupted data provider. Last known block instantiation attempt: '{$blockClass}'." .
|
||||
" Exception: {$e}",
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function _getBlocksToSkip()
|
||||
{
|
||||
$result = [];
|
||||
foreach (glob(__DIR__ . '/_files/skip_template_blocks*.php') as $file) {
|
||||
$blocks = include $file;
|
||||
$result = array_merge($result, $blocks);
|
||||
}
|
||||
return array_combine($result, $result);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests that existing page_layouts.xml files are valid to schema individually and merged.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class ThemeConfigFilesTest extends \Magento\TestFramework\TestCase\AbstractConfigFiles
|
||||
{
|
||||
/**
|
||||
* Returns the reader class name that will be instantiated via ObjectManager
|
||||
*
|
||||
* @return string reader class name
|
||||
*/
|
||||
protected function _getReaderClassName()
|
||||
{
|
||||
return \Magento\Theme\Model\Layout\Config\Reader::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string that represents the path to the config file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getConfigFilePathGlob()
|
||||
{
|
||||
return 'view/*/layouts.xml';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an absolute path to the XSD file corresponding to the XML files specified in _getConfigFilePathGlob
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getXsdPath()
|
||||
{
|
||||
return $this->componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework')
|
||||
. '/View/PageLayout/etc/layouts.xsd';
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
class ViewConfigFilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $file
|
||||
* @dataProvider viewConfigFileDataProvider
|
||||
*/
|
||||
public function testViewConfigFile($file)
|
||||
{
|
||||
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
|
||||
$validationStateMock->method('isValidationRequired')
|
||||
->willReturn(true);
|
||||
$domConfig = new \Magento\Framework\Config\Dom($file, $validationStateMock);
|
||||
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
|
||||
$result = $domConfig->validate(
|
||||
$urnResolver->getRealPath('urn:magento:framework:Config/etc/view.xsd'),
|
||||
$errors
|
||||
);
|
||||
$message = "Invalid XML-file: {$file}\n";
|
||||
foreach ($errors as $error) {
|
||||
$message .= "{$error->message} Line: {$error->line}\n";
|
||||
}
|
||||
$this->assertTrue($result, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function viewConfigFileDataProvider()
|
||||
{
|
||||
$result = [];
|
||||
$files = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\Module\Dir\Reader::class
|
||||
)->getConfigurationFiles(
|
||||
'view.xml'
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
$result[] = [$file];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests that existing widget.xml files are valid to schema individually and merged.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Test\Integrity\Modular;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class WidgetConfigFilesTest extends \Magento\TestFramework\TestCase\AbstractConfigFiles
|
||||
{
|
||||
/**
|
||||
* Returns the reader class name that will be instantiated via ObjectManager
|
||||
*
|
||||
* @return string reader class name
|
||||
*/
|
||||
protected function _getReaderClassName()
|
||||
{
|
||||
return \Magento\Widget\Model\Config\Reader::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string that represents the path to the config file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getConfigFilePathGlob()
|
||||
{
|
||||
return 'etc/widget.xml';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an absolute path to the XSD file corresponding to the XML files specified in _getConfigFilePathGlob
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getXsdPath()
|
||||
{
|
||||
return $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Widget')
|
||||
. '/etc/widget_file.xsd';
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* List of blocks to be skipped from instantiation test
|
||||
*
|
||||
* Format: array('Block_Class_Name', ...)
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
return [
|
||||
// Blocks with abstract constructor arguments
|
||||
\Magento\Email\Block\Adminhtml\Template::class,
|
||||
\Magento\Email\Block\Adminhtml\Template\Edit::class,
|
||||
\Magento\Config\Block\System\Config\Edit::class,
|
||||
\Magento\Config\Block\System\Config\Form::class,
|
||||
\Magento\Config\Block\System\Config\Tabs::class,
|
||||
\Magento\Review\Block\Form::class,
|
||||
// Fails because of dependence on registry
|
||||
\Magento\Reminder\Block\Adminhtml\Reminder\Edit\Tab\Customers::class,
|
||||
\Magento\LayeredNavigation\Block\Navigation::class,
|
||||
\Magento\LayeredNavigation\Block\Navigation\State::class,
|
||||
\Magento\Paypal\Block\Express\InContext\Minicart\Button::class,
|
||||
];
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* List of blocks to be skipped from template files test
|
||||
*
|
||||
* Format: array('Block_Class_Name', ...)
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
return [
|
||||
// Fails because of dependence on registry
|
||||
\Magento\Reminder\Block\Adminhtml\Reminder\Edit\Tab\Customers::class,
|
||||
\Magento\LayeredNavigation\Block\Navigation::class,
|
||||
\Magento\LayeredNavigation\Block\Navigation\State::class,
|
||||
\Magento\Paypal\Block\Express\InContext\Minicart\Button::class,
|
||||
];
|
||||
Reference in New Issue
Block a user