Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ArrayNodeConfigTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Config\Dom\ArrayNodeConfig;
9 
10 class ArrayNodeConfigTest 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 ArrayNodeConfig(
26  $this->nodePathMatcher,
27  ['/root/assoc/one' => 'name', '/root/assoc/two' => 'id', '/root/assoc/three' => 'key'],
28  ['/root/numeric/one', '/root/numeric/two', '/root/numeric/three']
29  );
30  }
31 
32  public function testIsNumericArrayMatched()
33  {
34  $xpath = '/root/numeric[@attr="value"]/two';
35  $this->nodePathMatcher->expects(
36  $this->at(0)
37  )->method(
38  'match'
39  )->with(
40  '/root/numeric/one',
41  $xpath
42  )->will(
43  $this->returnValue(false)
44  );
45  $this->nodePathMatcher->expects(
46  $this->at(1)
47  )->method(
48  'match'
49  )->with(
50  '/root/numeric/two',
51  $xpath
52  )->will(
53  $this->returnValue(true)
54  );
55  $this->assertTrue($this->object->isNumericArray($xpath));
56  }
57 
58  public function testIsNumericArrayNotMatched()
59  {
60  $xpath = '/root/numeric[@attr="value"]/four';
61  $this->nodePathMatcher->expects(
62  $this->at(0)
63  )->method(
64  'match'
65  )->with(
66  '/root/numeric/one',
67  $xpath
68  )->will(
69  $this->returnValue(false)
70  );
71  $this->nodePathMatcher->expects(
72  $this->at(1)
73  )->method(
74  'match'
75  )->with(
76  '/root/numeric/two',
77  $xpath
78  )->will(
79  $this->returnValue(false)
80  );
81  $this->nodePathMatcher->expects(
82  $this->at(2)
83  )->method(
84  'match'
85  )->with(
86  '/root/numeric/three',
87  $xpath
88  )->will(
89  $this->returnValue(false)
90  );
91  $this->assertFalse($this->object->isNumericArray($xpath));
92  }
93 
95  {
96  $xpath = '/root/assoc[@attr="value"]/two';
97  $this->nodePathMatcher->expects(
98  $this->at(0)
99  )->method(
100  'match'
101  )->with(
102  '/root/assoc/one',
103  $xpath
104  )->will(
105  $this->returnValue(false)
106  );
107  $this->nodePathMatcher->expects(
108  $this->at(1)
109  )->method(
110  'match'
111  )->with(
112  '/root/assoc/two',
113  $xpath
114  )->will(
115  $this->returnValue(true)
116  );
117  $this->assertEquals('id', $this->object->getAssocArrayKeyAttribute($xpath));
118  }
119 
121  {
122  $xpath = '/root/assoc[@attr="value"]/four';
123  $this->nodePathMatcher->expects(
124  $this->at(0)
125  )->method(
126  'match'
127  )->with(
128  '/root/assoc/one',
129  $xpath
130  )->will(
131  $this->returnValue(false)
132  );
133  $this->nodePathMatcher->expects(
134  $this->at(1)
135  )->method(
136  'match'
137  )->with(
138  '/root/assoc/two',
139  $xpath
140  )->will(
141  $this->returnValue(false)
142  );
143  $this->nodePathMatcher->expects(
144  $this->at(2)
145  )->method(
146  'match'
147  )->with(
148  '/root/assoc/three',
149  $xpath
150  )->will(
151  $this->returnValue(false)
152  );
153  $this->assertNull($this->object->getAssocArrayKeyAttribute($xpath));
154  }
155 }