public function testGetRssData() { $ruleData = ['to_date' => '12/12/14', 'from_date' => '12/12/14', 'coupon_code' => '1234567', 'description' => 'Rule Description', 'name' => 'Rule Name']; $rssData = ['title' => 'Frontend Name - Discounts and Coupons', 'description' => 'Frontend Name - Discounts and Coupons', 'link' => 'http://rss.magento.com/discount', 'charset' => 'UTF-8', 'language' => 'en_US', 'entries' => ['title' => 'Rule Name', 'link' => 'http://rss.magento.com', 'description' => ['description' => 'Rule Description', 'start_date' => '12/12/14', 'end_date' => '12/12/14', 'coupon_code' => '1234567']]]; $rssUrl = 'http://rss.magento.com/discount'; $url = 'http://rss.magento.com'; $ruleModel = $this->getMock('Magento\\SalesRule\\Model\\Rule', ['__wakeup', 'getCouponCode', 'getToDate', 'getFromDate', 'getDescription', 'getName'], [], '', false); $this->storeModel->expects($this->once())->method('getWebsiteId')->will($this->returnValue(1)); $this->storeModel->expects($this->never())->method('getName'); $this->storeModel->expects($this->atLeastOnce())->method('getFrontendName')->willReturn('Frontend Name'); $this->requestInterface->expects($this->any())->method('getParam')->will($this->returnValue(1)); $this->urlBuilderInterface->expects($this->any())->method('getUrl')->will($this->returnValue($url)); $this->rssBuilderInterface->expects($this->any())->method('getUrl')->will($this->returnValue($rssUrl)); $this->scopeConfigInterface->expects($this->any())->method('getValue')->will($this->returnValue('en_US')); $ruleModel->expects($this->any())->method('getCouponCode')->will($this->returnValue($ruleData['coupon_code'])); $ruleModel->expects($this->any())->method('getToDate')->will($this->returnValue($ruleData['to_date'])); $ruleModel->expects($this->once())->method('getFromDate')->will($this->returnValue($ruleData['from_date'])); $ruleModel->expects($this->once())->method('getDescription')->will($this->returnValue($ruleData['description'])); $ruleModel->expects($this->once())->method('getName')->will($this->returnValue($ruleData['name'])); $this->rssModel->expects($this->any())->method('getDiscountCollection')->will($this->returnValue([$ruleModel])); $this->timezoneInterface->expects($this->any())->method('formatDate')->will($this->returnValue('12/12/14')); $data = $this->block->getRssData(); $this->assertEquals($rssData['title'], $data['title']); $this->assertEquals($rssData['description'], $data['description']); $this->assertEquals($rssData['link'], $data['link']); $this->assertEquals($rssData['charset'], $data['charset']); $this->assertEquals($rssData['language'], $data['language']); $this->assertEquals($rssData['entries']['title'], $data['entries'][0]['title']); $this->assertEquals($rssData['entries']['link'], $data['entries'][0]['link']); $this->assertContains($rssData['entries']['description']['description'], $data['entries'][0]['description']); $this->assertContains($rssData['entries']['description']['start_date'], $data['entries'][0]['description']); $this->assertContains($rssData['entries']['description']['end_date'], $data['entries'][0]['description']); $this->assertContains($rssData['entries']['description']['coupon_code'], $data['entries'][0]['description']); }
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); }
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 testGetCollection() { $this->collectionMock->expects($this->once())->method('addAttributeToFilter'); $this->productLinkRepositoryMock->expects($this->once())->method('getList')->willReturn([]); $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturn(1); $this->assertInstanceOf(Collection::class, $this->getModel()->getCollection()); }
/** * @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()); }
protected function setUp() { $this->request = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->request->expects($this->at(0))->method('getParam')->with('store_id')->will($this->returnValue(null)); $this->request->expects($this->at(1))->method('getParam')->with('cid')->will($this->returnValue(null)); $this->httpContext = $this->getMockBuilder('Magento\\Framework\\App\\Http\\Context')->setMethods(['getValue'])->disableOriginalConstructor()->getMock(); $this->httpContext->expects($this->any())->method('getValue')->will($this->returnValue(1)); $this->imageHelper = $this->getMock('Magento\\Catalog\\Helper\\Image', [], [], '', false); $this->outputHelper = $this->getMock('Magento\\Catalog\\Helper\\Output', ['productAttribute'], [], '', false); $this->msrpHelper = $this->getMock('Magento\\Msrp\\Helper\\Data', ['canApplyMsrp'], [], '', false); $this->priceCurrency = $this->getMock('Magento\\Framework\\Pricing\\PriceCurrencyInterface'); $this->rssModel = $this->getMock('Magento\\Catalog\\Model\\Rss\\Product\\Special', [], [], '', false); $this->rssUrlBuilder = $this->getMock('Magento\\Framework\\App\\Rss\\UrlBuilderInterface'); $this->storeManager = $this->getMock('Magento\\Framework\\Store\\StoreManagerInterface'); $store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->setMethods(['getId', 'getFrontendName', '__wakeup'])->disableOriginalConstructor()->getMock(); $store->expects($this->any())->method('getId')->will($this->returnValue(1)); $store->expects($this->any())->method('getFrontendName')->will($this->returnValue('Store 1')); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store)); $this->scopeConfig = $this->getMock('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue('en_US')); $this->localeDate = $this->getMock('\\Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface'); $this->dateFactory = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateFactory', ['create'], [], '', false); $objectManagerHelper = new ObjectManagerHelper($this); $this->block = $objectManagerHelper->getObject('Magento\\Catalog\\Block\\Rss\\Product\\Special', ['request' => $this->request, 'httpContext' => $this->httpContext, 'imageHelper' => $this->imageHelper, 'outputHelper' => $this->outputHelper, 'msrpHelper' => $this->msrpHelper, 'priceCurrency' => $this->priceCurrency, 'rssModel' => $this->rssModel, 'rssUrlBuilder' => $this->rssUrlBuilder, 'storeManager' => $this->storeManager, 'scopeConfig' => $this->scopeConfig, 'localeDate' => $this->localeDate, 'dateFactory' => $this->dateFactory]); }
public function testExecute() { $this->request->expects($this->once()) ->method('isPost') ->willReturn(true); $this->request->expects($this->once()) ->method('getParam') ->with('files') ->willReturn('{"files":"file"}'); $jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false); $jsonData->expects($this->once()) ->method('jsonDecode') ->with('{"files":"file"}') ->willReturn(['files' => 'file']); $this->objectManager->expects($this->at(0)) ->method('get') ->with('Magento\Framework\Json\Helper\Data') ->willReturn($jsonData); $this->objectManager->expects($this->at(1)) ->method('get') ->with('Magento\Theme\Model\Wysiwyg\Storage') ->willReturn($this->storage); $this->storage->expects($this->once()) ->method('deleteFile') ->with('file'); $this->controller->executeInternal(); }
/** * @param bool $isSecure * @param string $actionUrl * @param int $productId * @dataProvider getActionDataProvider */ public function testGetAction($isSecure, $actionUrl, $productId) { $this->urlBuilder->expects($this->any())->method('getUrl')->with('review/product/post', ['_secure' => $isSecure, 'id' => $productId])->willReturn($actionUrl . '/id/' . $productId); $this->requestMock->expects($this->any())->method('getParam')->with('id', false)->willReturn($productId); $this->requestMock->expects($this->any())->method('isSecure')->willReturn($isSecure); $this->assertEquals($actionUrl . '/id/' . $productId, $this->object->getAction()); }
protected function setUp() { $this->_session = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false); $this->_agreement = $this->getMock('Magento\\Paypal\\Model\\Billing\\Agreement', ['load', 'getId', 'getCustomerId', 'getReferenceId', 'canCancel', 'cancel', '__wakeup'], [], '', false); $this->_agreement->expects($this->once())->method('load')->with(15)->will($this->returnSelf()); $this->_agreement->expects($this->once())->method('getId')->will($this->returnValue(15)); $this->_agreement->expects($this->once())->method('getCustomerId')->will($this->returnValue(871)); $this->_objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $this->_objectManager->expects($this->atLeastOnce())->method('get')->will($this->returnValueMap([['Magento\\Customer\\Model\\Session', $this->_session]])); $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Paypal\\Model\\Billing\\Agreement')->will($this->returnValue($this->_agreement)); $this->_request = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->_request->expects($this->once())->method('getParam')->with('agreement')->will($this->returnValue(15)); $response = $this->getMock('Magento\\Framework\\App\\ResponseInterface'); $redirect = $this->getMock('Magento\\Framework\\App\\Response\\RedirectInterface'); $this->_messageManager = $this->getMock('Magento\\Framework\\Message\\ManagerInterface'); $context = $this->getMock('Magento\\Framework\\App\\Action\\Context', [], [], '', false); $context->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->_objectManager)); $context->expects($this->any())->method('getRequest')->will($this->returnValue($this->_request)); $context->expects($this->any())->method('getResponse')->will($this->returnValue($response)); $context->expects($this->any())->method('getRedirect')->will($this->returnValue($redirect)); $context->expects($this->any())->method('getMessageManager')->will($this->returnValue($this->_messageManager)); $this->_registry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false); $title = $this->getMock('Magento\\Framework\\App\\Action\\Title', [], [], '', false); $this->_controller = new \Magento\Paypal\Controller\Billing\Agreement\Cancel($context, $this->_registry, $title); }
protected function setUp() { $this->requestMock = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getBasePath', 'isSecure', 'getHttpHost'], [], '', false, false); $this->requestMock->expects($this->atLeastOnce())->method('getBasePath')->will($this->returnValue('/')); $this->requestMock->expects($this->atLeastOnce())->method('getHttpHost')->will($this->returnValue('init.host')); $this->objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); }
/** * Test method afterGenerateXml with disabled module PageCache */ public function testAfterGenerateXmlPageCacheDisabled() { $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(false)); $this->requestMock->expects($this->never())->method('isAjax')->will($this->returnValue(false)); $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult); $this->assertEquals($expectedResult, $actualResult); }
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(); }
protected function setUp() { $this->requestMock = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getBasePath', 'isSecure', 'getHttpHost'], [], '', false, false); $this->requestMock->expects($this->atLeastOnce())->method('getBasePath')->will($this->returnValue('/')); $this->requestMock->expects($this->atLeastOnce())->method('getHttpHost')->will($this->returnValue('init.host')); $this->appState = $this->getMock('\\Magento\\Framework\\App\\State', ['isInstalled'], [], '', false, false); $this->appState->expects($this->atLeastOnce())->method('isInstalled')->will($this->returnValue(true)); }
/** * @covers \Magento\PageCache\Block\Javascript::getScriptOptions * @param bool $isSecure * @param string $url * @param string $expectedResult * @dataProvider getScriptOptionsDataProvider */ public function testGetScriptOptions($isSecure, $url, $expectedResult) { $handles = ['some', 'handles', 'here']; $this->requestMock->expects($this->once())->method('isSecure')->willReturn($isSecure); $this->urlBuilderMock->expects($this->once())->method('getUrl')->willReturn($url); $this->layoutUpdateMock->expects($this->once())->method('getHandles')->willReturn($handles); $this->assertRegExp($expectedResult, $this->blockJavascript->getScriptOptions()); }
public function testGetData() { $expected = ['totalRecords' => null, 'items' => []]; $this->collectionMock->expects($this->once())->method('addEntityFilter')->willReturnSelf(); $this->collectionMock->expects($this->once())->method('addStoreData')->willReturnSelf(); $this->requestMock->expects($this->once())->method('getParam')->with('current_product_id', 0)->willReturn(1); $this->assertSame($expected, $this->model->getData()); }
/** * @param string $route * @param string $path * @param array|bool $params * @return void * @dataProvider dataProviderRoutes */ public function testRoute($route, $path, $params) { /** @var Route $model */ $model = $this->objectManager->getObject('Magento\\Webapi\\Controller\\Rest\\Router\\Route', ['route' => $route]); $this->request->expects($this->once())->method('getPathInfo')->willReturn($path); $match = $model->match($this->request); $this->assertEquals($params, $match); }
public function testDeleteActionNoId() { $this->requestMock->expects($this->once())->method('getParam')->willReturn(null); $this->messageManagerMock->expects($this->once())->method('addError')->with(__('We can\'t find a synonym group to delete.')); $this->messageManagerMock->expects($this->never())->method('addSuccess'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->deleteController->execute()); }
public function testExecuteWithoutData() { $this->request->expects($this->at(0))->method('getParam')->with('isAjax')->willReturn(true); $this->request->expects($this->at(1))->method('getParam')->with('items', [])->willReturn([]); $this->jsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson); $this->resultJson->expects($this->once())->method('setData')->with(['messages' => ['Please correct the data sent.'], 'error' => true])->willReturnSelf(); $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(); }
/** * @param string $subjectPath * @param string $expectedConfigPath * @dataProvider aroundGetConfigPathDataProvider */ public function testAroundGetConfigPath($subjectPath, $expectedConfigPath) { $callback = function () { return null; }; $this->request->expects($this->once())->method('getParam')->with('section')->will($this->returnValue('payment')); $this->subject->expects($this->once())->method('getPath')->will($this->returnValue($subjectPath)); $this->assertEquals($expectedConfigPath, $this->model->aroundGetConfigPath($this->subject, $callback)); }
/** * Test execute() */ public function testExecute() { $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap(['remote_image' => 'https://pp.vk.me/c304605/v304605289/3ff9/s4rpaW_TZ6A.jpg'])); $readInterface = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface', [], [], '', false); $this->filesystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($readInterface); $readInterface->expects($this->any())->method('getAbsolutePath')->willReturn('/var/www/application/sample.jpg'); $this->abstractAdapter->expects($this->any())->method('validateUploadFile')->willReturn('true'); $this->image->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 testExecuteEmptyQuery() { $url = 'some url'; $searchString = ''; $this->request->expects($this->once())->method('getParam')->with('q')->will($this->returnValue($searchString)); $this->url->expects($this->once())->method('getBaseUrl')->willReturn($url); $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($url)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->controller->execute()); }
public function testGetProductInfo() { $productId = 3; $storeId = 1; $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue(new \Magento\Framework\Object(['id' => $storeId]))); $this->requestMock->expects($this->once())->method('getParam')->with('id', false)->willReturn($productId); $productMock = $this->getMock('Magento\\Catalog\\Api\\Data\\ProductInterface'); $this->productRepository->expects($this->once())->method('getById')->with($productId, false, $storeId)->willReturn($productMock); $this->assertSame($productMock, $this->object->getProductInfo()); }
public function testGetWishlistWithIdWithoutCustomer() { $wishlist = $this->getMock('\\Magento\\Wishlist\\Model\\Wishlist', ['loadByCustomerId', 'load', 'getId', 'getCustomerId', '__wakeup'], [], '', false); $wishlist->expects($this->once())->method('load')->will($this->returnSelf()); $wishlist->expects($this->any())->method('getId')->will($this->returnValue(1)); $wishlist->expects($this->once())->method('getCustomerId')->will($this->returnValue(1)); $this->wishlistFactory->expects($this->once())->method('create')->will($this->returnValue($wishlist)); $this->request->expects($this->once())->method('getParam')->will($this->returnValue(1)); $this->assertEquals(false, $this->wishlistProvider->getWishlist()); }
protected function setUp() { $this->_configMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->_stringHelperMock = $this->getMock('\\Magento\\Framework\\Stdlib\\String', array(), array(), '', false, false); $this->_requestMock = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', array('getBasePath', 'isSecure', 'getHttpHost'), array(), '', false, false); $this->_requestMock->expects($this->atLeastOnce())->method('getBasePath')->will($this->returnValue('/')); $this->_requestMock->expects($this->atLeastOnce())->method('getHttpHost')->will($this->returnValue('init.host')); $this->_filesystem = $this->getMock('\\Magento\\Framework\\App\\Filesystem', array(), array(), '', false, false); $this->config = new \Magento\Framework\Session\Config($this->_configMock, $this->_stringHelperMock, $this->_requestMock, $this->_filesystem, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, \Magento\Framework\Session\SaveHandlerInterface::DEFAULT_HANDLER, __DIR__); }
protected function setupCart() { $quoteMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['hasItems', 'getHasError', 'getPayment', 'getId'])->getMock(); $quoteMock->expects($this->any())->method('hasItems')->willReturn(true); $quoteMock->expects($this->any())->method('getHasError')->willReturn(false); $this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($quoteMock); $this->checkoutFactoryMock->expects($this->any())->method('create')->willReturn($this->checkoutMock); $this->requestMock->expects($this->any())->method('getPost')->willReturn([]); return $quoteMock; }
public function testExecute() { $ids = [1, 2]; $this->request->expects($this->once())->method('getParam')->with('search')->will($this->returnValue($ids)); $this->createQuery(0, 1); $this->createQuery(1, 2); $this->messageManager->expects($this->once())->method('addSuccess')->will($this->returnSelf()); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('search/*/')->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->controller->execute()); }
public function testConstruct() { $this->customerAccount = $this->getMockForAbstractClass('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface'); $this->customerAccount->expects($this->once())->method('getCustomer')->with('customer id')->will($this->returnValue(new \Magento\Framework\Object())); $this->request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface'); $this->request->expects($this->at(0))->method('getParam')->with('customerId', false)->will($this->returnValue('customer id')); $this->request->expects($this->at(1))->method('getParam')->with('productId', false)->will($this->returnValue(false)); $objectManagerHelper = new ObjectManagerHelper($this); $this->model = $objectManagerHelper->getObject('Magento\\Review\\Block\\Adminhtml\\Main', ['request' => $this->request, 'customerAccount' => $this->customerAccount]); }
/** * @param $filterModifier * @param $filterName * @param $conditionType * @param $value * @return void * @dataProvider getApplyFilterModifierDataProvider */ public function testApplyFilterModifierWith($filterModifier, $filterName, $conditionType, $value) { $filter = $this->getMock('Magento\\Framework\\Api\\Filter'); $this->request->expects($this->once())->method('getParam')->with(\Magento\Ui\Component\Filters\FilterModifier::FILTER_MODIFIER)->willReturn($filterModifier); $this->filterBuilder->expects($this->once())->method('setConditionType')->with($conditionType)->willReturnSelf(); $this->filterBuilder->expects($this->once())->method('setField')->with($filterName)->willReturnSelf(); $this->filterBuilder->expects($this->once())->method('setValue')->with($value)->willReturnSelf(); $this->filterBuilder->expects($this->once())->method('create')->with()->willReturn($filter); $this->dataProvider->expects($this->once())->method('addFilter')->with($filter); $this->unit->applyFilterModifier($this->dataProvider, $filterName); }