public function testExecute() { //Data $formKey = '<asdfaswqrwqe12>'; $escapedFormKey = 'asdfaswqrwqe12'; //Verification $this->_formKey->expects($this->once())->method('get')->will($this->returnValue($formKey)); $this->_escaper->expects($this->once())->method('escapeHtml')->with($formKey)->will($this->returnValue($escapedFormKey)); $this->_session->expects($this->once())->method('setData')->with(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $escapedFormKey); $this->_model->execute(); }
public function testSavePaymentInQuote() { $quoteId = 1; $response = new DataObject(); $payment = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock(); $payment->expects($this->once())->method('setAdditionalInformation')->with('pnref'); $this->errorHandlerMock->expects($this->once())->method('handle')->with($payment, $response); $quote = $this->getMock('Magento\\Quote\\Api\\Data\\CartInterface', [], [], '', false); $quote->expects($this->exactly(2))->method('getId')->willReturn($quoteId); $this->sessionTransparent->expects($this->once())->method('getQuoteId')->willReturn($quoteId); $this->quoteRepository->expects($this->once())->method('get')->willReturn($quote); $this->paymentMethodManagementInterface->expects($this->once())->method('get')->willReturn($payment); $this->paymentMethodManagementInterface->expects($this->once())->method('set'); $this->model->savePaymentInQuote($response); }
public function testSessionUrlVarWithoutMatchedHostsAndBaseUrl() { $requestMock = $this->getRequestMock(); $model = $this->getUrlModel( [ 'session' => $this->sessionMock, 'request' => $requestMock, 'sidResolver' => $this->sidResolverMock, 'scopeResolver' => $this->scopeResolverMock, 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), ] ); $requestMock->expects($this->once())->method('getHttpHost')->will($this->returnValue('localhost')); $this->scopeMock->expects($this->once()) ->method('getBaseUrl') ->will($this->returnValue('http://example.com')); $this->scopeResolverMock->expects($this->any()) ->method('getScope') ->will($this->returnValue($this->scopeMock)); $this->sidResolverMock->expects($this->once())->method('getSessionIdQueryParam') ->will($this->returnValue('SID')); $this->sessionMock->expects($this->once())->method('getSessionId') ->will($this->returnValue('session-id')); $this->assertEquals( '<a href="http://example.com/?SID=session-id">www.example.com</a>', $model->sessionUrlVar('<a href="http://example.com/?___SID=U">www.example.com</a>') ); }
/** * Set up before test * * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->_objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_installerMock = $this->getMock('\\Magento\\Install\\Model\\Installer', array('isApplicationInstalled'), array(), '', false); $this->_installerMock->expects($this->any())->method('isApplicationInstalled')->will($this->returnValue(true)); $this->_blockMock = $this->getMock('\\Magento\\Install\\Block\\Locale', array(), array(), '', false); $this->_layoutMock = $this->getMock('\\Magento\\Framework\\View\\Layout', array('getBlock', 'initMessages', 'addBlock'), array(), '', false); $this->_layoutMock->expects($this->any())->method('initMessages')->withAnyParameters()->will($this->returnValue(true)); $this->_layoutMock->expects($this->any())->method('addBlock')->withAnyParameters()->will($this->returnValue(true)); $this->_viewMock = $this->getMockForAbstractClass('\\Magento\\Framework\\App\\ViewInterface', array(), '', false, false, true, array('getLayout')); $this->_viewMock->expects($this->any())->method('getLayout')->withAnyParameters()->will($this->returnValue($this->_layoutMock)); $this->_requestMock = $this->_getClearMock('\\Magento\\Framework\\App\\RequestInterface'); $this->_responseMock = $this->_getClearMock('\\Magento\\Framework\\App\\ResponseInterface'); $this->_actionFlagMock = $this->_getClearMock('\\Magento\\Framework\\App\\ActionFlag'); $this->_contextMock = $this->getMock('\\Magento\\Framework\\App\\Action\\Context', array('getView', 'getRequest', 'getResponse', 'getActionFlag'), array(), '', false); $this->_contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->_viewMock)); $this->_contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->_requestMock)); $this->_contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->_responseMock)); $this->_contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->_actionFlagMock)); $this->_blockContextMock = $this->getMock('\\Magento\\Framework\\View\\Element\\Template\\Context', array(), array(), '', false); $this->_wizardMock = $this->getMock('\\Magento\\Install\\Model\\Wizard', array('getStepByRequest'), array(), '', false); $this->_wizardMock->expects($this->any())->method('getStepByRequest')->withAnyParameters()->will($this->returnValue(false)); $this->_sessionMock = $this->getMock('\\Magento\\Framework\\Session\\Generic', array('getLocale'), array(), '', false); $this->_sessionMock->expects($this->any())->method('getLocale')->will($this->returnValue(self::LOCALE)); $this->_block = $this->_objectManager->getObject('Magento\\Install\\Block\\Locale', array('context' => $this->_blockContextMock, 'installer' => $this->_installerMock, 'installWizard' => $this->_wizardMock, 'session' => $this->_sessionMock, 'data' => array())); $this->_layoutMock->expects($this->any())->method('getBlock')->with('install.locale')->will($this->returnValue($this->_block)); $this->_controller = $this->_objectManager->getObject('Magento\\Install\\Controller\\Wizard\\Locale', array('context' => $this->_contextMock, 'configScope' => $this->_getClearMock('Magento\\Framework\\Config\\Scope'), 'installer' => $this->_getClearMock('Magento\\Install\\Model\\Installer'), 'wizard' => $this->_wizardMock, 'session' => $this->_sessionMock, 'dbUpdater' => $this->_getClearMock('Magento\\Framework\\Module\\UpdaterInterface'), 'storeManager' => $this->_getClearMock('Magento\\Store\\Model\\StoreManagerInterface'), 'appState' => $this->_getClearMock('Magento\\Framework\\App\\State'))); }
/** * Run test execute method * * @param array $result * @param array $resultExpectation * * @dataProvider executeDataProvider */ public function testExecute(array $result, array $resultExpectation) { $quoteId = 99; $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock(); $tokenMock = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['getData', 'getSecuretoken'])->disableOriginalConstructor()->getMock(); $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock(); $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent'); $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock); $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId); $this->sessionTransparentMock->expects($this->once())->method('setQuoteId')->with($quoteId); $this->secureTokenServiceMock->expects($this->once())->method('requestToken')->with($quoteMock)->willReturn($tokenMock); $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent'); $tokenMock->expects($this->once())->method('getData')->willReturn($result['transparent']['fields']); $tokenMock->expects($this->once())->method('getSecuretoken')->willReturn($result['success']); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock); $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf(); $this->assertEquals($jsonMock, $this->controller->execute()); }
public function testToHtmlCoreRegistryRatingData() { $this->registry->expects($this->any())->method('registry')->will($this->returnValue($this->rating)); $this->form->expects($this->at(7))->method('getElement')->will($this->returnValue($this->element)); $this->form->expects($this->at(13))->method('getElement')->will($this->returnValue($this->element)); $this->form->expects($this->at(16))->method('getElement')->will($this->returnValue($this->element)); $this->form->expects($this->at(17))->method('getElement')->will($this->returnValue($this->element)); $this->form->expects($this->any())->method('getElement')->will($this->returnValue(false)); $this->session->expects($this->any())->method('getRatingData')->will($this->returnValue(false)); $ratingCodes = ['rating_codes' => ['0' => 'rating_code']]; $this->rating->expects($this->any())->method('getRatingCodes')->will($this->returnValue($ratingCodes)); $this->block->toHtml(); }
public function testExecuteTokenRequestException() { $quoteId = 99; $resultExpectation = ['success' => false, 'error' => true, 'error_messages' => __('Your payment has been declined. Please try again.')]; $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock(); $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock(); $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock); $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId); $this->sessionTransparentMock->expects($this->once())->method('setQuoteId')->with($quoteId); $this->secureTokenServiceMock->expects($this->once())->method('requestToken')->with($quoteMock)->willThrowException(new \Exception()); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock); $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf(); $this->assertEquals($jsonMock, $this->controller->execute()); }
public function testAfterGenerateXmlNoDepersonalize() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false); $this->visitorMock->expects($this->never())->method('setSkipRequestLogging'); $this->visitorMock->expects($this->never())->method('unsetData'); $this->sessionMock->expects($this->never())->method('clearStorage'); $this->customerSessionMock->expects($this->never())->method('clearStorage'); $this->customerSessionMock->expects($this->never())->method('setCustomerGroupId'); $this->customerMock->expects($this->never())->method('setGroupId'); $this->sessionMock->expects($this->never())->method('setData'); $this->customerSessionMock->expects($this->never())->method('setCustomer'); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertSame($expectedResult, $actualResult); }
/** * Test method afterGenerateXml with enabled module PageCache */ public function testAfterGenerateXmlPageCacheEnabled() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->will($this->returnValue(true)); $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false)); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true)); $this->visitorMock->expects($this->once())->method('setSkipRequestLogging')->with($this->equalTo(true)); $this->visitorMock->expects($this->once())->method('unsetData'); $this->sessionMock->expects($this->once())->method('clearStorage'); $this->customerSessionMock->expects($this->once())->method('clearStorage'); $this->customerSessionMock->expects($this->once())->method('setCustomerGroupId')->with($this->equalTo(null)); $this->customerMock->expects($this->once())->method('setGroupId')->with($this->equalTo(null)); $this->sessionMock->expects($this->once())->method('setData')->with($this->equalTo(\Magento\Framework\Data\Form\FormKey::FORM_KEY), $this->equalTo(null)); $this->customerSessionMock->expects($this->once())->method('setCustomer')->with($this->equalTo($this->customerMock)); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertSame($expectedResult, $actualResult); }