XsdTest.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Test\Unit\Topology;
  7. class XsdTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var string
  11. */
  12. private $schemaFile;
  13. protected function setUp()
  14. {
  15. if (!function_exists('libxml_set_external_entity_loader')) {
  16. $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
  17. }
  18. $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
  19. $this->schemaFile = $urnResolver->getRealPath('urn:magento:framework-message-queue:etc/topology.xsd');
  20. }
  21. /**
  22. * @param string $fixtureXml
  23. * @param array $expectedErrors
  24. * @dataProvider exemplarXmlDataProvider
  25. */
  26. public function testExemplarXml($fixtureXml, array $expectedErrors)
  27. {
  28. $validationState = $this->createMock(\Magento\Framework\Config\ValidationStateInterface::class);
  29. $validationState->expects($this->any())
  30. ->method('isValidationRequired')
  31. ->willReturn(true);
  32. $messageFormat = '%message%';
  33. $dom = new \Magento\Framework\Config\Dom($fixtureXml, $validationState, [], null, null, $messageFormat);
  34. $actualErrors = [];
  35. $actualResult = $dom->validate($this->schemaFile, $actualErrors);
  36. $this->assertEquals(empty($expectedErrors), $actualResult, "Validation result is invalid.");
  37. $this->assertEquals($expectedErrors, $actualErrors, "Validation errors does not match.");
  38. }
  39. /**
  40. * @return array
  41. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  42. */
  43. public function exemplarXmlDataProvider()
  44. {
  45. // @codingStandardsIgnoreStart
  46. return [
  47. /** Valid configurations */
  48. 'valid' => [
  49. '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
  50. <exchange name="ex01" type="topic" connection="amqp"/>
  51. <exchange name="ex02" type="topic" connection="amqp-02" />
  52. <exchange name="ex03" autoDelete="true" durable="false" internal="true" type="topic" connection="db">
  53. <arguments>
  54. <argument name="arg1" xsi:type="string">10</argument>
  55. </arguments>
  56. </exchange>
  57. <exchange name="ex04" connection="amqp-03">
  58. <binding id="bind01" destinationType="queue" destination="queue01" topic="top01" disabled="true" />
  59. <binding id="bind02" destinationType="queue" destination="queue01" topic="top01">
  60. <arguments>
  61. <argument name="arg01" xsi:type="string">10</argument>
  62. </arguments>
  63. </binding>
  64. </exchange>
  65. </config>',
  66. [],
  67. ],
  68. 'non-unique-exchange' => [
  69. '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
  70. <exchange name="ex01" type="topic" connection="amqp"/>
  71. <exchange name="ex01" type="topic" connection="amqp" />
  72. </config>',
  73. [
  74. "Element 'exchange': Duplicate key-sequence ['ex01', 'amqp'] in unique identity-constraint 'unique-exchange-name-connection'."
  75. ],
  76. ],
  77. 'non-unique-exchange-binding' => [
  78. '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
  79. <exchange name="ex01" connection="amqp">
  80. <binding id="bind01" destinationType="queue" destination="queue01" topic="top01" disabled="true" />
  81. <binding id="bind01" destinationType="queue" destination="queue01" topic="top01" />
  82. </exchange>
  83. </config>',
  84. [
  85. "Element 'binding': Duplicate key-sequence ['bind01'] in unique identity-constraint 'unique-binding-id'."
  86. ],
  87. ],
  88. 'invalid-destination-type-binding' => [
  89. '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
  90. <exchange name="ex01" type="topic" connection="amqp">
  91. <binding id="bind01" destinationType="topic" destination="queue01" topic="top01" />
  92. </exchange>
  93. </config>',
  94. [
  95. "Element 'binding', attribute 'destinationType': [facet 'enumeration'] The value 'topic' is not an element of the set {'queue'}.",
  96. "Element 'binding', attribute 'destinationType': 'topic' is not a valid value of the atomic type 'destinationType'."
  97. ],
  98. ],
  99. 'invalid-exchange-type-binding' => [
  100. '<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
  101. <exchange name="ex01" type="exchange" connection="amqp">
  102. <binding id="bind01" destinationType="queue" destination="queue01" topic="top01" />
  103. </exchange>
  104. </config>',
  105. [
  106. "Element 'exchange', attribute 'type': [facet 'enumeration'] The value 'exchange' is not an element of the set {'topic'}.",
  107. "Element 'exchange', attribute 'type': 'exchange' is not a valid value of the atomic type 'exchangeType'."
  108. ],
  109. ],
  110. ];
  111. // @codingStandardsIgnoreEnd
  112. }
  113. }