Exemplo n.º 1
0
 public function testSave()
 {
     $this->orderMock->expects($this->once())->method('validateBeforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('beforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('isSaveAllowed')->willReturn(true);
     $this->orderMock->expects($this->once())->method('getEntityType')->willReturn('order');
     $this->orderMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->once())->method('getGroup')->willReturn($this->storeGroupMock);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->salesSequenceManagerMock->expects($this->once())->method('getSequence')->with('order', 1)->willReturn($this->salesSequenceMock);
     $this->salesSequenceMock->expects($this->once())->method('getNextValue')->willReturn('10000001');
     $this->orderMock->expects($this->once())->method('setIncrementId')->with('10000001')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('getIncrementId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('getData')->willReturn(['increment_id' => '10000001']);
     $this->objectRelationProcessorMock->expects($this->once())->method('validateDataIntegrity')->with(null, ['increment_id' => '10000001']);
     $this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->orderMock);
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
     $this->adapterMock->expects($this->any())->method('quoteInto');
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('update');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->orderMock)->will($this->returnValue(true));
     $this->resource->save($this->orderMock);
 }
Exemplo n.º 2
0
 /**
  * @dataProvider canVoidDataProvider
  * @param bool $canVoid
  */
 public function testCanVoid($canVoid)
 {
     $this->_orderMock->expects($this->once())->method('getPayment')->will($this->returnValue($this->_paymentMock));
     $this->_paymentMock->expects($this->once())->method('canVoid', '__wakeup')->with($this->equalTo($this->_model))->will($this->returnValue($canVoid));
     $this->_model->setState(\Magento\Sales\Model\Order\Invoice::STATE_PAID);
     $this->assertEquals($canVoid, $this->_model->canVoid());
 }
 public function testSaveDownloadableOrderItem()
 {
     $itemId = 100;
     $itemMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->getMock();
     $itemMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($this->orderMock);
     $itemMock->expects($this->any())->method('getId')->willReturn($itemId);
     $itemMock->expects($this->any())->method('getProductType')->willReturn(DownloadableProductType::TYPE_DOWNLOADABLE);
     $this->orderMock->expects($this->once())->method('getStoreId')->willReturn(10500);
     $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $product->expects($this->once())->method('getTypeId')->willReturn(DownloadableProductType::TYPE_DOWNLOADABLE);
     $productType = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Product\\Type')->disableOriginalConstructor()->getMock();
     $product->expects($this->once())->method('getTypeInstance')->willReturn($productType);
     $product->expects($this->once())->method('setStoreId')->with(10500)->willReturnSelf();
     $product->expects($this->once())->method('load')->willReturnSelf();
     $this->productFactory->expects($this->once())->method('create')->willReturn($product);
     $linkItem = $this->createLinkItem(12, 12, true, 'pending');
     $this->itemFactory->expects($this->once())->method('create')->willReturn($linkItem);
     $productType->expects($this->once())->method('getLinks')->willReturn([123 => $linkItem]);
     $itemMock->expects($this->once())->method('getProductOptionByCode')->willReturn([123]);
     $itemMock->expects($this->once())->method('getProduct')->willReturn(null);
     $purchasedLink = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Link\\Purchased')->disableOriginalConstructor()->setMethods(['load', 'setLinkSectionTitle', 'save'])->getMock();
     $purchasedLink->expects($this->once())->method('load')->with($itemId, 'order_item_id')->willReturnSelf();
     $purchasedLink->expects($this->once())->method('setLinkSectionTitle')->willReturnSelf();
     $purchasedLink->expects($this->once())->method('save')->willReturnSelf();
     $this->purchasedFactory->expects($this->any())->method('create')->willReturn($purchasedLink);
     $event = new \Magento\Framework\DataObject(['item' => $itemMock]);
     $observer = new \Magento\Framework\Event\Observer(['event' => $event]);
     $this->saveDownloadableOrderItemObserver->execute($observer);
 }
