/** * @return array */ public function allTemplatesDataProvider() { $templates = array(); foreach (Utility_Classes::collectModuleClasses('Block') as $blockClass => $module) { if (!in_array($module, $this->_getEnabledModules())) { continue; } $class = new ReflectionClass($blockClass); if ($class->isAbstract() || !$class->isSubclassOf('Mage_Core_Block_Template')) { continue; } $area = 'frontend'; if ($module == 'Mage_Install') { $area = 'install'; } elseif ($module == 'Mage_Adminhtml' || strpos($blockClass, '_Adminhtml_') || strpos($blockClass, '_Backend_') || $this->_isClassInstanceOf($blockClass, 'Mage_Backend_Block_Template')) { $area = 'adminhtml'; } Mage::getConfig()->setCurrentAreaCode($area); $block = new $blockClass(); $template = $block->getTemplate(); if ($template) { $templates[] = array($module, $template, $blockClass, $area); } } return $templates; }
/** * Tests if methods are used with correct count of parameters * * @param string $file * @dataProvider phpFilesDataProvider */ public function testGetChildHtml($file) { $result = 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 = 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)); }
/** * @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; }
$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); } /** * Whether the given class name is a factory name
/** * @param string $path * @dataProvider layoutFileDataProvider */ public function testLayouts($path) { $xml = simplexml_load_file($path); $classes = Utility_Classes::collectLayoutClasses($xml); foreach (Utility_Classes::getXmlAttributeValues($xml, '/layout//@helper', 'helper') as $class) { $classes[] = Utility_Classes::getCallbackClass($class); } $classes = array_merge($classes, Utility_Classes::getXmlAttributeValues($xml, '/layout//@module', 'module')); $this->_assertNonFactoryName(array_unique($classes)); $tabs = Utility_Classes::getXmlNodeValues($xml, '/layout//action[@method="addTab"]/block'); $this->_assertNonFactoryName(array_unique($tabs), true); }
if (isPatternExist($content, $pattern, $factoryName)) { if (!isset($map[$classType])) { $map[$classType] = array(); } $map[$classType][$factoryName] = getClassName($module, $classType, $name); } } } } } // layouts $classType = 'Block'; $layouts = $utilityFiles->getLayoutFiles(array(), false); foreach ($layouts as $file) { $xml = simplexml_load_file($file); $classes = Utility_Classes::collectLayoutClasses($xml); $factoryNames = array_filter($classes, 'isFactoryName'); if (!$factoryNames) { continue; } foreach ($factoryNames as $factoryName) { list($module, $name) = getModuleName($factoryName, $compositeModules); $map[$classType][$factoryName] = getClassName($module, $classType, $name); } } echo Zend_Json::prettyPrint(Zend_Json::encode($map)); /** * Get combined array from similar files by pattern * * @param string $dirPath * @param string $filePattern
/** * @param string $path * @dataProvider layoutFileDataProvider */ public function testLayoutFile($path) { $xml = simplexml_load_file($path); $classes = Utility_Classes::getXmlNodeValues($xml, '/layout//*[contains(text(), "_Block_") or contains(text(), "_Model_") or contains(text(), "_Helper_")]'); foreach (Utility_Classes::getXmlAttributeValues($xml, '/layout//@helper', 'helper') as $class) { $classes[] = Utility_Classes::getCallbackClass($class); } foreach (Utility_Classes::getXmlAttributeValues($xml, '/layout//@module', 'module') as $module) { $classes[] = "{$module}_Helper_Data"; } $classes = array_merge($classes, Utility_Classes::collectLayoutClasses($xml)); $this->_assertClassesExist(array_unique($classes)); }