/**
  * @return array
  */
 public function allBlocksDataProvider()
 {
     $blockClass = '';
     try {
         /** @var $website \Magento\Store\Model\Website */
         \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->setWebsiteId(0);
         $enabledModules = $this->_getEnabledModules();
         $skipBlocks = $this->_getBlocksToSkip();
         $templateBlocks = [];
         $blockMods = \Magento\Framework\App\Utility\Classes::collectModuleClasses('Block');
         foreach ($blockMods as $blockClass => $module) {
             if (!isset($enabledModules[$module]) || isset($skipBlocks[$blockClass])) {
                 continue;
             }
             $class = new \ReflectionClass($blockClass);
             if ($class->isAbstract() || !$class->isSubclassOf('Magento\\Framework\\View\\Element\\Template')) {
                 continue;
             }
             $templateBlocks = $this->_addBlock($module, $blockClass, $class, $templateBlocks);
         }
         return $templateBlocks;
     } catch (\Exception $e) {
         trigger_error("Corrupted data provider. Last known block instantiation attempt: '{$blockClass}'." . " Exception: {$e}", E_USER_ERROR);
     }
 }
 public function testGetChildHtml()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $result = \Magento\Framework\App\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\Framework\App\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\Framework\App\Utility\Files::init()->getPhpFiles());
 }
 public function testGetChildHtml()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $result = \Magento\Framework\App\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\Framework\App\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));
     }, Files::init()->getPhpFiles(Files::INCLUDE_APP_CODE | Files::INCLUDE_PUB_CODE | Files::INCLUDE_LIBS | Files::INCLUDE_TEMPLATES | Files::INCLUDE_TESTS | Files::AS_DATA_SET | Files::INCLUDE_NON_CLASSES));
 }
Пример #4
0
 /**
  * @return array
  */
 public function getChildBlockDataProvider()
 {
     $result = [];
     foreach (Files::init()->getPhpFiles(true, false, true, false, false) as $file) {
         $aliases = \Magento\Framework\App\Utility\Classes::getAllMatches(file_get_contents($file), '/\\->getChildBlock\\(\'([^\']+)\'\\)/x');
         foreach ($aliases as $alias) {
             $result[$file] = [$alias, $file];
         }
     }
     return $result;
 }
Пример #5
0
 /**
  * @return array
  */
 public function getChildBlockDataProvider()
 {
     $result = [];
     $collectedFiles = Files::init()->getPhpFiles(Files::INCLUDE_APP_CODE | Files::INCLUDE_TEMPLATES | Files::INCLUDE_NON_CLASSES);
     foreach ($collectedFiles as $file) {
         $aliases = \Magento\Framework\App\Utility\Classes::getAllMatches(file_get_contents($file), '/\\->getChildBlock\\(\'([^\']+)\'\\)/x');
         foreach ($aliases as $alias) {
             $result[$file] = [$alias, $file];
         }
     }
     return $result;
 }
Пример #6
0
 public function testPaymentMethods()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($configFile, $moduleName) {
         $config = simplexml_load_file($configFile);
         $nodes = $config->xpath('/config/default/payment/*/model') ?: [];
         $formalModuleName = str_replace('_', '\\', $moduleName);
         foreach ($nodes as $node) {
             if (!Classes::isVirtual((string) $node)) {
                 $this->assertStringStartsWith($formalModuleName . '\\Model\\', (string) $node, "'{$node}' payment method is declared in '{$configFile}' module, " . "but doesn't belong to '{$moduleName}' module");
             }
         }
     }, $this->paymentMethodsDataProvider());
 }
Пример #7
0
 public function testLayouts()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($path) {
         $xml = simplexml_load_file($path);
         $classes = \Magento\Framework\App\Utility\Classes::collectLayoutClasses($xml);
         foreach (\Magento\Framework\App\Utility\Classes::getXmlAttributeValues($xml, '/layout//@helper', 'helper') as $class) {
             $classes[] = \Magento\Framework\App\Utility\Classes::getCallbackClass($class);
         }
         $classes = array_merge($classes, \Magento\Framework\App\Utility\Classes::getXmlAttributeValues($xml, '/layout//@module', 'module'));
         $this->_assertNonFactoryName(array_unique($classes), $path);
         $tabs = \Magento\Framework\App\Utility\Classes::getXmlNodeValues($xml, '/layout//action[@method="addTab"]/block');
         $this->_assertNonFactoryName(array_unique($tabs), $path, true);
     }, Files::init()->getLayoutFiles());
 }