Exemplo n.º 4
0
 public function testGetAllItems()
 {
     $items = [new \Magento\Framework\Object(['parent_item' => 'parent item 1', 'name' => 'name 1', 'qty_ordered' => 1, 'base_price' => 0.1]), new \Magento\Framework\Object(['parent_item' => 'parent item 2', 'name' => 'name 2', 'qty_ordered' => 2, 'base_price' => 1.2]), new \Magento\Framework\Object(['parent_item' => 'parent item 3', 'name' => 'name 3', 'qty_ordered' => 3, 'base_price' => 2.3])];
     $expected = [new \Magento\Framework\Object(['parent_item' => 'parent item 1', 'name' => 'name 1', 'qty' => 1, 'price' => 0.1, 'original_item' => $items[0]]), new \Magento\Framework\Object(['parent_item' => 'parent item 2', 'name' => 'name 2', 'qty' => 2, 'price' => 1.2, 'original_item' => $items[1]]), new \Magento\Framework\Object(['parent_item' => 'parent item 3', 'name' => 'name 3', 'qty' => 3, 'price' => 2.3, 'original_item' => $items[2]])];
     $this->_orderMock->expects($this->once())->method('getAllItems')->will($this->returnValue($items));
     $this->assertEquals($expected, $this->_model->getAllItems());
 }
Exemplo n.º 5
0
 public function testGetOrder()
 {
     $orderId = 100000041;
     $this->model->setOrderId($orderId);
     $entityName = 'invoice';
     $this->orderMock->expects($this->atLeastOnce())->method('setHistoryEntityName')->with($entityName)->will($this->returnSelf());
     $this->assertEquals($this->orderMock, $this->model->getOrder());
 }
Exemplo n.º 6
0
 /**
  * @param array $orderItemAppliedTaxes
  * @param array $expectedResults
  * @return void
  * @dataProvider getOrderTaxDetailsDataProvider
  */
 public function testGetOrderTaxDetails($orderItemAppliedTaxes, $expectedResults)
 {
     $orderId = 1;
     $this->order->expects($this->once())->method('load')->with($orderId)->will($this->returnValue(true));
     $this->orderItemTaxResource->expects($this->once())->method('getTaxItemsByOrderId')->with($orderId)->will($this->returnValue($orderItemAppliedTaxes));
     $orderTaxDetails = $this->ordertTaxService->getOrderTaxDetails($orderId);
     $this->assertEquals($expectedResults, $orderTaxDetails->__toArray());
 }
 public function testSendEmailWhenRedirectUrlExists()
 {
     $this->paymentMock->expects($this->once())->method('getOrderPlaceRedirectUrl')->willReturn(false);
     $this->orderMock->expects($this->once())->method('getCanSendNewEmailFlag');
     $this->orderSenderMock->expects($this->never())->method('send');
     $this->loggerMock->expects($this->never())->method('critical');
     $this->model->execute($this->observerMock);
 }
Exemplo n.º 8
0
 /**
  * test _beforeSaveMethod via save()
  */
 public function testSave()
 {
     $this->validatorMock->expects($this->once())->method('validate')->with($this->equalTo($this->addressMock))->will($this->returnValue([]));
     $this->addressMock->expects($this->any())->method('hasDataChanges')->will($this->returnValue(true));
     $this->addressMock->expects($this->exactly(2))->method('getOrder')->will($this->returnValue($this->orderMock));
     $this->orderMock->expects($this->once())->method('getId')->willReturn(1);
     $this->addressMock->expects($this->exactly(2))->method('getOrderId')->will($this->returnValue(2));
     $this->gridPoolMock->expects($this->once())->method('refreshByOrderId')->with($this->equalTo(2))->will($this->returnSelf());
     $this->addressResource->save($this->addressMock);
 }
