Skip to content

Commit 52b2639

Browse files
author
Alex Bomko
committed
MAGETWO-38738: [GITHUB] fix typo in getCurrentCategoryKey #1368
1 parent 1c9045e commit 52b2639

File tree

2 files changed

+90
-6
lines changed

2 files changed

+90
-6
lines changed

app/code/Magento/Catalog/Test/Unit/Block/NavigationTest.php

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ class NavigationTest extends \PHPUnit_Framework_TestCase
1212
*/
1313
protected $block;
1414

15+
/**
16+
* @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $registry;
19+
20+
/**
21+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $storeManager;
24+
25+
/**
26+
* @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $design;
29+
30+
/**
31+
* @var \Magento\Framework\App\Http\Context|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $httpContext;
34+
1535
protected function setUp()
1636
{
1737
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -22,22 +42,85 @@ protected function setUp()
2242
'',
2343
false
2444
);
45+
$this->registry = $this->getMock('Magento\Framework\Registry');
46+
$this->storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface');
47+
$this->design = $this->getMock('Magento\Framework\View\DesignInterface');
48+
$this->httpContext = $this->getMock('Magento\Framework\App\Http\Context', [], [], '', false);
2549
$this->block = $objectManager->getObject(
2650
'Magento\Catalog\Block\Navigation',
27-
['categoryFactory' => $categoryFactory]
51+
[
52+
'categoryFactory' => $categoryFactory,
53+
'registry' => $this->registry,
54+
'storeManager' => $this->storeManager,
55+
'design' => $this->design,
56+
'httpContext' => $this->httpContext
57+
]
2858
);
2959
}
3060

31-
protected function tearDown()
32-
{
33-
$this->block = null;
34-
}
35-
3661
public function testGetIdentities()
3762
{
3863
$this->assertEquals(
3964
[\Magento\Catalog\Model\Category::CACHE_TAG, \Magento\Store\Model\Group::CACHE_TAG],
4065
$this->block->getIdentities()
4166
);
4267
}
68+
69+
public function testGetCurrentCategoryKey()
70+
{
71+
$categoryKey = 101;
72+
$category = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false);
73+
$category->expects($this->any())->method('getPath')->willReturn($categoryKey);
74+
75+
$this->registry->expects($this->any())->method('registry')->with('current_category')->willReturn($category);
76+
77+
$this->assertEquals($categoryKey, $this->block->getCurrentCategoryKey());
78+
}
79+
80+
public function testGetCurrentCategoryKeyFromRootCategory()
81+
{
82+
$categoryKey = 102;
83+
$store = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
84+
$store->expects($this->any())->method('getRootCategoryId')->willReturn($categoryKey);
85+
86+
$this->storeManager->expects($this->any())->method('getStore')->willReturn($store);
87+
88+
$this->assertEquals($categoryKey, $this->block->getCurrentCategoryKey());
89+
}
90+
91+
public function testGetCacheKeyInfo()
92+
{
93+
$store = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
94+
$store->expects($this->atLeastOnce())->method('getId')->willReturn(55);
95+
$store->expects($this->atLeastOnce())->method('getRootCategoryId')->willReturn(60);
96+
97+
$this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($store);
98+
99+
$theme = $this->getMock('\Magento\Framework\View\Design\ThemeInterface');
100+
$theme->expects($this->atLeastOnce())->method('getId')->willReturn(65);
101+
102+
$this->design->expects($this->atLeastOnce())->method('getDesignTheme')->willReturn($theme);
103+
104+
$this->httpContext->expects($this->atLeastOnce())
105+
->method('getValue')
106+
->with(\Magento\Customer\Model\Context::CONTEXT_GROUP)
107+
->willReturn(70);
108+
109+
$this->block->setTemplate('block_template');
110+
$this->block->setNameInLayout('block_name');
111+
112+
$expectedResult = [
113+
'CATALOG_NAVIGATION',
114+
55,
115+
65,
116+
70,
117+
'template' => 'block_template',
118+
'name' => 'block_name',
119+
60,
120+
'category_path' => 60,
121+
'short_cache_id' => 'c3de6d1160d1e7730b04d6cad409a2b4'
122+
];
123+
124+
$this->assertEquals($expectedResult, $this->block->getCacheKeyInfo());
125+
}
43126
}

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,4 +2245,5 @@
22452245
['getOrigData', 'Magento\Framework\Object', 'Moved to Magento\Framework\Model\AbstractModel'],
22462246
['dataHasChangedFor', 'Magento\Framework\Object', 'Moved to Magento\Framework\Model\AbstractModel'],
22472247
['setDataChanges', 'Magento\Framework\Object', 'Moved to Magento\Framework\Model\AbstractModel'],
2248+
['getCurrenCategoryKey', 'Magento\Catalog\Block\Navigation', 'getCurrentCategoryKey'],
22482249
];

0 commit comments

Comments
 (0)