Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes
LayoutTest Class Reference
Inheritance diagram for LayoutTest:

Public Member Functions

 testPageTypesDeclaration ()
 
 testOverrideBaseFiles ()
 
 testOverrideThemeFiles ()
 
 overrideBaseFilesDataProvider ()
 
 overrideThemeFilesDataProvider ()
 

Static Public Member Functions

static setUpBeforeClass ()
 
static tearDownAfterClass ()
 

Protected Member Functions

 _collectHierarchyErrors ($node, $xml, &$errors)
 

Static Protected Member Functions

static _getCachedFiles ( $cacheKey, $sourceClass, \Magento\Framework\View\Design\ThemeInterface $theme)
 

Static Protected Attributes

static $_cachedFiles = []
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 14 of file LayoutTest.php.

Member Function Documentation

◆ _collectHierarchyErrors()

_collectHierarchyErrors (   $node,
  $xml,
$errors 
)
protected

Validate node's declared position in hierarchy and add errors to the specified array if found

Parameters
\SimpleXMLElement$node
\Magento\Framework\View\Layout\Element$xml
array&$errors

Definition at line 58 of file LayoutTest.php.

59  {
60  $name = $node->getName();
61  $refName = $node->getAttribute('type') == $node->getAttribute('parent');
62  if ($refName) {
63  $refNode = $xml->xpath("/layouts/{$refName}");
64  if (!$refNode) {
65  $errors[$name][] = "Node '{$refName}', referenced in hierarchy, does not exist";
66  }
67  }
68  }
$errors
Definition: overview.phtml:9
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ _getCachedFiles()

static _getCachedFiles (   $cacheKey,
  $sourceClass,
\Magento\Framework\View\Design\ThemeInterface  $theme 
)
staticprotected

Retrieve list of cached source files

Parameters
string$cacheKey
string$sourceClass
\Magento\Framework\View\Design\ThemeInterface$theme
Returns
\Magento\Framework\View\File[]

Definition at line 269 of file LayoutTest.php.

273  {
274  if (!isset(self::$_cachedFiles[$cacheKey])) {
275  /* @var $fileList \Magento\Framework\View\File[] */
277  ->create($sourceClass, ['subDir' => 'layout'])->getFiles($theme, '*.xml');
278  $files = [];
279  foreach ($fileList as $file) {
280  $files[$file->getModule() . '/' . $file->getName()] = true;
281  }
282  self::$_cachedFiles[$cacheKey] = $files;
283  }
284  return self::$_cachedFiles[$cacheKey];
285  }
$fileList
Definition: export.php:13
$theme
foreach($appDirs as $dir) $files

◆ overrideBaseFilesDataProvider()

overrideBaseFilesDataProvider ( )
Returns
array

Definition at line 290 of file LayoutTest.php.

291  {
292  return $this->_retrieveFilesForEveryTheme(
293  \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
294  ->create(
295  \Magento\Framework\View\File\Collector\Override\Base::class,
296  ['subDir' => 'layout/override/base']
297  )
298  );
299  }

◆ overrideThemeFilesDataProvider()

overrideThemeFilesDataProvider ( )
Returns
array

Definition at line 304 of file LayoutTest.php.

305  {
306  return $this->_retrieveFilesForEveryTheme(
307  \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
308  ->create(
309  \Magento\Framework\View\File\Collector\Override\ThemeModular::class,
310  ['subDir' => 'layout/override/theme']
311  )
312  );
313  }

◆ setUpBeforeClass()

static setUpBeforeClass ( )
static

Definition at line 23 of file LayoutTest.php.

24  {
26  ['preferences' => [\Magento\Theme\Model\Theme::class => \Magento\Theme\Model\Theme\Data::class]]
27  );
28  }

◆ tearDownAfterClass()

static tearDownAfterClass ( )
static

Definition at line 30 of file LayoutTest.php.

