/** * {@inheritdoc} */ public function log($message, $level) { $message .= ' ' . $this->request->getRequestUri(); if ($this->logLevel >= $level) { switch ($level) { case self::EMERGENCY: $this->logger->emergency($message); break; case self::ALERT: $this->logger->alert($message); break; case self::CRITICAL: $this->logger->critical($message); break; case self::ERROR: $this->logger->error($message); break; case self::WARNING: $this->logger->warning($message); break; case self::NOTICE: $this->logger->notice($message); break; case self::INFO: $this->logger->info($message); break; default: $this->logger->debug($message); } } }
/** * Handle private content version cookie * Set cookie if it is not set. * Increment version on post requests. * In all other cases do nothing. * * @return void */ public function process() { if ($this->request->isPost()) { $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration(self::COOKIE_PERIOD)->setPath('/')->setHttpOnly(false); $this->cookieManager->setPublicCookie(self::COOKIE_NAME, $this->generateValue(), $publicCookieMetadata); } }
/** * @dataProvider logDataProvider */ public function testLog($logLevel, $method) { $message = 'Error message'; $this->request->expects($this->once())->method('getRequestUri')->willReturn($this->requestUri); $this->psrLogger->expects($this->once())->method($method)->with($message . ' ' . $this->requestUri); $this->logger->log($message, $logLevel); }
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)); }
/** * @param \Magento\Framework\App\ActionInterface $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * @return mixed * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundExecute( \Magento\Framework\App\ActionInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request ) { /** @var \Magento\Store\Model\Store $defaultStore */ $defaultStore = $this->storeManager->getWebsite()->getDefaultStore(); $requestedStoreCode = $this->httpRequest->getParam( StoreResolverInterface::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie() ); /** @var \Magento\Store\Model\Store $currentStore */ $currentStore = $requestedStoreCode ? $this->storeManager->getStore($requestedStoreCode) : $defaultStore; $this->httpContext->setValue( StoreManagerInterface::CONTEXT_STORE, $currentStore->getCode(), $this->storeManager->getDefaultStoreView()->getCode() ); $this->httpContext->setValue( HttpContext::CONTEXT_CURRENCY, $this->session->getCurrencyCode() ?: $currentStore->getDefaultCurrencyCode(), $defaultStore->getDefaultCurrencyCode() ); return $proceed($request); }
/** * Set Cookie for msg box when it displays first * * @param \Magento\Framework\App\FrontController $subject * @param \Magento\Framework\App\ResponseInterface $response * * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterDispatch(\Magento\Framework\App\FrontController $subject, \Magento\Framework\App\ResponseInterface $response) { if ($this->request->isPost() && $this->messageManager->hasMessages()) { $this->cookie->set(self::COOKIE_NAME, 1, self::COOKIE_PERIOD, '/'); } return $response; }
/** * @param \Magento\Framework\App\Action\Action $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * @return mixed */ public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { $defaultStore = $this->storeManager->getWebsite()->getDefaultStore(); $this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_CURRENCY, $this->session->getCurrencyCode(), $defaultStore->getDefaultCurrency()->getCode()); $this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_STORE, $this->httpRequest->getParam('___store', $defaultStore->getStoreCodeFromCookie()), $this->storeManager->getWebsite()->getDefaultStore()->getCode()); return $proceed($request); }
protected function setUp() { $orderId = 1; $shipmentId = 1; $shipment = []; $tracking = []; $this->shipmentLoaderMock = $this->getMock('Magento\\Shipping\\Controller\\Adminhtml\\Order\\ShipmentLoader', ['setOrderId', 'setShipmentId', 'setShipment', 'setTracking', 'load'], [], '', false); $this->requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false); $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $this->responseMock = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false); $this->sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', ['setIsUrlNotice'], [], '', false); $this->actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', ['get'], [], '', false); $this->shipmentMock = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['__wakeup'], [], '', false); $this->fileFactoryMock = $this->getMock('Magento\\Framework\\App\\Response\\Http\\FileFactory', ['create'], [], '', false); $contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getObjectManager', 'getResponse', 'getSession', 'getActionFlag'], [], '', false); $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock)); $contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManagerMock)); $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock)); $contextMock->expects($this->any())->method('getSession')->will($this->returnValue($this->sessionMock)); $contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->actionFlag)); $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->controller = new \Magento\Shipping\Controller\Adminhtml\Order\Shipment\PrintPackage($contextMock, $this->shipmentLoaderMock, $this->fileFactoryMock); }
/** * 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()); }
/** * @dataProvider processProvider * @param bool $isPost */ public function testProcess($isPost) { $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost)); if ($isPost) { $publicCookieMetadataMock = $this->getMock('Magento\Framework\Stdlib\Cookie\PublicCookieMetadata'); $publicCookieMetadataMock->expects($this->once()) ->method('setPath') ->with('/') ->will($this->returnSelf()); $publicCookieMetadataMock->expects($this->once()) ->method('setDuration') ->with(Version::COOKIE_PERIOD) ->will($this->returnSelf()); $publicCookieMetadataMock->expects($this->once()) ->method('setHttpOnly') ->with(false) ->will($this->returnSelf()); $this->cookieMetadataFactoryMock->expects($this->once()) ->method('createPublicCookieMetadata') ->with() ->will( $this->returnValue($publicCookieMetadataMock) ); $this->cookieManagerMock->expects($this->once()) ->method('setPublicCookie'); } $this->version->process(); }
/** * @param bool $isSecure * @dataProvider getViewFileUrlDataProvider */ public function testGetViewFileUrl($isSecure) { $this->request->expects($this->once())->method('isSecure')->will($this->returnValue($isSecure)); $this->assetRepo->expects($this->once())->method('getUrlWithParams')->with('some file', $this->callback(function ($value) use($isSecure) { return isset($value['_secure']) && $value['_secure'] === $isSecure; }))->will($this->returnValue('result url')); $this->assertEquals('result url', $this->model->getViewFileUrl('some file')); }
public function testGetScopeTitleDefault() { $scope = 'default'; $scopeId = 0; $scopeTypeName = 'Default'; $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]); $this->assertEquals($scopeTypeName, $this->block->getScopeTitle()->render()); }
/** * Set Cookie for msg box when it displays first * * @param FrontController $subject * @param \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface $result * * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterDispatch(FrontController $subject, $result) { if ($this->request->isPost() && $this->messageManager->hasMessages()) { $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration(self::COOKIE_PERIOD)->setPath('/')->setHttpOnly(false); $this->cookieManager->setPublicCookie(self::COOKIE_NAME, 1, $publicCookieMetadata); } return $result; }
/** * @dataProvider processProvider * @param bool $isPost */ public function testProcess($isPost) { $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost)); if ($isPost) { $this->cookieMock->expects($this->once())->method('set'); } $this->version->process(); }
/** * @param string $userAgent * @param bool $useConfig * @param bool|string $result * @param array $expressions * @dataProvider getThemeByRequestDataProvider */ public function testGetThemeByRequest($userAgent, $useConfig, $result, $expressions = []) { $this->requestMock->expects($this->once())->method('getServer')->with($this->equalTo('HTTP_USER_AGENT'))->will($this->returnValue($userAgent)); if ($useConfig) { $this->scopeConfigMock->expects($this->once())->method('getValue')->with($this->equalTo($this->exceptionConfigPath), $this->equalTo($this->scopeType))->will($this->returnValue(serialize($expressions))); } $this->assertSame($result, $this->designExceptions->getThemeByRequest($this->requestMock)); }
/** * @param boolean $clean * @param string $expectedValue * * @dataProvider getRequestUriDataProvider */ public function testGetRequestUri($clean, $expectedValue) { $this->_request->expects($this->once())->method('getRequestUri')->will($this->returnValue('value')); $this->_prepareCleanString($clean); $headerObject = $this->_objectManager->getObject('Magento\\Framework\\HTTP\\Header', ['httpRequest' => $this->_request, 'converter' => $this->_converter]); $result = $headerObject->getRequestUri($clean); $this->assertEquals($expectedValue, $result); }
public function testExecuteNotPost() { $this->validatorMock->expects($this->once())->method('validate')->willReturn(false); $this->request->expects($this->once())->method('isPost')->willReturn(false); $this->messageManager->expects($this->once())->method('addError')->with('You have not canceled the item.'); $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf(); $this->assertEquals($this->resultRedirect, $this->controller->execute()); }
/** * Before model save * @param \Magefan\Blog\Model\Post $model * @param \Magento\Framework\App\Request\Http $request * @return void */ protected function _beforeSave($model, $request) { /* Prepare dates */ $dateFilter = $this->_objectManager->create('Magento\\Framework\\Stdlib\\DateTime\\Filter\\Date'); $data = $model->getData(); $filterRules = []; foreach (['publish_time', 'custom_theme_from', 'custom_theme_to'] as $dateField) { if (!empty($data[$dateField])) { $filterRules[$dateField] = $dateFilter; } } $inputFilter = new \Zend_Filter_Input($filterRules, [], $data); $data = $inputFilter->getUnescaped(); $model->setData($data); /* Prepare author */ if (!$model->getAuthorId()) { $authSession = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session'); $model->setAuthorId($authSession->getUser()->getId()); } /* Prepare relative links */ $data = $request->getPost('data'); $links = isset($data['links']) ? $data['links'] : null; if ($links && is_array($links)) { foreach (['post', 'product'] as $linkType) { if (!empty($links[$linkType]) && is_array($links[$linkType])) { $linksData = []; foreach ($links[$linkType] as $item) { $linksData[$item['id']] = ['position' => $item['position']]; } $links[$linkType] = $linksData; } } $model->setData('links', $links); } /* Prepare images */ $data = $model->getData(); foreach (['featured_img', 'og_img'] as $key) { if (isset($data[$key]) && is_array($data[$key])) { if (!empty($data[$key]['delete'])) { $model->setData($key, null); } else { if (isset($data[$key][0]['name']) && isset($data[$key][0]['tmp_name'])) { $image = $data[$key][0]['name']; $model->setData($key, Post::BASE_MEDIA_PATH . DIRECTORY_SEPARATOR . $image); $imageUploader = $this->_objectManager->get('Magefan\\Blog\\ImageUpload'); $imageUploader->moveFileFromTmp($image); } else { if (isset($data[$key][0]['name'])) { $model->setData($key, $data[$key][0]['name']); } } } } else { $model->setData($key, null); } } }
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(); }
public function testExecuteWithWishlist() { $url = 'http://redirect-url.com'; $quantity = 2; $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->willReturn($this->wishlistMock); $this->requestMock->expects($this->any())->method('getParam')->with('qty')->willReturn($quantity); $this->itemCarrierMock->expects($this->once())->method('moveAllToCart')->with($this->wishlistMock, 2)->willReturn($url); $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($url)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->allcartController->execute()); }
/** * Redirects tracking popup to specific URL * @param \Magento\Framework\Event\Observer $observer * * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $shippingInfoModel = $this->_shippingInfoFactory->create()->loadByHash($this->_request->getParam('hash')); if ($url = $this->shipmentHelper->getTrackingUrlByShippingInfo($shippingInfoModel)) { $controller = $observer->getControllerAction(); $controller->getResponse()->setRedirect($url); $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); } return $observer; }
public function testExecutePageDirectAccess() { $this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null); $this->request->expects($this->any())->method('getParams')->willReturn([]); $this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn(null); $resultRedirect = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->setMethods(['setPath'])->disableOriginalConstructor()->getMock(); $resultRedirect->expects($this->any())->method('setPath')->with('catalog/product/', ['_current' => true])->willReturnSelf(); $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($resultRedirect); $this->assertSame($resultRedirect, $this->object->execute()); }
/** * @dataProvider dataForTest */ public function testBeforeGetImage($expected) { $this->productMock->expects($this->once())->method('getTypeId')->willReturn('configurable'); $this->requestMock->expects($this->once())->method('getParams')->willReturn($expected['getParams']); $this->getFilterArray($expected); $this->canReplaceImageWithSwatch($expected); $this->swatchesHelperMock->expects($this->exactly($expected['loadVariationByFallback_count']))->method('loadVariationByFallback')->willReturn($expected['product']); $productImageMock = $this->getMock('Magento\\Catalog\\Block\\Product\\AbstractProduct', [], [], '', false); $result = $this->pluginModel->beforeGetImage($productImageMock, $this->productMock, $expected['page_handle']); $this->assertEquals([$this->productMock, $expected['page_handle'], []], $result); }
/** * Send Vary cookie * * @return void */ public function sendVary() { $varyString = $this->context->getVaryString(); if ($varyString) { $sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/'); $this->cookieManager->setSensitiveCookie(self::COOKIE_VARY_STRING, $varyString, $sensitiveCookMetadata); } elseif ($this->request->get(self::COOKIE_VARY_STRING)) { $cookieMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/'); $this->cookieManager->deleteCookie(self::COOKIE_VARY_STRING, $cookieMetadata); } }
public function testProcessNoDefault() { // Default path from config $this->configMock->expects($this->once())->method('getValue')->with('web/default/no_route', 'default')->willReturn(null); // Set expectations $this->requestMock->expects($this->once())->method('setModuleName')->with('core')->willReturnSelf(); $this->requestMock->expects($this->once())->method('setControllerName')->with('index')->willReturnSelf(); $this->requestMock->expects($this->once())->method('setActionName')->with('index')->willReturnSelf(); // Test $this->assertTrue($this->model->process($this->requestMock)); }
/** * @param bool $isPost * @param int $numOfCalls * @dataProvider afterDispatchTestDataProvider */ public function testAfterDispatch($isPost, $numOfCalls) { $this->messageManagerMock->expects($this->exactly($numOfCalls))->method('hasMessages')->will($this->returnValue(true)); $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost)); $this->cookieMetadataFactoryMock->expects($this->exactly($numOfCalls))->method('createPublicCookieMetadata')->will($this->returnValue($this->publicCookieMetadataMock)); $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setDuration')->with(MessageBox::COOKIE_PERIOD)->will($this->returnValue($this->publicCookieMetadataMock)); $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setPath')->with('/')->will($this->returnValue($this->publicCookieMetadataMock)); $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setHttpOnly')->with(false)->will($this->returnValue($this->publicCookieMetadataMock)); $this->cookieManagerMock->expects($this->exactly($numOfCalls))->method('setPublicCookie')->with(MessageBox::COOKIE_NAME, 1, $this->publicCookieMetadataMock); $this->assertSame($this->responseMock, $this->msgBox->afterDispatch($this->objectMock, $this->responseMock)); }
/** * Executes the controller action and asserts non exception logic */ public function testExecuteLocalizedException() { $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); $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Generate', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]); $this->assertSame($this->resultJson, $notification->execute()); }
/** * @param $observer * @return $this */ public function execute(EventObserver $observer) { $menu = $observer->getMenu(); $tree = $menu->getTree(); $fullAction = $this->request->getFullActionName(); $selectedActions = ['gemtoo_blog_article_index', 'gemtoo_blog_article_view']; $articleNodeId = 'articles'; $data = ['name' => __('Blog'), 'id' => $articleNodeId, 'url' => $this->articleUrl->getListUrl(), 'is_active' => in_array($fullAction, $selectedActions)]; $articlesNode = new Node($data, 'id', $tree, $menu); $menu->addChild($articlesNode); return $this; }
/** * @param array $requestResult * @param bool $moduleManagerResult * @param bool $cacheConfigResult * @param bool $layoutResult * @param bool $can Depersonalize * @dataProvider checkIfDepersonalizeDataProvider */ public function testCheckIfDepersonalize(array $requestResult, $moduleManagerResult, $cacheConfigResult, $layoutResult, $canDepersonalize) { $this->requestMock->expects($this->any())->method('isAjax')->willReturn($requestResult['ajax']); $this->requestMock->expects($this->any())->method('isGet')->willReturn($requestResult['get']); $this->requestMock->expects($this->any())->method('isHead')->willReturn($requestResult['head']); $this->moduleManagerMock->expects($this->any())->method('isEnabled')->with('Magento_PageCache')->willReturn($moduleManagerResult); $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn($cacheConfigResult); $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false); $layoutMock->expects($this->any())->method('isCacheable')->willReturn($layoutResult); $object = new DepersonalizeChecker($this->requestMock, $this->moduleManagerMock, $this->cacheConfigMock); $this->assertEquals($canDepersonalize, $object->checkIfDepersonalize($layoutMock)); }
/** * Replace original configurable product with first child * * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @param \Magento\Catalog\Block\Product\AbstractProduct $subject * @param \Magento\Catalog\Model\Product $product * @param string $location * @param array $attributes * @return array */ public function beforeGetImage(\Magento\Catalog\Block\Product\AbstractProduct $subject, \Magento\Catalog\Model\Product $product, $location, array $attributes = []) { if ($product->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE && ($location == self::CATEGORY_PAGE_GRID_LOCATION || $location == self::CATEGORY_PAGE_LIST_LOCATION)) { $request = $this->request->getParams(); if (is_array($request)) { $filterArray = $this->getFilterArray($request); if (!empty($filterArray)) { $product = $this->loadSimpleVariation($product, $filterArray); } } } return [$product, $location, $attributes]; }