Exemplo n.º 9
0
 protected function setUp()
 {
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->authorizationMock = $this->getMock('\\Magento\\Framework\\Authorization', [], [], '', false);
     $this->coreRegistryMock = $this->getMock('Magento\\Framework\\Registry', [], [], '', false);
     $this->orderMock = $this->getMock('\\Magento\\Sales\\Model\\Order', [], [], '', false);
     $this->paymentMock = $this->getMock('\\Magento\\Sales\\Model\\Order\\Payment', [], [], '', false);
     $this->coreRegistryMock->expects($this->any())->method('registry')->with('current_order')->willReturn($this->orderMock);
     $this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock);
     $this->transactionsTab = $this->objectManager->getObject('Magento\\Sales\\Block\\Adminhtml\\Order\\View\\Tab\\Transactions', ['authorization' => $this->authorizationMock, 'registry' => $this->coreRegistryMock]);
 }
Exemplo n.º 10
0
 /**
  * test check order - set state processing
  */
 public function testCheckSetStateProcessing()
 {
     $this->orderMock->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->orderMock->expects($this->once())->method('isCanceled')->will($this->returnValue(false));
     $this->orderMock->expects($this->once())->method('canUnhold')->will($this->returnValue(false));
     $this->orderMock->expects($this->once())->method('canInvoice')->will($this->returnValue(false));
     $this->orderMock->expects($this->once())->method('canShip')->will($this->returnValue(true));
     $this->orderMock->expects($this->once())->method('getState')->will($this->returnValue(Order::STATE_NEW));
     $this->orderMock->expects($this->once())->method('getIsInProcess')->will($this->returnValue(true));
     $this->orderMock->expects($this->once())->method('setState')->with(Order::STATE_PROCESSING)->will($this->returnSelf());
     $this->assertEquals($this->state, $this->state->check($this->orderMock));
 }
Exemplo n.º 11
0
    /**
     * @covers \Magento\Sales\Controller\Adminhtml\Order\View::executeInternal
     */
    public function testExecute()
    {
        $id = 111;
        $titlePart = '#111';
        $this->initOrder();
        $this->initOrderSuccess($id);
        $this->prepareRedirect();
        $this->initAction();

        $this->resultPageMock->expects($this->atLeastOnce())
            ->method('getConfig')
            ->willReturn($this->pageConfigMock);
        $this->pageConfigMock->expects($this->atLeastOnce())
            ->method('getTitle')
            ->willReturn($this->pageTitleMock);
        $this->orderMock->expects($this->atLeastOnce())
            ->method('getIncrementId')
            ->willReturn($id);
        $this->pageTitleMock->expects($this->exactly(2))
            ->method('prepend')
            ->withConsecutive(
                ['Orders'],
                [$titlePart]
            )
            ->willReturnSelf();

        $this->assertInstanceOf(
            'Magento\Backend\Model\View\Result\Page',
            $this->viewAction->executeInternal()
        );
    }
Exemplo n.º 12
0
 protected function setUp()
 {
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $arguments = array('productFactory' => $this->getMock('Magento\\Catalog\\Model\\ProductFactory', array(), array(), '', false), 'orderItemCollectionFactory' => $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Item\\CollectionFactory', array(), array(), '', false), 'serviceOrderFactory' => $this->getMock('Magento\\Sales\\Model\\Service\\OrderFactory', array(), array(), '', false), 'currencyFactory' => $this->getMock('Magento\\Directory\\Model\\CurrencyFactory', array(), array(), '', false), 'orderHistoryFactory' => $this->getMock('Magento\\Sales\\Model\\Order\\Status\\HistoryFactory', array(), array(), '', false), 'orderTaxCollectionFactory' => $this->getMock('Magento\\Tax\\Model\\Resource\\Sales\\Order\\Tax\\CollectionFactory', array(), array(), '', false));
     $orderConstructorArgs = $objectManager->getConstructArguments('Magento\\Sales\\Model\\Order', $arguments);
     $this->_order = $this->getMock('Magento\\Sales\\Model\\Order', array('formatPriceTxt'), $orderConstructorArgs);
     $this->_order->expects($this->any())->method('formatPriceTxt')->will($this->returnCallback(array($this, 'formatPrice')));
     $this->_pdf = $this->getMock('Magento\\Sales\\Model\\Order\\Pdf\\AbstractPdf', array('drawLineBlocks', 'getPdf'), array(), '', false, false);
     $filterManager = $this->getMock('Magento\\Framework\\Filter\\FilterManager', array('stripTags'), array(), '', false);
     $filterManager->expects($this->any())->method('stripTags')->will($this->returnArgument(0));
     $modelConstructorArgs = $objectManager->getConstructArguments('Magento\\Downloadable\\Model\\Sales\\Order\\Pdf\\Items\\Creditmemo', array('string' => new \Magento\Framework\Stdlib\String(), 'filterManager' => $filterManager));
     $this->_model = $this->getMock('Magento\\Downloadable\\Model\\Sales\\Order\\Pdf\\Items\\Creditmemo', array('getLinks', 'getLinksTitle'), $modelConstructorArgs);
     $this->_model->setOrder($this->_order);
     $this->_model->setPdf($this->_pdf);
     $this->_model->setPage(new \Zend_Pdf_Page('a4'));
 }
Exemplo n.º 13
0
 private function initOrderMock($orderId, $state)
 {
     $this->orderFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->orderMock));
     $this->orderMock->expects($this->once())->method('loadByIncrementId')->with($orderId)->will($this->returnSelf());
     $this->orderMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($orderId));
     $this->orderMock->expects($this->once())->method('getState')->will($this->returnValue($state));
 }
