Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ArrayTypeTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Data\Argument\Interpreter\ArrayType;
9 
10 class ArrayTypeTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_itemInterpreter;
16 
20  protected $_model;
21 
22  protected function setUp()
23  {
24  $this->_itemInterpreter = $this->getMockForAbstractClass(
25  \Magento\Framework\Data\Argument\InterpreterInterface::class
26  );
27  $this->_model = new ArrayType($this->_itemInterpreter);
28  }
29 
36  public function testEvaluateException($inputData)
37  {
38  $this->_model->evaluate($inputData);
39  }
40 
45  {
46  return [
47  'non-array item' => [['item' => 'non-array']],
48  ];
49  }
50 
57  public function testEvaluate(array $input, array $expected)
58  {
59  $this->_itemInterpreter->expects($this->any())
60  ->method('evaluate')
61  ->will($this->returnCallback(function ($input) {
62  return '-' . $input['value'] . '-';
63  }));
64  $actual = $this->_model->evaluate($input);
65  $this->assertSame($expected, $actual);
66  }
67 
71  public function evaluateDataProvider()
72  {
73  return [
74  'empty array items' => [
75  ['item' => []],
76  [],
77  ],
78  'absent array items' => [
79  [],
80  [],
81  ],
82  'present array items' => [
83  [
84  'item' => [
85  'key1' => ['value' => 'value 1'],
86  'key2' => ['value' => 'value 2'],
87  'key3' => ['value' => 'value 3'],
88  ],
89  ],
90  [
91  'key1' => '-value 1-',
92  'key2' => '-value 2-',
93  'key3' => '-value 3-',
94  ],
95  ],
96  'sorted array items' => [
97  [
98  'item' => [
99  'key1' => ['value' => 'value 1', 'sortOrder' => 50],
100  'key2' => ['value' => 'value 2'],
101  'key3' => ['value' => 'value 3', 'sortOrder' => 10],
102  'key4' => ['value' => 'value 4'],
103  ],
104  ],
105  [
106  'key2' => '-value 2-',
107  'key4' => '-value 4-',
108  'key3' => '-value 3-',
109  'key1' => '-value 1-',
110  ],
111  ],
112  'pre-sorted array items' => [
113  [
114  'item' => [
115  'key1' => ['value' => 'value 1'],
116  'key4' => ['value' => 'value 4'],
117  'key2' => ['value' => 'value 2', 'sortOrder' => 10],
118  'key3' => ['value' => 'value 3'],
119  ],
120  ],
121  [
122  'key1' => '-value 1-',
123  'key4' => '-value 4-',
124  'key3' => '-value 3-',
125  'key2' => '-value 2-',
126  ],
127  ],
128  'sort order edge case values' => [
129  [
130  'item' => [
131  'key1' => ['value' => 'value 1', 'sortOrder' => 101],
132  'key4' => ['value' => 'value 4'],
133  'key2' => ['value' => 'value 2', 'sortOrder' => -10],
134  'key3' => ['value' => 'value 3'],
135  'key5' => ['value' => 'value 5', 'sortOrder' => 20],
136  ],
137  ],
138  [
139  'key2' => '-value 2-',
140  'key4' => '-value 4-',
141  'key3' => '-value 3-',
142  'key5' => '-value 5-',
143  'key1' => '-value 1-',
144  ],
145  ],
146  ];
147  }
148 }