ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user