/** * Cover categoriesUrlRewriteGenerate(). */ public function testCategoriesUrlRewriteGenerate() { $urlPathWithCategory = 'category/simple-product.html'; $storeId = 10; $productId = 'product_id'; $canonicalUrlPathWithCategory = 'canonical-path-with-category'; $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $productsByStores = [$storeId => $product]; $products = [$productId => $productsByStores]; $categoryCache = [$productId => [$this->categoryId]]; $this->setPropertyValue($this->import, 'products', $products); $this->setPropertyValue($this->import, 'categoryCache', $categoryCache); $this->setPropertyValue($this->import, 'import', $this->importProduct); $this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($urlPathWithCategory)); $this->productUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($canonicalUrlPathWithCategory)); $category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false); $category->expects($this->any())->method('getId')->will($this->returnValue($this->categoryId)); $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityId')->with($productId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityType')->with(ProductUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($urlPathWithCategory)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($canonicalUrlPathWithCategory)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setMetadata')->with(['category_id' => $this->categoryId])->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->any())->method('create')->willReturn($this->urlRewrite); $actualResult = $this->invokeMethod($this->import, 'categoriesUrlRewriteGenerate'); $this->assertEquals([$this->urlRewrite], $actualResult); }
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)); }
public function testGenerateCategories() { $urlPathWithCategory = 'category/simple-product.html'; $storeId = 10; $productId = 'product_id'; $canonicalUrlPathWithCategory = 'canonical-path-with-category'; $categoryId = 'category_id'; $this->product->expects($this->any())->method('getId')->will($this->returnValue($productId)); $this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($urlPathWithCategory)); $this->productUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($canonicalUrlPathWithCategory)); $category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false); $category->expects($this->any())->method('getId')->will($this->returnValue($categoryId)); $this->categoryRegistry->expects($this->any())->method('getList')->will($this->returnValue([$category])); $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($urlPathWithCategory)->will($this->returnSelf()); $this->urlRewriteBuilder->expects($this->any())->method('setTargetPath')->with($canonicalUrlPathWithCategory)->will($this->returnSelf()); $this->urlRewriteBuilder->expects($this->any())->method('setMetadata')->with(['category_id' => $categoryId])->will($this->returnSelf()); $this->urlRewriteBuilder->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite)); $this->assertEquals([$this->urlRewrite], $this->categoriesUrlRewriteGenerator->generate($storeId, $this->product, $this->categoryRegistry)); }
public function testGenerationForCustomWithTargetPathGeneration() { $storeId = 12; $productId = 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->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($targetPath)); $this->product->expects($this->any())->method('getId')->will($this->returnValue($productId)); $this->prepareUrlRewriteMock($storeId, $productId, $requestPath, $targetPath, 'code', [], $description); $this->assertEquals([$this->urlRewrite], $this->currentUrlRewritesRegenerator->generate($storeId, $this->product, $this->objectRegistry)); }
/** * Cover currentUrlRewritesRegenerate(). * * @cover \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::generateForCustom */ public function testCurrentUrlRewritesRegenerateForCustomWithTargetPathGeneration() { $productId = 'entity id value'; $storeId = 'store id value'; $products = [$productId => [$storeId => 'value']]; $this->setPropertyValue($this->import, 'products', $products); $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->currentUrlRewritesRegeneratorGetCurrentRewritesMocks([[UrlRewrite::REQUEST_PATH => $requestPath, UrlRewrite::TARGET_PATH => 'custom-target-path.html', UrlRewrite::REDIRECT_TYPE => 'code', UrlRewrite::IS_AUTOGENERATED => 0, UrlRewrite::DESCRIPTION => $description, UrlRewrite::METADATA => [], UrlRewrite::ENTITY_ID => $productId, UrlRewrite::STORE_ID => $storeId]]))); $this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($targetPath)); $this->product->expects($this->any())->method('getId')->will($this->returnValue($productId)); $this->currentUrlRewritesRegeneratorPrepareUrlRewriteMock($storeId, $productId, $requestPath, $targetPath, 'code', [], $description); $actualResult = $this->import->currentUrlRewritesRegenerate(); $this->assertEquals([[$this->urlRewrite]], $actualResult); }