/** * @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); } }
/** * @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); } }