public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); $this->contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false); $resultRedirectFactory = $this->getMock('Magento\\Backend\\Model\\View\\Result\\RedirectFactory', [], [], '', false); $this->responseMock = $this->getMock('Magento\\Framework\\App\\ResponseInterface', [], [], '', false); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManager\\ObjectManager', [], [], '', false); $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\Manager', [], [], '', false); $this->orderCollectionMock = $this->getMockBuilder('Magento\\Sales\\Model\\ResourceModel\\Order\\Collection')->disableOriginalConstructor()->getMock(); $orderCollection = 'Magento\\Sales\\Model\\ResourceModel\\Order\\CollectionFactory'; $this->orderCollectionFactoryMock = $this->getMockBuilder($orderCollection)->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', ['setIsUrlNotice'], [], '', false); $this->actionFlagMock = $this->getMock('Magento\\Framework\\App\\ActionFlag', ['get', 'set'], [], '', false); $this->helperMock = $this->getMock('\\Magento\\Backend\\Helper\\Data', ['getUrl'], [], '', false); $this->resultRedirectMock = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Redirect', [], [], '', false); $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirectMock); $redirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $resultFactoryMock->expects($this->any())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($redirectMock); $this->contextMock->expects($this->once())->method('getMessageManager')->willReturn($this->messageManagerMock); $this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock); $this->contextMock->expects($this->once())->method('getResponse')->willReturn($this->responseMock); $this->contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock); $this->contextMock->expects($this->once())->method('getSession')->willReturn($this->sessionMock); $this->contextMock->expects($this->once())->method('getActionFlag')->willReturn($this->actionFlagMock); $this->contextMock->expects($this->once())->method('getHelper')->willReturn($this->helperMock); $this->contextMock->expects($this->once())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory); $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($resultFactoryMock); $this->filterMock = $this->getMock('Magento\\Ui\\Component\\MassAction\\Filter', [], [], '', false); $this->filterMock->expects($this->once())->method('getCollection')->with($this->orderCollectionMock)->willReturn($this->orderCollectionMock); $this->orderCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->orderCollectionMock); $this->massAction = $objectManagerHelper->getObject('Magento\\Sales\\Controller\\Adminhtml\\Order\\MassUnhold', ['context' => $this->contextMock, 'filter' => $this->filterMock, 'collectionFactory' => $this->orderCollectionFactoryMock]); }
public function testConstructMethod() { $data = []; $customerId = 25; $this->customerSession->expects($this->once())->method('getCustomerId')->will($this->returnValue($customerId)); $statuses = ['pending', 'processing', 'comlete']; $this->orderConfig->expects($this->once())->method('getVisibleOnFrontStatuses')->will($this->returnValue($statuses)); $orderCollection = $this->getMock('Magento\\Sales\\Model\\ResourceModel\\Order\\Collection', ['addFieldToSelect', 'addFieldToFilter', 'setOrder'], [], '', false, false); $this->context->expects($this->any())->method('getPageConfig')->willReturn($this->pageConfig); $orderCollection->expects($this->at(0))->method('addFieldToSelect')->with($this->equalTo('*'))->will($this->returnSelf()); $orderCollection->expects($this->at(1))->method('addFieldToFilter')->with('customer_id', $this->equalTo($customerId))->will($this->returnSelf()); $orderCollection->expects($this->at(2))->method('addFieldToFilter')->with('status', $this->equalTo(['in' => $statuses]))->will($this->returnSelf()); $orderCollection->expects($this->at(3))->method('setOrder')->with('created_at', 'desc')->will($this->returnSelf()); $this->orderCollectionFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($orderCollection)); $this->pageConfig->expects($this->atLeastOnce())->method('getTitle')->willReturn($this->pageTitleMock); $this->pageTitleMock->expects($this->atLeastOnce())->method('set')->willReturnSelf(); $this->model = new \Magento\Sales\Block\Order\History($this->context, $this->orderCollectionFactory, $this->customerSession, $this->orderConfig, $data); $this->assertEquals($orderCollection, $this->model->getOrders()); }
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 testConstructMethod() { $data = []; $attribute = ['customer_id', 'status']; $customerId = 25; $layout = $this->getMock('Magento\\Framework\\View\\Layout', ['getBlock'], [], '', false, false); $this->context->expects($this->once())->method('getLayout')->will($this->returnValue($layout)); $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)); $orderCollection = $this->getMock('Magento\\Sales\\Model\\ResourceModel\\Order\\Collection', ['addAttributeToSelect', 'addFieldToFilter', 'addAttributeToFilter', 'addAttributeToSort', 'setPageSize', 'load'], [], '', false, false); $this->orderCollectionFactory->expects($this->once())->method('create')->will($this->returnValue($orderCollection)); $orderCollection->expects($this->at(0))->method('addAttributeToSelect')->with($this->equalTo('*'))->will($this->returnSelf()); $orderCollection->expects($this->at(1))->method('addAttributeToFilter')->with($attribute[0], $this->equalTo($customerId))->willReturnSelf(); $orderCollection->expects($this->at(2))->method('addAttributeToFilter')->with($attribute[1], $this->equalTo(['in' => $statuses]))->will($this->returnSelf()); $orderCollection->expects($this->at(3))->method('addAttributeToSort')->with('created_at', 'desc')->will($this->returnSelf()); $orderCollection->expects($this->at(4))->method('setPageSize')->with('5')->will($this->returnSelf()); $orderCollection->expects($this->at(5))->method('load')->will($this->returnSelf()); $this->block = new \Magento\Sales\Block\Order\Recent($this->context, $this->orderCollectionFactory, $this->customerSession, $this->orderConfig, $data); $this->assertEquals($orderCollection, $this->block->getOrders()); }
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()); }