Skip to content

Commit b0f5a66

Browse files
committed
Add static test to detect blocks without name attribute
1 parent 117287f commit b0f5a66

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Test block names exists
4+
*
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
9+
namespace Magento\Test\Integrity\Layout;
10+
11+
class BlockNamesTest extends \PHPUnit\Framework\TestCase
12+
{
13+
public function testBlocksHasName()
14+
{
15+
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
16+
$invoker(
17+
/**
18+
* Test validate that blocks without name doesn't exist in layout file
19+
*
20+
* @param string $layoutFile
21+
*/
22+
function ($layoutFile) {
23+
$dom = new \DOMDocument();
24+
$dom->load($layoutFile);
25+
$xpath = new \DOMXpath($dom);
26+
$count = $xpath->query('//block[not(@name)]')->length;
27+
28+
if ($count) {
29+
$this->fail('Following file contains ' . $count . ' blocks without name. ' .
30+
'File Path:' . "\n" . $layoutFile);
31+
}
32+
},
33+
\Magento\Framework\App\Utility\Files::init()->getLayoutFiles()
34+
);
35+
}
36+
}

0 commit comments

Comments
 (0)