Пример #1
0
 public function testGenerate()
 {
     $requestPath = 'simple-product.html';
     $storeId = 10;
     $productId = 'product_id';
     $targetPath = 'catalog/product/view/id/' . $productId;
     $this->product->expects($this->any())->method('getId')->will($this->returnValue($productId));
     $this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($requestPath));
     $this->productUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($targetPath));
     $this->categoryRegistry->expects($this->any())->method('getList')->will($this->returnValue([]));
     $this->urlRewriteBuilder->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf());
     $this->urlRewriteBuilder->expects($this->any())->method('setEntityId')->with($productId)->will($this->returnSelf());
     $this->urlRewriteBuilder->expects($this->any())->method('setEntityType')->with(ProductUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf());
     $this->urlRewriteBuilder->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf());
     $this->urlRewriteBuilder->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf());
     $this->urlRewriteBuilder->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite));
     $this->assertEquals([$this->urlRewrite], $this->canonicalUrlRewriteGenerator->generate($storeId, $this->product));
 }
 /**
  * Generate list of urls for specific store view
  *
  * @param int $storeId
  * @param \Magento\Framework\Data\Collection $productCategories
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
  */
 protected function generateForSpecificStoreView($storeId, $productCategories)
 {
     $categories = [];
     foreach ($productCategories as $category) {
         if ($this->isCategoryProperForGenerating($category, $storeId)) {
             $categories[] = $category;
         }
     }
     $this->productCategories = $this->objectRegistryFactory->create(['entities' => $categories]);
     /**
      * @var $urls \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
      */
     $urls = array_merge($this->canonicalUrlRewriteGenerator->generate($storeId, $this->product), $this->categoriesUrlRewriteGenerator->generate($storeId, $this->product, $this->productCategories), $this->currentUrlRewritesRegenerator->generate($storeId, $this->product, $this->productCategories));
     /* Reduce duplicates. Last wins */
     $result = [];
     foreach ($urls as $url) {
         $result[$url->getTargetPath() . '-' . $url->getStoreId()] = $url;
     }
     $this->productCategories = null;
     return $result;
 }