Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CancelGuaranteeAbilityTest.php
Go to the documentation of this file.
1 <?php
7 
15 
19 class CancelGuaranteeAbilityTest extends \PHPUnit\Framework\TestCase
20 {
24  private $orderRepository;
25 
29  private $caseManagement;
30 
34  private $cancelGuaranteeAbility;
35 
39  protected function setUp()
40  {
41  $this->orderRepository = $this->getMockBuilder(OrderRepositoryInterface::class)
42  ->getMockForAbstractClass();
43 
44  $this->caseManagement = $this->getMockBuilder(CaseManagement::class)
45  ->disableOriginalConstructor()
46  ->getMock();
47 
48  $this->cancelGuaranteeAbility = new CancelGuaranteeAbility(
49  $this->caseManagement,
50  $this->orderRepository
51  );
52  }
53 
57  public function testIsAvailableSuccess()
58  {
59  $orderId = 123;
60 
62  $case = $this->getMockBuilder(CaseInterface::class)
63  ->disableOriginalConstructor()
64  ->getMock();
65 
66  $case->expects($this->once())
67  ->method('getGuaranteeDisposition')
68  ->willReturn(CaseEntity::GUARANTEE_APPROVED);
69 
70  $this->caseManagement->expects($this->once())
71  ->method('getByOrderId')
72  ->with($orderId)
73  ->willReturn($case);
74 
76  $order = $this->getMockBuilder(OrderInterface::class)
77  ->getMockForAbstractClass();
78 
79  $this->orderRepository->expects($this->once())
80  ->method('get')
81  ->with($orderId)
82  ->willReturn($order);
83 
84  $this->assertTrue($this->cancelGuaranteeAbility->isAvailable($orderId));
85  }
86 
90  public function testIsAvailableWithNullCase()
91  {
92  $orderId = 123;
93 
94  $this->caseManagement->expects($this->once())
95  ->method('getByOrderId')
96  ->with($orderId)
97  ->willReturn(null);
98 
99  $this->assertFalse($this->cancelGuaranteeAbility->isAvailable($orderId));
100  }
101 
105  public function testIsAvailableWithCanceledGuarantee()
106  {
107  $orderId = 123;
108 
110  $case = $this->getMockBuilder(CaseInterface::class)
111  ->disableOriginalConstructor()
112  ->getMock();
113 
114  $case->expects($this->once())
115  ->method('getGuaranteeDisposition')
116  ->willReturn(CaseEntity::GUARANTEE_CANCELED);
117 
118  $this->caseManagement->expects($this->once())
119  ->method('getByOrderId')
120  ->with($orderId)
121  ->willReturn($case);
122 
123  $this->assertFalse($this->cancelGuaranteeAbility->isAvailable($orderId));
124  }
125 
129  public function testIsAvailableWithNullOrder()
130  {
131  $orderId = 123;
132 
134  $case = $this->getMockBuilder(CaseInterface::class)
135  ->disableOriginalConstructor()
136  ->getMock();
137 
138  $case->expects($this->once())
139  ->method('getGuaranteeDisposition')
140  ->willReturn(CaseEntity::GUARANTEE_APPROVED);
141 
142  $this->caseManagement->expects($this->once())
143  ->method('getByOrderId')
144  ->with($orderId)
145  ->willReturn($case);
146 
147  $this->orderRepository->expects($this->once())
148  ->method('get')
149  ->with($orderId)
150  ->willThrowException(new NoSuchEntityException());
151 
152  $this->assertFalse($this->cancelGuaranteeAbility->isAvailable($orderId));
153  }
154 }
$case
$order
Definition: order.php:55