public function testSessionUrlVarWithoutMatchedHostsAndBaseUrl() { $requestMock = $this->getRequestMock(); $model = $this->getUrlModel( [ 'session' => $this->sessionMock, 'request' => $requestMock, 'sidResolver' => $this->sidResolverMock, 'scopeResolver' => $this->scopeResolverMock, 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), ] ); $requestMock->expects($this->once())->method('getHttpHost')->will($this->returnValue('localhost')); $this->scopeMock->expects($this->once()) ->method('getBaseUrl') ->will($this->returnValue('http://example.com')); $this->scopeResolverMock->expects($this->any()) ->method('getScope') ->will($this->returnValue($this->scopeMock)); $this->sidResolverMock->expects($this->once())->method('getSessionIdQueryParam') ->will($this->returnValue('SID')); $this->sessionMock->expects($this->once())->method('getSessionId') ->will($this->returnValue('session-id')); $this->assertEquals( '<a href="http://example.com/?SID=session-id">www.example.com</a>', $model->sessionUrlVar('<a href="http://example.com/?___SID=U">www.example.com</a>') ); }
/** * @dataProvider getUrlDataProvider * @covers Magento\Catalog\Model\Product\Url::getUrl * @covers Magento\Catalog\Model\Product\Url::getUrlInStore * @covers Magento\Catalog\Model\Product\Url::getProductUrl * * @param $getUrlMethod * @param $routePath * @param $requestPathProduct * @param $storeId * @param $categoryId * @param $routeParams * @param $routeParamsUrl * @param $entityId * @param $idPath * @param $requestPathUrlRewrite * @param $productId * @param $productUrlKey * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function testGetUrl($getUrlMethod, $routePath, $requestPathProduct, $storeId, $categoryId, $routeParams, $routeParamsUrl, $entityId, $idPath, $requestPathUrlRewrite, $productId, $productUrlKey) { $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getStoreId', 'getEntityId', 'getId', 'getUrlKey', 'setRequestPath', 'hasUrlDataObject', 'getRequestPath', 'getCategoryId', 'getDoNotUseCategoryId', '__wakeup'])->getMock(); $product->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $product->expects($this->any())->method('getCategoryId')->will($this->returnValue($categoryId)); $product->expects($this->any())->method('getRequestPath')->will($this->returnValue($requestPathProduct)); $product->expects($this->any())->method('getEntityId')->will($this->returnValue($entityId)); $product->expects($this->any())->method('setRequestPath')->with($requestPathUrlRewrite)->will($this->returnSelf()); $product->expects($this->any())->method('getId')->will($this->returnValue($productId)); $product->expects($this->any())->method('getUrlKey')->will($this->returnValue($productUrlKey)); $this->url->expects($this->any())->method('setScope')->with($storeId)->will($this->returnSelf()); $this->url->expects($this->any())->method('getUrl')->with($routePath, $routeParamsUrl)->will($this->returnValue($requestPathProduct)); $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('loadByIdPath')->with($idPath)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('getId')->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('getRequestPath')->will($this->returnValue($requestPathUrlRewrite)); switch ($getUrlMethod) { case 'getUrl': $this->assertEquals($requestPathProduct, $this->model->getUrl($product, $routeParams)); break; case 'getUrlInStore': $this->assertEquals($requestPathProduct, $this->model->getUrlInStore($product, $routeParams)); break; case 'getProductUrl': $this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, true)); $this->sidResolver->expects($this->once())->method('getUseSessionInUrl')->will($this->returnValue(true)); $this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, null)); break; } }
/** * Run test toHtml method * * @param bool $customerId * @return void * * @dataProvider dataProviderToHtml */ public function testToHtml($customerId) { $cacheData = false; $idQueryParam = 'id-query-param'; $sessionId = 'session-id'; $this->additional->setData('cache_lifetime', 789); $this->additional->setData('cache_key', 'cache-key'); $this->eventManagerMock->expects($this->once())->method('dispatch')->with('view_block_abstract_to_html_before', ['block' => $this->additional]); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('advanced/modules_disable_output/Magento_Persistent', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(false); // get cache $this->cacheStateMock->expects($this->at(0))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(true); // save cache $this->cacheStateMock->expects($this->at(1))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(false); $this->cacheMock->expects($this->once())->method('load')->willReturn($cacheData); $this->sidResolverMock->expects($this->never())->method('getSessionIdQueryParam')->with($this->sessionMock)->willReturn($idQueryParam); $this->sessionMock->expects($this->never())->method('getSessionId')->willReturn($sessionId); // call protected _toHtml method $sessionMock = $this->getMock('Magento\\Persistent\\Model\\Session', ['getCustomerId'], [], '', false); $this->persistentSessionHelperMock->expects($this->atLeastOnce())->method('getSession')->willReturn($sessionMock); $sessionMock->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($customerId); if ($customerId) { $this->assertEquals('<span><a >Not you?</a></span>', $this->additional->toHtml()); } else { $this->assertEquals('', $this->additional->toHtml()); } }