예제 #1
0
 public function testLocalXmlFilesAbsent()
 {
     $area = '*';
     $package = '*';
     $theme = '*';
     $this->assertEmpty(glob(\Magento\TestFramework\Utility\Files::init()->getPathToSource() . "/app/design/{$area}/{$package}/{$theme}/local.xml"));
 }
예제 #2
0
 public function testObsoleteBlockMethods()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $this->assertNotRegexp('/this->_[^_]+\\S*\\(/iS', file_get_contents($file), 'Access to protected and private members of Block class is ' . 'obsolete in phtml templates. Use only public members.');
     }, \Magento\TestFramework\Utility\Files::init()->getPhtmlFiles());
 }
예제 #3
0
 public function testObsoleteDirectives()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $this->assertNotRegExp('/\\{\\{htmlescape.*?\\}\\}/i', file_get_contents($file), 'Directive {{htmlescape}} is obsolete. Use {{escapehtml}} instead.');
     }, \Magento\TestFramework\Utility\Files::init()->getEmailTemplates());
 }
예제 #4
0
 /**
  * Gets alien dependencies information for current module by analyzing file's contents
  *
  * @param string $currentModule
  * @param string $fileType
  * @param string $file
  * @param string $contents
  * @return array
  */
 public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
 {
     if (!in_array($fileType, array('php', 'template'))) {
         return array();
     }
     $pattern = '~\\b(?<class>(?<module>(' . implode('_|', \Magento\TestFramework\Utility\Files::init()->getNamespaces()) . '[_\\\\])[a-zA-Z0-9]+)[a-zA-Z0-9_\\\\]*)\\b~';
     $dependenciesInfo = array();
     if (preg_match_all($pattern, $contents, $matches)) {
         $matches['module'] = array_unique($matches['module']);
         foreach ($matches['module'] as $i => $referenceModule) {
             $referenceModule = str_replace('_', '\\', $referenceModule);
             if ($currentModule == $referenceModule) {
                 continue;
             }
             $dependenciesInfo[] = array('module' => $referenceModule, 'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD, 'source' => trim($matches['class'][$i]));
         }
     }
     $result = $this->_caseGetUrl($currentModule, $contents);
     if (count($result)) {
         $dependenciesInfo = array_merge($dependenciesInfo, $result);
     }
     $result = $this->_caseLayoutBlock($currentModule, $fileType, $file, $contents);
     if (count($result)) {
         $dependenciesInfo = array_merge($dependenciesInfo, $result);
     }
     return $dependenciesInfo;
 }
예제 #5
0
 /**
  * Setup basics for all tests
  *
  * @return void
  */
 public static function setUpBeforeClass()
 {
     self::$reportDir = Utility\Files::init()->getPathToSource() . '/dev/tests/static/report';
     if (!is_dir(self::$reportDir)) {
         mkdir(self::$reportDir, 0777);
     }
     self::setupFileLists();
 }
예제 #6
0
 /**
  * Return layout handles that are declared in the base layouts for frontend
  *
  * @return array
  */
 protected function _getBaseFrontendHandles()
 {
     if ($this->_baseFrontendHandles === null) {
         $files = \Magento\TestFramework\Utility\Files::init()->getLayoutFiles(array('include_design' => false, 'area' => 'frontend'), false);
         $this->_baseFrontendHandles = $this->_extractLayoutHandles($files);
     }
     return $this->_baseFrontendHandles;
 }
 /**
  * @return array
  */
 public static function obsoleteLayoutLocationDataProvider()
 {
     $root = \Magento\TestFramework\Utility\Files::init()->getPathToSource();
     $modulePaths = glob("{$root}/app/code/*/*/view/*");
     $themePaths = glob("{$root}/app/design/*/*/*");
     $merged = array_merge($modulePaths, $themePaths);
     return \Magento\TestFramework\Utility\Files::composeDataSets($merged);
 }
예제 #8
0
 public function testSystemConfigurationDeclaration()
 {
     $fileList = \Magento\TestFramework\Utility\Files::init()->getConfigFiles('system.xml', array('wsdl.xml', 'wsdl2.xml', 'wsi.xml'), false);
     foreach ($fileList as $configFile) {
         $configXml = simplexml_load_file($configFile);
         $xpath = '/config/tabs|/config/sections';
         $this->assertEmpty($configXml->xpath($xpath), 'Obsolete system configuration structure detected in file ' . $configFile . '.');
     }
 }
예제 #9
0
 public function testBlocksIntoContainers()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $xml = simplexml_load_file($file);
         $this->assertSame(array(), $xml->xpath('/widgets/*/supported_blocks'), 'Obsolete node: <supported_blocks>. To be replaced with <supported_containers>');
         $this->assertSame(array(), $xml->xpath('/widgets/*/*/*/block_name'), 'Obsolete node: <block_name>. To be replaced with <container_name>');
     }, \Magento\TestFramework\Utility\Files::init()->getConfigFiles('widget.xml'));
 }