Exemplo n.º 14
0
 public function testUnHold()
 {
     $this->orderRepositoryMock->expects($this->once())->method('get')->with(123)->willReturn($this->orderMock);
     $this->orderRepositoryMock->expects($this->once())->method('save')->with($this->orderMock)->willReturn($this->orderMock);
     $this->orderMock->expects($this->once())->method('unHold')->willReturn($this->orderMock);
     $this->assertTrue($this->orderService->unHold(123));
 }
Exemplo n.º 15
0
 /**
  * @param array $orderData
  * @param array $invoiceData
  * @param array $expectedResults
  * @dataProvider collectDataProvider
  */
 public function testCollect($orderData, $invoiceData, $expectedResults)
 {
     $roundingDelta = [];
     //Set up order mock
     foreach ($orderData['data_fields'] as $key => $value) {
         $this->order->setData($key, $value);
     }
     /** @var \Magento\Sales\Model\Order\Invoice[] $previousInvoices */
     $previousInvoices = [];
     foreach ($orderData['previous_invoices'] as $previousInvoiceData) {
         $previousInvoice = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods(['isCanceled', '__wakeup'])->getMock();
         $previousInvoice->setData('shipping_amount', $previousInvoiceData['shipping_amount']);
         $previousInvoices[] = $previousInvoice;
     }
     $this->order->expects($this->once())->method('getInvoiceCollection')->will($this->returnValue($previousInvoices));
     //Set up invoice mock
     /** @var \Magento\Sales\Model\Order\Invoice\Item[] $invoiceItems */
     $invoiceItems = [];
     foreach ($invoiceData['items'] as $itemKey => $invoiceItemData) {
         $invoiceItems[$itemKey] = $this->getInvoiceItem($invoiceItemData);
     }
     $this->invoice->expects($this->once())->method('getAllItems')->will($this->returnValue($invoiceItems));
     $this->invoice->expects($this->once())->method('isLast')->will($this->returnValue($invoiceData['is_last']));
     foreach ($invoiceData['data_fields'] as $key => $value) {
         $this->invoice->setData($key, $value);
     }
     $this->invoice->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
         if (!isset($roundingDelta[$type])) {
             $roundingDelta[$type] = 0;
         }
         $roundedPrice = round($price + $roundingDelta[$type], 2);
         $roundingDelta[$type] = $price - $roundedPrice;
         return $roundedPrice;
     }));
     $this->model->collect($this->invoice);
     //verify invoice data
     foreach ($expectedResults['invoice_data'] as $key => $value) {
         $this->assertEquals($value, $this->invoice->getData($key));
     }
     //verify invoice item data
     foreach ($expectedResults['invoice_items'] as $itemKey => $itemData) {
         $invoiceItem = $invoiceItems[$itemKey];
         foreach ($itemData as $key => $value) {
             $this->assertEquals($value, $invoiceItem->getData($key));
         }
     }
 }
 public function testSetLinkStatusEmptyOrder()
 {
     $this->observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($this->eventMock));
     $this->eventMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
     $this->orderMock->expects($this->once())->method('getId')->willReturn(null);
     $result = $this->setLinkStatusObserver->execute($this->observerMock);
     $this->assertInstanceOf('\\Magento\\Downloadable\\Observer\\SetLinkStatusObserver', $result);
 }
