123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Config\Test\Unit\Model\Config\Structure;
- use Magento\Config\Model\Config\Structure\ElementVisibilityComposite;
- use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
- class ElementVisibilityCompositeTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var ElementVisibilityComposite
- */
- private $model;
- /**
- * @var ElementVisibilityInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $firstVisibilityMock;
- /**
- * @var ElementVisibilityInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $secondVisibilityMock;
- protected function setUp()
- {
- $this->firstVisibilityMock = $this->getMockBuilder(ElementVisibilityInterface::class)
- ->getMockForAbstractClass();
- $this->secondVisibilityMock = $this->getMockBuilder(ElementVisibilityInterface::class)
- ->getMockForAbstractClass();
- $this->model = new ElementVisibilityComposite([$this->firstVisibilityMock, $this->secondVisibilityMock]);
- }
- /**
- * @expectedException \Magento\Framework\Exception\ConfigurationMismatchException
- * @codingStandardsIgnoreStart
- * @expectedExceptionMessage stdClass: Instance of Magento\Config\Model\Config\Structure\ElementVisibilityInterface is expected, got stdClass instead
- * @codingStandardsIgnoreEnd
- */
- public function testException()
- {
- $visibility = [
- 'stdClass' => new \stdClass()
- ];
- new ElementVisibilityComposite($visibility);
- }
- /**
- * @param \PHPUnit\Framework\MockObject\Matcher\InvokedCount $firstExpects
- * @param bool $firstResult
- * @param \PHPUnit\Framework\MockObject\Matcher\InvokedCount $secondExpects
- * @param bool $secondResult
- * @param bool $expectedResult
- * @dataProvider visibilityDataProvider
- */
- public function testDisabled($firstExpects, $firstResult, $secondExpects, $secondResult, $expectedResult)
- {
- $path = 'some/path';
- $this->firstVisibilityMock->expects($firstExpects)
- ->method('isDisabled')
- ->with($path)
- ->willReturn($firstResult);
- $this->secondVisibilityMock->expects($secondExpects)
- ->method('isDisabled')
- ->with($path)
- ->willReturn($secondResult);
- $this->assertSame($expectedResult, $this->model->isDisabled($path));
- }
- /**
- * @param \PHPUnit\Framework\MockObject\Matcher\InvokedCount $firstExpects
- * @param bool $firstResult
- * @param \PHPUnit\Framework\MockObject\Matcher\InvokedCount $secondExpects
- * @param bool $secondResult
- * @param bool $expectedResult
- * @dataProvider visibilityDataProvider
- */
- public function testHidden($firstExpects, $firstResult, $secondExpects, $secondResult, $expectedResult)
- {
- $path = 'some/path';
- $this->firstVisibilityMock->expects($firstExpects)
- ->method('isHidden')
- ->with($path)
- ->willReturn($firstResult);
- $this->secondVisibilityMock->expects($secondExpects)
- ->method('isHidden')
- ->with($path)
- ->willReturn($secondResult);
- $this->assertSame($expectedResult, $this->model->isHidden($path));
- }
- /**
- * @return array
- */
- public function visibilityDataProvider()
- {
- return [
- [$this->once(), false, $this->once(), false, false],
- [$this->once(), false, $this->once(), true, true],
- [$this->once(), true, $this->never(), true, true],
- [$this->once(), true, $this->never(), false, true],
- ];
- }
- }
|