예제 #10
0
 /**
  * @return array
  */
 public function declaredConsistentlyDataProvider()
 {
     $result = [];
     $root = \Magento\TestFramework\Utility\Files::init()->getPathToSource();
     foreach (Package::readDeclarationFiles($root) as $row) {
         $result[] = $row;
     }
     return $result;
 }
예제 #11
0
 public function testMenuDeclaration()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($menuFile) {
         $menuXml = simplexml_load_file($menuFile);
         $xpath = '/config/menu/*[boolean(./children) or boolean(./title) or boolean(./action)]';
         $this->assertEmpty($menuXml->xpath($xpath), 'Obsolete menu structure detected in file ' . $menuFile . '.');
     }, \Magento\TestFramework\Utility\Files::init()->getMainConfigFiles());
 }
예제 #12
0
 public function testConfigFile()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $xml = simplexml_load_file($file);
         $path = '/config/check/php/extensions';
         $this->assertEmpty($xml->xpath($path), "Nodes from '{$path}' in install_wizard.xml have been moved to module.xml");
     }, \Magento\TestFramework\Utility\Files::init()->getConfigFiles('install_wizard.xml'));
 }
예제 #13
0
 public function testLayoutFormat()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($layoutFile) {
         $schemaFile = BP . '/app/code/Magento/Core/etc/layout_single.xsd';
         $domLayout = new \Magento\Framework\Config\Dom(file_get_contents($layoutFile));
         $result = $domLayout->validate($schemaFile, $errors);
         $this->assertTrue($result, print_r($errors, true));
     }, \Magento\TestFramework\Utility\Files::init()->getLayoutFiles());
 }
예제 #14
0
 public function testSchemaUsingPartialXml($expectedErrors = null)
 {
     $xmlFile = $this->_getKnownValidPartialXml();
     if (is_null($xmlFile)) {
         $this->markTestSkipped('No Partial File');
         return;
     }
     $schema = \Magento\TestFramework\Utility\Files::init()->getPathToSource() . $this->_getXsd();
     $this->_validateFileExpectFailure($xmlFile, $schema, $expectedErrors);
 }
예제 #15
0
 public function testWords()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $words = self::$_wordsFinder->findWords($file);
         if ($words) {
             $this->fail("Found words: '" . implode("', '", $words) . "' in '{$file}' file");
         }
     }, \Magento\TestFramework\Utility\Files::init()->getAllFiles());
 }
예제 #16
0
 public function testGetChildHtml()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $result = \Magento\TestFramework\Utility\Classes::getAllMatches(file_get_contents($file), "/(->getChildHtml\\([^,()]+, ?[^,()]+,)/i");
         $this->assertEmpty($result, "3rd parameter is not needed anymore for getChildHtml() in '{$file}': " . print_r($result, true));
         $result = \Magento\TestFramework\Utility\Classes::getAllMatches(file_get_contents($file), "/(->getChildChildHtml\\([^,()]+, ?[^,()]+, ?[^,()]+,)/i");
         $this->assertEmpty($result, "4th parameter is not needed anymore for getChildChildHtml() in '{$file}': " . print_r($result, true));
     }, \Magento\TestFramework\Utility\Files::init()->getPhpFiles());
 }
예제 #17
0
 /**
  * Gathers all tmplate file names
  */
 private static function _populateTemplateFiles()
 {
     $filesPaths = \Magento\TestFramework\Utility\Files::init()->getPhpFiles(false, false, true, false);
     foreach ($filesPaths as $filePath) {
         $filePathArray = explode('/', $filePath);
         $fileName = array_pop($filePathArray);
         if (!in_array($fileName, self::$_templateFileNames)) {
             self::$_templateFileNames[] = $fileName;
         }
     }
 }
