123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Signifyd\Test\Unit\Model;
- use Magento\Sales\Api\OrderManagementInterface;
- use Magento\Sales\Model\Order;
- use Magento\Sales\Model\OrderFactory;
- use Magento\Signifyd\Api\Data\CaseInterface;
- use Magento\Signifyd\Model\CommentsHistoryUpdater;
- use Magento\Signifyd\Model\OrderStateService;
- use PHPUnit_Framework_MockObject_MockObject as MockObject;
- class OrderStateServiceTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var int
- */
- private static $orderId = 123;
- /**
- * @var OrderFactory|MockObject
- */
- private $orderFactory;
- /**
- * @var OrderManagementInterface|MockObject
- */
- private $orderManagement;
- /**
- * @var CommentsHistoryUpdater|MockObject
- */
- private $commentsHistoryUpdater;
- /**
- * @var CaseInterface|MockObject
- */
- private $caseEntity;
- /**
- * @var Order|MockObject
- */
- private $order;
- /**
- * @var OrderStateService
- */
- private $orderStateService;
- /**
- * @inheritdoc
- */
- protected function setUp()
- {
- $this->orderManagement = $this->getMockBuilder(OrderManagementInterface::class)
- ->getMockForAbstractClass();
- $this->commentsHistoryUpdater = $this->getMockBuilder(CommentsHistoryUpdater::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->orderFactory = $this->getMockBuilder(OrderFactory::class)
- ->setMethods(['create'])
- ->disableOriginalConstructor()
- ->getMock();
- $this->order = $this->getMockBuilder(Order::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->order->expects($this->once())
- ->method('load')
- ->willReturnSelf();
- $this->orderFactory->expects($this->once())
- ->method('create')
- ->willReturn($this->order);
- $this->caseEntity = $this->getMockBuilder(CaseInterface::class)
- ->disableOriginalConstructor()
- ->getMockForAbstractClass();
- $this->caseEntity->expects($this->once())
- ->method('getOrderId')
- ->willReturn(self::$orderId);
- $this->orderStateService = new OrderStateService(
- $this->orderFactory,
- $this->orderManagement,
- $this->commentsHistoryUpdater
- );
- }
- /**
- * Tests update order state flow when case guarantee disposition is PENDING.
- *
- * @param bool $canHold
- * @param bool $hold
- * @param int $addCommentCall
- * @dataProvider updateByCaseWithGuaranteePendingDataProvider
- */
- public function testUpdateByCaseWithGuaranteePending($canHold, $hold, $addCommentCall)
- {
- $this->caseEntity->expects($this->once())
- ->method('getGuaranteeDisposition')
- ->willReturn(CaseInterface::GUARANTEE_PENDING);
- $this->order->expects($this->any())
- ->method('canHold')
- ->willReturn($canHold);
- $this->orderManagement->expects($this->any())
- ->method('hold')
- ->willReturn($hold);
- $this->commentsHistoryUpdater->expects($this->exactly($addCommentCall))
- ->method('addComment')
- ->with(
- $this->caseEntity,
- __('Awaiting the Signifyd guarantee disposition.'),
- Order::STATE_HOLDED
- );
- $this->orderStateService->updateByCase($this->caseEntity);
- }
- /**
- * @return array
- */
- public function updateByCaseWithGuaranteePendingDataProvider()
- {
- return [
- ['canHold' => true, 'hold' => true, 'addCommentCall' => 1],
- ['canHold' => false, 'hold' => true, 'addCommentCall' => 0],
- ['canHold' => true, 'hold' => false, 'addCommentCall' => 0],
- ];
- }
- /**
- * Tests update order state flow when case guarantee disposition is APPROVED.
- *
- * @param bool $canUnhold
- * @param int $unholdCall
- * @dataProvider updateByCaseWithGuaranteeApprovedDataProvider
- */
- public function testUpdateByCaseWithGuaranteeApproved($canUnhold, $unholdCall)
- {
- $this->caseEntity->expects($this->once())
- ->method('getGuaranteeDisposition')
- ->willReturn(CaseInterface::GUARANTEE_APPROVED);
- $this->order->expects($this->any())
- ->method('canUnhold')
- ->willReturn($canUnhold);
- $this->orderManagement->expects($this->exactly($unholdCall))
- ->method('unHold');
- $this->commentsHistoryUpdater->expects($this->never())
- ->method('addComment');
- $this->orderStateService->updateByCase($this->caseEntity);
- }
- /**
- * @return array
- */
- public function updateByCaseWithGuaranteeApprovedDataProvider()
- {
- return [
- ['canUnhold' => true, 'unholdCall' => 1],
- ['canUnhold' => false, 'unholdCall' => 0]
- ];
- }
- /**
- * Tests update order state flow when case guarantee disposition is DECLINED.
- *
- * @param bool $canHold
- * @param int $holdCall
- * @dataProvider updateByCaseWithGuaranteeDeclinedDataProvider
- */
- public function testUpdateByCaseWithGuaranteeDeclined($canHold, $holdCall)
- {
- $this->caseEntity->expects($this->once())
- ->method('getGuaranteeDisposition')
- ->willReturn(CaseInterface::GUARANTEE_DECLINED);
- $this->order->expects($this->any())
- ->method('canHold')
- ->willReturn($canHold);
- $this->orderManagement->expects($this->exactly($holdCall))
- ->method('hold');
- $this->commentsHistoryUpdater->expects($this->never())
- ->method('addComment');
- $this->orderStateService->updateByCase($this->caseEntity);
- }
- /**
- * @return array
- */
- public function updateByCaseWithGuaranteeDeclinedDataProvider()
- {
- return [
- ['canHold' => true, 'holdCall' => 1],
- ['canHold' => false, 'holdCall' => 0]
- ];
- }
- }
|