Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TemplateFilesTest.php
Go to the documentation of this file.
1 <?php
7 
9 
15 {
16  public function testAllTemplates()
17  {
18  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
19  $invoker(
20  function ($module, $template, $class, $area) {
22  \Magento\Framework\View\DesignInterface::class
23  )->setDefaultDesignTheme();
24  // intentionally to make sure the module files will be requested
25  $params = [
26  'area' => $area,
28  \Magento\Framework\View\Design\ThemeInterface::class
29  ),
30  'module' => $module,
31  ];
32  $file = \Magento\TestFramework\Helper\Bootstrap::getObjectmanager()->get(
33  \Magento\Framework\View\FileSystem::class
34  )->getTemplateFileName(
35  $template,
36  $params
37  );
38  $this->assertInternalType('string', $file, "Block class: {$class} {$template}");
39  $this->assertFileExists($file, "Block class: {$class}");
40  },
41  $this->allTemplatesDataProvider()
42  );
43  }
44 
49  public function allTemplatesDataProvider()
50  {
51  $blockClass = '';
52  try {
55  \Magento\Store\Model\StoreManagerInterface::class
56  )->getStore()->setWebsiteId(
57  0
58  );
59 
60  $templates = [];
61  $skippedBlocks = $this->_getBlocksToSkip();
62  foreach (\Magento\Framework\App\Utility\Classes::collectModuleClasses('Block') as $blockClass => $module) {
63  if (!in_array($module, $this->_getEnabledModules()) || in_array($blockClass, $skippedBlocks)) {
64  continue;
65  }
66  $class = new \ReflectionClass($blockClass);
67  if ($class->isAbstract() || !$class->isSubclassOf(\Magento\Framework\View\Element\Template::class)) {
68  continue;
69  }
70 
71  $area = 'frontend';
72  if ($module == 'Magento_Backend' || strpos(
73  $blockClass,
74  '\\Adminhtml\\'
75  ) !== false || strpos(
76  $blockClass,
77  '\\Backend\\'
78  ) !== false || $class->isSubclassOf(
79  \Magento\Backend\Block\Template::class
80  )
81  ) {
82  $area = 'adminhtml';
83  }
84 
86  \Magento\Framework\App\AreaList::class
87  )->getArea(
88  $area
89  )->load(
90  \Magento\Framework\App\Area::PART_CONFIG
91  );
93  \Magento\Framework\Config\ScopeInterface::class
94  )->setCurrentScope(
95  $area
96  );
98  \Magento\Framework\App\State::class
99  )->setAreaCode(
100  $area
101  );
103  \Magento\Framework\App\Http\Context::class
104  );
105  $context->setValue(Context::CONTEXT_AUTH, false, false);
106  $context->setValue(
108  \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID,
109  \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID
110  );
112  $template = $block->getTemplate();
113  if ($template) {
114  $templates[$module . ', ' . $template . ', ' . $blockClass . ', ' . $area] = [
115  $module,
116  $template,
117  $blockClass,
118  $area,
119  ];
120  }
121  }
122  return $templates;
123  } catch (\Exception $e) {
124  trigger_error(
125  "Corrupted data provider. Last known block instantiation attempt: '{$blockClass}'." .
126  " Exception: {$e}",
127  E_USER_ERROR
128  );
129  }
130  }
131 
135  protected function _getBlocksToSkip()
136  {
137  $result = [];
138  foreach (glob(__DIR__ . '/_files/skip_template_blocks*.php') as $file) {
139  $blocks = include $file;
140  $result = array_merge($result, $blocks);
141  }
142  return array_combine($result, $result);
143  }
144 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$block
Definition: block.php:8
$_option $_optionId $class
Definition: date.phtml:13
static collectModuleClasses($subTypePattern='[A-Za-z]+')
Definition: Classes.php:187
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
$template
Definition: export.php:12