Skip to content

Commit d1126e7

Browse files
committed
Fix #24656: add tests for layout XML validation
1 parent 20a97cd commit d1126e7

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Test\Integrity\Modular;
7+
8+
class LayoutConfigFilesTest extends \PHPUnit\Framework\TestCase
9+
{
10+
/**
11+
* Path to schema file
12+
*
13+
* @var string
14+
*/
15+
protected $schemaFile;
16+
17+
protected function setUp()
18+
{
19+
$urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
20+
$this->schemaFile = $urnResolver->getRealPath('urn:magento:framework:View/Layout/etc/elements.xsd');
21+
}
22+
23+
/**
24+
* Test a valid layout XML file
25+
*/
26+
public function testValidLayoutXmlFile()
27+
{
28+
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
29+
$validationStateMock->method('isValidationRequired')->willReturn(true);
30+
$domConfig = new \Magento\Framework\Config\Dom(
31+
'<referenceBlock name="product.info.something" group="column_left"></referenceBlock>',
32+
$validationStateMock
33+
);
34+
$result = $domConfig->validate($this->schemaFile, $errors);
35+
$this->assertTrue($result);
36+
$this->assertEmpty($errors);
37+
}
38+
39+
/**
40+
* Test a layout XML file having an invalid tag element
41+
*/
42+
public function testBrokenLayoutXmlFile()
43+
{
44+
$validationStateMock = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
45+
$validationStateMock->method('isValidationRequired')->willReturn(true);
46+
$domConfig = new \Magento\Framework\Config\Dom(
47+
'<invalidElement name="some.name"></invalidElement>',
48+
$validationStateMock
49+
);
50+
$result = $domConfig->validate($this->schemaFile, $errors);
51+
$this->assertFalse($result);
52+
$this->assertNotEmpty($errors);
53+
}
54+
}

0 commit comments

Comments
 (0)