public function testGetUrlPathWithSuffixAndCategoryAnsStore() { $storeId = 1; $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->storeManager->expects($this->never())->method('getStore'); $this->scopeConfig->expects($this->once())->method('getValue')->with(ProductUrlPathGenerator::XML_PATH_PRODUCT_URL_SUFFIX, \Magento\Framework\Store\ScopeInterface::SCOPE_STORE, $storeId)->will($this->returnValue('.html')); $this->assertEquals('category-url-path/product-path.html', $this->productUrlPathGenerator->getUrlPathWithSuffix($this->product, $storeId, $this->category)); }
public function testGenerate() { $requestPath = 'category.html'; $targetPath = 'target-path'; $storeId = 'store_id'; $categoryId = 'category_id'; $this->category->expects($this->any())->method('getId')->will($this->returnValue($categoryId)); $this->categoryUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($requestPath)); $this->categoryUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($targetPath)); $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityId')->with($categoryId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityType')->with(CategoryUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite)); $this->assertEquals(['category.html_store_id' => $this->urlRewrite], $this->canonicalUrlRewriteGenerator->generate($storeId, $this->category)); }
public function testGenerationForCustomWithTargetPathGeneration() { $storeId = 12; $categoryId = 123; $requestPath = 'generate-for-custom-without-redirect-type.html'; $targetPath = 'generated-target-path.html'; $description = 'description'; $this->urlFinder->expects($this->once())->method('findAllByData')->will($this->returnValue($this->getCurrentRewritesMocks([[UrlRewrite::REQUEST_PATH => $requestPath, UrlRewrite::TARGET_PATH => 'custom-target-path.html', UrlRewrite::REDIRECT_TYPE => 'code', UrlRewrite::IS_AUTOGENERATED => 0, UrlRewrite::DESCRIPTION => $description, UrlRewrite::METADATA => []]]))); $this->categoryUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($targetPath)); $this->category->expects($this->any())->method('getId')->will($this->returnValue($categoryId)); $this->urlRewriteBuilder->expects($this->once())->method('setDescription')->with($description)->will($this->returnSelf()); $this->prepareUrlRewriteMock($storeId, $categoryId, $requestPath, $targetPath, 'code'); $this->assertEquals([$this->urlRewrite], $this->currentUrlRewritesRegenerator->generate($storeId, $this->category)); }