MassActionTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Test\Unit\Component;
  7. use Magento\Ui\Component\MassAction;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. use Magento\Framework\View\Element\UiComponent\ContextInterface;
  10. /**
  11. * Class MassActionTest
  12. */
  13. class MassActionTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var ContextInterface|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $contextMock;
  19. /**
  20. * @var ObjectManager
  21. */
  22. protected $objectManager;
  23. /**
  24. * Set up
  25. */
  26. protected function setUp()
  27. {
  28. $this->objectManager = new ObjectManager($this);
  29. $this->contextMock = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
  30. ->getMockForAbstractClass();
  31. }
  32. /**
  33. * Run test getComponentName method
  34. *
  35. * @return void
  36. */
  37. public function testGetComponentName()
  38. {
  39. $this->contextMock->expects($this->never())->method('getProcessor');
  40. /** @var MassAction $massAction */
  41. $massAction = $this->objectManager->getObject(
  42. \Magento\Ui\Component\MassAction::class,
  43. [
  44. 'context' => $this->contextMock,
  45. 'data' => []
  46. ]
  47. );
  48. $this->assertTrue($massAction->getComponentName() === MassAction::NAME);
  49. }
  50. /**
  51. * Run test prepare method
  52. *
  53. * @param string $componentName
  54. * @param array $componentData
  55. * @return void
  56. * @dataProvider getPrepareDataProvider
  57. */
  58. public function testPrepare($componentName, $componentData)
  59. {
  60. $processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
  61. ->disableOriginalConstructor()
  62. ->getMock();
  63. $this->contextMock->expects($this->atLeastOnce())->method('getProcessor')->willReturn($processor);
  64. /** @var \Magento\Ui\Component\Action $action */
  65. $action = $this->objectManager->getObject(
  66. \Magento\Ui\Component\MassAction::class,
  67. [
  68. 'context' => $this->contextMock,
  69. 'data' => [
  70. 'name' => $componentName,
  71. 'config' => $componentData,
  72. ]
  73. ]
  74. );
  75. /** @var MassAction $massAction */
  76. $massAction = $this->objectManager->getObject(
  77. \Magento\Ui\Component\MassAction::class,
  78. [
  79. 'context' => $this->contextMock,
  80. 'data' => []
  81. ]
  82. );
  83. $massAction->addComponent('action', $action);
  84. $massAction->prepare();
  85. $this->assertEquals(['actions' => [$action->getConfiguration()]], $massAction->getConfiguration());
  86. }
  87. /**
  88. * @return array
  89. */
  90. public function getPrepareDataProvider()
  91. {
  92. return [
  93. [
  94. 'test_component1',
  95. [
  96. 'type' => 'first_action',
  97. 'label' => 'First Action',
  98. 'url' => '/module/controller/firstAction'
  99. ],
  100. ],
  101. [
  102. 'test_component2',
  103. [
  104. 'type' => 'second_action',
  105. 'label' => 'Second Action',
  106. 'actions' => [
  107. [
  108. 'type' => 'second_sub_action1',
  109. 'label' => 'Second Sub Action 1',
  110. 'url' => '/module/controller/secondSubAction1'
  111. ],
  112. [
  113. 'type' => 'second_sub_action2',
  114. 'label' => 'Second Sub Action 2',
  115. 'url' => '/module/controller/secondSubAction2'
  116. ],
  117. ]
  118. ],
  119. ],
  120. ];
  121. }
  122. }