Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CanRefundTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class CanRefundTest extends \PHPUnit\Framework\TestCase
14 {
18  private $model;
19 
23  private $objectManager;
24 
28  private $orderMock;
29 
33  private $priceCurrencyMock;
34 
35  protected function setUp()
36  {
37  $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
38 
39  $this->orderMock = $this->getMockBuilder(\Magento\Sales\Api\Data\OrderInterface::class)
40  ->disableOriginalConstructor()
41  ->setMethods(['getStatus', 'getItems'])
42  ->getMockForAbstractClass();
43 
44  $this->priceCurrencyMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceCurrencyInterface::class)
45  ->disableOriginalConstructor()
46  ->getMockForAbstractClass();
47 
48  $this->priceCurrencyMock->expects($this->any())
49  ->method('round')
50  ->willReturnArgument(0);
51  $this->model = new \Magento\Sales\Model\Order\Validation\CanRefund(
52  $this->priceCurrencyMock
53  );
54  }
55 
61  public function testCanCreditmemoWrongState($state)
62  {
63  $this->orderMock->expects($this->any())
64  ->method('getState')
65  ->willReturn($state);
66  $this->orderMock->expects($this->once())
67  ->method('getStatus')
68  ->willReturn('status');
69  $this->orderMock->expects($this->never())
70  ->method('getTotalPaid')
71  ->willReturn(15);
72  $this->orderMock->expects($this->never())
73  ->method('getTotalRefunded')
74  ->willReturn(14);
75  $this->assertEquals(
76  [__('A creditmemo can not be created when an order has a status of %1', 'status')],
77  $this->model->validate($this->orderMock)
78  );
79  }
80 
86  {
87  return [
92  ];
93  }
94 
95  public function testCanCreditmemoNoMoney()
96  {
97  $this->orderMock->expects($this->any())
98  ->method('getState')
99  ->willReturn(Order::STATE_PROCESSING);
100  $this->orderMock->expects($this->once())
101  ->method('getTotalPaid')
102  ->willReturn(15);
103  $this->orderMock->expects($this->once())
104  ->method('getTotalRefunded')
105  ->willReturn(15);
106  $this->assertEquals(
107  [
108  __('The order does not allow a creditmemo to be created.')
109  ],
110  $this->model->validate($this->orderMock)
111  );
112  }
113 }
__()
Definition: __.php:13