BulkStatusTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AsynchronousOperations\Model;
  7. use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface;
  8. class BulkStatusTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\AsynchronousOperations\Model\BulkStatus
  12. */
  13. private $model;
  14. protected function setUp()
  15. {
  16. $this->model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  17. \Magento\AsynchronousOperations\Model\BulkStatus::class
  18. );
  19. }
  20. /**
  21. * @magentoDataFixture Magento/AsynchronousOperations/_files/bulk.php
  22. */
  23. public function testGetBulkStatus()
  24. {
  25. $this->assertEquals(BulkSummaryInterface::NOT_STARTED, $this->model->getBulkStatus('bulk-uuid-1'));
  26. $this->assertEquals(BulkSummaryInterface::IN_PROGRESS, $this->model->getBulkStatus('bulk-uuid-2'));
  27. $this->assertEquals(BulkSummaryInterface::FINISHED_SUCCESSFULLY, $this->model->getBulkStatus('bulk-uuid-4'));
  28. $this->assertEquals(BulkSummaryInterface::FINISHED_WITH_FAILURE, $this->model->getBulkStatus('bulk-uuid-5'));
  29. }
  30. /**
  31. * @magentoDataFixture Magento/AsynchronousOperations/_files/bulk.php
  32. */
  33. public function testGetBulksByUser()
  34. {
  35. /** @var \Magento\AsynchronousOperations\Model\BulkSummary[] $bulks */
  36. $bulksUuidArray = ['bulk-uuid-1', 'bulk-uuid-2', 'bulk-uuid-3', 'bulk-uuid-4', 'bulk-uuid-5'];
  37. $bulks = $this->model->getBulksByUser(1);
  38. $this->assertEquals(5, count($bulks));
  39. foreach ($bulks as $bulk) {
  40. $this->assertTrue(in_array($bulk->getBulkId(), $bulksUuidArray));
  41. }
  42. }
  43. /**
  44. * @magentoDataFixture Magento/AsynchronousOperations/_files/bulk.php
  45. */
  46. public function testGetFailedOperationsByBulkId()
  47. {
  48. /** @var \Magento\AsynchronousOperations\Api\Data\OperationInterface[] $operations */
  49. $operations = $this->model->getFailedOperationsByBulkId('bulk-uuid-1');
  50. $this->assertEquals([], $operations);
  51. $operations = $this->model->getFailedOperationsByBulkId('bulk-uuid-5', 3);
  52. foreach ($operations as $operation) {
  53. $this->assertEquals(1111, $operation->getErrorCode());
  54. }
  55. $operations = $this->model->getFailedOperationsByBulkId('bulk-uuid-5', 2);
  56. foreach ($operations as $operation) {
  57. $this->assertEquals(2222, $operation->getErrorCode());
  58. }
  59. }
  60. }