35 private $storeManager;
50 private $stateKeyGenerator;
55 private $stateFactory;
65 private $collectionFilter;
75 private $collectionProvider;
85 private $abstractFilter;
90 private $categoryRepository;
95 private $currentCategory;
101 $this->category = $this->getMockBuilder(\
Magento\Catalog\Model\Category::class)
102 ->setMethods([
'getId',
'__wakeup'])
103 ->disableOriginalConstructor()
106 $this->registry = $this->getMockBuilder(\
Magento\Framework\Registry::class)
107 ->setMethods([
'registry'])
108 ->disableOriginalConstructor()
111 $this->store = $this->getMockBuilder(\
Magento\
Store\Model\Store::class)
112 ->setMethods([
'getRootCategoryId',
'getFilters',
'__wakeup'])
113 ->disableOriginalConstructor()
114 ->getMockForAbstractClass();
116 $this->storeManager = $this->getMockBuilder(\
Magento\
Store\Model\StoreManagerInterface::class)
117 ->setMethods([
'getStore'])
118 ->disableOriginalConstructor()
119 ->getMockForAbstractClass();
120 $this->storeManager->expects($this->any())->method(
'getStore')
121 ->will($this->returnValue($this->store));
123 $this->stateKeyGenerator = $this->getMockBuilder(\
Magento\Catalog\Model\Layer\
Category\StateKey::class)
124 ->setMethods([
'toString'])
125 ->disableOriginalConstructor()
128 $this->collectionFilter = $this->getMockBuilder(\
Magento\Catalog\Model\Layer\
Category\CollectionFilter::class)
129 ->setMethods([
'filter'])
130 ->disableOriginalConstructor()
133 $this->collectionProvider = $this->getMockBuilder(
134 \
Magento\Catalog\Model\Layer\ItemCollectionProviderInterface::class
135 )->disableOriginalConstructor()->getMockForAbstractClass();
137 $this->filter = $this->getMockBuilder(\
Magento\Catalog\Model\Layer\Filter\Item::class)
138 ->setMethods([
'getFilter',
'getValueString'])
139 ->disableOriginalConstructor()
142 $this->abstractFilter = $this->getMockBuilder(\
Magento\Catalog\Model\Layer\Filter\AbstractFilter::class)
143 ->setMethods([
'getRequestVar'])
144 ->disableOriginalConstructor()
147 $this->context = $this->getMockBuilder(\
Magento\Catalog\Model\Layer\ContextInterface::class)
148 ->setMethods([
'getStateKey',
'getCollectionFilter'])
149 ->disableOriginalConstructor()
150 ->getMockForAbstractClass();
151 $this->context->expects($this->any())->method(
'getStateKey')
152 ->will($this->returnValue($this->stateKeyGenerator));
153 $this->context->expects($this->any())->method(
'getCollectionFilter')
154 ->will($this->returnValue($this->collectionFilter));
155 $this->context->expects($this->any())->method(
'getCollectionProvider')
156 ->will($this->returnValue($this->collectionProvider));
158 $this->state = $this->getMockBuilder(\
Magento\Catalog\Model\Layer\State::class)
159 ->disableOriginalConstructor()
162 $this->stateFactory = $this->getMockBuilder(\
Magento\Catalog\Model\Layer\StateFactory::class)
163 ->setMethods([
'create'])
164 ->disableOriginalConstructor()
166 $this->stateFactory->expects($this->any())->method(
'create')->will($this->returnValue($this->state));
169 ->disableOriginalConstructor()
172 $this->categoryRepository = $this->createMock(\
Magento\Catalog\Api\CategoryRepositoryInterface::class);
173 $this->currentCategory = $this->createPartialMock(
174 \
Magento\Catalog\Model\Category::class,
175 [
'getId',
'__wakeup']
178 $this->model =
$helper->getObject(
179 \
Magento\Catalog\Model\Layer::class,
181 'registry' => $this->registry,
182 'storeManager' => $this->storeManager,
183 'context' => $this->context,
184 'layerStateFactory' => $this->stateFactory,
185 'categoryRepository' => $this->categoryRepository,
192 $this->assertInstanceOf(\
Magento\Catalog\Model\Layer\State::class, $this->model->getState());
198 $this->registry->expects($this->once())->method(
'registry')->with($this->equalTo(
'current_category'))
199 ->will($this->returnValue($this->category));
201 $this->stateKeyGenerator->expects($this->once())->method(
'toString')
202 ->with($this->equalTo($this->category))
203 ->will($this->returnValue($stateKey));
205 $this->assertEquals($stateKey, $this->model->getStateKey());
210 $this->registry->expects($this->once())->method(
'registry')->with($this->equalTo(
'current_category'))
211 ->will($this->returnValue($this->category));
213 $this->category->expects($this->any())->method(
'getId')->will($this->returnValue(333));
215 $this->collectionFilter->expects($this->once())->method(
'filter')
216 ->with($this->equalTo($this->collection), $this->equalTo($this->category));
218 $this->collectionProvider->expects($this->once())->method(
'getCollection')
219 ->with($this->equalTo($this->category))
220 ->will($this->returnValue($this->collection));
222 $result = $this->model->getProductCollection();
224 $result = $this->model->getProductCollection();
231 $this->registry->expects($this->once())->method(
'registry')->with($this->equalTo(
'current_category'))
232 ->will($this->returnValue($this->category));
234 $this->stateKeyGenerator->expects($this->once())->method(
'toString')
235 ->with($this->equalTo($this->category))
236 ->will($this->returnValue($stateKey));
238 $this->state->expects($this->any())->method(
'getFilters')->will($this->returnValue([$this->filter]));
240 $this->filter->expects($this->once())->method(
'getFilter')->will($this->returnValue($this->abstractFilter));
241 $this->filter->expects($this->once())->method(
'getValueString')->will($this->returnValue(
't'));
243 $this->abstractFilter->expects($this->once())->method(
'getRequestVar')->will($this->returnValue(
't'));
245 $result = $this->model->apply();
246 $this->assertInstanceOf(\
Magento\Catalog\Model\Layer::class,
$result);
251 $this->registry->expects($this->once())->method(
'registry')->with($this->equalTo(
'current_category'))
252 ->will($this->returnValue($this->category));
254 $this->collectionFilter->expects($this->once())->method(
'filter')
255 ->with($this->equalTo($this->collection), $this->equalTo($this->category));
257 $result = $this->model->prepareProductCollection($this->collection);
258 $this->assertInstanceOf(\
Magento\Catalog\Model\Layer::class,
$result);
263 $this->assertInstanceOf(\
Magento\
Store\Model\Store::class, $this->model->getCurrentStore());
269 $currentCategoryId = 334;
271 $this->category->expects($this->any())->method(
'getId')->will($this->returnValue($categoryId));
272 $this->categoryRepository->expects($this->once())->method(
'get')->with($categoryId)
273 ->willReturn($this->currentCategory);
275 $this->currentCategory->expects($this->any())->method(
'getId')->willReturn($currentCategoryId);
276 $this->registry->expects($this->once())->method(
'registry')->with(
'current_category')
277 ->willReturn($this->currentCategory);
279 $this->assertInstanceOf(\
Magento\Catalog\Model\Layer::class, $this->model->setCurrentCategory($categoryId));
280 $this->assertEquals($this->currentCategory, $this->model->getData(
'current_category'));
287 $this->category->expects($this->any())->method(
'getId')->will($this->returnValue($categoryId));
289 $this->categoryRepository->expects($this->once())->method(
'get')->with($categoryId)
290 ->willReturn($this->category);
291 $this->registry->expects($this->once())->method(
'registry')->with(
'current_category')
292 ->willReturn($this->category);
294 $this->assertInstanceOf(\
Magento\Catalog\Model\Layer::class, $this->model->setCurrentCategory($categoryId));
295 $this->assertEquals($this->category, $this->model->getData(
'current_category'));
304 $this->categoryRepository->expects($this->once())->method(
'get')
307 $this->model->setCurrentCategory(1);
316 $this->model->setCurrentCategory(
null);
325 $this->category->expects($this->once())->method(
'getId')->will($this->returnValue(
null));
327 $this->model->setCurrentCategory($this->category);
332 $this->currentCategory->getData(
'current_category',
null);
334 $this->registry->expects($this->once())->method(
'registry')->with(
'current_category')
335 ->willReturn($this->currentCategory);
337 $this->assertEquals($this->currentCategory, $this->model->getCurrentCategory());
338 $this->assertEquals($this->currentCategory, $this->model->getData(
'current_category'));
344 $this->currentCategory->getData(
'current_category',
null);
346 $this->registry->expects($this->once())->method(
'registry')->with($this->equalTo(
'current_category'))
348 $this->categoryRepository->expects($this->once())->method(
'get')->with(
$rootCategoryId)
349 ->willReturn($this->currentCategory);
350 $this->store->expects($this->any())->method(
'getRootCategoryId')
353 $this->assertEquals($this->currentCategory, $this->model->getCurrentCategory());
354 $this->assertEquals($this->currentCategory, $this->model->getData(
'current_category'));
testSetCurrentCategoryNotFoundException()
testSetNewCurrentCategoryIfCategoryIsNotFound()
testSetNewCurrentCategoryIfCurrentCategoryIsSame()
testPrepareProductCollection()
testGetProductCollection()
testSetCurrentCategoryInstanceOfException()
testGetCurrentCategoryIfCurrentCategoryIsNotSet()
testSetNewCurrentCategoryIfCurrentCategoryIsAnother()