CommunicationTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Test\Unit\Config\Converter;
  7. use Magento\Ui\Config\Converter\Communication;
  8. use Magento\Ui\Config\ConverterUtils;
  9. class CommunicationTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var Communication
  13. */
  14. private $converter;
  15. public function setUp()
  16. {
  17. $this->converter = new Communication(new ConverterUtils());
  18. }
  19. public function testExportsConvert()
  20. {
  21. $expectedResult = [
  22. 'name' => 'exports',
  23. 'xsi:type' => 'array',
  24. 'item' => [
  25. 'propertyOne' => [
  26. 'name' => 'propertyOne',
  27. 'xsi:type' => 'string',
  28. 'value' => 'valueOne',
  29. ],
  30. 'propertyTwo' => [
  31. 'name' => 'propertyTwo',
  32. 'xsi:type' => 'string',
  33. 'value' => 'valueTwo',
  34. ],
  35. ],
  36. ];
  37. $dom = new \DOMDocument('1.0', 'UTF-8');
  38. $dom->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'testForm.xml');
  39. $domXpath = new \DOMXPath($dom);
  40. $classes = $domXpath->query('//form/fieldset/settings/exports')->item(0);
  41. $this->assertEquals($expectedResult, $this->converter->convert($classes));
  42. }
  43. public function testImportsConvert()
  44. {
  45. $expectedResult = [
  46. 'name' => 'imports',
  47. 'xsi:type' => 'array',
  48. 'item' => [
  49. 'propertyOne' => [
  50. 'name' => 'propertyOne',
  51. 'xsi:type' => 'string',
  52. 'value' => 'valueOne',
  53. ],
  54. 'propertyTwo' => [
  55. 'name' => 'propertyTwo',
  56. 'xsi:type' => 'string',
  57. 'value' => 'valueTwo',
  58. ],
  59. ],
  60. ];
  61. $dom = new \DOMDocument('1.0', 'UTF-8');
  62. $dom->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'testForm.xml');
  63. $domXpath = new \DOMXPath($dom);
  64. $classes = $domXpath->query('//form/fieldset/settings/imports')->item(0);
  65. $this->assertEquals($expectedResult, $this->converter->convert($classes));
  66. }
  67. public function testListensConvert()
  68. {
  69. $expectedResult = [
  70. 'name' => 'listens',
  71. 'xsi:type' => 'array',
  72. 'item' => [
  73. 'propertyOne' => [
  74. 'name' => 'propertyOne',
  75. 'xsi:type' => 'string',
  76. 'value' => 'valueOne',
  77. ],
  78. 'propertyTwo' => [
  79. 'name' => 'propertyTwo',
  80. 'xsi:type' => 'string',
  81. 'value' => 'valueTwo',
  82. ],
  83. ],
  84. ];
  85. $dom = new \DOMDocument('1.0', 'UTF-8');
  86. $dom->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'testForm.xml');
  87. $domXpath = new \DOMXPath($dom);
  88. $classes = $domXpath->query('//form/fieldset/settings/listens')->item(0);
  89. $this->assertEquals($expectedResult, $this->converter->convert($classes));
  90. }
  91. public function testLinksConvert()
  92. {
  93. $expectedResult = [
  94. 'name' => 'links',
  95. 'xsi:type' => 'array',
  96. 'item' => [
  97. 'propertyOne' => [
  98. 'name' => 'propertyOne',
  99. 'xsi:type' => 'string',
  100. 'value' => 'valueOne',
  101. ],
  102. 'propertyTwo' => [
  103. 'name' => 'propertyTwo',
  104. 'xsi:type' => 'string',
  105. 'value' => 'valueTwo',
  106. ],
  107. ],
  108. ];
  109. $dom = new \DOMDocument('1.0', 'UTF-8');
  110. $dom->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'testForm.xml');
  111. $domXpath = new \DOMXPath($dom);
  112. $classes = $domXpath->query('//form/fieldset/settings/links')->item(0);
  113. $this->assertEquals($expectedResult, $this->converter->convert($classes));
  114. }
  115. }