/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/LayoutFilesTest.php
112 строк
4 KB
Raj Mohan R
AC-16236::Upgrade Core Test Framework to PHPUnit 12 and Migrate from PHPUnit 10
11 фев 2026, 13:51
11 фев 2026, 13:51
152ed41
Код
Авторство
О чём код?
<?php /** * Copyright 2013 Adobe * All Rights Reserved. */ namespace Magento\Test\Integrity\Modular; use PHPUnit\Framework\Attributes\DataProvider; /** * @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 static 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; } }