Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CatalogViewTest.php
Go to the documentation of this file.
1 <?php
7 
17 
18 class CatalogViewTest extends \PHPUnit\Framework\TestCase
19 {
23  private $catalogViewMock;
24 
28  private $categoryRepositoryMock;
29 
33  private $storeManagerMock;
34 
38  private $requestMock;
39 
43  private $queryMock;
44 
48  private $queryFilterMock;
49 
53  private $termFilterMock;
54 
58  private $name;
59 
63  private $categoryMock;
64 
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(false);
142  $this->assertFalse($this->catalogViewMock->isApplicable($this->requestMock));
143  }
144 }