Skip to content

Commit 1ffcfde

Browse files
committed
MAGETWO-67291: [Performance] Layered Navigation built for Non Anchored categories
1 parent 986adf1 commit 1ffcfde

File tree

4 files changed

+156
-5
lines changed

4 files changed

+156
-5
lines changed

app/code/Magento/CatalogSearch/Model/Adapter/Aggregation/Checker/Query/CatalogView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,4 @@ private function getCategoryIdsFromQuery(QueryInterface $queryExpression)
145145

146146
return $categoryIds;
147147
}
148-
}
148+
}

app/code/Magento/CatalogSearch/Model/Adapter/Aggregation/RequestCheckerComposite.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
use Magento\Catalog\Api\CategoryRepositoryInterface;
1010
use Magento\Store\Model\StoreManagerInterface;
1111

12-
/**
13-
* A Composite implementation for request checker.
14-
* Checker for attribute resolver class.
15-
*/
1612
class RequestCheckerComposite implements RequestCheckerInterface
1713
{
1814
/**

app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Aggregation/AggregationResolverTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ protected function setUp()
8787
);
8888
}
8989

90+
public function testIsNotAplicable()
91+
{
92+
$documentIds = [1];
93+
$this->aggregationChecker
94+
->expects($this->once())
95+
->method('isApplicable')
96+
->with($this->request)
97+
->willReturn(false);
98+
$this->assertEquals([], $this->aggregationResolver->resolve($this->request, $documentIds));
99+
}
100+
90101
public function testResolve()
91102
{
92103
$documentIds = [1, 2, 3];
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Test\Unit\Model\Adapter\Aggregation\Checker\Query;
7+
8+
use Magento\Catalog\Api\CategoryRepositoryInterface;
9+
use Magento\CatalogSearch\Model\Adapter\Aggregation\Checker\Query\CatalogView;
10+
use Magento\Framework\Search\RequestInterface;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Framework\Search\Request\QueryInterface;
13+
use Magento\Framework\Search\Request\Query\Filter;
14+
use Magento\Framework\Search\Request\Filter\Term;
15+
use Magento\Store\Api\Data\StoreInterface;
16+
use Magento\Catalog\Api\Data\CategoryInterface;
17+
18+
class CatalogViewTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* @var CatalogView
22+
*/
23+
private $catalogViewMock;
24+
25+
/**
26+
* @var CategoryRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $categoryRepositoryMock;
29+
30+
/**
31+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $storeManagerMock;
34+
35+
/**
36+
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $requestMock;
39+
40+
/**
41+
* @var QueryInterface|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $queryMock;
44+
45+
/**
46+
* @var Filter|\PHPUnit_Framework_MockObject_MockObject
47+
*/
48+
private $queryFilterMock;
49+
50+
/**
51+
* @var Term|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $termFilterMock;
54+
55+
/**
56+
* @var string
57+
*/
58+
private $name;
59+
60+
/**
61+
* @var CategoryInterface|\PHPUnit_Framework_MockObject_MockObject
62+
*/
63+
private $categoryMock;
64+
65+
/**
66+
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
67+
*/
68+
private $storeMock;
69+
70+
protected function setUp()
71+
{
72+
$this->categoryRepositoryMock = $this->getMockBuilder(CategoryRepositoryInterface::class)
73+
->disableOriginalConstructor()
74+
->getMockForAbstractClass();
75+
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
76+
->disableOriginalConstructor()
77+
->getMockForAbstractClass();
78+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
79+
->disableOriginalConstructor()
80+
->getMockForAbstractClass();
81+
$this->queryFilterMock = $this->getMockBuilder(Filter::class)
82+
->setMethods(['getReference'])
83+
->disableOriginalConstructor()
84+
->getMockForAbstractClass();
85+
$this->termFilterMock = $this->getMockBuilder(Term::class)
86+
->setMethods(['getValue'])
87+
->disableOriginalConstructor()
88+
->getMockForAbstractClass();
89+
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
90+
->disableOriginalConstructor()
91+
->getMockForAbstractClass();
92+
$this->categoryMock = $this->getMockBuilder(CategoryInterface::class)
93+
->setMethods(['getIsAnchor'])
94+
->disableOriginalConstructor()
95+
->getMockForAbstractClass();
96+
$this->queryMock = $this->getMockBuilder(QueryInterface::class)
97+
->setMethods(['getMust', 'getShould'])
98+
->disableOriginalConstructor()
99+
->getMockForAbstractClass();
100+
$this->name = 'Request';
101+
102+
$this->catalogViewMock = new CatalogView($this->categoryRepositoryMock, $this->storeManagerMock, $this->name);
103+
}
104+
105+
public function testIsApplicable()
106+
{
107+
$this->assertTrue($this->catalogViewMock->isApplicable($this->requestMock));
108+
}
109+
110+
public function testIsNotApplicable()
111+
{
112+
$this->requestMock->expects($this->once())
113+
->method('getName')
114+
->willReturn($this->name);
115+
$this->requestMock->expects($this->any())
116+
->method('getQuery')
117+
->willReturn($this->queryMock);
118+
$this->queryMock->expects($this->once())
119+
->method('getType')
120+
->willReturn(QueryInterface::TYPE_BOOL);
121+
$this->queryMock->expects($this->any())
122+
->method('getMust')
123+
->willReturn(['category' => $this->queryFilterMock]);
124+
$this->queryFilterMock->expects($this->any())
125+
->method('getReference')
126+
->willReturn($this->termFilterMock);
127+
$this->termFilterMock->expects($this->any())
128+
->method('getValue')
129+
->willReturn(1);
130+
$this->storeManagerMock->expects($this->any())
131+
->method('getStore')
132+
->willReturn($this->storeMock);
133+
$this->storeMock->expects($this->any())
134+
->method('getId')
135+
->willReturn(1);
136+
$this->categoryRepositoryMock->expects($this->once())
137+
->method('get')
138+
->willReturn($this->categoryMock);
139+
$this->categoryMock->expects($this->once())
140+
->method('getIsAnchor')
141+
->willReturn(true);
142+
$this->assertTrue($this->catalogViewMock->isApplicable($this->requestMock));
143+
}
144+
}

0 commit comments

Comments
 (0)