Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExtendsTest.php
Go to the documentation of this file.
1 <?php
7 
8 class ExtendsTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_sut;
14 
15  protected function setUp()
16  {
17  $this->_sut = new \Magento\Config\Model\Config\Structure\Mapper\ExtendsMapper(
18  new \Magento\Config\Model\Config\Structure\Mapper\Helper\RelativePathConverter()
19  );
20  }
21 
27  public function testMap($sourceData, $resultData)
28  {
29  $this->assertEquals($resultData, $this->_sut->map($sourceData));
30  }
31 
32  public function testMapWithBadPath()
33  {
34  $this->expectException('InvalidArgumentException');
35  $this->expectExceptionMessage('Invalid path in extends attribute of config/system/sections/section1 node');
36  $sourceData = [
37  'config' => [
38  'system' => ['sections' => ['section1' => ['extends' => 'nonExistentSection2']]],
39  ],
40  ];
41 
42  $this->_sut->map($sourceData);
43  }
44 
48  public function mapDataProvider()
49  {
50  return [
51  [[], []],
52  $this->_emptySectionsNodeData(),
53  $this->_extendFromASiblingData(),
55  $this->_extendWithMerge()
56  ];
57  }
58 
62  protected function _emptySectionsNodeData()
63  {
64  $data = ['config' => ['system' => ['sections' => 'some_non_array']]];
65 
66  return [$data, $data];
67  }
68 
72  protected function _extendFromASiblingData()
73  {
74  $source = $result = [
75  'config' => [
76  'system' => [
77  'sections' => [
78  'section1' => ['children' => ['child1', 'child2', 'child3']],
79  'section2' => ['extends' => 'section1'],
80  ],
81  ],
82  ],
83  ];
84 
85  $result['config']['system']['sections']['section2']['children'] =
86  $source['config']['system']['sections']['section1']['children'];
87 
88  return [$source, $result];
89  }
90 
94  protected function _extendFromNodeOnHigherLevelData()
95  {
96  $source = $result = [
97  'config' => [
98  'system' => [
99  'sections' => [
100  'section1' => [
101  'children' => [
102  'child1' => [
103  'children' => [
104  'subchild1' => 1,
105  'subchild2' => ['extends' => '*/child2'],
106  ],
107  ],
108  'child2' => ['some' => 'Data', 'for' => 'node', 'being' => 'extended'],
109  'child3' => 3,
110  ],
111  ],
112  ],
113  ],
114  ],
115  ];
116 
117  $result['config']['system']['sections']['section1']['children']['child1']['children']['subchild2']['some'] =
118  'Data';
119  $result['config']['system']['sections']['section1']['children']['child1']['children']['subchild2']['for'] =
120  'node';
121  $result['config']['system']['sections']['section1']['children']['child1']['children']['subchild2']['being'] =
122  'extended';
123 
124  return [$source, $result];
125  }
126 
130  protected function _extendWithMerge()
131  {
132  $source = $result = [
133  'config' => [
134  'system' => [
135  'sections' => [
136  'section1' => [
137  'scalarValue1' => 1,
138  'children' => ['child1' => 1, 'child2' => 2, 'child3' => 3],
139  ],
140  'section2' => [
141  'extends' => 'section1',
142  'scalarValue1' => 2,
143  'children' => ['child4' => 4, 'child5' => 5, 'child1' => 6],
144  ],
145  ],
146  ],
147  ],
148  ];
149 
150  $section2 = & $result['config']['system']['sections']['section2'];
151  $section2['children'] = ['child4' => 4, 'child5' => 5, 'child1' => 6, 'child2' => 2, 'child3' => 3];
152 
153  return [$source, $result];
154  }
155 }
$source
Definition: source.php:23