Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MetadataProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
12 use \PHPUnit_Framework_MockObject_MockObject as Mock;
13 
17 class MetadataProcessorTest extends \PHPUnit\Framework\TestCase
18 {
22  protected $_model;
23 
28 
32  protected $_modelPoolMock;
33 
37  protected $_backendModelMock;
38 
42  protected function setUp()
43  {
44  $this->_modelPoolMock = $this->getMockBuilder(ProcessorFactory::class)
45  ->disableOriginalConstructor()
46  ->getMock();
47  $this->_initialConfigMock = $this->getMockBuilder(Initial::class)
48  ->disableOriginalConstructor()
49  ->getMock();
50  $this->_backendModelMock = $this->getMockBuilder(ProcessorInterface::class)
51  ->getMockForAbstractClass();
52 
53  $this->_initialConfigMock->expects($this->any())
54  ->method('getMetadata')
55  ->willReturn(
56  ['some/config/path' => ['backendModel' => 'Custom_Backend_Model']]
57  );
58 
59  $this->_model = new \Magento\Framework\App\Config\MetadataProcessor(
60  $this->_modelPoolMock,
61  $this->_initialConfigMock
62  );
63  }
64 
65  public function testProcess()
66  {
67  $this->_modelPoolMock->expects($this->once())
68  ->method('get')
69  ->with('Custom_Backend_Model')
70  ->willReturn($this->_backendModelMock);
71  $this->_backendModelMock->expects($this->once())
72  ->method('processValue')
73  ->with('value')
74  ->willReturn('processed_value');
75 
76  $data = ['some' => ['config' => ['path' => 'value']], 'active' => 1];
77  $expectedResult = $data;
78  $expectedResult['some']['config']['path'] = 'processed_value';
79  $this->assertEquals($expectedResult, $this->_model->process($data));
80  }
81 }