Пример #8
0
 /**
  * Convert dom node tree to array
  *
  * @param \DOMDocument $source
  * @return array
  * @throws \InvalidArgumentException
  */
 public function convert($source)
 {
     $output = ['entities' => []];
     /** @var \DOMNodeList $entities */
     $entities = $source->getElementsByTagName('entity');
     /** @var \DOMNode $entityConfig */
     foreach ($entities as $entityConfig) {
         $attributes = $entityConfig->attributes;
         $name = $attributes->getNamedItem('name')->nodeValue;
         $label = $attributes->getNamedItem('label')->nodeValue;
         $behaviorModel = $attributes->getNamedItem('behaviorModel')->nodeValue;
         $model = $attributes->getNamedItem('model')->nodeValue;
         if (!$this->moduleManager->isOutputEnabled(Classes::getClassModuleName($model))) {
             continue;
         }
         $output['entities'][$name] = ['name' => $name, 'label' => $label, 'behaviorModel' => $behaviorModel, 'model' => $model, 'types' => [], 'relatedIndexers' => []];
     }
     /** @var \DOMNodeList $entityTypes */
     $entityTypes = $source->getElementsByTagName('entityType');
     /** @var \DOMNode $entityTypeConfig */
     foreach ($entityTypes as $entityTypeConfig) {
         $attributes = $entityTypeConfig->attributes;
         $name = $attributes->getNamedItem('name')->nodeValue;
         $model = $attributes->getNamedItem('model')->nodeValue;
         $entity = $attributes->getNamedItem('entity')->nodeValue;
         if (isset($output['entities'][$entity])) {
             $output['entities'][$entity]['types'][$name] = ['name' => $name, 'model' => $model];
         }
     }
     /** @var \DOMNodeList $relatedIndexers */
     $relatedIndexers = $source->getElementsByTagName('relatedIndexer');
     /** @var \DOMNode $relatedIndexerConfig */
     foreach ($relatedIndexers as $relatedIndexerConfig) {
         $attributes = $relatedIndexerConfig->attributes;
         $name = $attributes->getNamedItem('name')->nodeValue;
         $entity = $attributes->getNamedItem('entity')->nodeValue;
         if (isset($output['entities'][$entity])) {
             $output['entities'][$entity]['relatedIndexers'][$name] = ['name' => $name];
         }
     }
     return $output;
 }
Пример #9
0
 /**
  * Convert dom node tree to array
  *
  * @param \DOMDocument $source
  * @return array
  * @throws \InvalidArgumentException
  */
 public function convert($source)
 {
     $output = ['entities' => [], 'fileFormats' => []];
     /** @var \DOMNodeList $entities */
     $entities = $source->getElementsByTagName('entity');
     /** @var \DOMNode $entityConfig */
     foreach ($entities as $entityConfig) {
         $attributes = $entityConfig->attributes;
         $name = $attributes->getNamedItem('name')->nodeValue;
         $label = $attributes->getNamedItem('label')->nodeValue;
         $model = $attributes->getNamedItem('model')->nodeValue;
         if (!$this->moduleManager->isOutputEnabled(Classes::getClassModuleName($model))) {
             continue;
         }
         $entityAttributeFilterType = $attributes->getNamedItem('entityAttributeFilterType')->nodeValue;
         $output['entities'][$name] = ['name' => $name, 'label' => $label, 'model' => $model, 'types' => [], 'entityAttributeFilterType' => $entityAttributeFilterType];
     }
     /** @var \DOMNodeList $entityTypes */
     $entityTypes = $source->getElementsByTagName('entityType');
     /** @var \DOMNode $entityTypeConfig */
     foreach ($entityTypes as $entityTypeConfig) {
         $attributes = $entityTypeConfig->attributes;
         $model = $attributes->getNamedItem('model')->nodeValue;
         $name = $attributes->getNamedItem('name')->nodeValue;
         $entity = $attributes->getNamedItem('entity')->nodeValue;
         if (isset($output['entities'][$entity])) {
             $output['entities'][$entity]['types'][$name] = ['name' => $name, 'model' => $model];
         }
     }
     /** @var \DOMNodeList $fileFormats */
     $fileFormats = $source->getElementsByTagName('fileFormat');
     /** @var \DOMNode $fileFormatConfig */
     foreach ($fileFormats as $fileFormatConfig) {
         $attributes = $fileFormatConfig->attributes;
         $name = $attributes->getNamedItem('name')->nodeValue;
         $model = $attributes->getNamedItem('model')->nodeValue;
         $label = $attributes->getNamedItem('label')->nodeValue;
         $output['fileFormats'][$name] = ['name' => $name, 'model' => $model, 'label' => $label];
     }
     return $output;
 }
 /**
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function allTemplatesDataProvider()
 {
     $blockClass = '';
     try {
         /** @var $website \Magento\Store\Model\Website */
         \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->setWebsiteId(0);
         $templates = [];
         $skippedBlocks = $this->_getBlocksToSkip();
         foreach (\Magento\Framework\App\Utility\Classes::collectModuleClasses('Block') as $blockClass => $module) {
             if (!in_array($module, $this->_getEnabledModules()) || in_array($blockClass, $skippedBlocks)) {
                 continue;
             }
             $class = new \ReflectionClass($blockClass);
             if ($class->isAbstract() || !$class->isSubclassOf('Magento\\Framework\\View\\Element\\Template')) {
                 continue;
             }
             $area = 'frontend';
             if ($module == 'Magento_Backend' || strpos($blockClass, '\\Adminhtml\\') || strpos($blockClass, '\\Backend\\') || $class->isSubclassOf('Magento\\Backend\\Block\\Template')) {
                 $area = 'adminhtml';
             }
             \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\AreaList')->getArea($area)->load(\Magento\Framework\App\Area::PART_CONFIG);
             \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Config\\ScopeInterface')->setCurrentScope($area);
             \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\State')->setAreaCode($area);
             $context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\Http\\Context');
             $context->setValue(Context::CONTEXT_AUTH, false, false);
             $context->setValue(Context::CONTEXT_GROUP, \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID, \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID);
             $block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create($blockClass);
             $template = $block->getTemplate();
             if ($template) {
                 $templates[$module . ', ' . $template . ', ' . $blockClass . ', ' . $area] = [$module, $template, $blockClass, $area];
             }
         }
         return $templates;
     } catch (\Exception $e) {
         trigger_error("Corrupted data provider. Last known block instantiation attempt: '{$blockClass}'." . " Exception: {$e}", E_USER_ERROR);
     }
 }