예제 #18
0
 /**
  * @return array
  */
 public function getChildBlockDataProvider()
 {
     $result = array();
     foreach (\Magento\TestFramework\Utility\Files::init()->getPhpFiles(true, false, true, false) as $file) {
         $aliases = \Magento\TestFramework\Utility\Classes::getAllMatches(file_get_contents($file), '/\\->getChildBlock\\(\'([^\']+)\'\\)/x');
         foreach ($aliases as $alias) {
             $result[$file] = array($alias, $file);
         }
     }
     return $result;
 }
예제 #19
0
 /**
  * Get list of configuration files associated with modules
  *
  * @return array
  */
 protected function _getConfigFilesPerModule()
 {
     $configFiles = \Magento\TestFramework\Utility\Files::init()->getConfigFiles('config.xml', array(), false);
     $data = array();
     foreach ($configFiles as $configFile) {
         preg_match('#/([^/]+?/[^/]+?)/etc/config\\.xml$#', $configFile, $moduleName);
         $moduleName = str_replace('/', '_', $moduleName[1]);
         $data[$configFile] = $moduleName;
     }
     return $data;
 }
예제 #20
0
 public function testFileSchemaUsingInvalidXml()
 {
     $xmlFile = __DIR__ . '/_files/invalid_fieldset.xml';
     $dom = new \DOMDocument();
     $dom->loadXML(file_get_contents($xmlFile));
     $schema = \Magento\TestFramework\Utility\Files::init()->getPathToSource() . '/lib/internal/Magento/Framework/Object/etc/fieldset_file.xsd';
     $errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
     if (!$errors) {
         $this->fail('There is a problem with the schema.  A known bad XML file passed validation');
     }
 }
예제 #21
0
 /**
  * @return array
  */
 public function layoutArgumentsDataProvider()
 {
     $areas = ['adminhtml', 'frontend', 'install', 'email'];
     $data = [];
     foreach ($areas as $area) {
         $layoutFiles = \Magento\TestFramework\Utility\Files::init()->getLayoutFiles(['area' => $area], false);
         foreach ($layoutFiles as $layoutFile) {
             $data[substr($layoutFile, strlen(BP))] = [$area, $layoutFile];
         }
     }
     return $data;
 }
예제 #22
0
 /**
  * @return array
  */
 public function layoutArgumentsDataProvider()
 {
     $areas = array('adminhtml', 'frontend', 'install', 'email');
     $data = array();
     foreach ($areas as $area) {
         $layoutFiles = \Magento\TestFramework\Utility\Files::init()->getLayoutFiles(array('area' => $area), false);
         foreach ($layoutFiles as $layoutFile) {
             $data[$layoutFile] = array($area, $layoutFile);
         }
     }
     return $data;
 }
예제 #23
0
 public function testSchema()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($configFile) {
         $dom = new \DOMDocument();
         $dom->loadXML(file_get_contents($configFile));
         $schema = \Magento\TestFramework\Utility\Files::init()->getPathToSource() . '/app/code/Magento/Backend/etc/system_file.xsd';
         $errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
         if ($errors) {
             $this->fail('XML-file has validation errors:' . PHP_EOL . implode(PHP_EOL . PHP_EOL, $errors));
         }
     }, \Magento\TestFramework\Utility\Files::init()->getConfigFiles('adminhtml/system.xml', array()));
 }
예제 #24
0
 /**
  * Build modules dependencies
  */
 protected function buildModulesDependencies()
 {
     $configFiles = Files::init()->getConfigFiles('module.xml', array(), false);
     foreach ($configFiles as $configFile) {
         preg_match('#/([^/]+?/[^/]+?)/etc/module\\.xml$#', $configFile, $moduleName);
         $moduleName = str_replace('/', '_', $moduleName[1]);
         $config = simplexml_load_file($configFile);
         $result = $config->xpath("/config/module/depends/module") ?: array();
         while (list(, $node) = each($result)) {
             /** @var \SimpleXMLElement $node */
             $this->moduleDependencies[$moduleName][] = (string) $node['name'];
         }
     }
 }
예제 #25
0
 /**
  * @return array
  */
 public function getLocalePlacePath()
 {
     $pathToSource = \Magento\TestFramework\Utility\Files::init()->getPathToSource();
     $places = array();
     foreach (glob("{$pathToSource}/app/code/*/*", GLOB_ONLYDIR) as $modulePath) {
         $places[basename($modulePath)] = ['placePath' => $modulePath];
     }
     foreach (glob("{$pathToSource}/app/design/*/*/*", GLOB_ONLYDIR) as $themePath) {
         $placeName = basename(dirname(dirname($themePath))) . '_' . basename($themePath);
         $places[$placeName] = ['placePath' => $themePath];
     }
     $places['lib_web'] = ['placePath' => "{$pathToSource}/lib/web"];
     return $places;
 }
