public function testSetProductWithQuoteAndStockItem() { $productMock = $this->generateProductMock(self::PRODUCT_ID, self::PRODUCT_TYPE, self::PRODUCT_SKU, self::PRODUCT_NAME, self::PRODUCT_WEIGHT, self::PRODUCT_TAX_CLASS_ID, self::PRODUCT_COST); $this->eventDispatcher->expects($this->once())->method('dispatch')->with('sales_quote_item_set_product', ['product' => $productMock, 'quote_item' => $this->model]); $isQtyDecimal = true; $this->stockItemMock->expects($this->any())->method('getStockId')->will($this->returnValue(99)); $this->stockItemMock->expects($this->once())->method('getIsQtyDecimal')->will($this->returnValue($isQtyDecimal)); $storeId = 15; $customerGroupId = 11; $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getStoreId', 'getCustomerGroupId', '__wakeup'])->getMock(); $quoteMock->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $quoteMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($customerGroupId)); $this->model->setQuote($quoteMock); $productMock->expects($this->once())->method('setStoreId')->with($storeId); $productMock->expects($this->once())->method('setCustomerGroupId')->with($customerGroupId); $this->model->setProduct($productMock); $this->assertEquals($productMock, $this->model->getProduct()); $this->assertEquals(self::PRODUCT_ID, $this->model->getProductId()); $this->assertEquals(self::PRODUCT_TYPE, $this->model->getRealProductType()); $this->assertEquals(self::PRODUCT_SKU, $this->model->getSku()); $this->assertEquals(self::PRODUCT_NAME, $this->model->getName()); $this->assertEquals(self::PRODUCT_WEIGHT, $this->model->getWeight()); $this->assertEquals(self::PRODUCT_TAX_CLASS_ID, $this->model->getTaxClassId()); $this->assertEquals(self::PRODUCT_COST, $this->model->getBaseCost()); $this->assertEquals($isQtyDecimal, $this->model->getIsQtyDecimal()); }
public function testProcessRelations() { $this->relationProcessorMock->expects($this->once())->method('processRelation')->with($this->salesModelMock); $this->salesModelMock->expects($this->once())->method('getEventPrefix')->willReturn('sales_event_prefix'); $this->eventManagerMock->expects($this->once())->method('dispatch')->with('sales_event_prefix_process_relation', ['object' => $this->salesModelMock]); $this->entityRelationComposite->processRelations($this->salesModelMock); }
public function testDispatchPostDispatch() { $this->_requestMock->expects($this->exactly(3))->method('getFullActionName')->will($this->returnValue(self::FULL_ACTION_NAME)); $this->_requestMock->expects($this->exactly(2))->method('getRouteName')->will($this->returnValue(self::ROUTE_NAME)); $expectedEventParameters = ['controller_action' => $this->action, 'request' => $this->_requestMock]; $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with('controller_action_predispatch', $expectedEventParameters); $this->_eventManagerMock->expects($this->at(1))->method('dispatch')->with('controller_action_predispatch_' . self::ROUTE_NAME, $expectedEventParameters); $this->_eventManagerMock->expects($this->at(2))->method('dispatch')->with('controller_action_predispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters); $this->_requestMock->expects($this->once())->method('isDispatched')->will($this->returnValue(true)); $this->_actionFlagMock->expects($this->at(0))->method('get')->with('', Action::FLAG_NO_DISPATCH)->will($this->returnValue(false)); // _forward expectations $this->_requestMock->expects($this->once())->method('initForward'); $this->_requestMock->expects($this->once())->method('setParams')->with(self::$actionParams); $this->_requestMock->expects($this->once())->method('setControllerName')->with(self::CONTROLLER_NAME); $this->_requestMock->expects($this->once())->method('setModuleName')->with(self::MODULE_NAME); $this->_requestMock->expects($this->once())->method('setActionName')->with(self::ACTION_NAME); $this->_requestMock->expects($this->once())->method('setDispatched')->with(false); // _redirect expectations $this->_redirectMock->expects($this->once())->method('redirect')->with($this->_responseMock, self::FULL_ACTION_NAME, self::$actionParams); $this->_actionFlagMock->expects($this->at(1))->method('get')->with('', Action::FLAG_NO_POST_DISPATCH)->will($this->returnValue(false)); $this->_eventManagerMock->expects($this->at(3))->method('dispatch')->with('controller_action_postdispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters); $this->_eventManagerMock->expects($this->at(4))->method('dispatch')->with('controller_action_postdispatch_' . self::ROUTE_NAME, $expectedEventParameters); $this->_eventManagerMock->expects($this->at(5))->method('dispatch')->with('controller_action_postdispatch', $expectedEventParameters); $this->assertEquals($this->_responseMock, $this->action->dispatch($this->_requestMock)); }
public function testGetHtmlTxnIdIsNull() { $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->transaction->setData('txn_id', 'test'); $this->assertEquals('test', $this->transaction->getHtmlTxnId()); $this->assertEquals(null, $this->transaction->getData('html_txn_id')); }
/** * @param bool $result * * @dataProvider dataProviderForTestIsAvailable */ public function testIsAvailable($result) { $storeId = 15; $this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('payment/' . Stub::STUB_CODE . '/active', ScopeInterface::SCOPE_STORE, $storeId)->willReturn($result); $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('payment_method_is_active'), $this->countOf(3)); $this->assertEquals($result, $this->payment->isAvailable($this->quoteMock)); }
public function testAfterSaveDispatchWithStore() { $this->designConfig->expects($this->exactly(2))->method('getScope')->willReturn('store'); $this->designConfig->expects($this->once())->method('getScopeId')->willReturn(1); $this->storeManager->expects($this->once())->method('getStore')->with(1)->willReturn($this->store); $this->eventManager->expects($this->once())->method('dispatch')->with('admin_system_config_changed_section_design', ['website' => '', 'store' => $this->store]); $this->plugin->afterSave($this->repository, $this->designConfig); }
public function testAssignData() { $data = new DataObject(); $paymentInfo = $this->getMock(InfoInterface::class); $this->payment->setInfoInstance($paymentInfo); $eventData = [AbstractDataAssignObserver::METHOD_CODE => $this, AbstractDataAssignObserver::MODEL_CODE => $paymentInfo, AbstractDataAssignObserver::DATA_CODE => $data]; $this->eventManagerMock->expects(static::exactly(2))->method('dispatch')->willReturnMap([['payment_method_assign_data_' . Stub::STUB_CODE, $eventData], ['payment_method_assign_data', $eventData]]); $this->payment->assignData($data); }
public function testUpdateAndGetTranslations() { $translations = ['phrase1' => 'translated1', 'phrase2' => 'translated2']; $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->translateResourceMock->expects($this->once())->method('getTranslationArray')->willReturn($translations); $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn('en_US'); $this->fileManagerMock->expects($this->once())->method('updateTranslationFileContent'); $this->assertEquals($translations, $this->model->updateAndGetTranslations()); }
public function testCheckThemeIsAssigned() { $themeMock = $this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->getMockForAbstractClass(); $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->getMock(); $eventMock->expects($this->any())->method('getData')->with('theme')->willReturn($themeMock); $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock(); $observerMock->expects($this->any())->method('getEvent')->willReturn($eventMock); $this->themeConfig->expects($this->any())->method('isThemeAssignedToStore')->with($themeMock)->willReturn(true); $this->eventDispatcher->expects($this->any())->method('dispatch')->with('assigned_theme_changed', ['theme' => $themeMock]); $this->themeObserver->checkThemeIsAssigned($observerMock); }
/** * @expectedException \Exception * @expectedExceptionMessage Expected Exception * @throws \Exception */ public function testSaveFailed() { $this->modelMock->expects($this->any())->method('getEventPrefix')->will($this->returnValue('event_prefix')); $this->modelMock->expects($this->any())->method('getEventObject')->will($this->returnValue('event_object')); $this->appResourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->connectionMock)); $exception = new \Exception('Expected Exception'); $this->modelMock->expects($this->any())->method('getId')->will($this->throwException($exception)); $this->connectionMock->expects($this->once())->method('beginTransaction'); $this->connectionMock->expects($this->once())->method('rollback'); $this->eventManagerMock->expects($this->once())->method('dispatch')->with('event_prefix_save_attribute_before', ['event_object' => $this->attribute, 'object' => $this->modelMock, 'attribute' => ['attribute']]); $this->attribute->saveAttribute($this->modelMock, 'attribute'); }
public function testGetProductCollection() { $reviewModel = $this->getMock('Magento\\Review\\Model\\Review', ['__wakeUp', 'getProductCollection'], [], '', false); $productCollection = $this->getMock('Magento\\Review\\Model\\Resource\\Review\\Product\\Collection', ['addStatusFilter', 'addAttributeToSelect', 'setDateOrder'], [], '', false); $reviewModel->expects($this->once())->method('getProductCollection')->will($this->returnValue($productCollection)); $this->reviewFactory->expects($this->once())->method('create')->will($this->returnValue($reviewModel)); $productCollection->expects($this->once())->method('addStatusFilter')->will($this->returnSelf()); $productCollection->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf()); $productCollection->expects($this->once())->method('setDateOrder')->will($this->returnSelf()); $this->managerInterface->expects($this->once())->method('dispatch')->will($this->returnSelf()); $this->assertEquals($productCollection, $this->rss->getProductCollection()); }
public function testGetProductsCollection() { /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */ $productCollection = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', [], [], '', false); $this->product->expects($this->once())->method('getCollection')->will($this->returnValue($productCollection)); $productCollection->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf()); $productCollection->expects($this->once())->method('addAttributeToFilter')->will($this->returnSelf()); $productCollection->expects($this->once())->method('setOrder')->will($this->returnSelf()); $this->eventManager->expects($this->once())->method('dispatch')->with('rss_catalog_notify_stock_collection_select'); $this->stock->expects($this->once())->method('addLowStockFilter')->with($productCollection); $products = $this->notifyStock->getProductsCollection(); $this->assertEquals($productCollection, $products); }
public function testDeleteActionThrowsException() { $errorMsg = 'Can\'t delete the page'; $this->requestMock->expects($this->once())->method('getParam')->willReturn($this->pageId); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Page')->willReturn($this->pageMock); $this->pageMock->expects($this->once())->method('load')->with($this->pageId); $this->pageMock->expects($this->once())->method('getTitle')->willReturn($this->title); $this->pageMock->expects($this->once())->method('delete')->willThrowException(new \Exception(__($errorMsg))); $this->eventManagerMock->expects($this->once())->method('dispatch')->with('adminhtml_cmspage_on_delete', ['title' => $this->title, 'status' => 'fail']); $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMsg); $this->messageManagerMock->expects($this->never())->method('addSuccess'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/edit', ['page_id' => $this->pageId])->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->deleteController->execute()); }
/** * @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()); }
/** * Run test toHtml method * * @param bool $customerId * @return void * * @dataProvider dataProviderToHtml */ public function testToHtml($customerId) { $cacheData = false; $idQueryParam = 'id-query-param'; $sessionId = 'session-id'; $this->additional->setData('cache_lifetime', 789); $this->additional->setData('cache_key', 'cache-key'); $this->eventManagerMock->expects($this->once())->method('dispatch')->with('view_block_abstract_to_html_before', ['block' => $this->additional]); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('advanced/modules_disable_output/Magento_Persistent', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(false); // get cache $this->cacheStateMock->expects($this->at(0))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(true); // save cache $this->cacheStateMock->expects($this->at(1))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(false); $this->cacheMock->expects($this->once())->method('load')->willReturn($cacheData); $this->sidResolverMock->expects($this->never())->method('getSessionIdQueryParam')->with($this->sessionMock)->willReturn($idQueryParam); $this->sessionMock->expects($this->never())->method('getSessionId')->willReturn($sessionId); // call protected _toHtml method $sessionMock = $this->getMock('Magento\\Persistent\\Model\\Session', ['getCustomerId'], [], '', false); $this->persistentSessionHelperMock->expects($this->atLeastOnce())->method('getSession')->willReturn($sessionMock); $sessionMock->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($customerId); if ($customerId) { $this->assertEquals('<span><a >Not you?</a></span>', $this->additional->toHtml()); } else { $this->assertEquals('', $this->additional->toHtml()); } }
public function testGeneralSave() { $customerId = 1; $currentPassword = '******'; $customerEmail = '*****@*****.**'; $address = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->getMockForAbstractClass(); $currentCustomerMock = $this->getCurrentCustomerMock($customerId, $address); $newCustomerMock = $this->getNewCustomerMock($customerId, $address); $currentCustomerMock->expects($this->any())->method('getEmail')->willReturn($customerEmail); $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId); $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($currentCustomerMock); $this->validator->expects($this->once())->method('validate')->with($this->request)->willReturn(true); $this->request->expects($this->once())->method('isPost')->willReturn(true); $this->request->expects($this->exactly(3))->method('getParam')->withConsecutive(['change_email'], ['change_email'], ['change_password'])->willReturnOnConsecutiveCalls(true, true, false); $this->request->expects($this->once())->method('getPost')->with('current_password')->willReturn($currentPassword); $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($currentCustomerMock); $this->customerRepository->expects($this->once())->method('save')->with($newCustomerMock)->willReturnSelf(); $this->customerExtractor->expects($this->once())->method('extract')->with('customer_account_edit', $this->request)->willReturn($newCustomerMock); $this->emailNotification->expects($this->once())->method('credentialsChanged')->with($currentCustomerMock, $customerEmail, false)->willReturnSelf(); $newCustomerMock->expects($this->once())->method('getEmail')->willReturn($customerEmail); $this->eventManager->expects($this->once())->method('dispatch')->with('customer_account_edited', ['email' => $customerEmail]); $this->messageManager->expects($this->once())->method('addSuccess')->with(__('You saved the account information.'))->willReturnSelf(); $this->resultRedirect->expects($this->once())->method('setPath')->with('customer/account')->willReturnSelf(); $this->authenticationMock->expects($this->once())->method('authenticate')->willReturn(true); $this->assertSame($this->resultRedirect, $this->model->execute()); }
public function testSubmit() { $orderData = []; $isGuest = true; $isVirtual = false; $customerId = 1; $quoteId = 1; $quoteItem = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', [], [], '', false); $billingAddress = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false); $shippingAddress = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false); $payment = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false); $baseOrder = $this->getMock('Magento\\Sales\\Api\\Data\\OrderInterface', [], [], '', false); $convertedBillingAddress = $this->getMock('Magento\\Sales\\Api\\Data\\OrderAddressInterface', [], [], '', false); $convertedShippingAddress = $this->getMock('Magento\\Sales\\Api\\Data\\OrderAddressInterface', [], [], '', false); $convertedPayment = $this->getMock('Magento\\Sales\\Api\\Data\\OrderPaymentInterface', [], [], '', false); $convertedQuoteItem = $this->getMock('Magento\\Sales\\Api\\Data\\OrderItemInterface', [], [], '', false); $addresses = [$convertedShippingAddress, $convertedBillingAddress]; $payments = [$convertedPayment]; $quoteItems = [$quoteItem]; $convertedItems = [$convertedQuoteItem]; $quote = $this->getQuote($isGuest, $isVirtual, $billingAddress, $payment, $customerId, $quoteId, $quoteItems, $shippingAddress); $this->quoteValidator->expects($this->once())->method('validateBeforeSubmit')->with($quote); $this->quoteAddressToOrder->expects($this->once())->method('convert')->with($shippingAddress, $orderData)->willReturn($baseOrder); $this->quoteAddressToOrderAddress->expects($this->at(0))->method('convert')->with($shippingAddress, ['address_type' => 'shipping', 'email' => '*****@*****.**'])->willReturn($convertedShippingAddress); $this->quoteAddressToOrderAddress->expects($this->at(1))->method('convert')->with($billingAddress, ['address_type' => 'billing', 'email' => '*****@*****.**'])->willReturn($convertedBillingAddress); $this->quoteItemToOrderItem->expects($this->once())->method('convert')->with($quoteItem, ['parent_item' => null])->willReturn($convertedQuoteItem); $this->quotePaymentToOrderPayment->expects($this->once())->method('convert')->with($payment)->willReturn($convertedPayment); $order = $this->prepareOrderFactory($baseOrder, $convertedBillingAddress, $addresses, $payments, $convertedItems, $quoteId, $convertedShippingAddress); $this->orderManagement->expects($this->once())->method('place')->with($order)->willReturn($order); $this->eventManager->expects($this->at(0))->method('dispatch')->with('sales_model_service_quote_submit_before', ['order' => $order, 'quote' => $quote]); $this->eventManager->expects($this->at(1))->method('dispatch')->with('sales_model_service_quote_submit_success', ['order' => $order, 'quote' => $quote]); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quote); $this->assertEquals($order, $this->model->submit($quote, $orderData)); }
/** * Test for execute method * * @return void */ public function testExecuteWithSuccessOrderSave() { $testData = $this->getExecuteWithSuccessOrderSaveTestData(); $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $paymentMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock(); $checkoutMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods(['getRedirectUrl'])->getMock(); $resultJsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock(); $redirectMock->expects($this->never())->method('setPath')->with('*/*/')->willReturn('redirect'); $this->formKeyValidatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true); $this->resultRedirectFactoryMock->expects($this->never())->method('create')->willReturn($redirectMock); $this->objectManagerMock->expects($this->atLeastOnce())->method('get')->willReturnMap($testData['objectManager.get']); // call _expireAjax method $this->expireAjaxFlowHasItemsFalse(); $this->requestMock->expects($this->atLeastOnce())->method('getPost')->willReturnMap($testData['request.getPost']); $this->agreementsValidatorMock->expects($this->once())->method('isValid')->with($testData['agreementsValidator.isValid'])->willReturn(true); $this->quoteMock->expects($this->atLeastOnce())->method('getPayment')->willReturn($paymentMock); $paymentMock->expects($this->once())->method('setQuote')->with($this->quoteMock); $paymentMock->expects($this->once())->method('importData')->with($testData['payment.importData']); $this->onepageMock->expects($this->once())->method('saveOrder'); $this->onepageMock->expects($this->once())->method('getCheckout')->willReturn($checkoutMock); $checkoutMock->expects($this->once())->method('getRedirectUrl')->willReturn(null); $this->eventManagerMock->expects($this->once())->method('dispatch')->withConsecutive($this->equalTo('checkout_controller_onepage_saveOrder'), $this->countOf(2)); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($resultJsonMock); $resultJsonMock->expects($this->once())->method('setData')->with($testData['resultJson.setData'])->willReturnSelf(); $this->assertEquals($resultJsonMock, $this->controller->execute()); }
public function testToHtml() { $this->eventManager->expects($this->once())->method('dispatch')->with('view_block_abstract_to_html_before', ['block' => $this->block]); $this->scopeConfig->expects($this->once())->method('getValue')->willReturn(false); $this->urlBuilder->expects($this->once())->method('getUrl')->with('paypal/billing_agreement/startWizard', []); $this->block->toHtml(); }
public function testAddMessages() { $messageCollection = $this->getMock('Magento\\Framework\\Message\\Collection', ['getItems', 'addMessage'], [], '', false); $this->session->expects($this->any())->method('getData')->will($this->returnValue($messageCollection)); $this->eventManager->expects($this->once())->method('dispatch')->with('session_abstract_add_message'); $messageCollection->expects($this->once())->method('addMessage')->with($this->messageMock); $this->model->addMessages([$this->messageMock]); }
/** * @covers \Magento\Paypal\Model\Payflowpro::assignData */ public function testAssignData() { $data = ['cc_type' => 'VI', 'cc_last_4' => 1111, 'cc_exp_month' => 12, 'cc_exp_year' => 2023]; $dataObject = new DataObject($data); $infoInstance = $this->getMockForAbstractClass(InfoInterface::class); $this->payflowpro->setData('info_instance', $infoInstance); $this->eventManager->expects(static::exactly(2))->method('dispatch'); $this->payflowpro->assignData($dataObject); }
/** * @param bool $allowedValue * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function generalSettingsIsUsingStaticUrlsAllowed($allowedValue) { $storeId = 1; $this->imagesHelper->setStoreId($storeId); $checkResult = new \StdClass(); $checkResult->isAllowed = false; $this->eventManagerMock->expects($this->any())->method('dispatch')->with('cms_wysiwyg_images_static_urls_allowed', ['result' => $checkResult, 'store_id' => $storeId])->willReturnCallback(function ($str, $arr) use($allowedValue) { $arr['result']->isAllowed = $allowedValue; }); }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @return void */ public function testAuthenticateException() { $username = '******'; $password = '******'; $config = 'config'; $this->configMock->expects($this->once())->method('isSetFlag')->with('admin/security/use_case_sensitive_login')->willReturn($config); $this->eventManagerMock->expects($this->any())->method('dispatch'); $this->resourceMock->expects($this->once())->method('loadByUsername')->willThrowException(new \Magento\Framework\Exception\LocalizedException(__())); $this->model->authenticate($username, $password); }
/** * @param array $data * @param array $convertedData * @param array $dataToAssign * @param array $checks * @dataProvider importDataPositiveCheckDataProvider */ public function testImportDataPositiveCheck(array $data, array $convertedData, array $dataToAssign, array $checks) { $quoteId = 1; $storeId = 1; $paymentMethod = $this->getMock(MethodInterface::class); $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock(); $methodSpecification = $this->getMockBuilder(Composite::class)->disableOriginalConstructor()->getMock(); $quote->expects(static::once())->method('getId')->willReturn($quoteId); $this->model->setQuote($quote); $this->model->setMethodInstance($paymentMethod); $this->eventManager->expects(static::once())->method('dispatch')->with('sales_quote_payment_import_data_before', ['payment' => $this->model, 'input' => new DataObject($convertedData)]); $quote->expects(static::once())->method('getStoreId')->willReturn($storeId); $quote->expects(static::once())->method('collectTotals'); $this->specificationFactory->expects(static::once())->method('create')->with($checks)->willReturn($methodSpecification); $paymentMethod->expects(static::once())->method('isAvailable')->with($quote)->willReturn(true); $methodSpecification->expects(static::once())->method('isApplicable')->with($paymentMethod, $quote)->willReturn(true); $paymentMethod->expects(static::once())->method('assignData')->with(new DataObject($dataToAssign)); $paymentMethod->expects(static::once())->method('validate'); $this->model->importData($data); }
/** * @covers \Magento\Cms\Helper\Page::renderPageExtended * @param integer|null $pageId * @param integer|null $internalPageId * @param integer $pageLoadResultIndex * @param string $customPageLayout * @param string $handle * @param string $customLayoutUpdateXml * @param string $layoutUpdate * @param boolean $expectedResult * * @dataProvider renderPageExtendedDataProvider * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testRenderPageExtended($pageId, $internalPageId, $pageLoadResultIndex, $customPageLayout, $handle, $customLayoutUpdateXml, $layoutUpdate, $expectedResult) { $storeId = 321; $customThemeFrom = 'customThemeFrom'; $customThemeTo = 'customThemeTo'; $isScopeDateInInterval = true; $customTheme = 'customTheme'; $pageLayout = 'pageLayout'; $pageIdentifier = 111; $layoutUpdateXml = 'layoutUpdateXml'; $contentHeading = 'contentHeading'; $escapedContentHeading = 'escapedContentHeading'; $defaultGroup = 'defaultGroup'; $pageLoadResultCollection = [null, $this->pageMock]; $this->pageMock->expects($this->any())->method('getId')->willReturn($internalPageId); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId); $this->pageMock->expects($this->any())->method('setStoreId')->with($storeId)->willReturnSelf(); $this->pageMock->expects($this->any())->method('load')->with($pageId)->willReturn($pageLoadResultCollection[$pageLoadResultIndex]); $this->pageMock->expects($this->any())->method('getCustomThemeFrom')->willReturn($customThemeFrom); $this->pageMock->expects($this->any())->method('getCustomThemeTo')->willReturn($customThemeTo); $this->localeDateMock->expects($this->any())->method('isScopeDateInInterval')->with(null, $customThemeFrom, $customThemeTo)->willReturn($isScopeDateInInterval); $this->pageMock->expects($this->any())->method('getCustomTheme')->willReturn($customTheme); $this->designMock->expects($this->any())->method('setDesignTheme')->with($customTheme)->willReturnSelf(); $this->pageMock->expects($this->any())->method('getPageLayout')->willReturn($pageLayout); $this->pageMock->expects($this->any())->method('getCustomPageLayout')->willReturn($customPageLayout); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('setPageLayout')->with($handle)->willReturnSelf(); $this->viewMock->expects($this->any())->method('getPage')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->any())->method('initLayout')->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->layoutProcessorMock); $this->layoutProcessorMock->expects($this->any())->method('addHandle')->with('cms_page_view')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getIdentifier')->willReturn($pageIdentifier); $this->viewMock->expects($this->any())->method('addPageLayoutHandles')->with(['id' => $pageIdentifier])->willReturn(true); $this->eventManagerMock->expects($this->any())->method('dispatch')->with('cms_page_render', ['page' => $this->pageMock, 'controller_action' => $this->actionMock]); $this->viewMock->expects($this->any())->method('loadLayoutUpdates')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getCustomLayoutUpdateXml')->willReturn($customLayoutUpdateXml); $this->pageMock->expects($this->any())->method('getLayoutUpdateXml')->willReturn($layoutUpdateXml); $this->layoutProcessorMock->expects($this->any())->method('addUpdate')->with($layoutUpdate)->willReturnSelf(); $this->viewMock->expects($this->any())->method('generateLayoutXml')->willReturnSelf(); $this->viewMock->expects($this->any())->method('generateLayoutBlocks')->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getBlock')->with('page_content_heading')->willReturn($this->blockMock); $this->pageMock->expects($this->any())->method('getContentHeading')->willReturn($contentHeading); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($contentHeading)->willReturn($escapedContentHeading); $this->blockMock->expects($this->any())->method('setContentHeading')->with($escapedContentHeading)->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getMessagesBlock')->willReturn($this->messagesBlockMock); $this->messageManagerMock->expects($this->any())->method('getDefaultGroup')->willReturn($defaultGroup); $this->messagesBlockMock->expects($this->any())->method('addStorageType')->with($defaultGroup); $this->messageManagerMock->expects($this->any())->method('getMessages')->with(true)->willReturn($this->messageCollectionMock); $this->messagesBlockMock->expects($this->any())->method('addMessages')->with($this->messageCollectionMock)->willReturnSelf(); $this->viewMock->expects($this->any())->method('renderLayout')->willReturnSelf(); $this->assertEquals($expectedResult, $this->object->renderPageExtended($this->actionMock, $pageId)); }
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'); }
public function testLoadByCustomerId() { $customerId = 1; $customerIdFieldName = 'customer_id'; $sharingCode = 'expected_sharing_code'; $this->eventDispatcher->expects($this->any())->method('dispatch'); $this->resource->expects($this->any())->method('getCustomerIdFieldName'); $this->resource->expects($this->once())->method('load')->with($this->logicalOr($this->wishlist, $customerId, $customerIdFieldName)); $this->mathRandom->expects($this->once())->method('getUniqueHash')->will($this->returnValue($sharingCode)); $this->assertInstanceOf('Magento\\Wishlist\\Model\\Wishlist', $this->wishlist->loadByCustomerId($customerId, true)); $this->assertEquals($customerId, $this->wishlist->getCustomerId()); $this->assertEquals($sharingCode, $this->wishlist->getSharingCode()); }
/** * @return void */ public function testAuthenticate() { $username = '******'; $password = '******'; $customerData = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customerModel = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock(); $customerModel->expects($this->once())->method('updateData')->willReturn($customerModel); $this->customerRepository->expects($this->once())->method('get')->with($username)->willReturn($customerData); $this->accountManagementHelper->expects($this->once())->method('checkIfLocked')->with($customerData); $this->accountManagementHelper->expects($this->once())->method('validatePasswordAndLockStatus')->with($customerData, $password); $this->customerFactory->expects($this->once())->method('create')->willReturn($customerModel); $this->manager->expects($this->exactly(2))->method('dispatch')->withConsecutive(['customer_customer_authenticated', ['model' => $customerModel, 'password' => $password]], ['customer_data_object_login', ['customer' => $customerData]]); $this->assertEquals($customerData, $this->accountManagement->authenticate($username, $password)); }
/** * @covers \Magento\Cms\Helper\Page::prepareResultPage * @param integer|null $pageId * @param integer|null $internalPageId * @param integer $pageLoadResultIndex * @param string $customPageLayout * @param string $handle * @param string $customLayoutUpdateXml * @param string $layoutUpdate * @param boolean $expectedResult * * @dataProvider renderPageExtendedDataProvider * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testPrepareResultPage($pageId, $internalPageId, $pageLoadResultIndex, $customPageLayout, $handle, $customLayoutUpdateXml, $layoutUpdate, $expectedResult) { $storeId = 321; $customThemeFrom = 'customThemeFrom'; $customThemeTo = 'customThemeTo'; $isScopeDateInInterval = true; $customTheme = 'customTheme'; $pageLayout = 'pageLayout'; $pageIdentifier = 111; $layoutUpdateXml = 'layoutUpdateXml'; $contentHeading = 'contentHeading'; $escapedContentHeading = 'escapedContentHeading'; $pageLoadResultCollection = [null, $this->pageMock]; $this->pageMock->expects($this->any())->method('getId')->willReturn($internalPageId); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId); $this->pageMock->expects($this->any())->method('setStoreId')->with($storeId)->willReturnSelf(); $this->pageMock->expects($this->any())->method('load')->with($pageId)->willReturn($pageLoadResultCollection[$pageLoadResultIndex]); $this->pageMock->expects($this->any())->method('getCustomThemeFrom')->willReturn($customThemeFrom); $this->pageMock->expects($this->any())->method('getCustomThemeTo')->willReturn($customThemeTo); $this->localeDateMock->expects($this->any())->method('isScopeDateInInterval')->with(null, $customThemeFrom, $customThemeTo)->willReturn($isScopeDateInInterval); $this->pageMock->expects($this->any())->method('getCustomTheme')->willReturn($customTheme); $this->designMock->expects($this->any())->method('setDesignTheme')->with($customTheme)->willReturnSelf(); $this->pageMock->expects($this->any())->method('getPageLayout')->willReturn($pageLayout); $this->pageMock->expects($this->any())->method('getCustomPageLayout')->willReturn($customPageLayout); $this->resultPageFactory->expects($this->any())->method('create')->will($this->returnValue($this->resultPageMock)); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('setPageLayout')->with($handle)->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('initLayout')->willReturnSelf(); $this->resultPageMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->layoutProcessorMock); $this->layoutProcessorMock->expects($this->any())->method('addHandle')->with('cms_page_view')->willReturnSelf(); $this->pageMock->expects($this->any())->method('getIdentifier')->willReturn($pageIdentifier); $this->eventManagerMock->expects($this->any())->method('dispatch')->with('cms_page_render', ['page' => $this->pageMock, 'controller_action' => $this->actionMock]); $this->pageMock->expects($this->any())->method('getCustomLayoutUpdateXml')->willReturn($customLayoutUpdateXml); $this->pageMock->expects($this->any())->method('getLayoutUpdateXml')->willReturn($layoutUpdateXml); $this->layoutProcessorMock->expects($this->any())->method('addUpdate')->with($layoutUpdate)->willReturnSelf(); $this->layoutMock->expects($this->any())->method('getBlock')->with('page_content_heading')->willReturn($this->blockMock); $this->pageMock->expects($this->any())->method('getContentHeading')->willReturn($contentHeading); $this->escaperMock->expects($this->any())->method('escapeHtml')->with($contentHeading)->willReturn($escapedContentHeading); $this->blockMock->expects($this->any())->method('setContentHeading')->with($escapedContentHeading)->willReturnSelf(); if ($expectedResult) { $expectedResult = $this->resultPageMock; } $this->assertSame($expectedResult, $this->object->prepareResultPage($this->actionMock, $pageId)); }
/** * @return void */ public function testAuthenticate() { $username = '******'; $password = '******'; $passwordHash = '1a2b3f4c'; $customerData = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customerModel = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock(); $customerModel->expects($this->once())->method('updateData')->willReturn($customerModel); $this->customerRepository->expects($this->once())->method('get')->with($username)->willReturn($customerData); $this->authenticationMock->expects($this->once())->method('authenticate'); $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['getPasswordHash'])->disableOriginalConstructor()->getMock(); $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($passwordHash); $this->customerRegistry->expects($this->any())->method('retrieveSecureData')->willReturn($customerSecure); $this->customerFactory->expects($this->once())->method('create')->willReturn($customerModel); $this->manager->expects($this->exactly(2))->method('dispatch')->withConsecutive(['customer_customer_authenticated', ['model' => $customerModel, 'password' => $password]], ['customer_data_object_login', ['customer' => $customerData]]); $this->assertEquals($customerData, $this->accountManagement->authenticate($username, $password)); }