6 declare(strict_types=1);
40 protected function setUp(): void
42 $this->category = $this->createMock(\
Magento\Catalog\Model\Category::class);
54 $this->product = $this->createPartialMock(\
Magento\Catalog\Model\Product::class, $productMethods);
55 $this->storeManager = $this->createMock(\
Magento\
Store\Model\StoreManagerInterface::class);
56 $this->scopeConfig = $this->createMock(\
Magento\Framework\
App\
Config\ScopeConfigInterface::class);
57 $this->categoryUrlPathGenerator = $this->createMock(
58 \
Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator::class
60 $this->productRepository = $this->createMock(\
Magento\Catalog\Api\ProductRepositoryInterface::class);
61 $this->productRepository->expects($this->any())->method(
'getById')->willReturn($this->product);
63 $this->productUrlPathGenerator = (
new ObjectManager($this))->getObject(
64 \
Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator::class,
66 'storeManager' => $this->storeManager,
67 'scopeConfig' => $this->scopeConfig,
68 'categoryUrlPathGenerator' => $this->categoryUrlPathGenerator,
69 'productRepository' => $this->productRepository,
80 'path based on url key' => [
'url-key',
null,
'url-key'],
81 'path based on product name 1' => [
'',
'product-name',
'product-name'],
82 'path based on product name 2' => [
null,
'product-name',
'product-name'],
83 'path based on product name 3' => [
false,
'product-name',
'product-name']
96 $this->product->expects($this->once())->method(
'getData')->with(
'url_path')
97 ->will($this->returnValue(
null));
98 $this->product->expects($this->any())->method(
'getUrlKey')->will($this->returnValue($urlKey));
99 $this->product->expects($this->any())->method(
'getName')->will($this->returnValue($productName));
100 $this->product->expects($this->once())->method(
'formatUrlKey')->will($this->returnArgument(0));
102 $this->assertEquals(
$result, $this->productUrlPathGenerator->getUrlPath($this->product,
null));
113 $this->product->expects($this->any())->method(
'getUrlKey')->will($this->returnValue($productUrlKey));
114 $this->product->expects($this->any())->method(
'formatUrlKey')->will($this->returnValue($productUrlKey));
115 $this->assertSame($expectedUrlKey, $this->productUrlPathGenerator->getUrlKey($this->product));
124 'URL Key use default' => [
false,
null],
125 'URL Key empty' => [
'product-url',
'product-url'],
138 $this->product->expects($this->once())->method(
'getData')->with(
'url_path')
139 ->will($this->returnValue(
null));
140 $this->product->expects($this->any())->method(
'getUrlKey')->willReturnOnConsecutiveCalls(
false, $storedUrlKey);
141 $this->product->expects($this->any())->method(
'getName')->will($this->returnValue($productName));
142 $this->product->expects($this->any())->method(
'formatUrlKey')->will($this->returnArgument(0));
143 $this->assertEquals($expectedUrlKey, $this->productUrlPathGenerator->getUrlPath($this->product,
null));
152 [
'default-store-view-url-key',
null,
'default-store-view-url-key'],
153 [
false,
'default-store-view-product-name',
'default-store-view-product-name']
162 $this->product->expects($this->once())->method(
'getData')->with(
'url_path')
163 ->will($this->returnValue(
'product-path'));
164 $this->categoryUrlPathGenerator->expects($this->once())->method(
'getUrlPath')
165 ->will($this->returnValue(
'category-url-path'));
168 'category-url-path/product-path',
169 $this->productUrlPathGenerator->getUrlPath($this->product, $this->category)
179 $this->product->expects($this->once())->method(
'getData')->with(
'url_path')
180 ->will($this->returnValue(
'product-path'));
182 $store->expects($this->once())->method(
'getId')->will($this->returnValue(
$storeId));
183 $this->storeManager->expects($this->once())->method(
'getStore')->will($this->returnValue(
$store));
184 $this->scopeConfig->expects($this->once())->method(
'getValue')
186 ->will($this->returnValue(
'.html'));
190 $this->productUrlPathGenerator->getUrlPathWithSuffix($this->product,
null)
200 $this->product->expects($this->once())->method(
'getData')->with(
'url_path')
201 ->will($this->returnValue(
'product-path'));
202 $this->categoryUrlPathGenerator->expects($this->once())->method(
'getUrlPath')
203 ->will($this->returnValue(
'category-url-path'));
204 $this->storeManager->expects($this->never())->method(
'getStore');
205 $this->scopeConfig->expects($this->once())->method(
'getValue')
207 ->will($this->returnValue(
'.html'));
210 'category-url-path/product-path.html',
211 $this->productUrlPathGenerator->getUrlPathWithSuffix($this->product,
$storeId, $this->category)
220 $this->product->expects($this->once())->method(
'getId')->will($this->returnValue(1));
223 'catalog/product/view/id/1',
224 $this->productUrlPathGenerator->getCanonicalUrlPath($this->product)
233 $this->product->expects($this->once())->method(
'getId')->will($this->returnValue(1));
234 $this->category->expects($this->once())->method(
'getId')->will($this->returnValue(1));
237 'catalog/product/view/id/1/category/1',
238 $this->productUrlPathGenerator->getCanonicalUrlPath($this->product, $this->category)
testGetUrlPathWithCategory()
testGetUrlPathWithSuffixAndCategoryAndStore()
testGetUrlPath($urlKey, $productName, $result)
$categoryUrlPathGenerator
getUrlPathDefaultUrlKeyDataProvider()
testGetCanonicalUrlPath()
testGetUrlPathWithSuffix()
testGetUrlPathDefaultUrlKey($storedUrlKey, $productName, $expectedUrlKey)
testGetCanonicalUrlPathWithCategory()
const XML_PATH_PRODUCT_URL_SUFFIX
testGetUrlKey($productUrlKey, $expectedUrlKey)