Exemplo n.º 17
0
 /**
  * Test method removeEmptyAddresses
  */
 public function testRemoveEmptyAddresses()
 {
     $this->orderMock->expects($this->once())->method('hasBillingAddressId')->will($this->returnValue(true));
     $this->orderMock->expects($this->once())->method('getBillingAddressId')->will($this->returnValue(null));
     $this->orderMock->expects($this->once())->method('unsBillingAddressId')->will($this->returnSelf());
     $this->orderMock->expects($this->once())->method('hasShippingAddressId')->will($this->returnValue(true));
     $this->orderMock->expects($this->once())->method('getShippingAddressId')->will($this->returnValue(null));
     $this->orderMock->expects($this->once())->method('unsShippingAddressId')->will($this->returnSelf());
     $this->assertEquals($this->address, $this->address->removeEmptyAddresses($this->orderMock));
 }
Exemplo n.º 18
0
 public function testSave()
 {
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
     $this->adapterMock->expects($this->any())->method('quoteInto');
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('update');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->orderMock->expects($this->once())->method('hasDataChanges')->will($this->returnValue(true));
     $this->resource->save($this->orderMock);
 }
Exemplo n.º 19
0
 public function testExecuteSuccess()
 {
     $params = ['success' => 1, 'controller_action_name' => 'action', 'x_invoice_num' => 1];
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($params);
     $this->helperMock->expects($this->once())->method('getSuccessOrderUrl')->willReturn('redirect_parent_url');
     $this->directpostSessionMock->expects($this->once())->method('unsetData')->with('quote_id');
     $this->orderMock->expects($this->once())->method('getId')->willReturn(null);
     $this->sessionQuoteMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($this->orderMock);
     $this->adminOrderCreateMock->expects($this->atLeastOnce())->method('getSession')->willReturn($this->sessionQuoteMock);
     $this->coreRegistryMock->expects($this->once())->method('register')->with(Iframe::REGISTRY_KEY);
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Result\\Layout', $this->controller->execute());
 }
Exemplo n.º 20
0
 public function mockPay($hasForcedState, $forcedState)
 {
     $this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock);
     $this->paymentMock->expects($this->once())->method('hasForcedState')->willReturn($hasForcedState);
     if ($hasForcedState) {
         $this->paymentMock->expects($this->once())->method('getForcedState')->willReturn($forcedState);
     } else {
         $this->paymentMock->expects($this->never())->method('getForcedState');
     }
     $this->paymentMock->expects($this->once())->method('pay')->with($this->model)->willReturnSelf();
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('sales_order_invoice_pay');
 }
Exemplo n.º 21
0
 public function testSave()
 {
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
     $this->adapterMock->expects($this->any())->method('quoteInto');
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('update');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->addressHandlerMock->expects($this->once())->method('removeEmptyAddresses')->with($this->equalTo($this->orderMock))->will($this->returnSelf());
     $this->stateHandlerMock->expects($this->once())->method('check')->with($this->equalTo($this->orderMock))->will($this->returnSelf());
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->orderMock->expects($this->once())->method('getRelatedObjects')->willReturn([]);
     $this->resource->save($this->orderMock);
 }
