Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BehaviorAbstractTest.php
Go to the documentation of this file.
1 <?php
11 
13 {
19  protected $_sourceArray = ['key_1' => 'label_1', 'key_2' => 'label_2'];
20 
26  protected $_expectedOptions = [
27  ['value' => 'key_1', 'label' => 'label_1'],
28  ['value' => 'key_2', 'label' => 'label_2'],
29  ];
30 
31  protected function setUp()
32  {
33  parent::setUp();
34 
35  $model = $this->getMockForAbstractClass(
36  \Magento\ImportExport\Model\Source\Import\AbstractBehavior::class,
37  [[]],
38  '',
39  false,
40  true,
41  true,
42  ['toArray']
43  );
44  $model->expects($this->any())->method('toArray')->will($this->returnValue($this->_sourceArray));
45 
46  $this->_model = $model;
47  }
48 
54  public function testToOptionArray()
55  {
56  $actualOptions = $this->_model->toOptionArray();
57 
58  // all elements must have value and label fields
59  foreach ($actualOptions as $option) {
60  $this->assertArrayHasKey('value', $option);
61  $this->assertArrayHasKey('label', $option);
62  }
63 
64  // first element must has empty value
65  $firstElement = $actualOptions[0];
66  $this->assertEquals('', $firstElement['value']);
67 
68  // other elements must be equal to expected data
69  $actualOptions = array_slice($actualOptions, 1);
70  $this->assertEquals($this->_expectedOptions, $actualOptions);
71  }
72 }