コード例 #1
0
 /**
  * @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;
     }
 }