BlockNamesTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. namespace Magento\Test\Integrity\Layout;
  9. class BlockNamesTest extends \PHPUnit\Framework\TestCase
  10. {
  11. public function testBlocksHasName()
  12. {
  13. $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
  14. $invoker(
  15. /**
  16. * Test validate that blocks without name doesn't exist in layout file
  17. *
  18. * @param string $layoutFile
  19. */
  20. function ($layoutFile) {
  21. $dom = new \DOMDocument();
  22. $dom->load($layoutFile);
  23. $xpath = new \DOMXpath($dom);
  24. $count = $xpath->query('//block[not(@name)]')->length;
  25. if ($count) {
  26. $this->fail('Following file contains ' . $count . ' blocks without name. ' .
  27. 'File Path:' . "\n" . $layoutFile);
  28. }
  29. },
  30. \Magento\Framework\App\Utility\Files::init()->getLayoutFiles()
  31. );
  32. }
  33. }