DataProviderTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AsynchronousOperations\Test\Unit\Ui\Component\Operation;
  7. use Magento\AsynchronousOperations\Ui\Component\Operation\DataProvider;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. class DataProviderTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var DataProvider
  13. */
  14. private $dataProvider;
  15. /**
  16. * @var \PHPUnit_Framework_MockObject_MockObject
  17. */
  18. private $bulkCollectionFactoryMock;
  19. /**
  20. * @var \PHPUnit_Framework_MockObject_MockObject
  21. */
  22. private $bulkCollectionMock;
  23. /**
  24. * @var \PHPUnit_Framework_MockObject_MockObject
  25. */
  26. private $operationDetailsMock;
  27. /**
  28. * @var \PHPUnit_Framework_MockObject_MockObject
  29. */
  30. private $requestMock;
  31. /**
  32. * @var \PHPUnit_Framework_MockObject_MockObject
  33. */
  34. private $bulkMock;
  35. /**
  36. * Set up
  37. *
  38. * @return void
  39. */
  40. protected function setUp()
  41. {
  42. $helper = new ObjectManager($this);
  43. $this->bulkCollectionFactoryMock = $this->createPartialMock(
  44. \Magento\AsynchronousOperations\Model\ResourceModel\Bulk\CollectionFactory::class,
  45. ['create']
  46. );
  47. $this->bulkCollectionMock = $this->createMock(
  48. \Magento\AsynchronousOperations\Model\ResourceModel\Bulk\Collection::class
  49. );
  50. $this->operationDetailsMock = $this->createMock(\Magento\AsynchronousOperations\Model\Operation\Details::class);
  51. $this->bulkMock = $this->createMock(\Magento\AsynchronousOperations\Model\BulkSummary::class);
  52. $this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
  53. $this->bulkCollectionFactoryMock
  54. ->expects($this->once())
  55. ->method('create')
  56. ->willReturn($this->bulkCollectionMock);
  57. $this->dataProvider = $helper->getObject(
  58. \Magento\AsynchronousOperations\Ui\Component\Operation\DataProvider::class,
  59. [
  60. 'name' => 'test-name',
  61. 'bulkCollectionFactory' => $this->bulkCollectionFactoryMock,
  62. 'operationDetails' => $this->operationDetailsMock,
  63. 'request' => $this->requestMock
  64. ]
  65. );
  66. }
  67. public function testGetData()
  68. {
  69. $testData = [
  70. 'id' => '1',
  71. 'uuid' => 'bulk-uuid1',
  72. 'user_id' => '2',
  73. 'description' => 'Description'
  74. ];
  75. $testOperationData = [
  76. 'operations_total' => 2,
  77. 'operations_successful' => 1,
  78. 'operations_failed' => 2
  79. ];
  80. $testSummaryData = [
  81. 'summary' => '2 items selected for mass update, 1 successfully updated, 2 failed to update'
  82. ];
  83. $resultData[$testData['id']] = array_merge($testData, $testOperationData, $testSummaryData);
  84. $this->bulkCollectionMock
  85. ->expects($this->once())
  86. ->method('getItems')
  87. ->willReturn([$this->bulkMock]);
  88. $this->bulkMock
  89. ->expects($this->once())
  90. ->method('getData')
  91. ->willReturn($testData);
  92. $this->operationDetailsMock
  93. ->expects($this->once())
  94. ->method('getDetails')
  95. ->with($testData['uuid'])
  96. ->willReturn($testOperationData);
  97. $this->bulkMock
  98. ->expects($this->once())
  99. ->method('getBulkId')
  100. ->willReturn($testData['id']);
  101. $expectedResult = $this->dataProvider->getData();
  102. $this->assertEquals($resultData, $expectedResult);
  103. }
  104. public function testPrepareMeta()
  105. {
  106. $resultData['retriable_operations']['arguments']['data']['disabled'] = true;
  107. $resultData['failed_operations']['arguments']['data']['disabled'] = true;
  108. $testData = [
  109. 'uuid' => 'bulk-uuid1',
  110. 'failed_retriable' => 0,
  111. 'failed_not_retriable' => 0
  112. ];
  113. $this->requestMock
  114. ->expects($this->once())
  115. ->method('getParam')
  116. ->willReturn($testData['uuid']);
  117. $this->operationDetailsMock
  118. ->expects($this->once())
  119. ->method('getDetails')
  120. ->with($testData['uuid'])
  121. ->willReturn($testData);
  122. $expectedResult = $this->dataProvider->prepareMeta([]);
  123. $this->assertEquals($resultData, $expectedResult);
  124. }
  125. }