|
6 | 6 |
|
7 | 7 | namespace Magento\LayeredNavigation\Test\Unit\Block;
|
8 | 8 |
|
| 9 | +use Magento\Catalog\Model\Category; |
| 10 | + |
9 | 11 | class NavigationTest extends \PHPUnit\Framework\TestCase
|
10 | 12 | {
|
11 | 13 | /**
|
@@ -98,9 +100,62 @@ public function testCanShowBlock()
|
98 | 100 | ->method('isEnabled')
|
99 | 101 | ->with($this->catalogLayerMock, $filters)
|
100 | 102 | ->will($this->returnValue($enabled));
|
| 103 | + |
| 104 | + $category = $this->createMock(Category::class); |
| 105 | + $this->catalogLayerMock->expects($this->atLeastOnce())->method('getCurrentCategory')->willReturn($category); |
| 106 | + $category->expects($this->once())->method('getDisplayMode')->willReturn(Category::DM_PRODUCT); |
| 107 | + |
101 | 108 | $this->assertEquals($enabled, $this->model->canShowBlock());
|
102 | 109 | }
|
103 | 110 |
|
| 111 | + /** |
| 112 | + * Test canShowBlock() with different category display types. |
| 113 | + * |
| 114 | + * @param string $mode |
| 115 | + * @param bool $result |
| 116 | + * |
| 117 | + * @dataProvider canShowBlockDataProvider |
| 118 | + */ |
| 119 | + public function testCanShowBlockWithDifferentDisplayModes(string $mode, bool $result) |
| 120 | + { |
| 121 | + $filters = ['To' => 'be', 'or' => 'not', 'to' => 'be']; |
| 122 | + |
| 123 | + $this->filterListMock->expects($this->atLeastOnce())->method('getFilters') |
| 124 | + ->with($this->catalogLayerMock) |
| 125 | + ->will($this->returnValue($filters)); |
| 126 | + $this->assertEquals($filters, $this->model->getFilters()); |
| 127 | + |
| 128 | + $this->visibilityFlagMock |
| 129 | + ->expects($this->any()) |
| 130 | + ->method('isEnabled') |
| 131 | + ->with($this->catalogLayerMock, $filters) |
| 132 | + ->will($this->returnValue(true)); |
| 133 | + |
| 134 | + $category = $this->createMock(Category::class); |
| 135 | + $this->catalogLayerMock->expects($this->atLeastOnce())->method('getCurrentCategory')->willReturn($category); |
| 136 | + $category->expects($this->once())->method('getDisplayMode')->willReturn($mode); |
| 137 | + |
| 138 | + $this->assertEquals($result, $this->model->canShowBlock()); |
| 139 | + } |
| 140 | + |
| 141 | + public function canShowBlockDataProvider() |
| 142 | + { |
| 143 | + return [ |
| 144 | + [ |
| 145 | + Category::DM_PRODUCT, |
| 146 | + true, |
| 147 | + ], |
| 148 | + [ |
| 149 | + Category::DM_PAGE, |
| 150 | + false, |
| 151 | + ], |
| 152 | + [ |
| 153 | + Category::DM_MIXED, |
| 154 | + true, |
| 155 | + ], |
| 156 | + ]; |
| 157 | + } |
| 158 | + |
104 | 159 | public function testGetClearUrl()
|
105 | 160 | {
|
106 | 161 | $this->filterListMock->expects($this->any())->method('getFilters')->will($this->returnValue([]));
|
|
0 commit comments