Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MergedXsdTest.php
Go to the documentation of this file.
1 <?php
7 
8 class MergedXsdTest extends \PHPUnit\Framework\TestCase
9 {
13  private $schemaFile;
14 
15  protected function setUp()
16  {
17  if (!function_exists('libxml_set_external_entity_loader')) {
18  $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
19  }
20  $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
21  $this->schemaFile = $urnResolver->getRealPath('urn:magento:framework-message-queue:etc/topology_merged.xsd');
22  }
23 
29  public function testExemplarXml($fixtureXml, array $expectedErrors)
30  {
31  $validationState = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
32  $validationState->expects($this->any())
33  ->method('isValidationRequired')
34  ->willReturn(true);
35  $messageFormat = '%message%';
36  $dom = new \Magento\Framework\Config\Dom($fixtureXml, $validationState, [], null, null, $messageFormat);
37  $actualErrors = [];
38  $actualResult = $dom->validate($this->schemaFile, $actualErrors);
39  $this->assertEquals(empty($expectedErrors), $actualResult, "Validation result is invalid.");
40  $this->assertEquals($expectedErrors, $actualErrors, "Validation errors does not match.");
41  }
42 
47  public function exemplarXmlDataProvider()
48  {
49  // @codingStandardsIgnoreStart
50  return [
52  'valid' => [
53  '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
54  <exchange name="ex01" type="topic" connection="amqp" />
55  <exchange name="ex02" type="topic" connection="amqp" />
56  <exchange name="ex03" autoDelete="true" durable="false" internal="true" type="topic" connection="db">
57  <arguments>
58  <argument name="arg1" xsi:type="string">10</argument>
59  </arguments>
60  </exchange>
61  <exchange name="ex04" type="topic" connection="amqp">
62  <binding id="bind01" destinationType="queue" destination="queue01" topic="top01" disabled="true" />
63  <binding id="bind02" destinationType="queue" destination="queue01" topic="top01">
64  <arguments>
65  <argument name="arg01" xsi:type="string">10</argument>
66  </arguments>
67  </binding>
68  </exchange>
69  </config>',
70  [],
71  ],
72  'non-unique-exchange' => [
73  '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
74  <exchange name="ex01" type="topic" connection="amqp"/>
75  <exchange name="ex01" type="topic" connection="amqp" />
76  </config>',
77  [
78  "Element 'exchange': Duplicate key-sequence ['ex01', 'amqp'] in unique identity-constraint 'unique-exchange-name-connection'."
79  ],
80  ],
81  'non-unique-exchange-binding' => [
82  '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
83  <exchange name="ex01" connection="amqp" type="topic">
84  <binding id="bind01" destinationType="queue" destination="queue01" topic="top01" disabled="true" />
85  <binding id="bind01" destinationType="queue" destination="queue01" topic="top01" />
86  </exchange>
87  </config>',
88  [
89  "Element 'binding': Duplicate key-sequence ['bind01'] in unique identity-constraint 'unique-binding-id'."
90  ],
91  ],
92  'invalid-destination-type-binding' => [
93  '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
94  <exchange name="ex01" type="topic" connection="amqp">
95  <binding id="bind01" destinationType="topic" destination="queue01" topic="top01" />
96  </exchange>
97  </config>',
98  [
99  "Element 'binding', attribute 'destinationType': [facet 'enumeration'] The value 'topic' is not an element of the set {'queue'}.",
100  "Element 'binding', attribute 'destinationType': 'topic' is not a valid value of the atomic type 'destinationType'."
101  ],
102  ],
103  'invalid-exchange-type-binding' => [
104  '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
105  <exchange name="ex01" type="exchange" connection="db">
106  <binding id="bind01" destinationType="queue" destination="queue01" topic="top01" />
107  </exchange>
108  </config>',
109  [
110  "Element 'exchange', attribute 'type': [facet 'enumeration'] The value 'exchange' is not an element of the set {'topic'}.",
111  "Element 'exchange', attribute 'type': 'exchange' is not a valid value of the atomic type 'exchangeType'."
112  ],
113  ],
114  'missed-required-attributes' => [
115  '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
116  <exchange name="ex01" type="topic" />
117  <exchange name="ex02" connection="amqp" />
118  </config>',
119  [
120  "Element 'exchange': The attribute 'connection' is required but missing.",
121  "Element 'exchange': The attribute 'type' is required but missing."
122  ],
123  ],
124  ];
125  // @codingStandardsIgnoreEnd
126  }
127 }