31  {
32  self::$_cachedFiles = []; // Free memory
33  }

◆ testOverrideBaseFiles()

testOverrideBaseFiles ( )

Check, that for an overriding file ($themeFile) in a theme ($theme), there is a corresponding base file

Parameters
\Magento\Framework\View\File$themeFile
\Magento\Framework\View\Design\ThemeInterface$theme

Definition at line 184 of file LayoutTest.php.

185  {
186  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
187  $invoker(
194  function ($themeFile, $theme) {
195  $baseFiles = self::_getCachedFiles(
196  $theme->getArea(),
197  \Magento\Framework\View\File\Collector\Base::class,
198  $theme
199  );
200  $fileKey = $themeFile->getModule() . '/' . $themeFile->getName();
201  $this->assertArrayHasKey(
202  $fileKey,
203  $baseFiles,
204  sprintf("Could not find base file, overridden by theme file '%s'.", $themeFile->getFilename())
205  );
206  },
208  );
209  }
static _getCachedFiles( $cacheKey, $sourceClass, \Magento\Framework\View\Design\ThemeInterface $theme)
Definition: LayoutTest.php:269
$theme

◆ testOverrideThemeFiles()

testOverrideThemeFiles ( )

Check, that for an ancestor-overriding file ($themeFile) in a theme ($theme), there is a corresponding file in that ancestor theme

Parameters
\Magento\Framework\View\File$themeFile
\Magento\Framework\View\Design\ThemeInterface$theme

Definition at line 211 of file LayoutTest.php.

212  {
213  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
214  $invoker(
222  function ($themeFile, $theme) {
223  // Find an ancestor theme, where a file is to be overridden
224  $ancestorTheme = $theme;
225  while ($ancestorTheme = $ancestorTheme->getParentTheme()) {
226  if ($ancestorTheme == $themeFile->getTheme()) {
227  break;
228  }
229  }
230  $this->assertNotNull(
231  $ancestorTheme,
232  sprintf(
233  'Could not find ancestor theme "%s", ' .
234  'its layout file is supposed to be overridden by file "%s".',
235  $themeFile->getTheme()->getCode(),
236  $themeFile->getFilename()
237  )
238  );
239 
240  // Search for the overridden file in the ancestor theme
241  $ancestorFiles = self::_getCachedFiles(
242  $ancestorTheme->getFullPath(),
243  \Magento\Framework\View\File\Collector\ThemeModular::class,
244  $ancestorTheme
245  );
246  $fileKey = $themeFile->getModule() . '/' . $themeFile->getName();
247  $this->assertArrayHasKey(
248  $fileKey,
249  $ancestorFiles,
250  sprintf(
251  "Could not find original file in '%s' theme, overridden by file '%s'.",
252  $themeFile->getTheme()->getCode(),
253  $themeFile->getFilename()
254  )
255  );
256  },
258  );
259  }
static _getCachedFiles( $cacheKey, $sourceClass, \Magento\Framework\View\Design\ThemeInterface $theme)
Definition: LayoutTest.php:269
$theme

◆ testPageTypesDeclaration()

testPageTypesDeclaration ( )

Check whether page types are declared only in layout update files allowed for it - base ones

Definition at line 132 of file LayoutTest.php.

133  {
134  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
135  $invoker(
139  function (\Magento\Framework\View\File $layout) {
140  $content = simplexml_load_file($layout->getFilename());
141  $this->assertEmpty(
142  $content->xpath(\Magento\Framework\View\Model\Layout\Merge::XPATH_HANDLE_DECLARATION),
143  "Theme layout update '" . $layout->getFilename() . "' contains page type declaration(s)"
144  );
145  },
146  $this->pageTypesDeclarationDataProvider()
147  );
148  }

Field Documentation

◆ $_cachedFiles

$_cachedFiles = []
staticprotected

Definition at line 21 of file LayoutTest.php.


The documentation for this class was generated from the following file: