45 $this->category = $this->createPartialMock(\
Magento\Catalog\Model\Category::class, $categoryMethods);
46 $this->storeManager = $this->createMock(\
Magento\
Store\Model\StoreManagerInterface::class);
47 $this->scopeConfig = $this->createMock(\
Magento\Framework\
App\
Config\ScopeConfigInterface::class);
48 $this->categoryRepository = $this->createMock(\
Magento\Catalog\Api\CategoryRepositoryInterface::class);
50 $this->categoryUrlPathGenerator = (
new ObjectManager($this))->getObject(
51 \
Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator::class,
53 'storeManager' => $this->storeManager,
54 'scopeConfig' => $this->scopeConfig,
55 'categoryRepository' => $this->categoryRepository,
75 $dataChangedForUrlKey,
76 $dataChangedForParentId,
79 $this->category->expects($this->any())->method(
'getParentId')->will($this->returnValue($parentId));
80 $this->category->expects($this->any())->method(
'isObjectNew')->will($this->returnValue(
false));
81 $this->category->expects($this->any())->method(
'getLevel')->will($this->returnValue($level));
82 $this->category->expects($this->any())->method(
'getUrlPath')->will($this->returnValue($urlPath));
83 $this->category->expects($this->any())->method(
'getUrlKey')->will($this->returnValue($urlKey));
84 $this->category->expects($this->any())->method(
'dataHasChangedFor')
85 ->will($this->returnValueMap([[
'url_key', $dataChangedForUrlKey], [
'parent_id', $dataChangedForParentId]]));
87 $this->assertEquals(
$result, $this->categoryUrlPathGenerator->getUrlPath($this->category));
98 [13,
'url-path', $noGenerationLevel,
'',
false,
false,
'url-path'],
99 [13,
'url-path', $noGenerationLevel,
'url-key',
true,
false,
'url-key'],
100 [13,
'url-path', $noGenerationLevel,
'url-key',
false,
true,
'url-key'],
112 [
'url-key',
false, $requireGenerationLevel, 13,
'parent-path',
'parent-path/url-key'],
131 $parentCategoryParentId,
137 $this->category->expects($this->any())->method(
'getParentId')
138 ->will($this->returnValue(13));
139 $this->category->expects($this->any())->method(
'getLevel')
140 ->will($this->returnValue($level));
141 $this->category->expects($this->any())->method(
'getUrlPath')->will($this->returnValue($urlPath));
142 $this->category->expects($this->any())->method(
'getUrlKey')->will($this->returnValue($urlKey));
143 $this->category->expects($this->any())->method(
'isObjectNew')->will($this->returnValue($isCategoryNew));
145 $methods = [
'__wakeup',
'getUrlPath',
'getParentId',
'getLevel',
'dataHasChangedFor',
'load'];
146 $parentCategory = $this->createPartialMock(\
Magento\Catalog\Model\Category::class,
$methods);
147 $parentCategory->expects($this->any())->method(
'getParentId')
148 ->will($this->returnValue($parentCategoryParentId));
149 $parentCategory->expects($this->any())->method(
'getLevel')->will($this->returnValue($parentLevel));
150 $parentCategory->expects($this->any())->method(
'getUrlPath')->will($this->returnValue($parentUrlPath));
151 $parentCategory->expects($this->any())->method(
'dataHasChangedFor')
152 ->will($this->returnValueMap([[
'url_key',
false], [
'path_ids',
false]]));
154 $this->categoryRepository->expects($this->any())->method(
'get')->with(13)
155 ->will($this->returnValue($parentCategory));
157 $this->assertEquals(
$result, $this->categoryUrlPathGenerator->getUrlPath($this->category));
166 [
'url-path', 1,
null,
'.html',
'url-path.html'],
167 [
'url-path',
null, 1,
'.html',
'url-path.html'],
181 $this->category->expects($this->any())->method(
'getStoreId')->will($this->returnValue($categoryStoreId));
182 $this->category->expects($this->once())->method(
'getParentId')->will($this->returnValue(123));
183 $this->category->expects($this->once())->method(
'getUrlPath')->will($this->returnValue($urlPath));
184 $this->category->expects($this->exactly(2))->method(
'dataHasChangedFor')
185 ->will($this->returnValueMap([[
'url_key',
false], [
'path_ids',
false]]));
188 $this->scopeConfig->expects($this->once())->method(
'getValue')
190 ->will($this->returnValue(
$suffix));
194 $this->categoryUrlPathGenerator->getUrlPathWithSuffix($this->category,
$storeId)
200 $urlPath =
'url-path';
206 $this->category->expects($this->any())->method(
'getStoreId')->will($this->returnValue(
$storeId));
207 $this->category->expects($this->once())->method(
'getParentId')->will($this->returnValue(2));
208 $this->category->expects($this->once())->method(
'getUrlPath')->will($this->returnValue($urlPath));
209 $this->category->expects($this->exactly(2))->method(
'dataHasChangedFor')
210 ->will($this->returnValueMap([[
'url_key',
false], [
'path_ids',
false]]));
214 $this->storeManager->expects($this->once())->method(
'getStore')->will($this->returnValue(
$store));
215 $this->scopeConfig->expects($this->once())->method(
'getValue')
217 ->will($this->returnValue(
$suffix));
221 $this->categoryUrlPathGenerator->getUrlPathWithSuffix($this->category,
$storeId)
227 $this->category->expects($this->once())->method(
'getId')->will($this->returnValue(1));
229 'catalog/category/view/id/1',
230 $this->categoryUrlPathGenerator->getCanonicalUrlPath($this->category)
240 [
'url-key',
null,
'url-key'],
241 [
'',
'category-name',
'category-name'],
253 $this->category->expects($this->once())->method(
'getUrlKey')->will($this->returnValue($urlKey));
254 $this->category->expects($this->any())->method(
'getName')->will($this->returnValue(
$name));
255 $this->category->expects($this->once())->method(
'formatUrlKey')->will($this->returnArgument(0));
257 $this->assertEquals(
$result, $this->categoryUrlPathGenerator->getUrlKey($this->category));
testGetUrlKey($urlKey, $name, $result)
getUrlPathWithParentDataProvider()
$categoryUrlPathGenerator
const MINIMAL_CATEGORY_LEVEL_FOR_PROCESSING
testGetUrlPath( $parentId, $urlPath, $level, $urlKey, $dataChangedForUrlKey, $dataChangedForParentId, $result)
testGetUrlPathWithSuffixAndStore($urlPath, $storeId, $categoryStoreId, $suffix, $result)
testGetCanonicalUrlPath()
testGetUrlPathWithParent( $urlKey, $isCategoryNew, $level, $parentCategoryParentId, $parentUrlPath, $result)
testGetUrlPathWithSuffixWithoutStore()
getUrlPathWithSuffixDataProvider()
const XML_PATH_CATEGORY_URL_SUFFIX
if(!isset($_GET['name'])) $name