/** * Prepare required values * * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->_request = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->_response = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http')->disableOriginalConstructor()->setMethods(array('setRedirect', 'getHeader'))->getMock(); $this->_response->expects($this->any())->method('getHeader')->with($this->equalTo('X-Frame-Options'))->will($this->returnValue(true)); $this->_objectManager = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->setMethods(array('get', 'create'))->getMock(); $frontControllerMock = $this->getMockBuilder('Magento\\Framework\\App\\FrontController')->disableOriginalConstructor()->getMock(); $actionFlagMock = $this->getMockBuilder('Magento\\Framework\\App\\ActionFlag')->disableOriginalConstructor()->getMock(); $this->_session = $this->getMockBuilder('Magento\\Backend\\Model\\Session')->disableOriginalConstructor()->setMethods(array('setIsUrlNotice', '__wakeup'))->getMock(); $this->_session->expects($this->any())->method('setIsUrlNotice'); $this->_helper = $this->getMockBuilder('Magento\\Backend\\Helper\\Data')->disableOriginalConstructor()->setMethods(array('getUrl'))->getMock(); $this->messageManager = $this->getMockBuilder('Magento\\Framework\\Message\\Manager')->disableOriginalConstructor()->setMethods(array('addSuccess', 'addMessage', 'addException'))->getMock(); $contextArgs = array('getHelper', 'getSession', 'getAuthorization', 'getTranslator', 'getObjectManager', 'getFrontController', 'getActionFlag', 'getMessageManager', 'getLayoutFactory', 'getEventManager', 'getRequest', 'getResponse', 'getTitle', 'getView'); $contextMock = $this->getMockBuilder('\\Magento\\Backend\\App\\Action\\Context')->disableOriginalConstructor()->setMethods($contextArgs)->getMock(); $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->_request)); $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->_response)); $contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->_objectManager)); $contextMock->expects($this->any())->method('getFrontController')->will($this->returnValue($frontControllerMock)); $contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlagMock)); $contextMock->expects($this->any())->method('getHelper')->will($this->returnValue($this->_helper)); $contextMock->expects($this->any())->method('getSession')->will($this->returnValue($this->_session)); $contextMock->expects($this->any())->method('getMessageManager')->will($this->returnValue($this->messageManager)); $titleMock = $this->getMockBuilder('\\Magento\\Framework\\App\\Action\\Title')->getMock(); $contextMock->expects($this->any())->method('getTitle')->will($this->returnValue($titleMock)); $viewMock = $this->getMockBuilder('\\Magento\\Framework\\App\\ViewInterface')->getMock(); $viewMock->expects($this->any())->method('loadLayout')->will($this->returnSelf()); $contextMock->expects($this->any())->method('getView')->will($this->returnValue($viewMock)); $this->_acctServiceMock = $this->getMockBuilder('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface')->getMock(); $args = array('context' => $contextMock, 'accountService' => $this->_acctServiceMock); $helperObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_testedObject = $helperObjectManager->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Newsletter', $args); }
public function testRender() { $content = '<content>test</content>'; $this->raw->setContents($content); $this->response->expects($this->once())->method('setBody')->with($content); $this->assertSame($this->raw, $this->raw->renderResult($this->response)); }
public function testExecuteEmptyQuery() { $searchString = ""; $this->request->expects($this->once())->method('getParam')->with('q')->will($this->returnValue($searchString)); $this->url->expects($this->once())->method('getBaseUrl'); $this->response->expects($this->once())->method('setRedirect'); $this->controller->execute(); }
public function testIndexActionException() { $this->request->expects($this->once())->method('isPost')->will($this->returnValue(true)); $exception = new \Exception(); $this->request->expects($this->once())->method('getPostValue')->will($this->throwException($exception)); $this->logger->expects($this->once())->method('critical')->with($this->identicalTo($exception)); $this->response->expects($this->once())->method('setHttpResponseCode')->with(500); $this->model->executeInternal(); }
public function testExecuteRandom() { $newKey = 'RSASHA9000VERYSECURESUPERMANKEY'; $this->requestMock->expects($this->at(0))->method('getPost')->with($this->equalTo('generate_random'))->willReturn(1); $this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey); $this->managerMock->expects($this->once())->method('addSuccessMessage'); $this->managerMock->expects($this->once())->method('addNoticeMessage'); $this->cacheMock->expects($this->once())->method('clean'); $this->responseMock->expects($this->once())->method('setRedirect'); $this->model->execute(); }
public function testExecuteWithException() { $this->requestMock->expects($this->once())->method('getParam')->with('item_id', null)->willReturn('1'); $exception = new \Exception('Error message!'); $this->sidebarMock->expects($this->once())->method('checkQuoteItem')->with(1)->willThrowException($exception); $this->loggerMock->expects($this->once())->method('critical')->with($exception)->willReturn(null); $this->sidebarMock->expects($this->once())->method('getResponseData')->with('Error message!')->willReturn(['success' => false, 'error_message' => 'Error message!']); $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with(['success' => false, 'error_message' => 'Error message!'])->willReturn('json encoded'); $this->responseMock->expects($this->once())->method('representJson')->with('json encoded')->willReturn('json represented'); $this->assertEquals('json represented', $this->removeItem->executeInternal()); }
/** * @return void */ public function testExecute() { $successMessage = 'All other open sessions for this account were terminated.'; $this->sessionsManager->expects($this->once())->method('logoutOtherUserSessions'); $this->messageManager->expects($this->once())->method('addSuccess')->with($successMessage); $this->messageManager->expects($this->never())->method('addError'); $this->messageManager->expects($this->never())->method('addException'); $this->responseMock->expects($this->once())->method('setRedirect'); $this->actionFlagMock->expects($this->once())->method('get')->with('', \Magento\Backend\App\AbstractAction::FLAG_IS_URLS_CHECKED); $this->backendHelperMock->expects($this->once())->method('getUrl'); $this->controller->execute(); }
public function testExecute() { $type = 'sampleType'; $feed = $this->getMockBuilder('Magento\\SampleServiceContractNew\\API\\Data\\FeedInterface')->getMockForAbstractClass(); $xml = 'xmlDataString'; $this->request->expects($this->once())->method('getParam')->with('type')->willReturn($type); $this->feedRepository->expects($this->once())->method('getById')->with($type)->willReturn($feed); $this->response->expects($this->once())->method('setHeader')->with('Content-type', 'text/xml; charset=UTF-8')->willReturnSelf(); $this->feedTransformer->expects($this->once())->method('toXml')->with($feed)->willReturn($xml); $this->response->expects($this->once())->method('setBody')->with($xml)->willReturnSelf(); $this->controller->execute(); }
public function testExecute() { $layout = $this->getMock('\\Magento\\Framework\\View\\LayoutInterface'); $block = $this->getMockBuilder('Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Bundle\\Option\\Search\\Grid')->disableOriginalConstructor()->setMethods(['setIndex', 'toHtml'])->getMock(); $this->response->expects($this->once())->method('setBody')->willReturnSelf(); $this->request->expects($this->once())->method('getParam')->with('index')->willReturn('index'); $this->view->expects($this->once())->method('getLayout')->willReturn($layout); $layout->expects($this->once())->method('createBlock')->willReturn($block); $block->expects($this->once())->method('setIndex')->willReturnSelf(); $block->expects($this->once())->method('toHtml')->willReturnSelf(); $this->assertEquals($this->response, $this->controller->execute()); }
public function testExecute() { $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getId'])->getMock(); $layout = $this->getMock('\\Magento\\Framework\\View\\LayoutInterface'); $block = $this->getMockBuilder('Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Bundle')->disableOriginalConstructor()->setMethods(['setIndex', 'toHtml'])->getMock(); $this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product); $this->initializationHelper->expects($this->any())->method('initialize')->willReturn($product); $this->response->expects($this->once())->method('setBody')->willReturnSelf(); $this->view->expects($this->once())->method('getLayout')->willReturn($layout); $layout->expects($this->once())->method('createBlock')->willReturn($block); $block->expects($this->once())->method('toHtml')->willReturnSelf(); $this->controller->execute(); }
public function testExecute() { $firstElement = 'firstElement'; $symbolsDataArray = [$firstElement]; $redirectUrl = 'redirectUrl'; $this->requestMock->expects($this->once())->method('getParam')->with('custom_currency_symbol')->willReturn($symbolsDataArray); $this->helperMock->expects($this->once())->method('getUrl')->with('*'); $this->redirectMock->expects($this->once())->method('getRedirectUrl')->willReturn($redirectUrl); $this->currencySymbolMock->expects($this->once())->method('setCurrencySymbolsData')->with($symbolsDataArray); $this->responseMock->expects($this->once())->method('setRedirect'); $this->filterManagerMock->expects($this->once())->method('stripTags')->with($firstElement)->willReturn($firstElement); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\CurrencySymbol\\Model\\System\\Currencysymbol')->willReturn($this->currencySymbolMock); $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\Filter\\FilterManager')->willReturn($this->filterManagerMock); $this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('You applied the custom currency symbols.')); $this->action->execute(); }
public function testExecute() { $carrier = 'carrier'; $number = 'number'; $title = 'title'; $shipmentId = 1000012; $orderId = 10003; $tracking = []; $shipmentData = ['items' => [], 'send_email' => '']; $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['addTrack', '__wakeup'], [], '', false); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipmentData], ['tracking', null, $tracking]])); $this->request->expects($this->any())->method('getPost')->will($this->returnValueMap([['carrier', $carrier], ['number', $number], ['title', $title]])); $this->shipmentLoader->expects($this->any())->method('setShipmentId')->with($shipmentId); $this->shipmentLoader->expects($this->any())->method('setOrderId')->with($orderId); $this->shipmentLoader->expects($this->any())->method('setShipment')->with($shipmentData); $this->shipmentLoader->expects($this->any())->method('setTracking')->with($tracking); $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($shipment)); $this->title->expects($this->any())->method('add')->with('Shipments')->will($this->returnSelf()); $track = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment\\Track')->disableOriginalConstructor()->setMethods(['__wakeup', 'setNumber', 'setCarrierCode', 'setTitle'])->getMock(); $this->objectManager->expects($this->atLeastOnce())->method('create')->with('Magento\\Sales\\Model\\Order\\Shipment\\Track')->will($this->returnValue($track)); $track->expects($this->once())->method('setNumber')->with($number)->will($this->returnSelf()); $track->expects($this->once())->method('setCarrierCode')->with($carrier)->will($this->returnSelf()); $track->expects($this->once())->method('setTitle')->with($title)->will($this->returnSelf()); $this->view->expects($this->once())->method('loadLayout')->will($this->returnSelf()); $layout = $this->getMock('Magento\\Framework\\View\\Layout\\Element\\Layout', ['getBlock'], [], '', false); $menuBlock = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface', ['toHtml'], [], '', false); $html = 'html string'; $this->view->expects($this->once())->method('getLayout')->will($this->returnValue($layout)); $layout->expects($this->once())->method('getBlock')->with('shipment_tracking')->will($this->returnValue($menuBlock)); $menuBlock->expects($this->once())->method('toHtml')->will($this->returnValue($html)); $shipment->expects($this->once())->method('addTrack')->with($this->equalTo($track))->will($this->returnSelf()); $shipment->expects($this->any())->method('save')->will($this->returnSelf()); $this->response->expects($this->once())->method('setBody')->with($html); $this->assertNull($this->controller->execute()); }
/** * @param array $indexerIds * @param \Exception $exception * @param array $expectsExceptionValues * @dataProvider executeDataProvider */ public function testExecute($indexerIds, $exception, $expectsExceptionValues) { $this->model = new \Magento\Indexer\Controller\Adminhtml\Indexer\MassChangelog($this->contextMock); $this->request->expects($this->any())->method('getParam')->with('indexer_ids')->will($this->returnValue($indexerIds)); if (!is_array($indexerIds)) { $this->messageManager->expects($this->once())->method('addError')->with(__('Please select indexers.'))->will($this->returnValue(1)); } else { $this->objectManager->expects($this->any())->method('get')->with('Magento\\Framework\\Indexer\\IndexerRegistry')->will($this->returnValue($this->indexReg)); $indexerInterface = $this->getMockForAbstractClass('Magento\\Framework\\Indexer\\IndexerInterface', ['setScheduled'], '', false); $this->indexReg->expects($this->any())->method('get')->with(1)->will($this->returnValue($indexerInterface)); if ($exception !== null) { $indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->throwException($exception)); } else { $indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->returnValue(1)); } $this->messageManager->expects($this->any())->method('addSuccess')->will($this->returnValue(1)); if ($exception !== null) { $this->messageManager->expects($this->exactly($expectsExceptionValues[2]))->method('addError')->with($exception->getMessage()); $this->messageManager->expects($this->exactly($expectsExceptionValues[1]))->method('addException')->with($exception, "We couldn't change indexer(s)' mode because of an error."); } } $this->helper->expects($this->any())->method("getUrl")->willReturn("magento.com"); $this->response->expects($this->any())->method("setRedirect")->willReturn(1); $this->model->executeInternal(); }
/** * @param int $cmId */ protected function prepareRedirect($cmId) { $this->actionFlag->expects($this->once())->method('get')->with('', 'check_url_settings')->will($this->returnValue(true)); $this->session->expects($this->once())->method('setIsUrlNotice')->with(true); $path = 'sales/order_creditmemo/view'; $this->response->expects($this->once())->method('setRedirect')->with($path . '/' . $cmId); $this->helper->expects($this->atLeastOnce())->method('getUrl')->with($path, ['creditmemo_id' => $cmId])->will($this->returnValue($path . '/' . $cmId)); }
/** * @param string $path * @param array $arguments * @param int $index */ protected function prepareRedirect($path, $arguments, $index) { $this->actionFlag->expects($this->any())->method('get')->with('', 'check_url_settings')->will($this->returnValue(true)); $this->session->expects($this->any())->method('setIsUrlNotice')->with(true); $url = $path . '/' . (!empty($arguments) ? $arguments['shipment_id'] : ''); $this->helper->expects($this->at($index))->method('getUrl')->with($path, $arguments)->will($this->returnValue($url)); $this->response->expects($this->at($index))->method('setRedirect')->with($url); }
/** * @param $cacheState * @param $layoutIsCacheable * @param $expectedTags * @param $configCacheType * @param $ttl * @dataProvider afterGetOutputDataProvider */ public function testAfterGetOutput($cacheState, $layoutIsCacheable, $expectedTags, $configCacheType, $ttl) { $html = 'html'; $this->configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState)); $blockStub = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', null, [], '', false); $blockStub->setTtl($ttl); $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue($layoutIsCacheable)); $this->layoutMock->expects($this->any())->method('getAllBlocks')->will($this->returnValue([$blockStub])); $this->configMock->expects($this->any())->method('getType')->will($this->returnValue($configCacheType)); if ($layoutIsCacheable && $cacheState) { $this->responseMock->expects($this->once())->method('setHeader')->with('X-Magento-Tags', $expectedTags); } else { $this->responseMock->expects($this->never())->method('setHeader'); } $output = $this->model->afterGetOutput($this->layoutMock, $html); $this->assertSame($output, $html); }
public function testExecute() { $type = 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product|attribute_set_id'; $this->request->expects($this->at(0))->method('getParam')->with('id')->will($this->returnValue('1--1')); $this->request->expects($this->at(1))->method('getParam')->with('type')->will($this->returnValue($type)); $this->request->expects($this->at(2))->method('getParam')->with('form')->will($this->returnValue('request_form_param_value')); $condition = $this->getMockBuilder('Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product')->setMethods(['setId', 'setType', 'setRule', 'setPrefix', 'setAttribute', 'asHtmlRecursive', 'setJsFormObject'])->disableOriginalConstructor()->getMock(); $condition->expects($this->once())->method('setId')->with('1--1')->will($this->returnSelf()); $condition->expects($this->once())->method('setType')->with('Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product')->will($this->returnSelf()); $condition->expects($this->once())->method('setRule')->with($this->rule)->will($this->returnSelf()); $condition->expects($this->once())->method('setPrefix')->with('conditions')->will($this->returnSelf()); $condition->expects($this->once())->method('setJsFormObject')->with('request_form_param_value')->will($this->returnSelf()); $condition->expects($this->once())->method('setAttribute')->with('attribute_set_id')->will($this->returnSelf()); $condition->expects($this->once())->method('asHtmlRecursive')->will($this->returnValue('<some_html>')); $this->objectManager->expects($this->once())->method('create')->will($this->returnValue($condition)); $this->response->expects($this->once())->method('setBody')->with('<some_html>')->will($this->returnSelf()); $this->controller->execute(); }
/** * Test the basic Request action. */ public function testRequestAction() { $this->request->expects($this->any())->method('getMethod')->willReturn('GET'); $this->helperMock->expects($this->once())->method('getRequestUrl'); $this->helperMock->expects($this->once())->method('prepareRequest'); $this->frameworkOauthSvcMock->expects($this->once())->method('getRequestToken')->willReturn(['response']); $this->response->expects($this->once())->method('setBody'); $this->requestAction->execute(); }
public function testExecuteInvalidArgument() { $themeId = 1; $fileParam = '/path/to/file.ext'; $fileId = 'fileId'; $refererUrl = 'referer/url'; $this->request->expects($this->any()) ->method('getParam') ->willReturnMap( [ ['theme_id', null, $themeId], ['file', null, $fileParam], ] ); $theme = $this->getMockBuilder('Magento\Framework\View\Design\ThemeInterface') ->setMethods(['getId', 'load']) ->getMockForAbstractClass(); $urlDecoder = $this->getMockBuilder('Magento\Framework\Url\DecoderInterface')->getMock(); $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); $this->objectManager->expects($this->any()) ->method('get') ->willReturnMap( [ ['Magento\Framework\Url\DecoderInterface', $urlDecoder], ['Psr\Log\LoggerInterface', $logger], ] ); $this->objectManager->expects($this->any()) ->method('create') ->with('Magento\Framework\View\Design\ThemeInterface') ->willReturn($theme); $urlDecoder->expects($this->once()) ->method('decode') ->with($fileParam) ->willReturn($fileId); $theme->expects($this->once()) ->method('load') ->with($themeId) ->willReturnSelf(); $theme->expects($this->once()) ->method('getId') ->willReturn(null); $this->messageManager->expects($this->once()) ->method('addException'); $logger->expects($this->once()) ->method('critical'); $this->redirect->expects($this->once()) ->method('getRefererUrl') ->willReturn($refererUrl); $this->response->expects($this->once()) ->method('setRedirect') ->with($refererUrl); $this->controller->executeInternal(); }
/** * Execute download sample url action */ public function testExecuteUrl() { $this->request->expects($this->at(0))->method('getParam')->with('id', 0)->will($this->returnValue(1)); $this->response->expects($this->once())->method('setHttpResponseCode')->will($this->returnSelf()); $this->response->expects($this->once())->method('clearBody')->will($this->returnSelf()); $this->response->expects($this->any())->method('setHeader')->will($this->returnSelf()); $this->response->expects($this->once())->method('sendHeaders')->will($this->returnSelf()); $this->objectManager->expects($this->at(1))->method('get')->with('Magento\\Downloadable\\Helper\\Download')->will($this->returnValue($this->downloadHelper)); $this->downloadHelper->expects($this->once())->method('setResource')->will($this->returnSelf()); $this->downloadHelper->expects($this->once())->method('getFilename')->will($this->returnValue('sample.jpg')); $this->downloadHelper->expects($this->once())->method('getContentType')->will($this->returnSelf('url')); $this->downloadHelper->expects($this->once())->method('getFileSize')->will($this->returnValue(null)); $this->downloadHelper->expects($this->once())->method('getContentDisposition')->will($this->returnValue(null)); $this->downloadHelper->expects($this->once())->method('output')->will($this->returnSelf()); $this->sampleModel->expects($this->once())->method('load')->will($this->returnSelf()); $this->sampleModel->expects($this->once())->method('getId')->will($this->returnValue('1')); $this->sampleModel->expects($this->any())->method('getSampleType')->will($this->returnValue('url')); $this->objectManager->expects($this->once())->method('create')->will($this->returnValue($this->sampleModel)); $this->sample->execute(); }
public function testExecuteException() { $redirectPath = 'path/to/redirect'; $quoteMock = $this->getQuoteMock(); $quoteMock->expects(self::once())->method('getItemsCount')->willReturn(0); $this->requestMock->expects(self::exactly(1))->method('getParam')->willReturnMap([['isAjax', null, true]]); $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quoteMock); $this->shippingMethodUpdaterMock->expects(self::never())->method('execute'); $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf('\\InvalidArgumentException'), 'We can\'t initialize checkout.'); $this->urlMock->expects(self::once())->method('getUrl')->with('*/*/review', ['_secure' => true])->willReturn($redirectPath); $this->responseMock->expects(self::once())->method('setBody')->with(sprintf('<script>window.location.href = "%s";</script>', $redirectPath)); $this->saveShippingMethod->execute(); }
public function testApplyCustomLayoutUpdate() { $categoryId = 123; $pageLayout = 'page_layout'; $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Catalog\\Helper\\Category', $this->categoryHelper], ['Magento\\Theme\\Helper\\Layout', $this->layoutHelper]])); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([[Action::PARAM_NAME_URL_ENCODED], ['id', false, $categoryId]])); $this->categoryRepository->expects($this->any())->method('get')->with($categoryId)->will($this->returnValue($this->category)); $this->categoryHelper->expects($this->any())->method('canShow')->will($this->returnValue(true)); $settings = $this->getMock('Magento\\Framework\\Object', ['getPageLayout'], [], '', false); $settings->expects($this->atLeastOnce())->method('getPageLayout')->will($this->returnValue($pageLayout)); $this->catalogDesign->expects($this->any())->method('getDesignSettings')->will($this->returnValue($settings)); $this->action->execute(); }
/** * @param string $targetPath * @dataProvider externalRedirectTargetPathDataProvider */ public function testMatchWithCustomExternalRedirect($targetPath) { $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); $urlRewrite = $this->getMockBuilder('Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite')->disableOriginalConstructor()->getMock(); $urlRewrite->expects($this->any())->method('getEntityType')->will($this->returnValue('custom')); $urlRewrite->expects($this->any())->method('getRedirectType')->will($this->returnValue('redirect-code')); $urlRewrite->expects($this->any())->method('getTargetPath')->will($this->returnValue($targetPath)); $this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue($urlRewrite)); $this->response->expects($this->once())->method('setRedirect')->with($targetPath, 'redirect-code'); $this->url->expects($this->never())->method('getUrl'); $this->request->expects($this->once())->method('setDispatched')->with(true); $this->actionFactory->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Action\\Redirect'); $this->router->match($this->request); }
public function testExecuteInvalidArgument() { $themeId = 1; $refererUrl = 'referer/url'; $this->request->expects($this->any())->method('getParam')->with('theme_id')->willReturn($themeId); $themeFactory = $this->getMockBuilder('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock(); $this->objectManager->expects($this->any())->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger); $this->objectManager->expects($this->any())->method('create')->with('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory')->willReturn($themeFactory); $themeFactory->expects($this->once())->method('create')->with($themeId)->willReturn(null); $this->messageManager->expects($this->once())->method('addException'); $logger->expects($this->once())->method('critical'); $this->redirect->expects($this->once())->method('getRefererUrl')->willReturn($refererUrl); $this->response->expects($this->once())->method('setRedirect')->with($refererUrl); $this->controller->execute(); }
/** * Test the basic Access action. */ public function testAccessAction() { $this->request->expects($this->any())->method('getMethod')->willReturn('GET'); $this->helperMock->expects($this->once())->method('getRequestUrl'); $this->helperMock->expects($this->once())->method('prepareRequest'); $this->frameworkOauthSvcMock->expects($this->once())->method('getAccessToken')->willReturn(['response']); /** @var \Magento\Integration\Model\Oauth\Consumer|\PHPUnit_Framework_MockObject_MockObject */ $consumerMock = $this->getMock('Magento\\Integration\\Model\\Oauth\\Consumer', [], [], '', false); $consumerMock->expects($this->once())->method('getId'); $this->intOauthServiceMock->expects($this->once())->method('loadConsumerByKey')->willReturn($consumerMock); /** @var \Magento\Integration\Model\Integration|\PHPUnit_Framework_MockObject_MockObject */ $integrationMock = $this->getMock('Magento\\Integration\\Model\\Integration', [], [], '', false); $integrationMock->expects($this->once())->method('save')->willReturnSelf(); $this->integrationServiceMock->expects($this->once())->method('findByConsumerId')->willReturn($integrationMock); $this->response->expects($this->once())->method('setBody'); $this->accessAction->executeInternal(); }
/** * @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::execute */ public function testExecuteException() { $exception = new \Exception('epic fail'); $placeholderPath = 'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png'; $mimeType = 'image/png'; $imageBody = '0123456789abcdefghijklmnopqrstuvwxyz'; $this->prepareExecuteTest(); $this->imageAdapterMock->expects($this->at(0))->method('open')->with(self::IMAGE_PATH)->willThrowException($exception); $this->wysiwygConfigMock->expects($this->once())->method('getSkinImagePlaceholderPath')->willReturn($placeholderPath); $this->imageAdapterMock->expects($this->at(1))->method('open')->with($placeholderPath); $this->imageAdapterMock->expects($this->once())->method('getMimeType')->willReturn($mimeType); $this->responseMock->expects($this->once())->method('setHeader')->with('Content-Type', $mimeType)->willReturnSelf(); $this->imageAdapterMock->expects($this->once())->method('getImage')->willReturn($imageBody); $this->responseMock->expects($this->once())->method('setBody')->with($imageBody)->willReturnSelf(); $this->loggerMock->expects($this->once())->method('critical')->with($exception); $this->wysiwygDirective->execute(); }
private function processDownload($resource, $resourceType) { $this->objectManager->expects($this->at(3))->method('get')->with('Magento\\Downloadable\\Helper\\Download')->willReturn($this->downloadHelper); $this->downloadHelper->expects($this->once())->method('setResource')->with($resource, $resourceType)->willReturnSelf(); $this->downloadHelper->expects($this->once())->method('getFilename')->willReturn('file_name'); $this->downloadHelper->expects($this->once())->method('getContentType')->willReturn('content_type'); $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf(); $this->response->expects($this->at(1))->method('setHeader')->with('Pragma', 'public', true)->willReturnSelf(); $this->response->expects($this->at(2))->method('setHeader')->with('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->willReturnSelf(); $this->response->expects($this->at(3))->method('setHeader')->with('Content-type', 'content_type', true)->willReturnSelf(); $this->downloadHelper->expects($this->once())->method('getFileSize')->willReturn('file_size'); $this->response->expects($this->at(4))->method('setHeader')->with('Content-Length', 'file_size')->willReturnSelf(); $this->downloadHelper->expects($this->once())->method('getContentDisposition')->willReturn('content_disposition'); $this->response->expects($this->at(5))->method('setHeader')->with('Content-Disposition', 'content_disposition; filename=file_name')->willReturnSelf(); $this->response->expects($this->once())->method('clearBody')->willReturnSelf(); $this->response->expects($this->once())->method('sendHeaders')->willReturnSelf(); $this->downloadHelper->expects($this->once())->method('output'); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExecuteWithoutQuantityArrayAndConfigurable() { $itemId = 2; $wishlistId = 1; $qty = []; $productId = 4; $indexUrl = 'index_url'; $configureUrl = 'configure_url'; $options = [5 => 'option']; $params = ['item' => $itemId, 'qty' => $qty]; $itemMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->setMethods(['load', 'getId', 'getWishlistId', 'setQty', 'setOptions', 'getBuyRequest', 'mergeBuyRequest', 'addToCart', 'getProduct', 'getProductId'])->getMock(); $this->requestMock->expects($this->at(0))->method('getParam')->with('item', null)->willReturn($itemId); $this->itemFactoryMock->expects($this->once())->method('create')->willReturn($itemMock); $itemMock->expects($this->once())->method('load')->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->exactly(2))->method('getId')->willReturn($itemId); $itemMock->expects($this->once())->method('getWishlistId')->willReturn($wishlistId); $wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock(); $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->with($wishlistId)->willReturn($wishlistMock); $this->requestMock->expects($this->at(1))->method('getParam')->with('qty', null)->willReturn($qty); $this->quantityProcessorMock->expects($this->once())->method('process')->with(1)->willReturnArgument(0); $itemMock->expects($this->once())->method('setQty')->with(1)->willReturnSelf(); $this->urlMock->expects($this->at(0))->method('getUrl')->with('*/*', null)->willReturn($indexUrl); $itemMock->expects($this->once())->method('getProductId')->willReturn($productId); $this->urlMock->expects($this->at(1))->method('getUrl')->with('*/*/configure/', ['id' => $itemId, 'product_id' => $productId])->willReturn($configureUrl); $optionMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item\\Option')->disableOriginalConstructor()->getMock(); $this->optionFactoryMock->expects($this->once())->method('create')->willReturn($optionMock); $optionsMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Resource\\Item\\Option\\Collection')->disableOriginalConstructor()->getMock(); $optionMock->expects($this->once())->method('getCollection')->willReturn($optionsMock); $optionsMock->expects($this->once())->method('addItemFilter')->with([$itemId])->willReturnSelf(); $optionsMock->expects($this->once())->method('getOptionsByItem')->with($itemId)->willReturn($options); $itemMock->expects($this->once())->method('setOptions')->with($options)->willReturnSelf(); $this->requestMock->expects($this->once())->method('getParams')->willReturn($params); $buyRequestMock = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->getMock(); $itemMock->expects($this->once())->method('getBuyRequest')->willReturn($buyRequestMock); $this->productHelperMock->expects($this->once())->method('addParamsToBuyRequest')->with($params, ['current_config' => $buyRequestMock])->willReturn($buyRequestMock); $itemMock->expects($this->once())->method('mergeBuyRequest')->with($buyRequestMock)->willReturnSelf(); $itemMock->expects($this->once())->method('addToCart')->with($this->checkoutCartMock, true)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message'))); $this->messageManagerMock->expects($this->once())->method('addNotice')->with('message', null)->willReturnSelf(); $this->helperMock->expects($this->once())->method('calculate')->willReturnSelf(); $this->responseMock->expects($this->once())->method('setRedirect')->with($configureUrl)->willReturn($this->responseMock); $this->assertEquals($this->responseMock, $this->model->execute()); }
public function testExecuteLinkTypeFile() { $sampleMock = $this->getMockBuilder('Magento\\Downloadable\\Model\\Sample')->disableOriginalConstructor()->setMethods(['getId', 'load', 'getSampleType', 'getSampleUrl', 'getBaseSamplePath'])->getMock(); $fileHelperMock = $this->getMockBuilder('Magento\\Downloadable\\Helper\\File')->disableOriginalConstructor()->setMethods(['getFilePath'])->getMock(); $this->request->expects($this->once())->method('getParam')->with('sample_id', 0)->willReturn('some_sample_id'); $this->objectManager->expects($this->at(0))->method('create')->with('Magento\\Downloadable\\Model\\Sample')->willReturn($sampleMock); $sampleMock->expects($this->once())->method('load')->with('some_sample_id')->willReturnSelf(); $sampleMock->expects($this->once())->method('getId')->willReturn('some_sample_id'); $sampleMock->expects($this->any())->method('getSampleType')->willReturn(\Magento\Downloadable\Helper\Download::LINK_TYPE_FILE); $this->objectManager->expects($this->at(1))->method('get')->with('Magento\\Downloadable\\Helper\\File')->willReturn($fileHelperMock); $fileHelperMock->expects($this->once())->method('getFilePath')->willReturn('file_path'); $this->objectManager->expects($this->at(2))->method('get')->with('Magento\\Downloadable\\Helper\\Download')->willReturn($this->downloadHelper); $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf(); $this->response->expects($this->any())->method('setHeader')->willReturnSelf(); $this->downloadHelper->expects($this->once())->method('output')->willThrowException(new \Exception()); $this->messageManager->expects($this->once())->method('addError')->with('Sorry, there was an error getting requested content. Please contact the store owner.')->willReturnSelf(); $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('redirect_url'); $this->response->expects($this->once())->method('setRedirect')->with('redirect_url')->willReturnSelf(); $this->assertEquals($this->response, $this->sample->execute()); }
public function testResetPasswordActionSendEmail() { $customerId = 1; $email = "*****@*****.**"; $websiteId = 1; $redirectLink = 'http://example.com'; $this->_request->expects($this->once())->method('getParam')->with($this->equalTo('customer_id'), $this->equalTo(0))->will($this->returnValue($customerId)); $customerBuilder = $this->getMock('\\Magento\\Customer\\Service\\V1\\Data\\CustomerBuilder', [], [], '', false); $data = ['id' => $customerId, 'email' => $email, 'website_id' => $websiteId]; $customerBuilder->expects($this->once())->method('getData')->will($this->returnValue($data)); $customer = new \Magento\Customer\Service\V1\Data\Customer($customerBuilder); $this->_acctServiceMock->expects($this->once())->method('getCustomer')->with($customerId)->will($this->returnValue($customer)); // verify initiatePasswordReset() is called $this->_acctServiceMock->expects($this->once())->method('initiatePasswordReset')->with($email, CustomerAccountServiceInterface::EMAIL_REMINDER, $websiteId); // verify success message $this->messageManager->expects($this->once())->method('addSuccess')->with($this->equalTo('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(array('id' => $customerId, '_current' => true)))->will($this->returnValue($redirectLink)); $this->_response->expects($this->once())->method('setRedirect')->with($this->equalTo($redirectLink)); $this->_testedObject->execute(); }