Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
18 use PHPUnit_Framework_MockObject_MockObject as Mock;
19 
26 class DefaultProcessorTest extends \PHPUnit\Framework\TestCase
27 {
31  private $model;
32 
36  private $deploymentConfigMock;
37 
41  private $configPathResolverMock;
42 
46  private $preparedValueFactoryMock;
47 
51  private $valueMock;
52 
56  private $resourceModelMock;
57 
61  protected function setUp()
62  {
63  $this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
64  ->disableOriginalConstructor()
65  ->getMock();
66  $this->configPathResolverMock = $this->getMockBuilder(ConfigPathResolver::class)
67  ->disableOriginalConstructor()
68  ->getMock();
69  $this->resourceModelMock = $this->getMockBuilder(AbstractDb::class)
70  ->disableOriginalConstructor()
71  ->setMethods(['save'])
72  ->getMockForAbstractClass();
73  $this->valueMock = $this->getMockBuilder(Value::class)
74  ->disableOriginalConstructor()
75  ->setMethods(['getResource'])
76  ->getMock();
77  $this->preparedValueFactoryMock = $this->getMockBuilder(PreparedValueFactory::class)
78  ->disableOriginalConstructor()
79  ->getMock();
80 
81  $this->model = new DefaultProcessor(
82  $this->preparedValueFactoryMock,
83  $this->deploymentConfigMock,
84  $this->configPathResolverMock
85  );
86  }
87 
97  public function testProcess($path, $value, $scope, $scopeCode)
98  {
99  $this->configMockForProcessTest($path, $scope, $scopeCode);
100 
101  $this->preparedValueFactoryMock->expects($this->once())
102  ->method('create')
103  ->willReturn($this->valueMock);
104  $this->valueMock->expects($this->once())
105  ->method('getResource')
106  ->willReturn($this->resourceModelMock);
107  $this->resourceModelMock->expects($this->once())
108  ->method('save')
109  ->with($this->valueMock)
110  ->willReturnSelf();
111 
112  $this->model->process($path, $value, $scope, $scopeCode);
113  }
114 
118  public function processDataProvider()
119  {
120  return [
121  ['test/test/test', 'value', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
122  ['test/test/test', 'value', ScopeInterface::SCOPE_WEBSITE, 'base'],
123  ['test/test/test', 'value', ScopeInterface::SCOPE_STORE, 'test'],
124  ];
125  }
126 
128  {
129  $path = 'test/test/test';
131  $scopeCode = null;
132  $value = 'value';
133  $valueInterfaceMock = $this->getMockBuilder(ValueInterface::class)
134  ->getMockForAbstractClass();
135 
136  $this->configMockForProcessTest($path, $scope, $scopeCode);
137 
138  $this->preparedValueFactoryMock->expects($this->once())
139  ->method('create')
140  ->willReturn($valueInterfaceMock);
141  $this->valueMock->expects($this->never())
142  ->method('getResource');
143  $this->resourceModelMock->expects($this->never())
144  ->method('save');
145 
146  $this->model->process($path, $value, $scope, $scopeCode);
147  }
148 
154  private function configMockForProcessTest($path, $scope, $scopeCode)
155  {
156  $this->configPathResolverMock->expects($this->once())
157  ->method('resolve')
158  ->with($path, $scope, $scopeCode, System::CONFIG_TYPE)
159  ->willReturn('system/default/test/test/test');
160  $this->deploymentConfigMock->expects($this->once())
161  ->method('get')
162  ->willReturnMap([
163  ['system/default/test/test/test', null],
164  ]);
165  }
166 
173  public function testProcessLockedValue()
174  {
175  $path = 'test/test/test';
176  $value = 'value';
177 
178  $this->deploymentConfigMock->expects($this->once())
179  ->method('get')
180  ->willReturnMap([
181  ['db', null, 'exists'],
182  ['system/default/test/test/test', null, 5],
183  ]);
184  $this->configPathResolverMock->expects($this->once())
185  ->method('resolve')
186  ->willReturn('system/default/test/test/test');
187 
188  $this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
189  }
190 }
$value
Definition: gender.phtml:16