public function testExecute() { $this->objectManager->expects($this->once())->method('get')->with('Magento\\Theme\\Helper\\Storage')->willReturn($this->storageHelper); $this->storageHelper->expects($this->once())->method('getRelativeUrl')->willReturn('http://relative.url/'); $this->response->expects($this->once())->method('setBody')->with('http://relative.url/'); $this->controller->execute(); }
public function testDisplay() { $this->markTestSkipped('Remove it when task(MAGETWO-33495) will be fixed'); $this->_response->expects($this->atLeastOnce())->method('sendHeaders'); $this->_request->expects($this->atLeastOnce())->method('getHeader'); $stat = (include __DIR__ . '/_files/timers.php'); $this->_output->display($stat); $actualHeaders = $this->_response->getHeaders(); $this->assertNotEmpty($actualHeaders); $actualProtocol = false; $actualProfilerData = false; foreach ($actualHeaders as $oneHeader) { $headerName = $oneHeader->getFieldName(); $headerValue = $oneHeader->getFieldValue(); if (!$actualProtocol && $headerName == 'X-Wf-Protocol-1') { $actualProtocol = $headerValue; } if (!$actualProfilerData && $headerName == 'X-Wf-1-1-1-1') { $actualProfilerData = $headerValue; } } $this->assertNotEmpty($actualProtocol, 'Cannot get protocol header'); $this->assertNotEmpty($actualProfilerData, 'Cannot get profiler header'); $this->assertContains('Protocol/JsonStream', $actualProtocol); $this->assertRegExp('/"Type":"TABLE","Label":"Code Profiler \\(Memory usage: real - \\d+, emalloc - \\d+\\)"/', $actualProfilerData); $this->assertContains('[' . '["Timer Id","Time","Avg","Cnt","Emalloc","RealMem"],' . '["root","0.080000","0.080000","1","1,000","50,000"],' . '[". init","0.040000","0.040000","1","200","2,500"],' . '[". . init_store","0.020000","0.010000","2","100","2,000"],' . '["system","0.030000","0.015000","2","400","20,000"]' . ']', $actualProfilerData); }
/** * Run test execute method */ public function testExecute() { $orderId = 1; $shipmentId = 1; $shipment = []; $tracking = []; $result = 'result-html'; $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['createBlock'], [], '', false); $gridMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid', ['setIndex', 'toHtml'], [], '', false); $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId)); $this->requestMock->expects($this->at(1))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId)); $this->requestMock->expects($this->at(2))->method('getParam')->with('shipment')->will($this->returnValue($shipment)); $this->requestMock->expects($this->at(3))->method('getParam')->with('tracking')->will($this->returnValue($tracking)); $this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId); $this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId); $this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment); $this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking); $this->shipmentLoaderMock->expects($this->once())->method('load'); $layoutMock->expects($this->once())->method('createBlock')->with('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid')->will($this->returnValue($gridMock)); $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock)); $this->responseMock->expects($this->once())->method('setBody')->with($result)->will($this->returnSelf()); $this->requestMock->expects($this->at(4))->method('getParam')->with('index'); $gridMock->expects($this->once())->method('setIndex')->will($this->returnSelf()); $gridMock->expects($this->once())->method('toHtml')->will($this->returnValue($result)); $this->assertNotEmpty('result-html', $this->controller->execute()); }
public function testExecute() { $this->_getTreeBlock(); $testHtml = '<div>Some test html</div>'; $this->chooserBlockMock->expects($this->once())->method('toHtml')->will($this->returnValue($testHtml)); $this->responseMock->expects($this->once())->method('setBody')->with($this->equalTo($testHtml)); $this->controller->execute(); }
/** * @dataProvider dataProvider */ public function testAroundDispatchDisabled($state) { $this->configMock->expects($this->any())->method('getType')->will($this->returnValue(null)); $this->versionMock->expects($this->never())->method('process'); $this->stateMock->expects($this->any())->method('getMode')->will($this->returnValue($state)); $this->responseMock->expects($this->never())->method('setHeader'); $this->plugin->aroundDispatch($this->frontControllerMock, $this->closure, $this->requestMock); }
public function testExecuteWithWrongRequest() { $this->request->expects($this->once())->method('isPost')->willReturn(false); $jsonData = $this->getMock('Magento\\Framework\\Json\\Helper\\Data', [], [], '', false); $jsonData->expects($this->once())->method('jsonEncode')->with(['error' => true, 'message' => 'Wrong request'])->willReturn('{"error":"true","message":"Wrong request"}'); $this->objectManager->expects($this->once())->method('get')->with('Magento\\Framework\\Json\\Helper\\Data')->willReturn($jsonData); $this->response->expects($this->once())->method('representJson')->with('{"error":"true","message":"Wrong request"}'); $this->controller->execute(); }
public function testAuthenticate() { $urlMock = $this->getMock('Magento\\Framework\\Url', [], [], '', false); $urlMock->expects($this->exactly(2))->method('getUrl')->will($this->returnValue('')); $urlMock->expects($this->once())->method('getRebuiltUrl')->will($this->returnValue('')); $this->urlFactoryMock->expects($this->exactly(3))->method('create')->will($this->returnValue($urlMock)); $this->responseMock->expects($this->once())->method('setRedirect')->with('')->will($this->returnValue('')); $this->assertFalse($this->_model->authenticate()); }
public function testExecuteWithWishlist() { $wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock(); $this->wishlistProvider->expects($this->once())->method('getWishlist')->willReturn($wishlist); $this->request->expects($this->once())->method('getParam')->with('qty')->will($this->returnValue(2)); $this->itemCarrier->expects($this->once())->method('moveAllToCart')->with($wishlist, 2)->will($this->returnValue('http://redirect-url.com')); $this->response->expects($this->once())->method('setRedirect')->will($this->returnValue('http://redirect-url.com')); $controller = $this->getController(); $controller->execute(); }
/** * Executes the controller action and asserts non exception logic */ public function testExecuteLocalizedException() { $phrase = new \Magento\Framework\Phrase('some error'); $objectManager = new ObjectManager($this); $this->vault->expects($this->once())->method('processNonce')->willThrowException(new LocalizedException($phrase)); $this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'some error']); $this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson); $this->messageManager->expects($this->once())->method('addError')->with($phrase); $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\AjaxSave', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]); $this->assertSame($this->resultJson, $notification->execute()); }
public function testAroundResultWithPluginDeveloperMode() { $this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->willReturn(true); $this->state->expects($this->once())->method('getMode')->willReturn(\Magento\Framework\App\State::MODE_DEVELOPER); $this->header->expects($this->any())->method('getFieldValue')->willReturnOnConsecutiveCalls('test', 'tag,tag2'); $this->response->expects($this->any())->method('setHeader')->withConsecutive(['X-Magento-Cache-Control', 'test'], ['X-Magento-Cache-Debug', 'MISS', true], ['X-Magento-Tags', 'tag,tag2,' . \Magento\PageCache\Model\Cache\Type::CACHE_TAG]); $this->response->expects($this->once())->method('clearHeader')->with('X-Magento-Tags'); $this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->will($this->returnValue(true)); $this->kernel->expects($this->once())->method('process')->with($this->response); $result = call_user_func($this->closure); $this->assertSame($result, $this->plugin->aroundRenderResult($this->subject, $this->closure, $this->response)); }
/** * Executes the controller action and asserts non exception logic */ public function testExecuteInternalLocalizedException() { $phrase = new \Magento\Framework\Phrase('Something went wrong while processing.'); $objectManager = new ObjectManager($this); $this->vault->expects($this->once())->method('generatePaymentMethodToken')->willThrowException(new LocalizedException($phrase)); $this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'Something went wrong while processing.']); $this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson); $this->messageManager->expects($this->once())->method('addError')->with($phrase); $this->request->expects($this->any())->method('getParam')->willReturn(true); /** @var \Magento\Braintree\Controller\Creditcard\Generate $controller */ $controller = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Generate', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]); $this->assertSame($this->resultJson, $controller->executeInternal()); }
public function testExecute() { $blocks = ['block1', 'block2']; $handles = ['handle1', 'handle2']; $originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}'; $expectedData = ['block1' => 'data1', 'block2' => 'data2']; $blockInstance1 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false); $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1'])); $blockInstance2 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false); $blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2'])); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true)); $this->requestMock->expects($this->at(1))->method('getRouteName')->will($this->returnValue('magento_pagecache')); $this->requestMock->expects($this->at(2))->method('getControllerName')->will($this->returnValue('block')); $this->requestMock->expects($this->at(3))->method('getActionName')->will($this->returnValue('render')); $this->requestMock->expects($this->at(4))->method('getRequestUri')->will($this->returnValue('uri')); $this->requestMock->expects($this->at(5))->method('getParam')->with($this->equalTo('originalRequest'))->will($this->returnValue($originalRequest)); $this->requestMock->expects($this->at(10))->method('getParam')->with($this->equalTo('blocks'), $this->equalTo(''))->will($this->returnValue(json_encode($blocks))); $this->requestMock->expects($this->at(11))->method('getParam')->with($this->equalTo('handles'), $this->equalTo(''))->will($this->returnValue(json_encode($handles))); $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles)); $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->at(0))->method('getBlock')->with($this->equalTo($blocks[0]))->will($this->returnValue($blockInstance1)); $this->layoutMock->expects($this->at(1))->method('getBlock')->with($this->equalTo($blocks[1]))->will($this->returnValue($blockInstance2)); $this->translateInline->expects($this->once())->method('processResponseBody')->with($expectedData)->willReturnSelf(); $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData))); $this->action->execute(); }
/** * Run test execute method (fail generate label) */ public function testExecuteLabelGenerateFail() { $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock)); $this->labelGenerator->expects($this->once())->method('create')->with($this->shipmentMock, $this->requestMock)->will($this->throwException(new \Magento\Framework\Model\Exception())); $this->responseMock->expects($this->once())->method('representJson'); $this->assertNull($this->controller->execute()); }
/** * Redirect into response section * * @return void */ protected function redirectSection() { $this->actionFlag->expects($this->once())->method('get')->with('', \Magento\Backend\App\AbstractAction::FLAG_IS_URLS_CHECKED)->will($this->returnValue(true)); $this->sessionMock->expects($this->once())->method('setIsUrlNotice')->with(true); $this->helperMock->expects($this->once())->method('getUrl')->will($this->returnValue('redirect-path')); $this->responseMock->expects($this->once())->method('setRedirect'); }
/** * Run test execute method */ public function testExecute() { $data = ['comment' => 'comment']; $result = 'result-html'; $orderId = 1; $shipmentId = 1; $shipment = []; $tracking = []; $resultLayoutMock = $this->getMock('Magento\\Framework\\View\\Result\\Layout', ['getBlock', 'getDefaultLayoutHandle', 'addDefaultHandle', 'getLayout'], [], '', false); $this->requestMock->expects($this->once())->method('setParam')->with('shipment_id', $shipmentId); $this->requestMock->expects($this->once())->method('getPost')->with('comment')->will($this->returnValue($data)); $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap([['id', null, $shipmentId], ['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipment], ['tracking', null, $tracking]])); $this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId); $this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId); $this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment); $this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking); $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock)); $this->shipmentMock->expects($this->once())->method('addComment'); $this->shipmentCommentSenderMock->expects($this->once())->method('send'); $this->shipmentMock->expects($this->once())->method('save'); $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['getBlock'], [], '', false); $blockMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\View\\Comments', ['toHtml'], [], '', false); $blockMock->expects($this->once())->method('toHtml')->willReturn($result); $layoutMock->expects($this->once())->method('getBlock')->with('shipment_comments')->willReturn($blockMock); $resultLayoutMock->expects($this->once())->method('getLayout')->willReturn($layoutMock); $resultLayoutMock->expects($this->once())->method('addDefaultHandle'); $this->resultLayoutFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultLayoutMock)); $this->responseMock->expects($this->once())->method('setBody')->with($result); $this->assertNull($this->controller->execute()); }
public function testExecute() { $layout = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false); $storage = $this->getMock('Magento\\Theme\\Model\\Wysiwyg\\Storage', [], [], '', false); $block = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\BlockInterface', [], '', false, false, true, ['setStorage']); $this->view->expects($this->once())->method('loadLayout')->with('empty'); $this->view->expects($this->once())->method('getLayout')->willReturn($layout); $layout->expects($this->once())->method('getBlock')->with('wysiwyg_files.files')->willReturn($block); $block->expects($this->once())->method('setStorage')->with($storage); $this->objectManager->expects($this->at(0))->method('get')->with('Magento\\Theme\\Model\\Wysiwyg\\Storage')->willReturn($storage); $this->storage->expects($this->once())->method('getCurrentPath')->willThrowException(new \Exception('Message')); $jsonData = $this->getMock('Magento\\Framework\\Json\\Helper\\Data', [], [], '', false); $jsonData->expects($this->once())->method('jsonEncode')->with(['error' => true, 'message' => 'Message'])->willReturn('{"error":"true","message":"Message"}'); $this->objectManager->expects($this->at(1))->method('get')->with('Magento\\Framework\\Json\\Helper\\Data')->willReturn($jsonData); $this->response->expects($this->once())->method('representJson'); $this->controller->execute(); }
public function testExecutePassed() { $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false); $this->formKeyValidator->expects($this->once())->method('validate')->with($this->request)->will($this->returnValue(true)); $this->request->expects($this->once())->method('getParam')->with('qty')->will($this->returnValue(2)); $this->response->expects($this->once())->method('setRedirect')->will($this->returnValue('http://redirect-url.com')); $this->wishlistProvider->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlist)); $this->itemCarrier->expects($this->once())->method('moveAllToCart')->with($wishlist, 2)->will($this->returnValue('http://redirect-url.com')); $this->getController()->execute(); }
/** * @dataProvider processNotSaveCacheProvider * @param string $cacheControlHeader * @param int $httpCode * @param bool $isGet * @param bool $overrideHeaders */ public function testProcessNotSaveCache($cacheControlHeader, $httpCode, $isGet, $overrideHeaders) { $this->responseMock->expects($this->once())->method('getHeader')->with('Cache-Control')->will($this->returnValue(array('value' => $cacheControlHeader))); $this->responseMock->expects($this->any())->method('getHttpResponseCode')->will($this->returnValue($httpCode)); $this->requestMock->expects($this->any())->method('isGet')->will($this->returnValue($isGet)); if ($overrideHeaders) { $this->responseMock->expects($this->once())->method('setNoCacheHeaders'); } $this->cacheMock->expects($this->never())->method('save'); $this->kernel->process($this->responseMock); }
/** * @dataProvider processNotSaveCacheProvider * @param string $cacheControlHeader * @param int $httpCode * @param bool $isGet * @param bool $overrideHeaders */ public function testProcessNotSaveCache($cacheControlHeader, $httpCode, $isGet, $overrideHeaders) { $header = \Zend\Http\Header\CacheControl::fromString("Cache-Control: {$cacheControlHeader}"); $this->responseMock->expects($this->once())->method('getHeader')->with('Cache-Control')->will($this->returnValue($header)); $this->responseMock->expects($this->any())->method('getHttpResponseCode')->will($this->returnValue($httpCode)); $this->requestMock->expects($this->any())->method('isGet')->will($this->returnValue($isGet)); if ($overrideHeaders) { $this->responseMock->expects($this->once())->method('setNoCacheHeaders'); } $this->fullPageCacheMock->expects($this->never())->method('save'); $this->kernel->process($this->responseMock); }
/** * @dataProvider executeDataProvider * @param string $blockClass * @param bool $shouldSetHeaders */ public function testExecute($blockClass, $shouldSetHeaders) { $block = 'block'; $handles = array('handle1', 'handle2'); $html = 'some-html'; $mapData = array(array('blocks', '', json_encode(array($block))), array('handles', '', json_encode($handles))); $blockInstance1 = $this->getMock($blockClass, array('toHtml'), array(), '', false); $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($html)); $blockInstance1->setTtl(360); $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap($mapData)); $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles)); $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->once())->method('getBlock')->with($this->equalTo($block))->will($this->returnValue($blockInstance1)); if ($shouldSetHeaders) { $this->responseMock->expects($this->once())->method('setHeader')->with('X-Magento-Tags', implode(',', $blockInstance1->getIdentities())); } else { $this->responseMock->expects($this->never())->method('setHeader'); } $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo($html)); $this->action->execute(); }
public function testExecute() { $this->_getTreeBlock(); $testCategoryId = 1; $this->requestMock->expects($this->any())->method('getPost')->will($this->returnValue($testCategoryId)); $categoryMock = $this->getMock('Magento\\Catalog\\Model\\Category', array(), array(), '', false); $categoryMock->expects($this->once())->method('load')->will($this->returnValue($categoryMock)); $categoryMock->expects($this->once())->method('getId')->will($this->returnValue($testCategoryId)); $this->objectManagerMock->expects($this->once())->method('create')->with($this->equalTo('Magento\\Catalog\\Model\\Category'))->will($this->returnValue($categoryMock)); $this->chooserBlockMock->expects($this->once())->method('setSelectedCategories')->will($this->returnValue($this->chooserBlockMock)); $testHtml = '<div>Some test html</div>'; $this->chooserBlockMock->expects($this->once())->method('getTreeJson')->will($this->returnValue($testHtml)); $this->responseMock->expects($this->once())->method('representJson')->with($this->equalTo($testHtml)); $this->controller->execute(); }
/** * Check if validation throws a localized catched exception in case of incorrect id */ public function testExecuteException() { $taxRateId = 999; $exceptionMessage = __('An error occurred while loading this tax rate.'); $noSuchEntityEx = new \Exception(); $objectManager = new ObjectManager($this); $this->request->expects($this->any())->method('getParam')->will($this->returnValue($taxRateId)); $this->taxRateRepository->expects($this->any())->method('get')->with($taxRateId)->willThrowException($noSuchEntityEx); $jsonObject = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->setMethods(['setData'])->getMock(); $jsonObject->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => $exceptionMessage]); $this->resultFactory->expects($this->any())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_JSON)->willReturn($jsonObject); $notification = $objectManager->getObject('Magento\\Tax\\Controller\\Adminhtml\\Rate\\AjaxLoad', ['taxRateRepository' => $this->taxRateRepository, 'request' => $this->request, 'resultFactory' => $this->resultFactory]); //exception thrown with catch $this->assertSame($jsonObject, $notification->execute()); }
/** * Run test execute method */ public function testExecute() { $response = 'html-data'; $this->shipmentLoad(); $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->shipmentMock)); $this->shipmentTrackMock->expects($this->once())->method('delete')->will($this->returnSelf()); $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['getBlock'], [], '', false); $trackingBlockMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\Order\\Tracking', ['toHtml'], [], '', false); $trackingBlockMock->expects($this->once())->method('toHtml')->will($this->returnValue($response)); $layoutMock->expects($this->once())->method('getBlock')->with('shipment_tracking')->will($this->returnValue($trackingBlockMock)); $this->viewMock->expects($this->once())->method('loadLayout')->will($this->returnSelf()); $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $this->responseMock->expects($this->once())->method('setBody')->with($response); $this->assertNull($this->controller->execute()); }
public function testExecute() { $blocks = array('block1', 'block2'); $handles = array('handle1', 'handle2'); $expectedData = array('block1' => 'data1', 'block2' => 'data2'); $blockInstance1 = $this->getMock('Magento\\PageCache\\Block\\Controller\\StubBlock', array('toHtml'), array(), '', false); $blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1'])); $blockInstance2 = $this->getMock('Magento\\PageCache\\Block\\Controller\\StubBlock', array('toHtml'), array(), '', false); $blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2'])); $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true)); $this->requestMock->expects($this->at(1))->method('getParam')->with($this->equalTo('blocks'), $this->equalTo(''))->will($this->returnValue(json_encode($blocks))); $this->requestMock->expects($this->at(2))->method('getParam')->with($this->equalTo('handles'), $this->equalTo(''))->will($this->returnValue(json_encode($handles))); $this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles)); $this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock)); $this->layoutMock->expects($this->at(0))->method('getBlock')->with($this->equalTo($blocks[0]))->will($this->returnValue($blockInstance1)); $this->layoutMock->expects($this->at(1))->method('getBlock')->with($this->equalTo($blocks[1]))->will($this->returnValue($blockInstance2)); $this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData))); $this->action->execute(); }
public function testExecuteCanNotSaveWishlistAndWithRedirect() { $referer = 'http://referer-url.com'; $exception = new \Exception('Message'); $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false); $wishlist->expects($this->once())->method('save')->willThrowException($exception); $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(2)->willReturn($wishlist); $this->messageManager->expects($this->once())->method('addError')->with('An error occurred while deleting the item from wish list.')->willReturn(true); $wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false); $wishlistHelper->expects($this->once())->method('calculate')->willReturnSelf(); $this->om->expects($this->once())->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper)); $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false); $item->expects($this->once())->method('load')->with(1)->willReturnSelf(); $item->expects($this->once())->method('getId')->willReturn(1); $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(2); $item->expects($this->once())->method('delete')->willReturn(true); $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item); $this->request->expects($this->once())->method('getServer')->with('HTTP_REFERER')->willReturn($referer); $this->request->expects($this->exactly(3))->method('getParam')->willReturnMap([['item', null, 1], ['referer_url', null, $referer], ['uenc', null, false]]); $this->url->expects($this->once())->method('getUrl')->with('*/*')->willReturn('http:/test.com/frontname/module/controller/action'); $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('http:/test.com/frontname/module/controller/action'); $this->response->expects($this->once())->method('setRedirect')->with('http:/test.com/frontname/module/controller/action')->willReturn(true); $this->getController()->execute(); }
/** * @param \Exception $exception * @param array $expected * @return void * @dataProvider dataProviderForPrepareErrorResponseTest */ public function testPrepareErrorResponse($exception, $expected) { $this->response->expects($this->once())->method('setHttpResponseCode')->with($expected[1]); $errorResponse = $this->oauthRequestHelper->prepareErrorResponse($exception, $this->response); $this->assertEquals(['oauth_problem' => $expected[0]], $errorResponse); }