ElementVisibilityCompositeTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Test\Unit\Model\Config\Structure;
  7. use Magento\Config\Model\Config\Structure\ElementVisibilityComposite;
  8. use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
  9. class ElementVisibilityCompositeTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var ElementVisibilityComposite
  13. */
  14. private $model;
  15. /**
  16. * @var ElementVisibilityInterface|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. private $firstVisibilityMock;
  19. /**
  20. * @var ElementVisibilityInterface|\PHPUnit_Framework_MockObject_MockObject
  21. */
  22. private $secondVisibilityMock;
  23. protected function setUp()
  24. {
  25. $this->firstVisibilityMock = $this->getMockBuilder(ElementVisibilityInterface::class)
  26. ->getMockForAbstractClass();
  27. $this->secondVisibilityMock = $this->getMockBuilder(ElementVisibilityInterface::class)
  28. ->getMockForAbstractClass();
  29. $this->model = new ElementVisibilityComposite([$this->firstVisibilityMock, $this->secondVisibilityMock]);
  30. }
  31. /**
  32. * @expectedException \Magento\Framework\Exception\ConfigurationMismatchException
  33. * @codingStandardsIgnoreStart
  34. * @expectedExceptionMessage stdClass: Instance of Magento\Config\Model\Config\Structure\ElementVisibilityInterface is expected, got stdClass instead
  35. * @codingStandardsIgnoreEnd
  36. */
  37. public function testException()
  38. {
  39. $visibility = [
  40. 'stdClass' => new \stdClass()
  41. ];
  42. new ElementVisibilityComposite($visibility);
  43. }
  44. /**
  45. * @param \PHPUnit\Framework\MockObject\Matcher\InvokedCount $firstExpects
  46. * @param bool $firstResult
  47. * @param \PHPUnit\Framework\MockObject\Matcher\InvokedCount $secondExpects
  48. * @param bool $secondResult
  49. * @param bool $expectedResult
  50. * @dataProvider visibilityDataProvider
  51. */
  52. public function testDisabled($firstExpects, $firstResult, $secondExpects, $secondResult, $expectedResult)
  53. {
  54. $path = 'some/path';
  55. $this->firstVisibilityMock->expects($firstExpects)
  56. ->method('isDisabled')
  57. ->with($path)
  58. ->willReturn($firstResult);
  59. $this->secondVisibilityMock->expects($secondExpects)
  60. ->method('isDisabled')
  61. ->with($path)
  62. ->willReturn($secondResult);
  63. $this->assertSame($expectedResult, $this->model->isDisabled($path));
  64. }
  65. /**
  66. * @param \PHPUnit\Framework\MockObject\Matcher\InvokedCount $firstExpects
  67. * @param bool $firstResult
  68. * @param \PHPUnit\Framework\MockObject\Matcher\InvokedCount $secondExpects
  69. * @param bool $secondResult
  70. * @param bool $expectedResult
  71. * @dataProvider visibilityDataProvider
  72. */
  73. public function testHidden($firstExpects, $firstResult, $secondExpects, $secondResult, $expectedResult)
  74. {
  75. $path = 'some/path';
  76. $this->firstVisibilityMock->expects($firstExpects)
  77. ->method('isHidden')
  78. ->with($path)
  79. ->willReturn($firstResult);
  80. $this->secondVisibilityMock->expects($secondExpects)
  81. ->method('isHidden')
  82. ->with($path)
  83. ->willReturn($secondResult);
  84. $this->assertSame($expectedResult, $this->model->isHidden($path));
  85. }
  86. /**
  87. * @return array
  88. */
  89. public function visibilityDataProvider()
  90. {
  91. return [
  92. [$this->once(), false, $this->once(), false, false],
  93. [$this->once(), false, $this->once(), true, true],
  94. [$this->once(), true, $this->never(), true, true],
  95. [$this->once(), true, $this->never(), false, true],
  96. ];
  97. }
  98. }