Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NodeMergingConfigTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Config\Dom\NodeMergingConfig;
9 
10 class NodeMergingConfigTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $object;
16 
20  protected $nodePathMatcher;
21 
22  protected function setUp()
23  {
24  $this->nodePathMatcher = $this->createMock(\Magento\Framework\Config\Dom\NodePathMatcher::class);
25  $this->object = new NodeMergingConfig(
26  $this->nodePathMatcher,
27  ['/root/one' => 'name', '/root/two' => 'id', '/root/three' => 'key']
28  );
29  }
30 
31  public function testGetIdAttributeMatched()
32  {
33  $xpath = '/root/two[@attr="value"]';
34  $this->nodePathMatcher->expects(
35  $this->at(0)
36  )->method(
37  'match'
38  )->with(
39  '/root/one',
40  $xpath
41  )->will(
42  $this->returnValue(false)
43  );
44  $this->nodePathMatcher->expects(
45  $this->at(1)
46  )->method(
47  'match'
48  )->with(
49  '/root/two',
50  $xpath
51  )->will(
52  $this->returnValue(true)
53  );
54  $this->assertEquals('id', $this->object->getIdAttribute($xpath));
55  }
56 
57  public function testGetIdAttributeNotMatched()
58  {
59  $xpath = '/root/four[@attr="value"]';
60  $this->nodePathMatcher->expects(
61  $this->at(0)
62  )->method(
63  'match'
64  )->with(
65  '/root/one',
66  $xpath
67  )->will(
68  $this->returnValue(false)
69  );
70  $this->nodePathMatcher->expects(
71  $this->at(1)
72  )->method(
73  'match'
74  )->with(
75  '/root/two',
76  $xpath
77  )->will(
78  $this->returnValue(false)
79  );
80  $this->nodePathMatcher->expects(
81  $this->at(2)
82  )->method(
83  'match'
84  )->with(
85  '/root/three',
86  $xpath
87  )->will(
88  $this->returnValue(false)
89  );
90  $this->assertNull($this->object->getIdAttribute($xpath));
91  }
92 }