Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SaveProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
15 use PHPUnit_Framework_MockObject_MockObject as Mock;
16 
22 class SaveProcessorTest extends \PHPUnit\Framework\TestCase
23 {
27  private $model;
28 
32  private $arrayUtilsMock;
33 
37  private $valueFactoryMock;
38 
42  private $scopeConfigMock;
43 
47  private $valueMock;
48 
52  private $currencyValueMock;
53 
57  protected function setUp()
58  {
59  $this->arrayUtilsMock = $this->getMockBuilder(ArrayUtils::class)
60  ->disableOriginalConstructor()
61  ->getMock();
62  $this->valueFactoryMock = $this->getMockBuilder(PreparedValueFactory::class)
63  ->disableOriginalConstructor()
64  ->getMock();
65  $this->valueMock = $this->getMockBuilder(Value::class)
66  ->disableOriginalConstructor()
67  ->getMock();
68  $this->currencyValueMock = $this->getMockBuilder(Base::class)
69  ->disableOriginalConstructor()
70  ->setMethods(['beforeSave', 'afterSave'])
71  ->getMock();
72  $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
73  ->getMockForAbstractClass();
74 
75  $this->model = new SaveProcessor(
76  $this->arrayUtilsMock,
77  $this->valueFactoryMock,
78  $this->scopeConfigMock
79  );
80  }
81 
82  public function testProcess()
83  {
84  $data = [
85  'default' => [
86  'web' => ['unsecure' => ['base_url' => 'http://magento2.local/']],
87  'currency' => ['options' => ['base' => 'EUR']]
88  ],
89  'websites' => ['base' => ['web' => ['unsecure' => ['base_url' => 'http://magento3.local/']]]],
90  ];
91 
92  $this->valueMock->expects($this->exactly(2))
93  ->method('beforeSave');
94  $this->valueMock->expects($this->exactly(2))
95  ->method('afterSave');
96 
97  $value1 = clone $this->valueMock;
98  $value2 = clone $this->valueMock;
99 
100  $this->arrayUtilsMock->expects($this->exactly(2))
101  ->method('flatten')
102  ->willReturnMap([
103  [
104  [
105  'web' => ['unsecure' => ['base_url' => 'http://magento2.local/']],
106  'currency' => ['options' => ['base' => 'EUR']]
107  ],
108  '',
109  '/',
110  [
111  'web/unsecure/base_url' => 'http://magento2.local/',
112  'currency/options/base' => 'EUR'
113  ]
114  ],
115  [
116  ['web' => ['unsecure' => ['base_url' => 'http://magento3.local/']]],
117  '',
118  '/',
119  ['web/unsecure/base_url' => 'http://magento3.local/']
120  ]
121  ]);
122  $this->scopeConfigMock->expects($this->exactly(3))
123  ->method('getValue')
124  ->willReturnMap([
125  ['web/unsecure/base_url', 'default', null, 'http://magento2.local/'],
126  ['currency/options/base', 'default', null, 'EUR'],
127  ['web/unsecure/base_url', 'websites', 'base', 'http://magento3.local/']
128  ]);
129  $this->valueFactoryMock->expects($this->exactly(3))
130  ->method('create')
131  ->willReturnMap([
132  ['web/unsecure/base_url', 'http://magento2.local/', 'default', null, $value1],
133  ['currency/options/base', 'EUR', 'default', null, $this->currencyValueMock],
134  ['web/unsecure/base_url', 'http://magento3.local/', 'websites', 'base', $value2]
135  ]);
136 
137  $this->assertSame(null, $this->model->process($data));
138  }
139 }