Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HandlesTest.php
Go to the documentation of this file.
1 <?php
9 
10 class HandlesTest extends \PHPUnit\Framework\TestCase
11 {
15  public function testHandleDeclarations()
16  {
17  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
18  $invoker(
24  function ($layoutFile) {
25  $issues = [];
26  $node = simplexml_load_file($layoutFile);
27  $label = $node['label'];
28  $designAbstraction = $node['design_abstraction'];
29  if (!$label) {
30  if ($designAbstraction) {
31  $issues[] = 'Attribute "design_abstraction" is defined, but "label" is not';
32  }
33  }
34 
35  if ($issues) {
36  $this->fail("Issues found in handle declaration:\n" . implode("\n", $issues) . "\n");
37  }
38  },
40  );
41  }
42 
43  public function testContainerDeclarations()
44  {
45  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
46  $invoker(
52  function ($layoutFile) {
53  $issues = [];
54  $xml = simplexml_load_file($layoutFile);
55  $containers = $xml->xpath('/layout//container') ?: [];
57  foreach ($containers as $node) {
58  if (!isset($node['htmlTag']) && (isset($node['htmlId']) || isset($node['htmlClass']))) {
59  $issues[] = $node->asXML();
60  }
61  }
62  if ($issues) {
63  $this->fail(
64  'The following containers declare attribute "htmlId" and/or "htmlClass", but not "htmlTag":' .
65  "\n" .
66  implode(
67  "\n",
68  $issues
69  ) . "\n"
70  );
71  }
72  },
74  );
75  }
76 
77  public function testHeadBlockUsage()
78  {
79  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
80  $invoker(
86  function ($layoutFile) {
87  $dom = new \DOMDocument();
88  $dom->load($layoutFile);
89  $xpath = new \DOMXpath($dom);
90  if ($xpath->query("//*[@name='head']")->length) {
91  $this->fail('Following file contains deprecated head block. File Path:' . "\n" . $layoutFile);
92  }
93  },
95  );
96  }
97 }
$label
Definition: details.phtml:21