public function testSystemConfigurationDeclaration() { $fileList = 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 . '.'); } }
/** * Setter/Getter for an instance of self * * @param Utility_Files $instance * @return Utility_Files * @throws Exception when there is no instance set */ public static function init(Utility_Files $instance = null) { if ($instance) { self::$_instance = $instance; } if (!self::$_instance) { throw new Exception('Instance is not set yet.'); } return self::$_instance; }
/** * @depends testDeclaredLocales */ public function testExistingFilesDeclared($verifiedFiles) { $root = Utility_Files::init()->getPathToSource(); $failures = array(); foreach (glob("{$root}/app/code/*/*/*", GLOB_ONLYDIR) as $modulePath) { $localeFiles = glob("{$modulePath}/locale/*/*.csv"); foreach ($localeFiles as $file) { $file = realpath($file); $assertFile = dirname(dirname($file)) . DIRECTORY_SEPARATOR . 'en_US' . DIRECTORY_SEPARATOR . basename($file); if (!isset($verifiedFiles[$assertFile])) { $failures[] = $file; } } } $this->assertEmpty($failures, 'Translation files exist, but not declared in configuration:' . "\n" . var_export($failures, 1)); }
public function legacyCommentDataProvider() { $root = Utility_Files::init()->getPathToSource(); $recursiveIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS)); $rootFolderName = substr(strrchr($root, DIRECTORY_SEPARATOR), 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/(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; }
public function testObsoleteDirectories() { $area = '*'; $package = '*'; $theme = '*'; $root = Utility_Files::init()->getPathToSource(); $dirs = glob("{$root}/app/design/{$area}/{$package}/{$theme}/template", GLOB_ONLYDIR); $msg = array(); if ($dirs) { $msg[] = 'Theme "template" directories are obsolete. Relocate files as follows:'; foreach ($dirs as $dir) { $msg[] = str_replace($root, '', "{$dir} => " . realpath($dir . '/..') . '/Namespace_Module/*'); } } $dirs = glob("{$root}/app/design/{$area}/{$package}/{$theme}/layout", GLOB_ONLYDIR); if ($dirs) { $msg[] = 'Theme "layout" directories are obsolete. Relocate layout files into the root of theme directory.'; $msg = array_merge($msg, $dirs); } if ($msg) { $this->fail(implode(PHP_EOL, $msg)); } }
/** * @return array */ public function getChildBlockDataProvider() { $result = array(); foreach (Utility_Files::init()->getPhpFiles(true, false, true, false) as $file) { $aliases = Utility_Classes::getAllMatches(file_get_contents($file), '/\\->getChildBlock\\(\'([^\']+)\'\\)/x'); foreach ($aliases as $alias) { $result[$file] = array($alias); } } return $result; }
/** * @return array */ public function widgetXmlFilesDataProvider() { return Utility_Files::init()->getConfigFiles('widget.xml'); }
/** * @return array */ public function layoutFilesDataProvider() { return Utility_Files::init()->getLayoutFiles(array('area' => 'frontend')); }
$xml = simplexml_load_file($file); $classes = Utility_Classes::collectLayoutClasses($xml); $factoryNames = array_filter($classes, 'isFactoryName'); if (!$factoryNames) { continue; } $search = array(); $replace = array(); foreach ($factoryNames as $factoryName) { list($module, $name) = getModuleName($factoryName); addReplace($factoryName, $module, $name, 'type="%s"', '_Block_', $search, $replace); } replaceAndOutput($file, $search, $replace, $factoryNames); } // modules in configuration and layouts $configs = Utility_Files::init()->getConfigFiles('*.xml', array('wsdl.xml', 'wsdl2.xml', 'wsi.xml'), false); foreach (array_merge($layouts, $configs) as $file) { $modules = array_unique(Utility_Classes::getXmlAttributeValues(simplexml_load_file($file), '//@module', 'module')); $factoryNames = array_filter($modules, 'isFactoryName'); if (!$factoryNames) { continue; } $search = array(); $replace = array(); foreach ($factoryNames as $factoryName) { list($module, ) = getModuleName($factoryName); $search[] = 'module="' . $factoryName . '"'; $replace[] = 'module="' . implode('_', array_map('ucfirst', explode('_', $module))) . '"'; } replaceAndOutput($file, $search, $replace, $factoryNames); }
/** * @return array */ public function configFileDataProvider() { return Utility_Files::init()->getConfigFiles('config.xml'); }
/** * @return array */ public function menuFilesDataProvider() { return Utility_Files::init()->getConfigFiles(); }
public function phpFilesDataProvider() { return Utility_Files::init()->getPhpFiles(); }
$moduleEtcFiles = "../../../app/etc/modules/*.xml"; } $isCleanupEnabled = defined('TESTS_CLEANUP') && TESTS_CLEANUP == 'enabled'; $isDeveloperMode = defined('TESTS_MAGENTO_DEVELOPER_MODE') && TESTS_MAGENTO_DEVELOPER_MODE == 'enabled'; /* Enable profiler if necessary */ if (defined('TESTS_PROFILER_FILE') && TESTS_PROFILER_FILE) { $driver = new Magento_Profiler_Driver_Standard(); $driver->registerOutput(new Magento_Profiler_Driver_Standard_Output_Csvfile(array('baseDir' => $testsBaseDir, 'filePath' => TESTS_PROFILER_FILE))); Magento_Profiler::add($driver); } /* Enable profiler with bamboo friendly output format */ if (defined('TESTS_BAMBOO_PROFILER_FILE') && defined('TESTS_BAMBOO_PROFILER_METRICS_FILE')) { $driver = new Magento_Profiler_Driver_Standard(); $driver->registerOutput(new Magento_Test_Profiler_OutputBamboo(array('baseDir' => $testsBaseDir, 'filePath' => TESTS_BAMBOO_PROFILER_FILE, 'metrics' => require $testsBaseDir . DIRECTORY_SEPARATOR . TESTS_BAMBOO_PROFILER_METRICS_FILE))); Magento_Profiler::add($driver); } /* * Activate custom DocBlock annotations. * Note: order of registering (and applying) annotations is important. * To allow config fixtures to deal with fixture stores, data fixtures should be processed before config fixtures. */ $eventManager = new Magento_Test_EventManager(array(new Magento_Test_ClearProperties(), new Magento_Test_Annotation_AppIsolation(), new Magento_Test_Event_Transaction(new Magento_Test_EventManager(array(new Magento_Test_Annotation_DbIsolation(), new Magento_Test_Annotation_DataFixture("{$testsBaseDir}/testsuite")))), new Magento_Test_Annotation_ConfigFixture())); Magento_Test_Event_PhpUnit::setDefaultEventManager($eventManager); Magento_Test_Event_Magento::setDefaultEventManager($eventManager); /* Initialize object manager instance */ Mage::initializeObjectManager(null, new Magento_Test_ObjectManager()); /* Bootstrap the application */ Magento_Test_Bootstrap::setInstance(new Magento_Test_Bootstrap($magentoBaseDir, $testsBaseDir, $localXmlFile, $globalEtcFiles, $moduleEtcFiles, 'etc/integration-tests-config.xml', $testsTmpDir, new Magento_Shell(), $isCleanupEnabled, $isDeveloperMode)); Utility_Files::init(new Utility_Files($magentoBaseDir)); /* Unset declared global variables to release PHPUnit from maintaining their values between tests */ unset($testsBaseDir, $testsTmpDir, $magentoBaseDir, $localXmlFile, $globalEtcFiles, $moduleEtcFiles, $eventManager);
-h print usage USAGE ); $options = getopt('p:h'); if (isset($options['h'])) { print USAGE; exit(0); } require_once realpath(dirname(dirname(dirname(__DIR__)))) . '/dev/tests/static/framework/bootstrap.php'; require_once realpath(dirname(dirname(dirname(__DIR__)))) . '/lib/Zend/Json.php'; $magentoBaseDir = dirname(__DIR__) . '/../../'; if (isset($options['p'])) { $magentoBaseDir = $options['p']; } $utilityFiles = new Utility_Files($magentoBaseDir); $map = array(); $compositeModules = getFilesCombinedArray(dirname(__FILE__) . '/aliases_map', '/^composite_modules_.*\\.php$/'); // PHP code foreach ($utilityFiles->getPhpFiles(true, true, true, false) as $file) { $content = file_get_contents($file); $classes = Legacy_ClassesTest::collectPhpCodeClasses($content); if ($classes) { $factoryNames = array_filter($classes, 'isFactoryName'); foreach ($factoryNames as $factoryName) { list($module, $name) = getModuleName($factoryName, $compositeModules); $patterns = array('::getModel(\'%s\'' => 'Model', '::getSingleton(\'%s\'' => 'Model', '::getResourceModel(\'%s\'' => 'Model_Resource', '::getResourceSingleton(\'%s\'' => 'Model_Resource', 'addBlock(\'%s\'' => 'Block', 'createBlock(\'%s\'' => 'Block', 'getBlockClassName(\'%s\'' => 'Block', 'getBlockSingleton(\'%s\'' => 'Block'); foreach ($patterns as $pattern => $classType) { if (isPatternExist($content, $pattern, $factoryName)) { if (!isset($map[$classType])) { $map[$classType] = array();
/** * Get list of configuration files associated with modules * * @return array */ protected function _getConfigFilesPerModule() { $configFiles = 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]); if (in_array($moduleName, self::$_brokenModules)) { continue; } $data[$configFile] = $moduleName; } return $data; }
public function obsoleteDirectivesDataProvider() { return Utility_Files::init()->getEmailTemplates(); }
* * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Magento * @package Magento * @subpackage static_tests * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $includePath = array(__DIR__, dirname(__DIR__) . '/testsuite', get_include_path()); set_include_path(implode(PATH_SEPARATOR, $includePath)); spl_autoload_register(function ($class) { $file = str_replace('_', '/', $class) . '.php'; require_once $file; }); Utility_Files::init(new Utility_Files(realpath(__DIR__ . '/../../../..')));
/** * Check whether specified classes correspond to a file according PSR-0 standard * * Cyclomatic complexity is because of temporary marking test as incomplete * Suppressing "unused variable" because of the "catch" block * * @param array $classes * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function _assertClassesExist($classes) { if (!$classes) { return; } $badClasses = array(); $isBug = false; foreach ($classes as $class) { try { if ('Mage_Catalog_Model_Resource_Convert' == $class) { $isBug = true; continue; } $this->assertTrue(isset(self::$_existingClasses[$class]) || Utility_Files::init()->codePoolClassFileExists($class)); self::$_existingClasses[$class] = 1; } catch (PHPUnit_Framework_AssertionFailedError $e) { $badClasses[] = $class; } } if ($badClasses) { $this->fail("Missing files with declaration of classes:\n" . implode("\n", $badClasses)); } if ($isBug) { $this->markTestIncomplete('Bug MAGE-4763'); } }
/** * @return array */ public function layoutFileDataProvider() { return Utility_Files::init()->getLayoutFiles(); }
/** * @return array */ public function jsFileDataProvider() { return Utility_Files::init()->getJsFiles(); }
-h print usage USAGE ); $shortOpts = 'ehds'; $options = getopt($shortOpts); if (isset($options['h'])) { print USAGE; exit(0); } $outputWithErrors = isset($options['e']); $isDryRunMode = isset($options['d']); $isSearchTables = isset($options['s']); require realpath(dirname(dirname(dirname(__DIR__)))) . '/dev/tests/static/framework/bootstrap.php'; $tablesAssociation = getFilesCombinedArray(dirname(__FILE__) . '/factory_table_names', 'replace_*.php'); $blackList = getFilesCombinedArray(dirname(__FILE__) . '/factory_table_names', 'blacklist_*.php'); $phpFiles = Utility_Files::init()->getPhpFiles(true, false, false, false); $replacementResult = false; if (!$isSearchTables || $isDryRunMode) { $replacementResult = replaceTableNames($phpFiles, $tablesAssociation, $outputWithErrors, $isDryRunMode); } $searchResult = $isSearchTables ? searchTableNamesNotInReplacedList($phpFiles, $tablesAssociation, $blackList) : false; if ($replacementResult || $searchResult) { exit(1); } exit(0); /** * Get combined array from similar files by pattern * * @param $dirPath * @param $filePattern * @return array
/** * Read all text files by specified glob pattern and combine them into an array of valid files/directories * * The Magento root path is prepended to all (non-empty) entries * * @param string $globPattern * @return array * @throws Exception if any of the patterns don't return any result */ protected static function _readLists($globPattern) { $patterns = array(); foreach (glob($globPattern) as $list) { $patterns = array_merge($patterns, file($list, FILE_IGNORE_NEW_LINES)); } $result = array(); foreach ($patterns as $pattern) { if (0 === strpos($pattern, '#')) { continue; } /** * Note that glob() for directories will be returned as is, * but passing directory is supported by the tools (phpcpd, phpmd, phpcs) */ $files = glob(Utility_Files::init()->getPathToSource() . '/' . $pattern, GLOB_BRACE); if (empty($files)) { throw new Exception("The glob() pattern '{$pattern}' didn't return any result."); } $result = array_merge($result, $files); } return $result; }
/** * Read all text files by specified glob pattern and combine them into an array of valid files/directories * * The Magento root path is prepended to all (non-empty) entries * * @param string $globPattern * @return array */ protected static function _readLists($globPattern) { $result = array(); foreach (glob($globPattern) as $list) { $result = array_merge($result, file($list)); } $map = function ($value) { return trim($value) ? Utility_Files::init()->getPathToSource() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, trim($value)) : ''; }; return array_filter(array_map($map, $result), 'file_exists'); }
/** * @return array */ public function wordsDataProvider() { return Utility_Files::init()->getAllFiles(); }
/** * Scan application source code and find classes * * Sub-type pattern allows to distinguish "type" of a class within a module (for example, Block, Model) * Returns array(<class> => <module>) * * @param string $subTypePattern * @return array */ public static function collectModuleClasses($subTypePattern = '[A-Za-z]+') { $pattern = '/^' . preg_quote(Utility_Files::init()->getPathToSource(), '/') . '\\/app\\/code\\/[a-z]+\\/([A-Za-z]+)\\/([A-Za-z]+)\\/(' . $subTypePattern . '\\/.+)\\.php$/'; $result = array(); foreach (Utility_Files::init()->getPhpFiles(true, false, false, false) as $file) { if (preg_match($pattern, $file, $matches)) { $module = "{$matches[1]}_{$matches[2]}"; $class = "{$module}_" . str_replace('/', '_', $matches[3]); $result[$class] = $module; } } return $result; }
/** * Convert config data to the uniform format: * array( * '<entity>' => array( * 'suggestion' => '<suggestion>', * 'class_scope' => '<class_scope>', * ), * ... * ) * * @param array $config * @return array */ protected function _normalizeConfigData(array $config) { $result = array(); foreach ($config as $key => $value) { $row = array('suggestion' => null, 'class_scope' => null, 'directory' => null); if (is_string($key)) { $row = array_merge($row, $value); if ($row['suggestion']) { $row['suggestion'] = sprintf(self::SUGGESTION_MESSAGE, $row['suggestion']); } if ($row['directory']) { $row['directory'] = Utility_Files::init()->getPathToSource() . '/' . $row['directory']; } $result[$key] = $row; } else { $result[$value] = $row; } } return $result; }