|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\LayeredNavigation\Test\Unit\Observer\Grid; |
| 9 | + |
| 10 | +use Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid; |
| 11 | +use Magento\Framework\Event\Observer; |
| 12 | +use Magento\Framework\Module\Manager; |
| 13 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 14 | +use Magento\LayeredNavigation\Observer\Grid\ProductAttributeGridBuildObserver; |
| 15 | +use PHPUnit\Framework\MockObject\MockObject; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | + |
| 18 | +/** |
| 19 | + * Class ProductAttributeGridBuildObserverTest |
| 20 | + * |
| 21 | + * Testing adding new grid column for Layered Navigation |
| 22 | + */ |
| 23 | +class ProductAttributeGridBuildObserverTest extends TestCase |
| 24 | +{ |
| 25 | + /** |
| 26 | + * @var ProductAttributeGridBuildObserver |
| 27 | + */ |
| 28 | + private $observer; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var Manager|MockObject |
| 32 | + */ |
| 33 | + private $moduleManagerMock; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var Observer|MockObject |
| 37 | + */ |
| 38 | + private $observerMock; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var Grid|MockObject |
| 42 | + */ |
| 43 | + private $gridMock; |
| 44 | + |
| 45 | + /** |
| 46 | + * Set Up |
| 47 | + */ |
| 48 | + protected function setUp() |
| 49 | + { |
| 50 | + $objectManager = new ObjectManager($this); |
| 51 | + $this->moduleManagerMock = $this->createMock(Manager::class); |
| 52 | + $this->gridMock = $this->createMock(Grid::class); |
| 53 | + $this->observerMock = $this->getMockBuilder(Observer::class) |
| 54 | + ->disableOriginalConstructor() |
| 55 | + ->setMethods(['getGrid']) |
| 56 | + ->getMock(); |
| 57 | + |
| 58 | + $this->observer = $objectManager->getObject( |
| 59 | + ProductAttributeGridBuildObserver::class, |
| 60 | + [ |
| 61 | + 'moduleManager' => $this->moduleManagerMock, |
| 62 | + ] |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Testing the column adding if the output is not enabled |
| 68 | + */ |
| 69 | + public function testColumnAddingOnDisabledOutput() |
| 70 | + { |
| 71 | + $enabledOutput = false; |
| 72 | + |
| 73 | + $this->moduleManagerMock->expects($this->once()) |
| 74 | + ->method('isOutputEnabled') |
| 75 | + ->with('Magento_LayeredNavigation') |
| 76 | + ->willReturn($enabledOutput); |
| 77 | + |
| 78 | + $this->observerMock->expects($this->never()) |
| 79 | + ->method('getGrid'); |
| 80 | + |
| 81 | + $this->observer->execute($this->observerMock); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Testing the column adding if the output is enabled |
| 86 | + */ |
| 87 | + public function testColumnAddingOnEnabledOutput() |
| 88 | + { |
| 89 | + $enabledOutput = true; |
| 90 | + |
| 91 | + $this->moduleManagerMock->expects($this->once()) |
| 92 | + ->method('isOutputEnabled') |
| 93 | + ->with('Magento_LayeredNavigation') |
| 94 | + ->willReturn($enabledOutput); |
| 95 | + |
| 96 | + $this->observerMock->expects($this->once()) |
| 97 | + ->method('getGrid') |
| 98 | + ->willReturn($this->gridMock); |
| 99 | + |
| 100 | + $this->observer->execute($this->observerMock); |
| 101 | + } |
| 102 | +} |
0 commit comments