protected function setUp() { $this->objectManager = new ObjectManager($this); $this->quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', ['getCustomerNoteNotify'], [], '', false); $this->sessionQuoteMock = $this->getMock('\\Magento\\Backend\\Model\\Session\\Quote', [], [], '', false); $this->sessionQuoteMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock); $this->totals = $this->objectManager->getObject('\\Magento\\Sales\\Block\\Adminhtml\\Order\\Create\\Totals', ['sessionQuote' => $this->sessionQuoteMock]); }
/** * Init */ protected function setUp() { $this->helperManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->sessionQuoteMock = $this->getMockBuilder('Magento\\Backend\\Model\\Session\\Quote')->disableOriginalConstructor()->getMock(); $this->quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['setTotalsCollectedFlag', 'collectTotals', 'getTotals', 'isVirtual', 'getBillingAddress', 'getShippingAddress'])->getMock(); $this->shippingAddressMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Address')->disableOriginalConstructor()->getMock(); $this->billingAddressMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Address')->disableOriginalConstructor()->getMock(); $this->quoteMock->expects($this->any())->method('getBillingAddress')->willreturn($this->billingAddressMock); $this->quoteMock->expects($this->any())->method('getShippingAddress')->willreturn($this->shippingAddressMock); $this->sessionQuoteMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock); $this->totals = $this->helperManager->getObject('Magento\\Sales\\Block\\Adminhtml\\Order\\Create\\Totals', ['sessionQuote' => $this->sessionQuoteMock]); }
/** * @param bool $noDiscount * @param string $couponCode * @param string $errorMessage * @param string $actualCouponCode * @dataProvider isApplyDiscountDataProvider */ public function testExecute($noDiscount, $couponCode, $errorMessage, $actualCouponCode) { $quote = $this->getMock('Magento\\Quote\\Model\\Quote', ['getCouponCode', 'isVirtual', 'getAllItems'], [], '', false); $create = $this->getMock('Magento\\Sales\\Model\\AdminOrder\\Create', [], [], '', false); $paramReturnMap = [['customer_id', null, null], ['store_id', null, null], ['currency_id', null, null]]; $this->request->expects($this->atLeastOnce())->method('getParam')->willReturnMap($paramReturnMap); $objectManagerParamMap = [['Magento\\Sales\\Model\\AdminOrder\\Create', $create], ['Magento\\Backend\\Model\\Session\\Quote', $this->session]]; $this->objectManager->expects($this->atLeastOnce())->method('get')->willReturnMap($objectManagerParamMap); $this->eventManager->expects($this->any())->method('dispatch'); $data = ['coupon' => ['code' => $couponCode]]; $postReturnMap = [['order', $data], ['reset_shipping', false], ['collect_shipping_rates', false], ['sidebar', false], ['add_product', false], ['', false], ['update_items', false], ['remove_item', 1], ['from', 2], ['move_item', 1], ['to', 2], ['qty', 3], ['payment', false], [null, 'request'], ['payment', false], ['giftmessage', false], ['add_products', false], ['update_items', false]]; $this->request->expects($this->atLeastOnce())->method('getPost')->willReturnMap($postReturnMap); $create->expects($this->once())->method('importPostData')->willReturnSelf(); $create->expects($this->once())->method('initRuleData')->willReturnSelf(); $create->expects($this->any())->method('getQuote')->willReturn($quote); $address = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false); $create->expects($this->once())->method('getBillingAddress')->willReturn($address); $quote->expects($this->any())->method('isVirtual')->willReturn(true); $this->request->expects($this->once())->method('has')->with('item')->willReturn(false); $create->expects($this->once())->method('saveQuote')->willReturnSelf(); $this->session->expects($this->any())->method('getQuote')->willReturn($quote); $item = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], '', false, true, true, ['getNoDiscount']); $quote->expects($this->any())->method('getAllItems')->willReturn([$item]); $item->expects($this->any())->method('getNoDiscount')->willReturn($noDiscount); if (!$noDiscount) { $quote->expects($this->once())->method('getCouponCode')->willReturn($actualCouponCode); } $errorMessageManager = __($errorMessage, $couponCode); $this->escaper->expects($this->once())->method('escapeHtml')->with($couponCode)->willReturn($couponCode); $this->messageManager->expects($this->once())->method('addError')->with($errorMessageManager)->willReturnSelf(); $this->resultForward->expects($this->once())->method('forward')->with('index')->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->processData->execute()); }
public function testGetMerchantId() { $this->sessionQuote->expects($this->once())->method('getStoreId')->willReturn(1); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(1); $result = $this->model->getMerchantId(); $this->assertEquals(1, $result); }
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()); }
/** * @covers \Magento\Vault\Model\Ui\Adminhtml\TokensConfigProvider::getTokensComponents */ public function testGetTokensComponentsEmptyComponentProvider() { $storeId = 1; $customerId = 2; $code = 'vault_payment'; $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId); $this->initStoreMock(); $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true); $this->vaultPayment->expects(static::once())->method('getProviderCode')->with($storeId)->willReturn($code); $this->paymentTokenRepository->expects(static::never())->method('getList'); $configProvider = new TokensConfigProvider($this->session, $this->paymentTokenRepository, $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, $this->vaultPayment, $this->dateTimeFactory); static::assertEmpty($configProvider->getTokensComponents()); }
/** * @covers \Magento\Vault\Model\Ui\Adminhtml\TokensConfigProvider::getTokensComponents */ public function testGetTokensComponentsEmptyComponentProvider() { $storeId = 1; $customerId = 2; $vaultPaymentCode = 'vault_payment'; $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId); $this->initStoreMock(); $this->paymentDataHelper->expects(static::once())->method('getMethodInstance')->with($vaultPaymentCode)->willReturn($this->vaultPayment); $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(false); $this->paymentTokenRepository->expects(static::never())->method('getList'); $configProvider = new TokensConfigProvider($this->session, $this->paymentTokenRepository, $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, $this->dateTimeFactory); $this->objectManager->setBackwardCompatibleProperty($configProvider, 'paymentDataHelper', $this->paymentDataHelper); static::assertEmpty($configProvider->getTokensComponents($vaultPaymentCode)); }
public function testUpdateQuoteItemsWithConfiguredOption() { $qty = 100000000; $items = [1 => ['qty' => 10, 'configured' => true, 'action' => false]]; $itemMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', [], [], '', false); $itemMock->expects($this->once())->method('getQty')->will($this->returnValue($qty)); $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false); $quoteMock->expects($this->once())->method('updateItem')->will($this->returnValue($itemMock)); $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); $expectedInfo = $items[1]; $expectedInfo['qty'] = $qty; $this->itemUpdater->expects($this->once())->method('update')->with($this->equalTo($itemMock), $this->equalTo($expectedInfo)); $this->adminOrderCreate->setRecollect(false); $this->adminOrderCreate->updateQuoteItems($items); }
/** * Run test getQuote method * * @return void * @dataProvider getQuoteDataProvider */ public function testGetQuoteWithQuoteId($customerId, $quoteCustomerId, $expectedNumberOfInvokes) { $quoteId = 22; $storeId = 10; $this->quote->expects($this->any())->method('getQuoteId')->will($this->returnValue($quoteId)); $this->quote->expects($this->any())->method('setQuoteId')->with($quoteId); $this->quote->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $this->quote->expects($this->any())->method('getCustomerId')->will($this->returnValue($customerId)); $dataCustomerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock(); $this->customerRepositoryMock->expects($this->{$expectedNumberOfInvokes}())->method('getById')->with($customerId)->willReturn($dataCustomerMock); $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['setStoreId', 'setCustomerGroupId', 'setIsActive', 'getId', 'assignCustomer', 'setIgnoreOldQty', 'setIsSuperMode', 'getCustomerId', '__wakeup'], [], '', false); $quoteMock->expects($this->once())->method('setStoreId')->with($storeId); $quoteMock->expects($this->{$expectedNumberOfInvokes}())->method('assignCustomer')->with($dataCustomerMock); $quoteMock->expects($this->once())->method('setIgnoreOldQty')->with(true); $quoteMock->expects($this->once())->method('setIsSuperMode')->with(true); $quoteMock->expects($this->once())->method('getCustomerId')->will($this->returnValue($quoteCustomerId)); $this->quoteRepositoryMock->expects($this->once())->method('get')->with($quoteId)->willReturn($quoteMock); $this->assertEquals($quoteMock, $this->quote->getQuote()); }
/** * Create mock for session quote */ private function initSessionQuoteMock() { $this->sessionQuote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->setMethods(['getQuote', 'getBillingAddress', 'getCountryId', '__wakeup'])->getMock(); $this->sessionQuote->expects(static::any())->method('getQuote')->willReturnSelf(); $this->sessionQuote->expects(static::any())->method('getBillingAddress')->willReturnSelf(); }