PathValidatorTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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;
  7. use Magento\Config\Model\Config\PathValidator;
  8. use Magento\Config\Model\Config\Structure;
  9. use PHPUnit_Framework_MockObject_MockObject as Mock;
  10. /**
  11. * Test class for PathValidator.
  12. *
  13. * @see PathValidator
  14. */
  15. class PathValidatorTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var PathValidator
  19. */
  20. private $model;
  21. /**
  22. * @var Structure|Mock
  23. */
  24. private $structureMock;
  25. /**
  26. * @inheritdoc
  27. */
  28. protected function setUp()
  29. {
  30. $this->structureMock = $this->getMockBuilder(Structure::class)
  31. ->disableOriginalConstructor()
  32. ->getMock();
  33. $this->model = new PathValidator(
  34. $this->structureMock
  35. );
  36. }
  37. public function testValidate()
  38. {
  39. $this->structureMock->expects($this->once())
  40. ->method('getFieldPaths')
  41. ->willReturn([
  42. 'test/test/test' => [
  43. 'test/test/test'
  44. ]
  45. ]);
  46. $this->assertTrue($this->model->validate('test/test/test'));
  47. }
  48. /**
  49. * @expectedException \Magento\Framework\Exception\ValidatorException
  50. * @expectedExceptionMessage The "test/test/test" path doesn't exist. Verify and try again.
  51. */
  52. public function testValidateWithException()
  53. {
  54. $this->structureMock->expects($this->once())
  55. ->method('getFieldPaths')
  56. ->willReturn([]);
  57. $this->assertTrue($this->model->validate('test/test/test'));
  58. }
  59. }