public function testExecuteWithException() { $objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock(); $this->transactionMock->expects($this->once())->method('getResponseObject')->willReturn($objectMock); $this->responseValidatorMock->expects($this->once())->method('validate')->with($objectMock)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('Error'))); $this->coreRegistryMock->expects($this->once())->method('register')->with('transparent_form_params', $this->arrayHasKey('error')); $this->resultLayoutMock->expects($this->once())->method('addDefaultHandle')->willReturnSelf(); $this->resultLayoutMock->expects($this->once())->method('getLayout')->willReturn($this->getLayoutMock()); $this->assertInstanceOf('\\Magento\\Framework\\Controller\\ResultInterface', $this->object->executeInternal()); }
/** * @covers \Magento\Marketplace\Controller\Adminhtml\Partners\Index::executeInternal */ public function testExecute() { $requestMock = $this->getRequestMock(['isAjax']); $requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true)); $this->partnersControllerMock->expects($this->once())->method('getRequest')->will($this->returnValue($requestMock)); $layoutMock = $this->getLayoutMock(); $blockMock = $this->getBlockInterfaceMock(); $blockMock->expects($this->once())->method('toHtml')->will($this->returnValue('')); $layoutMock->expects($this->once())->method('createBlock')->will($this->returnValue($blockMock)); $layoutMockFactory = $this->getLayoutFactoryMock(['create']); $layoutMockFactory->expects($this->once())->method('create')->will($this->returnValue($layoutMock)); $this->partnersControllerMock->expects($this->once())->method('getLayoutFactory')->will($this->returnValue($layoutMockFactory)); $responseMock = $this->getResponseMock(['appendBody']); $responseMock->expects($this->once())->method('appendBody')->will($this->returnValue('')); $this->partnersControllerMock->expects($this->once())->method('getResponse')->will($this->returnValue($responseMock)); $this->partnersControllerMock->executeInternal(); }
public function testNewsletterAction() { $subscriberMock = $this->getMock('\\Magento\\Newsletter\\Model\\Subscriber', [], [], '', false); $this->resultLayoutFactoryMock->expects($this->once())->method('create')->willReturn($this->resultLayoutMock); $subscriberMock->expects($this->once())->method('loadByCustomerId'); $this->_objectManager->expects($this->any())->method('create')->with('Magento\\Newsletter\\Model\\Subscriber')->willReturn($subscriberMock); $this->assertInstanceOf('Magento\\Framework\\View\\Result\\Layout', $this->_testedObject->executeInternal()); }
public function testExecuteEmptyQuoteError() { $resultExpectation = ['success' => false, 'error' => true, 'error_messages' => __('Your payment has been declined. Please try again.')]; $quoteMock = null; $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock(); $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock); $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf(); $this->assertEquals($jsonMock, $this->controller->executeInternal()); }
public function testExecuteInternalSuccess() { $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->executeInternal()); }
public function testExecuteValidPost() { $post = ['name' => 'Name', 'comment' => 'Comment', 'email' => '*****@*****.**', 'hideit' => null]; $this->_request->expects($this->any())->method('getPostValue')->will($this->returnValue($post)); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface', [], [], '', false); $this->_transportBuilder->expects($this->once())->method('setTemplateIdentifier')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setTemplateOptions')->with(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setTemplateVars')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setFrom')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('addTo')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setReplyTo')->with($post['email'])->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('getTransport')->will($this->returnValue($transport)); $transport->expects($this->once())->method('sendMessage'); $this->_inlineTranslation->expects($this->once())->method('resume'); $this->_inlineTranslation->expects($this->once())->method('suspend'); $this->_controller->executeInternal(); }
public function testResetPasswordActionSendEmail() { $customerId = 1; $email = '*****@*****.**'; $websiteId = 1; $redirectLink = 'customer/*/edit'; $this->_request->expects($this->once())->method('getParam')->with($this->equalTo('customer_id'), $this->equalTo(0))->will($this->returnValue($customerId)); $customer = $this->getMockForAbstractClass('\\Magento\\Customer\\Api\\Data\\CustomerInterface', ['getId', 'getEmail', 'getWebsiteId']); $customer->expects($this->once())->method('getEmail')->will($this->returnValue($email)); $customer->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId)); $this->_customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->will($this->returnValue($customer)); // verify initiatePasswordReset() is called $this->_customerAccountManagementMock->expects($this->once())->method('initiatePasswordReset')->with($email, AccountManagement::EMAIL_REMINDER, $websiteId); // verify success message $this->messageManager->expects($this->once())->method('addSuccess')->with($this->equalTo('The customer will receive an email with a link to reset password.')); // verify redirect $this->_helper->expects($this->any())->method('getUrl')->with($this->equalTo('customer/*/edit'), $this->equalTo(['id' => $customerId, '_current' => true]))->will($this->returnValue($redirectLink)); $this->resultRedirectMock->expects($this->once())->method('setPath')->with($redirectLink, ['id' => $customerId, '_current' => true]); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->_testedObject->executeInternal()); }
public function testExecuteBadSecretKey() { $this->itemOptionMock->expects($this->once())->method('load')->willReturnSelf(); $this->itemOptionMock->expects($this->once())->method('getId')->willReturn(self::OPTION_ID); $this->itemOptionMock->expects($this->any())->method('getCode')->willReturn(self::OPTION_CODE); $this->itemOptionMock->expects($this->any())->method('getProductId')->willReturn(self::OPTION_PRODUCT_ID); $this->itemOptionMock->expects($this->any())->method('getValue')->willReturn(self::OPTION_VALUE); $this->productOptionMock->expects($this->once())->method('load')->willReturnSelf(); $this->productOptionMock->expects($this->any())->method('getId')->willReturn(self::OPTION_ID); $this->productOptionMock->expects($this->any())->method('getProductId')->willReturn(self::OPTION_PRODUCT_ID); $this->productOptionMock->expects($this->any())->method('getType')->willReturn(self::OPTION_TYPE); $this->unserializeMock->expects($this->once()) ->method('unserialize') ->with(self::OPTION_VALUE) ->willReturn([self::SECRET_KEY => 'bad_test_secret_key']); $this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturn(true); $this->objectMock->executeInternal(); }