Exemplo n.º 22
0
 public function testCollect()
 {
     $this->creditmemoMock->expects($this->exactly(2))->method('setDiscountAmount')->willReturnSelf();
     $this->creditmemoMock->expects($this->exactly(2))->method('setBaseDiscountAmount')->willReturnSelf();
     $this->creditmemoMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
     $this->creditmemoMock->expects($this->once())->method('getBaseShippingAmount')->willReturn(1);
     $this->orderMock->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn(1);
     $this->orderMock->expects($this->exactly(2))->method('getBaseShippingAmount')->willReturn(1);
     $this->orderMock->expects($this->once())->method('getShippingAmount')->willReturn(1);
     $this->creditmemoMock->expects($this->once())->method('getAllItems')->willReturn([$this->creditmemoItemMock]);
     $this->creditmemoItemMock->expects($this->atLeastOnce())->method('getOrderItem')->willReturn($this->orderItemMock);
     $this->orderItemMock->expects($this->once())->method('isDummy')->willReturn(false);
     $this->orderItemMock->expects($this->once())->method('getDiscountInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getBaseDiscountInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getDiscountRefunded')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(0);
     $this->creditmemoItemMock->expects($this->once())->method('isLast')->willReturn(false);
     $this->creditmemoItemMock->expects($this->atLeastOnce())->method('getQty')->willReturn(1);
     $this->creditmemoItemMock->expects($this->exactly(1))->method('setDiscountAmount')->willReturnSelf();
     $this->creditmemoItemMock->expects($this->exactly(1))->method('setBaseDiscountAmount')->willReturnSelf();
     $this->creditmemoMock->expects($this->exactly(2))->method('roundPrice')->willReturnMap([[1, 'regular', true, 1], [1, 'base', true, 1]]);
     $this->assertEquals($this->total, $this->total->collect($this->creditmemoMock));
 }
Exemplo n.º 23
0
 /**
  * @param $state
  * @param $restoreQuote
  * @param $expectedGotoSection
  * @dataProvider testNotAllowedOrderStateDataProvider
  */
 public function testExecuteNotAllowedOrderState($state, $restoreQuote, $expectedGotoSection)
 {
     $lastRealOrderId = '000000001';
     $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock));
     $this->layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->blockMock));
     $this->checkoutSessionMock->expects($this->any())->method('getLastRealOrderId')->will($this->returnValue($lastRealOrderId));
     $this->checkoutSessionMock->expects($this->any())->method('getLastRealOrder')->will($this->returnValue($this->orderMock));
     $this->checkoutSessionMock->expects($this->any())->method('restoreQuote')->will($this->returnValue($restoreQuote));
     $this->orderFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->orderMock));
     $this->orderMock->expects($this->once())->method('loadByIncrementId')->with($lastRealOrderId)->will($this->returnSelf());
     $this->orderMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($lastRealOrderId));
     $this->orderMock->expects($this->once())->method('getState')->will($this->returnValue($state));
     $this->blockMock->expects($this->at(0))->method('setData')->with('goto_section', $expectedGotoSection)->will($this->returnSelf());
     $this->blockMock->expects($this->at(1))->method('setData')->with('error_msg', __('Your payment has been declined. Please try again.'))->will($this->returnSelf());
     $this->returnUrl->execute();
 }
Exemplo n.º 24
0
 /**
  * test order mapper
  */
 public function testInvoke()
 {
     $this->orderMock->expects($this->once())->method('getData')->will($this->returnValue(['field-1' => 'value-1']));
     $this->orderMock->expects($this->once())->method('getItemsCollection')->will($this->returnValue([$this->orderItemMock]));
     $this->orderMock->expects($this->once())->method('getPaymentsCollection')->will($this->returnValue([$this->orderPaymentMock]));
     $this->orderMock->expects($this->exactly(2))->method('getBillingAddress')->will($this->returnValue($this->orderAddressMock));
     $this->orderMock->expects($this->exactly(2))->method('getShippingAddress')->will($this->returnValue($this->orderAddressMock));
     $this->orderBuilderMock->expects($this->once())->method('populateWithArray')->with($this->equalTo(['field-1' => 'value-1']))->will($this->returnSelf());
     $this->orderItemMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->orderItemMock))->will($this->returnValue('item-1'));
     $this->orderPaymentMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->orderPaymentMock))->will($this->returnValue('payment-1'));
     $this->orderAddressMapperMock->expects($this->exactly(2))->method('extractDto')->with($this->equalTo($this->orderAddressMock))->will($this->returnValue('address-1'));
     $this->orderBuilderMock->expects($this->once())->method('setItems')->with($this->equalTo(['item-1']))->will($this->returnSelf());
     $this->orderBuilderMock->expects($this->once())->method('setPayments')->with($this->equalTo(['payment-1']))->will($this->returnSelf());
     $this->orderBuilderMock->expects($this->once())->method('setBillingAddress')->with($this->equalTo('address-1'))->will($this->returnSelf());
     $this->orderBuilderMock->expects($this->once())->method('setShippingAddress')->with($this->equalTo('address-1'))->will($this->returnSelf());
     $this->orderBuilderMock->expects($this->once())->method('create')->will($this->returnValue('data-object-with-order'));
     $this->assertEquals('data-object-with-order', $this->orderMapper->extractDto($this->orderMock));
 }
