Skip to content

Commit

Permalink
ENGCOM-6912: Unit Test for Magento\LayeredNavigation\Observer\Edit\Ta…
Browse files Browse the repository at this point in the history
…b\Front\ProductAttributeFormBuildFrontTabObserver #26617
  • Loading branch information
VladimirZaets authored Feb 18, 2020
2 parents 22fcb70 + 5e66998 commit bcae7e3
Showing 1 changed file with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\LayeredNavigation\Test\Unit\Observer\Edit\Tab\Front;

use Magento\Config\Model\Config\Source\Yesno;
use Magento\Framework\Data\Form;
use Magento\Framework\Data\Form\Element\Fieldset;
use Magento\Framework\Event\Observer;
use Magento\Framework\Module\Manager;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\LayeredNavigation\Observer\Edit\Tab\Front\ProductAttributeFormBuildFrontTabObserver;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Unit Test for \Magento\LayeredNavigation\Observer\Edit\Tab\Front\ProductAttributeFormBuildFrontTabObserver
*/
class ProductAttributeFormBuildFrontTabObserverTest extends TestCase
{
/**
* @var MockObject|Observer
*/
private $eventObserverMock;

/**
* @var MockObject|Yesno
*/
private $optionListLock;

/**
* @var MockObject|Manager
*/
private $moduleManagerMock;

/**
* @var ProductAttributeFormBuildFrontTabObserver
*/
private $observer;

/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->optionListLock = $this->createMock(Yesno::class);
$this->moduleManagerMock = $this->createMock(Manager::class);
$this->eventObserverMock = $this->getMockBuilder(Observer::class)
->disableOriginalConstructor()
->setMethods(['getForm'])
->getMock();

$objectManager = new ObjectManager($this);
$this->observer = $objectManager->getObject(
ProductAttributeFormBuildFrontTabObserver::class,
[
'optionList' => $this->optionListLock,
'moduleManager' => $this->moduleManagerMock,
]
);
}

/**
* Test case when module output is disabled
*/
public function testExecuteWhenOutputDisabled(): void
{
$this->moduleManagerMock->expects($this->once())
->method('isOutputEnabled')
->with('Magento_LayeredNavigation')
->willReturn(false);

$this->eventObserverMock->expects($this->never())->method('getForm');

$this->observer->execute($this->eventObserverMock);
}

/**
* Test case when module output is enabled
*/
public function testExecuteWhenOutputEnabled(): void
{
$this->moduleManagerMock->expects($this->once())
->method('isOutputEnabled')
->with('Magento_LayeredNavigation')
->willReturn(true);

$fieldsetMock = $this->createMock(Fieldset::class);
$fieldsetMock->expects($this->exactly(3))->method('addField');
$formMock = $this->createMock(Form::class);
$formMock->expects($this->once())
->method('getElement')
->with('front_fieldset')
->willReturn($fieldsetMock);

$this->eventObserverMock->expects($this->once())
->method('getForm')
->willReturn($formMock);

$this->observer->execute($this->eventObserverMock);
}
}

0 comments on commit bcae7e3

Please sign in to comment.