Example #1
0
 public function testGetUrlPath()
 {
     /** @var $product \Magento\Catalog\Model\Product */
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->setUrlPath('product.html');
     /** @var $category \Magento\Catalog\Model\Category */
     $category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Category', ['data' => ['url_path' => 'category', 'entity_id' => 5, 'path_ids' => [2, 3, 5]]]);
     $category->setOrigData();
     $this->assertEquals('product.html', $this->urlPathGenerator->getUrlPath($product));
     $this->assertEquals('category/product.html', $this->urlPathGenerator->getUrlPath($product, $category));
 }
 /**
  * Generate list based on store view
  *
  * @return UrlRewrite[]
  */
 protected function canonicalUrlRewriteGenerate()
 {
     $urls = [];
     foreach ($this->products as $productId => $productsByStores) {
         foreach ($productsByStores as $storeId => $product) {
             if ($this->productUrlPathGenerator->getUrlPath($product)) {
                 $urls[] = $this->urlRewriteFactory->create()->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($productId)->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId))->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product))->setStoreId($storeId);
             }
         }
     }
     return $urls;
 }
 public function testGetUrlPathWithCategory()
 {
     $this->product->expects($this->once())->method('getData')->with('url_path')->will($this->returnValue('product-path'));
     $this->categoryUrlPathGenerator->expects($this->once())->method('getUrlPath')->will($this->returnValue('category-url-path'));
     $this->assertEquals('category-url-path/product-path', $this->productUrlPathGenerator->getUrlPath($this->product, $this->category));
 }