Exemplo n.º 25
0
 /**
  * @param string $expected
  * @param bool $dataObjectIsOrder
  * @param bool $isCurrencyDifferent
  * @param bool $magentoDataObjectHasOrder
  * @param bool $strong
  * @param string $separator
  * @dataProvider displayPricesDataProvider
  */
 public function testDisplayPriceAttribute($expected, $dataObjectIsOrder, $isCurrencyDifferent = true, $magentoDataObjectHasOrder = true, $strong = false, $separator = '<br/>')
 {
     $this->orderMock->expects($this->any())->method('isCurrencyDifferent')->will($this->returnValue($isCurrencyDifferent));
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
     $this->priceCurrency->expects($this->any())->method('format')->will($this->returnValue('storeFormattedPrice'));
     $dataObject = $this->orderMock;
     if (!$dataObjectIsOrder) {
         $returnRes = false;
         if ($magentoDataObjectHasOrder) {
             $returnRes = $this->orderMock;
         }
         $this->magentoObjectMock->expects($this->once())->method('getOrder')->will($this->returnValue($returnRes));
         $this->magentoObjectMock->expects($this->any())->method('getData')->will($this->returnValue('data'));
         $dataObject = $this->magentoObjectMock;
     }
     $this->assertEquals($expected, $this->adminHelper->displayPriceAttribute($dataObject, 'code', $strong, $separator));
 }
Exemplo n.º 26
0
 public function testCalcRowTotal()
 {
     $this->item->setData(['order_item_id' => 1, 'qty' => 2]);
     $this->item->setInvoice($this->invoiceMock);
     $this->invoiceMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
     $this->orderMock->expects($this->once())->method('getItemById')->with(1)->willReturn($this->orderItemMock);
     $this->orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getRowTotal')->willReturn(2);
     $this->orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getBaseRowTotal')->willReturn(2);
     $this->orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(0);
     $this->invoiceMock->expects($this->exactly(4))->method('roundPrice')->willReturnMap([[2, 'regular', false, 2], [2, 'base', false, 2], [2, 'including', false, 2], [2, 'including_base', false, 2]]);
     $this->assertEquals($this->item->calcRowTotal(), $this->item);
 }
Exemplo n.º 27
0
 protected function setUp()
 {
     $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     $this->urlInterface = $this->getMock('Magento\\Framework\\UrlInterface');
     $this->requestInterface = $this->getMock('Magento\\Framework\\App\\RequestInterface');
     $this->orderStatusFactory = $this->getMockBuilder('Magento\\Sales\\Model\\ResourceModel\\Order\\Rss\\OrderStatusFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->timezoneInterface = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface');
     $this->orderFactory = $this->getMock('Magento\\Sales\\Model\\OrderFactory', ['create'], [], '', false);
     $this->scopeConfigInterface = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->order = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->setMethods(['__sleep', '__wakeup', 'getIncrementId', 'getId', 'getCustomerId', 'load', 'getStatusLabel', 'formatPrice', 'getGrandTotal'])->disableOriginalConstructor()->getMock();
     $this->order->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->order->expects($this->any())->method('getIncrementId')->will($this->returnValue('100000001'));
     $this->order->expects($this->any())->method('getCustomerId')->will($this->returnValue(1));
     $this->order->expects($this->any())->method('getStatusLabel')->will($this->returnValue('Pending'));
     $this->order->expects($this->any())->method('formatPrice')->will($this->returnValue('15.00'));
     $this->order->expects($this->any())->method('getGrandTotal')->will($this->returnValue(15));
     $this->order->expects($this->any())->method('load')->with(1)->will($this->returnSelf());
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->model = $this->objectManagerHelper->getObject('Magento\\Sales\\Model\\Rss\\OrderStatus', ['objectManager' => $this->objectManager, 'urlBuilder' => $this->urlInterface, 'request' => $this->requestInterface, 'orderResourceFactory' => $this->orderStatusFactory, 'localeDate' => $this->timezoneInterface, 'orderFactory' => $this->orderFactory, 'scopeConfig' => $this->scopeConfigInterface]);
 }
