ActionsTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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\Actions;
  8. use Magento\Ui\Config\ConverterInterface;
  9. use Magento\Ui\Config\ConverterUtils;
  10. class ActionsTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var Actions
  14. */
  15. private $converter;
  16. /**
  17. * @var ConverterInterface|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $urlConverter;
  20. public function setUp()
  21. {
  22. $this->urlConverter = $this->getMockBuilder(ConverterInterface::class)->getMockForAbstractClass();
  23. $this->converter = new Actions($this->urlConverter, new ConverterUtils());
  24. }
  25. /**
  26. * @param array $expectedResult
  27. * @param string $xpath
  28. * @dataProvider convertDataProvider
  29. */
  30. public function testConvert(array $expectedResult, $xpath)
  31. {
  32. $dom = new \DOMDocument('1.0', 'UTF-8');
  33. $dom->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.xml');
  34. $domXpath = new \DOMXPath($dom);
  35. $actions = $domXpath->query($xpath)->item(0);
  36. $urlResult = [
  37. 'name' => 'url',
  38. 'xsi:type' => 'url',
  39. 'path' => 'url',
  40. 'param' => [
  41. 'first' => [
  42. 'name' => 'first',
  43. 'value' => 'first_value'
  44. ],
  45. 'second' => [
  46. 'name' => 'second',
  47. 'value' => 'second_value'
  48. ],
  49. ],
  50. ];
  51. $this->urlConverter->expects($this->any())
  52. ->method('convert')
  53. ->willReturn($urlResult);
  54. $this->assertEquals($expectedResult, $this->converter->convert($actions));
  55. }
  56. /**
  57. * @return array
  58. */
  59. public function convertDataProvider()
  60. {
  61. return [
  62. [
  63. [
  64. 'name' => 'actions',
  65. 'xsi:type' => 'array',
  66. 'item' => [
  67. 'action_one' => [
  68. 'name' => 'action_one',
  69. 'xsi:type' => 'array',
  70. 'item' => [
  71. 'label' => [
  72. 'name' => 'label',
  73. 'xsi:type' => 'string',
  74. 'translate' => 'true',
  75. 'value' => 'Label Actions One',
  76. ],
  77. 'custom_param_one' => [
  78. 'name' => 'custom_param_one',
  79. 'xsi:type' => 'string',
  80. 'value' => 'custom_value_one'
  81. ],
  82. 'type' => [
  83. 'name' => 'type',
  84. 'xsi:type' => 'string',
  85. 'value' => 'action_one_type',
  86. ],
  87. 'url' => [
  88. 'name' => 'url',
  89. 'xsi:type' => 'url',
  90. 'path' => 'url',
  91. 'param' => [
  92. 'first' => [
  93. 'name' => 'first',
  94. 'value' => 'first_value'
  95. ],
  96. 'second' => [
  97. 'name' => 'second',
  98. 'value' => 'second_value'
  99. ],
  100. ],
  101. ],
  102. ],
  103. ],
  104. 'action_two' => [
  105. 'name' => 'action_two',
  106. 'xsi:type' => 'array',
  107. 'item' => [
  108. 'label' => [
  109. 'name' => 'label',
  110. 'xsi:type' => 'string',
  111. 'translate' => 'true',
  112. 'value' => 'Label Actions Two',
  113. ],
  114. 'custom_param_two' => [
  115. 'name' => 'custom_param_two',
  116. 'xsi:type' => 'string',
  117. 'value' => 'custom_value_two'
  118. ],
  119. 'type' => [
  120. 'name' => 'type',
  121. 'xsi:type' => 'string',
  122. 'value' => 'action_two_type',
  123. ],
  124. 'url' => [
  125. 'name' => 'url',
  126. 'xsi:type' => 'url',
  127. 'path' => 'url',
  128. 'param' => [
  129. 'first' => [
  130. 'name' => 'first',
  131. 'value' => 'first_value'
  132. ],
  133. 'second' => [
  134. 'name' => 'second',
  135. 'value' => 'second_value'
  136. ],
  137. ],
  138. ],
  139. ],
  140. ],
  141. ],
  142. ],
  143. '//listing/listingToolbar/massaction[@name="listing_massaction"]/settings/actions'
  144. ],
  145. [
  146. [
  147. 'name' => 'actions',
  148. 'xsi:type' => 'object',
  149. 'value' => 'Some_Actions_Class'
  150. ],
  151. '//listing/listingToolbar/massaction[@name="listing_massaction"]/action/settings/actions'
  152. ]
  153. ];
  154. }
  155. }