BulkStatusTest.php 2.47 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\AsynchronousOperations\Model;

use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface;

class BulkStatusTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var \Magento\AsynchronousOperations\Model\BulkStatus
     */
    private $model;

    protected function setUp()
    {
        $this->model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
            \Magento\AsynchronousOperations\Model\BulkStatus::class
        );
    }

    /**
     * @magentoDataFixture Magento/AsynchronousOperations/_files/bulk.php
     */
    public function testGetBulkStatus()
    {
        $this->assertEquals(BulkSummaryInterface::NOT_STARTED, $this->model->getBulkStatus('bulk-uuid-1'));
        $this->assertEquals(BulkSummaryInterface::IN_PROGRESS, $this->model->getBulkStatus('bulk-uuid-2'));
        $this->assertEquals(BulkSummaryInterface::FINISHED_SUCCESSFULLY, $this->model->getBulkStatus('bulk-uuid-4'));
        $this->assertEquals(BulkSummaryInterface::FINISHED_WITH_FAILURE, $this->model->getBulkStatus('bulk-uuid-5'));
    }

    /**
     * @magentoDataFixture Magento/AsynchronousOperations/_files/bulk.php
     */
    public function testGetBulksByUser()
    {
        /** @var \Magento\AsynchronousOperations\Model\BulkSummary[] $bulks */
        $bulksUuidArray = ['bulk-uuid-1', 'bulk-uuid-2', 'bulk-uuid-3', 'bulk-uuid-4', 'bulk-uuid-5'];
        $bulks =  $this->model->getBulksByUser(1);
        $this->assertEquals(5, count($bulks));
        foreach ($bulks as $bulk) {
            $this->assertTrue(in_array($bulk->getBulkId(), $bulksUuidArray));
        }
    }

    /**
     * @magentoDataFixture Magento/AsynchronousOperations/_files/bulk.php
     */
    public function testGetFailedOperationsByBulkId()
    {
        /** @var  \Magento\AsynchronousOperations\Api\Data\OperationInterface[] $operations */
        $operations =  $this->model->getFailedOperationsByBulkId('bulk-uuid-1');
        $this->assertEquals([], $operations);
        $operations =  $this->model->getFailedOperationsByBulkId('bulk-uuid-5', 3);
        foreach ($operations as $operation) {
            $this->assertEquals(1111, $operation->getErrorCode());
        }
        $operations =  $this->model->getFailedOperationsByBulkId('bulk-uuid-5', 2);
        foreach ($operations as $operation) {
            $this->assertEquals(2222, $operation->getErrorCode());
        }
    }
}