Exemplo n.º 28
0
 public function testLoadValidOrderStoredCookie()
 {
     $protectedCode = 'protectedCode';
     $incrementId = 1;
     $cookieData = $protectedCode . ':' . $incrementId;
     $cookieDataHash = base64_encode($cookieData);
     $this->sessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
     $this->orderFactoryMock->expects($this->once())->method('create')->willReturn($this->salesOrderMock);
     $this->cookieManagerMock->expects($this->once())->method('getCookie')->with(Guest::COOKIE_NAME)->willReturn($cookieDataHash);
     $this->salesOrderMock->expects($this->once())->method('loadByIncrementId')->with($incrementId)->willReturnSelf();
     $this->salesOrderMock->expects($this->exactly(1))->method('getId')->willReturn($incrementId);
     $this->salesOrderMock->expects($this->once())->method('getProtectCode')->willReturn($protectedCode);
     $metaDataMock = $this->getMock('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata', [], [], '', false);
     $metaDataMock->expects($this->once())->method('setPath')->with(Guest::COOKIE_PATH)->willReturnSelf();
     $metaDataMock->expects($this->once())->method('setHttpOnly')->with(true)->willReturnSelf();
     $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->willReturn($metaDataMock);
     $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with(Guest::COOKIE_NAME, $this->anything(), $metaDataMock);
     $requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $this->assertTrue($this->guest->loadValidOrder($requestMock));
 }
Exemplo n.º 29
0
 public function testProcessRelation()
 {
     $this->addressHandlerMock->expects($this->once())->method('removeEmptyAddresses')->with($this->orderMock)->willReturnSelf();
     $this->addressHandlerMock->expects($this->once())->method('process')->with($this->orderMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getItems')->willReturn([$this->orderItemMock]);
     $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn('order-id-value');
     $this->orderItemMock->expects($this->once())->method('setOrderId')->with('order-id-value')->willReturnSelf();
     $this->orderItemMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->orderItemRepositoryMock->expects($this->once())->method('save')->with($this->orderItemMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getPayment')->willReturn($this->orderPaymentMock);
     $this->orderPaymentMock->expects($this->once())->method('setParentId')->with('order-id-value')->willReturnSelf();
     $this->orderPaymentMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->orderPaymentResourceMock->expects($this->once())->method('save')->with($this->orderPaymentMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getStatusHistories')->willReturn([$this->orderStatusHistoryMock]);
     $this->orderStatusHistoryMock->expects($this->once())->method('setParentId')->with('order-id-value')->willReturnSelf();
     $this->orderStatusHistoryMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->statusHistoryResource->expects($this->once())->method('save')->with($this->orderStatusHistoryMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getRelatedObjects')->willReturn([$this->orderInvoiceMock]);
     $this->orderInvoiceMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->orderInvoiceMock->expects($this->once())->method('save')->willReturnSelf();
     $this->relationProcessor->processRelation($this->orderMock);
 }
Exemplo n.º 30
0
 /**
  * Test case when email has not been sent
  */
 public function testNotifyFail()
 {
     $this->creditmemo->expects($this->once())->method('getEmailSent')->will($this->returnValue(false));
     $this->assertFalse($this->notifier->notify($this->creditmemo));
 }