Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NamedParamsTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\View\Layout\Argument\Interpreter\NamedParams;
9 
10 class NamedParamsTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_interpreter;
16 
20  protected $_model;
21 
22  protected function setUp()
23  {
24  $this->_interpreter = $this->getMockForAbstractClass(
25  \Magento\Framework\Data\Argument\InterpreterInterface::class
26  );
27  $this->_model = new NamedParams($this->_interpreter);
28  }
29 
30  public function testEvaluate()
31  {
32  $input = [
33  'param' => ['param1' => ['value' => 'value 1'], 'param2' => ['value' => 'value 2']],
34  ];
35 
36  $this->_interpreter->expects(
37  $this->at(0)
38  )->method(
39  'evaluate'
40  )->with(
41  ['value' => 'value 1']
42  )->will(
43  $this->returnValue('value 1 (evaluated)')
44  );
45  $this->_interpreter->expects(
46  $this->at(1)
47  )->method(
48  'evaluate'
49  )->with(
50  ['value' => 'value 2']
51  )->will(
52  $this->returnValue('value 2 (evaluated)')
53  );
54  $expected = ['param1' => 'value 1 (evaluated)', 'param2' => 'value 2 (evaluated)'];
55 
56  $actual = $this->_model->evaluate($input);
57  $this->assertSame($expected, $actual);
58  }
59 
63  public function testEvaluateWrongParam($input, $expectedExceptionMessage)
64  {
65  $this->expectException('\InvalidArgumentException');
66  $this->expectExceptionMessage($expectedExceptionMessage);
67  $this->_model->evaluate($input);
68  }
69 
74  {
75  return [
76  'root param is non-array' => [
77  ['param' => 'non-array'],
78  'Layout argument parameters are expected to be an array',
79  ],
80  'individual param is non-array' => [
81  ['param' => ['sub-param' => 'non-array']],
82  'Parameter data of layout argument is expected to be an array',
83  ]
84  ];
85  }
86 }