/** * Order throws exception while canceling */ public function testException() { $exception = new \Exception('Can not cancel'); $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn([$order1]); $order1->expects($this->once())->method('canCancel')->willReturn(true); $order1->expects($this->once())->method('cancel')->willThrowException($exception); $this->messageManagerMock->expects($this->once())->method('addError')->with('Can not cancel'); $this->massAction->execute(); }
public function testLoadByIncrementIdAndStoreId() { $incrementId = '000000001'; $storeId = '2'; $this->salesOrderCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->salesOrderCollectionMock); $this->salesOrderCollectionMock->expects($this->any())->method('addFieldToFilter')->willReturnSelf(); $this->salesOrderCollectionMock->expects($this->once())->method('load')->willReturnSelf(); $this->salesOrderCollectionMock->expects($this->once())->method('getFirstItem')->willReturn($this->order); $this->assertSame($this->order, $this->order->loadByIncrementIdAndStoreId($incrementId, $storeId)); }
public function testExecuteNoReleasedOrderFromHold() { $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $order2 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $orders = [$order1, $order2]; $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn($orders); $order1->expects($this->once())->method('canUnhold')->willReturn(false); $this->orderCollectionMock->expects($this->once())->method('count')->willReturn(count($orders)); $order2->expects($this->once())->method('canUnhold')->willReturn(false); $this->messageManagerMock->expects($this->once())->method('addError')->with('No order(s) were released from on hold status.'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf(); $this->massAction->execute(); }
public function testInitOrders() { $customerId = 25; $attribute = ['customer_id', 'status']; $this->httpContext->expects($this->once())->method('getValue')->with($this->equalTo(Context::CONTEXT_AUTH))->will($this->returnValue(true)); $this->customerSession->expects($this->once())->method('getCustomerId')->will($this->returnValue($customerId)); $statuses = ['pending', 'processing', 'complete']; $this->orderConfig->expects($this->once())->method('getVisibleOnFrontStatuses')->will($this->returnValue($statuses)); $this->orderCollection->expects($this->at(0))->method('addAttributeToFilter')->with($attribute[0], $this->equalTo($customerId))->will($this->returnSelf()); $this->orderCollection->expects($this->at(1))->method('addAttributeToFilter')->with($attribute[1], $this->equalTo(['in' => $statuses]))->will($this->returnSelf()); $this->orderCollection->expects($this->at(2))->method('addAttributeToSort')->with('created_at', 'desc')->will($this->returnSelf()); $this->orderCollection->expects($this->at(3))->method('setPage')->with($this->equalTo(1), $this->equalTo(1))->will($this->returnSelf()); $this->orderCollectionFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->orderCollection)); $this->createBlockObject(); $this->assertEquals($this->orderCollection, $this->block->getOrders()); }
public function testExecuteNoOrdersPutOnHold() { $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); $order2 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); $orders = [$order1, $order2]; $countOrders = count($orders); $this->orderCollectionMock->expects($this->any()) ->method('getItems') ->willReturn($orders); $order1->expects($this->once()) ->method('canHold') ->willReturn(false); $this->orderCollectionMock->expects($this->once()) ->method('count') ->willReturn($countOrders); $order2->expects($this->once()) ->method('canHold') ->willReturn(false); $this->messageManagerMock->expects($this->once()) ->method('addError') ->with('No order(s) were put on hold.'); $this->resultRedirectMock->expects($this->once()) ->method('setPath') ->with('sales/*/') ->willReturnSelf(); $this->massAction->executeInternal(); }