예제 #26
0
 public function testConfigFiles()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $obsoleteNodes = array();
         $obsoleteNodesFiles = glob(__DIR__ . '/_files/obsolete_config_nodes*.php');
         foreach ($obsoleteNodesFiles as $obsoleteNodesFile) {
             $obsoleteNodes = array_merge($obsoleteNodes, include $obsoleteNodesFile);
         }
         $xml = simplexml_load_file($file);
         foreach ($obsoleteNodes as $xpath => $suggestion) {
             $this->assertEmpty($xml->xpath($xpath), "Nodes identified by XPath '{$xpath}' are obsolete. {$suggestion}");
         }
     }, \Magento\TestFramework\Utility\Files::init()->getMainConfigFiles());
 }
예제 #27
0
 public function testLayouts()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($path) {
         $xml = simplexml_load_file($path);
         $classes = \Magento\TestFramework\Utility\Classes::collectLayoutClasses($xml);
         foreach (\Magento\TestFramework\Utility\Classes::getXmlAttributeValues($xml, '/layout//@helper', 'helper') as $class) {
             $classes[] = \Magento\TestFramework\Utility\Classes::getCallbackClass($class);
         }
         $classes = array_merge($classes, \Magento\TestFramework\Utility\Classes::getXmlAttributeValues($xml, '/layout//@module', 'module'));
         $this->_assertNonFactoryName(array_unique($classes), $path);
         $tabs = \Magento\TestFramework\Utility\Classes::getXmlNodeValues($xml, '/layout//action[@method="addTab"]/block');
         $this->_assertNonFactoryName(array_unique($tabs), $path, true);
     }, \Magento\TestFramework\Utility\Files::init()->getLayoutFiles());
 }
예제 #28
0
 /**
  * Returns array of PHP-files, that use or declare Magento application classes and Magento libs
  *
  * @param string $changedFilesList
  * @return array
  */
 public static function getPhpFiles($changedFilesList)
 {
     $fileHelper = \Magento\TestFramework\Utility\Files::init();
     $allPhpFiles = $fileHelper->getPhpFiles();
     if (isset($_ENV['INCREMENTAL_BUILD'])) {
         $phpFiles = file($changedFilesList, FILE_IGNORE_NEW_LINES);
         foreach ($phpFiles as $key => $phpFile) {
             $phpFiles[$key] = $fileHelper->getPathToSource() . '/' . $phpFile;
         }
         $phpFiles = \Magento\TestFramework\Utility\Files::composeDataSets($phpFiles);
         $phpFiles = array_intersect_key($phpFiles, $allPhpFiles);
     } else {
         $phpFiles = $allPhpFiles;
     }
     return $phpFiles;
 }
예제 #29
0
 public function testTableName()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($filePath) {
         $tables = self::extractTables($filePath);
         $legacyTables = array();
         foreach ($tables as $table) {
             $tableName = $table['name'];
             if (strpos($tableName, '/') === false) {
                 continue;
             }
             $legacyTables[] = $table;
         }
         $message = $this->_composeFoundsMessage($legacyTables);
         $this->assertEmpty($message, $message);
     }, \Magento\TestFramework\Utility\Files::init()->getPhpFiles());
 }
예제 #30
0
 public function legacyCommentDataProvider()
 {
     $root = \Magento\TestFramework\Utility\Files::init()->getPathToSource();
     $recursiveIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS));
     $rootFolderName = substr(strrchr($root, '/'), 1);
     $extensions = '(xml|css|php|phtml|js|dist|sample|additional)';
     $paths = array($rootFolderName . '/[^/]+\\.' . $extensions, $rootFolderName . '/app/.+\\.' . $extensions, $rootFolderName . '/dev/(?!tests/integration/tmp|tests/functional).+\\.' . $extensions, $rootFolderName . '/downloader/.+\\.' . $extensions, $rootFolderName . '/lib/internal/(Mage|Magento|Varien)/.+\\.' . $extensions, $rootFolderName . '/pub/.+\\.' . $extensions);
     $regexIterator = new \RegexIterator($recursiveIterator, '#(' . implode(' | ', $paths) . ')$#x');
     $result = array();
     foreach ($regexIterator as $fileInfo) {
         $filename = (string) $fileInfo;
         if (!file_exists($filename) || !is_readable($filename)) {
             continue;
         }
         $result[] = array($filename);
     }
     return $result;
 }