|
| 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