|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\FunctionalTestingFramework\Page\Config; |
| 8 | + |
| 9 | +use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; |
| 10 | +use Magento\FunctionalTestingFramework\Exceptions\Collector\ExceptionCollector; |
| 11 | +use Magento\FunctionalTestingFramework\Config\Dom\NodeMergingConfig; |
| 12 | +use Magento\FunctionalTestingFramework\Config\Dom\NodePathMatcher; |
| 13 | +use Magento\FunctionalTestingFramework\Util\ModulePathExtractor; |
| 14 | + |
| 15 | +class Dom extends \Magento\FunctionalTestingFramework\Config\Dom |
| 16 | +{ |
| 17 | + /** |
| 18 | + * Module Path extractor |
| 19 | + * |
| 20 | + * @var ModulePathExtractor |
| 21 | + */ |
| 22 | + private $modulePathExtractor; |
| 23 | + |
| 24 | + /** |
| 25 | + * TestDom constructor. |
| 26 | + * @param string $xml |
| 27 | + * @param string $filename |
| 28 | + * @param ExceptionCollector $exceptionCollector |
| 29 | + * @param array $idAttributes |
| 30 | + * @param string $typeAttributeName |
| 31 | + * @param string $schemaFile |
| 32 | + * @param string $errorFormat |
| 33 | + */ |
| 34 | + public function __construct( |
| 35 | + $xml, |
| 36 | + $filename, |
| 37 | + $exceptionCollector, |
| 38 | + array $idAttributes = [], |
| 39 | + $typeAttributeName = null, |
| 40 | + $schemaFile = null, |
| 41 | + $errorFormat = self::ERROR_FORMAT_DEFAULT |
| 42 | + ) { |
| 43 | + $this->schemaFile = $schemaFile; |
| 44 | + $this->nodeMergingConfig = new NodeMergingConfig(new NodePathMatcher(), $idAttributes); |
| 45 | + $this->typeAttributeName = $typeAttributeName; |
| 46 | + $this->errorFormat = $errorFormat; |
| 47 | + $this->modulePathExtractor = new ModulePathExtractor(); |
| 48 | + $this->dom = $this->initDom($xml, $filename, $exceptionCollector); |
| 49 | + $this->rootNamespace = $this->dom->lookupNamespaceUri($this->dom->namespaceURI); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Takes a dom element from xml and appends the filename based on location |
| 54 | + * |
| 55 | + * @param string $xml |
| 56 | + * @param string|null $filename |
| 57 | + * @param ExceptionCollector $exceptionCollector |
| 58 | + * @return \DOMDocument |
| 59 | + */ |
| 60 | + public function initDom($xml, $filename = null, $exceptionCollector = null) |
| 61 | + { |
| 62 | + $dom = parent::initDom($xml); |
| 63 | + |
| 64 | + $pageNodes = $dom->getElementsByTagName('page'); |
| 65 | + $currentModule = |
| 66 | + $this->modulePathExtractor->extractModuleName($filename) . |
| 67 | + '_' . |
| 68 | + $this->modulePathExtractor->getExtensionPath($filename); |
| 69 | + foreach ($pageNodes as $pageNode) { |
| 70 | + $pageModule = $pageNode->getAttribute("module"); |
| 71 | + $pageName = $pageNode->getAttribute("name"); |
| 72 | + if ($pageModule !== $currentModule) { |
| 73 | + if (MftfApplicationConfig::getConfig()->verboseEnabled()) { |
| 74 | + print( |
| 75 | + "Page Module does not match path Module. " . |
| 76 | + "(Page, Module): ($pageName, $pageModule) - Path Module: $currentModule" . |
| 77 | + PHP_EOL |
| 78 | + ); |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + return $dom; |
| 83 | + } |
| 84 | +} |
0 commit comments