NodePathMatcherTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Config\Test\Unit\Dom;
  7. use \Magento\Framework\Config\Dom\NodePathMatcher;
  8. class NodePathMatcherTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var NodePathMatcher
  12. */
  13. protected $_model;
  14. protected function setUp()
  15. {
  16. $this->_model = new NodePathMatcher();
  17. }
  18. /**
  19. * @param string $pathPattern
  20. * @param string $xpathSubject
  21. * @param boolean $expectedResult
  22. *
  23. * @dataProvider getNodeInfoDataProvider
  24. */
  25. public function testMatch($pathPattern, $xpathSubject, $expectedResult)
  26. {
  27. $actualResult = $this->_model->match($pathPattern, $xpathSubject);
  28. $this->assertSame($expectedResult, $actualResult);
  29. }
  30. /**
  31. * @return array
  32. */
  33. public function getNodeInfoDataProvider()
  34. {
  35. return [
  36. 'no match' => ['/root/node', '/root', false],
  37. 'partial match' => ['/root/node', '/wrapper/root/node', false],
  38. 'exact match' => ['/root/node', '/root/node', true],
  39. 'regexp match' => ['/root/node/(sub-)+node', '/root/node/sub-node', true],
  40. 'match with namespace' => ['/root/node', '/mage:root/node', true],
  41. 'match with predicate' => ['/root/node', '/root/node[@name="test"]', true]
  42. ];
  43. }
  44. }