NodeMergingConfigTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\NodeMergingConfig;
  8. class NodeMergingConfigTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var NodeMergingConfig
  12. */
  13. protected $object;
  14. /**
  15. * @var NodePathMatcher|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $nodePathMatcher;
  18. protected function setUp()
  19. {
  20. $this->nodePathMatcher = $this->createMock(\Magento\Framework\Config\Dom\NodePathMatcher::class);
  21. $this->object = new NodeMergingConfig(
  22. $this->nodePathMatcher,
  23. ['/root/one' => 'name', '/root/two' => 'id', '/root/three' => 'key']
  24. );
  25. }
  26. public function testGetIdAttributeMatched()
  27. {
  28. $xpath = '/root/two[@attr="value"]';
  29. $this->nodePathMatcher->expects(
  30. $this->at(0)
  31. )->method(
  32. 'match'
  33. )->with(
  34. '/root/one',
  35. $xpath
  36. )->will(
  37. $this->returnValue(false)
  38. );
  39. $this->nodePathMatcher->expects(
  40. $this->at(1)
  41. )->method(
  42. 'match'
  43. )->with(
  44. '/root/two',
  45. $xpath
  46. )->will(
  47. $this->returnValue(true)
  48. );
  49. $this->assertEquals('id', $this->object->getIdAttribute($xpath));
  50. }
  51. public function testGetIdAttributeNotMatched()
  52. {
  53. $xpath = '/root/four[@attr="value"]';
  54. $this->nodePathMatcher->expects(
  55. $this->at(0)
  56. )->method(
  57. 'match'
  58. )->with(
  59. '/root/one',
  60. $xpath
  61. )->will(
  62. $this->returnValue(false)
  63. );
  64. $this->nodePathMatcher->expects(
  65. $this->at(1)
  66. )->method(
  67. 'match'
  68. )->with(
  69. '/root/two',
  70. $xpath
  71. )->will(
  72. $this->returnValue(false)
  73. );
  74. $this->nodePathMatcher->expects(
  75. $this->at(2)
  76. )->method(
  77. 'match'
  78. )->with(
  79. '/root/three',
  80. $xpath
  81. )->will(
  82. $this->returnValue(false)
  83. );
  84. $this->assertNull($this->object->getIdAttribute($xpath));
  85. }
  86. }