Пример #11
0
 /**
  * Get application plugins
  *
  * @return array
  */
 protected function pluginDataProvider()
 {
     $files = \Magento\Framework\App\Utility\Files::init()->getDiConfigs();
     $plugins = [];
     foreach ($files as $file) {
         $dom = new \DOMDocument();
         $dom->load($file);
         $xpath = new \DOMXPath($dom);
         $pluginList = $xpath->query('//config/type/plugin');
         foreach ($pluginList as $node) {
             /** @var $node \DOMNode */
             $type = $node->parentNode->attributes->getNamedItem('name')->nodeValue;
             $type = \Magento\Framework\App\Utility\Classes::resolveVirtualType($type);
             if ($node->attributes->getNamedItem('type')) {
                 $plugin = $node->attributes->getNamedItem('type')->nodeValue;
                 $plugin = \Magento\Framework\App\Utility\Classes::resolveVirtualType($plugin);
                 $plugins[] = ['plugin' => $plugin, 'intercepted type' => $type];
             }
         }
     }
     return $plugins;
 }
Пример #12
0
                if (isPatternExist($content, $pattern, $factoryName)) {
                    if (!isset($map[$classType])) {
                        $map[$classType] = [];
                    }
                    $map[$classType][$factoryName] = getClassName($module, $classType, $name);
                }
            }
        }
    }
}
// layouts
$classType = 'Block';
$layouts = $utilityFiles->getLayoutFiles([], false);
foreach ($layouts as $file) {
    $xml = simplexml_load_file($file);
    $classes = \Magento\Framework\App\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
Пример #13
0
 /**
  * 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, $path)
 {
     if (!$classes) {
         return;
     }
     $badClasses = [];
     $badUsages = [];
     foreach ($classes as $class) {
         try {
             if (strrchr($class, '\\') === false and !Classes::isVirtual($class)) {
                 $badUsages[] = $class;
                 continue;
             } else {
                 $this->assertTrue(isset(self::$_existingClasses[$class]) || Files::init()->classFileExists($class) || Classes::isVirtual($class) || Classes::isAutogenerated($class));
             }
             self::$_existingClasses[$class] = 1;
         } catch (\PHPUnit_Framework_AssertionFailedError $e) {
             $badClasses[] = $class;
         }
     }
     if ($badClasses) {
         $this->fail("Files not found for following usages in {$path}:\n" . implode("\n", $badClasses));
     }
     if ($badUsages) {
         $this->fail("Bad usages of classes in {$path}: \n" . implode("\n", $badUsages));
     }
 }
Пример #14
0
    $factoryNames = array_filter($classes, 'isFactoryName');
    if (!$factoryNames) {
        continue;
    }
    $search = [];
    $replace = [];
    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 = \Magento\Framework\App\Utility\Files::init()->getConfigFiles('*.xml', ['wsdl.xml', 'wsdl2.xml', 'wsi.xml'], false);
foreach (array_merge($layouts, $configs) as $file) {
    $modules = array_unique(\Magento\Framework\App\Utility\Classes::getXmlAttributeValues(simplexml_load_file($file), '//@module', 'module'));
    $factoryNames = array_filter($modules, 'isFactoryName');
    if (!$factoryNames) {
        continue;
    }
    $search = [];
    $replace = [];
    foreach ($factoryNames as $factoryName) {
        list($module, $name) = getModuleName($factoryName);
        if ($module) {
            $search[] = 'module="' . $factoryName . '"';
            $replace[] = 'module="' . implode('\\', array_map('ucfirst', explode('_', $module))) . '"';
        } else {
            $search[] = 'module="' . $factoryName . '"';
            $replace[] = 'module="' . implode('\\', array_map('ucfirst', explode('_', $name))) . '"';
        }