92 $sourceFileOne = $this->createPartialMock(\
Magento\
Theme\Model\
Theme\File::class, [
'__wakeup',
'delete']);
93 $sourceFileOne->setData(
95 'file_path' =>
'fixture_file_path_one',
96 'file_type' =>
'fixture_file_type_one',
97 'content' =>
'fixture_content_one',
101 $sourceFileTwo = $this->createPartialMock(\
Magento\
Theme\Model\
Theme\File::class, [
'__wakeup',
'delete']);
102 $sourceFileTwo->setData(
104 'file_path' =>
'fixture_file_path_two',
105 'file_type' =>
'fixture_file_type_two',
106 'content' =>
'fixture_content_two',
110 $this->sourceFiles = [$sourceFileOne, $sourceFileTwo];
111 $this->sourceTheme = $this->createPartialMock(
113 [
'__wakeup',
'getCustomization']
116 $this->targetFiles = [
117 $this->createPartialMock(\
Magento\
Theme\Model\
Theme\File::class, [
'__wakeup',
'delete']),
118 $this->createPartialMock(\
Magento\
Theme\Model\
Theme\File::class, [
'__wakeup',
'delete']),
120 $this->targetTheme = $this->createPartialMock(
122 [
'__wakeup',
'getCustomization']
124 $this->targetTheme->setId(123);
126 $this->customizationPath = $this->createMock(\
Magento\Framework\View\
Design\
Theme\Customization\Path::class);
128 $this->fileFactory = $this->createPartialMock(
133 $this->createPartialMock(\
Magento\Framework\Filesystem::class, [
'getDirectoryWrite']);
134 $this->dirWriteMock = $this->createPartialMock(
136 [
'isDirectory',
'search',
'copy',
'delete',
'read',
'copyFile',
'isExist']
138 $this->filesystem->expects(
145 $this->returnValue($this->dirWriteMock)
149 $this->updateFactory = $this->createPartialMock(\
Magento\Widget\Model\Layout\UpdateFactory::class, [
'create']);
150 $this->update = $this->createPartialMock(
151 \
Magento\Widget\Model\Layout\Update::class,
152 [
'__wakeup',
'getCollection']
154 $this->updateFactory->expects($this->at(0))->method(
'create')->will($this->returnValue($this->update));
155 $this->updateCollection = $this->createPartialMock(
157 [
'addThemeFilter',
'delete',
'getIterator']
159 $this->update->expects(
164 $this->returnValue($this->updateCollection)
168 $this->link = $this->createPartialMock(\
Magento\Widget\Model\Layout\Link::class, [
'__wakeup',
'getCollection']);
169 $this->linkCollection = $this->createPartialMock(
171 [
'addThemeFilter',
'getIterator',
'addFieldToFilter']
173 $this->link->expects($this->any())->method(
'getCollection')->will($this->returnValue($this->linkCollection));
175 $eventManager = $this->createPartialMock(\
Magento\Framework\Event\ManagerInterface::class, [
'dispatch']);
177 $this->
object = new \Magento\Theme\Model\CopyService(
181 $this->updateFactory,
183 $this->customizationPath
189 $this->
object =
null;
190 $this->filesystem =
null;
191 $this->fileFactory =
null;
192 $this->sourceTheme =
null;
193 $this->targetTheme =
null;
195 $this->linkCollection =
null;
196 $this->updateCollection =
null;
197 $this->updateFactory =
null;
198 $this->sourceFiles = [];
199 $this->targetFiles = [];
207 $customization = $this->createPartialMock(
211 $customization->expects($this->atLeastOnce())->method(
'getFiles')->will($this->returnValue([]));
212 $this->sourceTheme->expects(
217 $this->returnValue($customization)
219 $this->targetTheme->expects(
224 $this->returnValue($customization)
227 $this->updateCollection->expects($this->once())->method(
'delete');
228 $this->linkCollection->expects($this->once())->method(
'addThemeFilter');
230 $targetLinkOne = $this->createPartialMock(
231 \
Magento\Widget\Model\Layout\Link::class,
232 [
'__wakeup',
'setId',
'setThemeId',
'save',
'setLayoutUpdateId']
234 $targetLinkOne->setData([
'id' => 1,
'layout_update_id' => 1]);
235 $targetLinkTwo = $this->createPartialMock(
236 \
Magento\Widget\Model\Layout\Link::class,
237 [
'__wakeup',
'setId',
'setThemeId',
'save',
'setLayoutUpdateId']
239 $targetLinkTwo->setData([
'id' => 2,
'layout_update_id' => 2]);
241 $targetLinkOne->expects($this->at(0))->method(
'setThemeId')->with(123);
242 $targetLinkOne->expects($this->at(1))->method(
'setLayoutUpdateId')->with(1);
243 $targetLinkOne->expects($this->at(2))->method(
'setId')->with(
null);
244 $targetLinkOne->expects($this->at(3))->method(
'save');
246 $targetLinkTwo->expects($this->at(0))->method(
'setThemeId')->with(123);
247 $targetLinkTwo->expects($this->at(1))->method(
'setLayoutUpdateId')->with(2);
248 $targetLinkTwo->expects($this->at(2))->method(
'setId')->with(
null);
249 $targetLinkTwo->expects($this->at(3))->method(
'save');
251 $linkReturnValues = $this->onConsecutiveCalls(
new \ArrayIterator([$targetLinkOne, $targetLinkTwo]));
252 $this->linkCollection->expects($this->any())->method(
'getIterator')->will($linkReturnValues);
254 $targetUpdateOne = $this->createPartialMock(
255 \
Magento\Widget\Model\Layout\Update::class,
256 [
'__wakeup',
'setId',
'load',
'save']
258 $targetUpdateOne->setData([
'id' => 1]);
259 $targetUpdateTwo = $this->createPartialMock(
260 \
Magento\Widget\Model\Layout\Update::class,
261 [
'__wakeup',
'setId',
'load',
'save']
263 $targetUpdateTwo->setData([
'id' => 2]);
264 $updateReturnValues = $this->onConsecutiveCalls($this->update, $targetUpdateOne, $targetUpdateTwo);
265 $this->updateFactory->expects($this->any())->method(
'create')->will($updateReturnValues);
267 $this->
object->copy($this->sourceTheme, $this->targetTheme);
276 $sourceCustom = $this->createPartialMock(
280 $sourceCustom->expects(
285 $this->returnValue($this->sourceFiles)
287 $this->sourceTheme->expects(
292 $this->returnValue($sourceCustom)
294 $targetCustom = $this->createPartialMock(
298 $targetCustom->expects(
303 $this->returnValue($this->targetFiles)
305 $this->targetTheme->expects(
310 $this->returnValue($targetCustom)
313 $this->linkCollection->expects(
318 $this->returnValue($this->linkCollection)
320 $this->linkCollection->expects(
325 $this->returnValue(
new \ArrayIterator([]))
328 foreach ($this->targetFiles as $targetFile) {
329 $targetFile->expects($this->once())->method(
'delete');
332 $newFileOne = $this->createPartialMock(\
Magento\
Theme\Model\
Theme\File::class, [
'__wakeup',
'setData',
'save']);
333 $newFileTwo = $this->createPartialMock(\
Magento\
Theme\Model\
Theme\File::class, [
'__wakeup',
'setData',
'save']);
334 $newFileOne->expects(
341 'file_path' =>
'fixture_file_path_one',
342 'file_type' =>
'fixture_file_type_one',
343 'content' =>
'fixture_content_one',
347 $newFileOne->expects($this->at(1))->method(
'save');
348 $newFileTwo->expects(
355 'file_path' =>
'fixture_file_path_two',
356 'file_type' =>
'fixture_file_type_two',
357 'content' =>
'fixture_content_two',
361 $newFileTwo->expects($this->at(1))->method(
'save');
362 $this->fileFactory->expects(
369 $this->onConsecutiveCalls($newFileOne, $newFileTwo)
372 $this->
object->copy($this->sourceTheme, $this->targetTheme);
382 $customization = $this->createPartialMock(
386 $customization->expects($this->atLeastOnce())->method(
'getFiles')->will($this->returnValue([]));
387 $this->sourceTheme->expects(
392 $this->returnValue($customization)
394 $this->targetTheme->expects(
399 $this->returnValue($customization)
402 $this->linkCollection->expects(
407 $this->returnValue($this->linkCollection)
409 $this->linkCollection->expects(
414 $this->returnValue(
new \ArrayIterator([]))
417 $this->customizationPath->expects(
420 'getCustomizationPath' 422 $this->returnValue(
'source/path')
425 $this->customizationPath->expects(
428 'getCustomizationPath' 430 $this->returnValue(
'target/path')
433 $this->dirWriteMock->expects(
438 $this->returnValueMap([[
'source/path',
true], [
'source/path/subdir',
true]])
441 $this->dirWriteMock->expects(
446 $this->returnValueMap(
448 [
'target/path',
true]
453 $this->dirWriteMock->expects(
458 $this->returnValueMap(
460 [
'target/path', [
'target/path/subdir']],
461 [
'source/path', [
'source/path/subdir']],
462 [
'source/path/subdir', [
'source/path/subdir/file_one.jpg',
'source/path/subdir/file_two.png']],
467 $expectedCopyEvents = [
468 [
'source/path/subdir/file_one.jpg',
'target/path/subdir/file_one.jpg',
null],
469 [
'source/path/subdir/file_two.png',
'target/path/subdir/file_two.png',
null],
471 $actualCopyEvents = [];
472 $recordCopyEvent =
function () use (&$actualCopyEvents) {
473 $actualCopyEvents[] = func_get_args();
475 $this->dirWriteMock->expects($this->any())->method(
'copyFile')->will($this->returnCallback($recordCopyEvent));
477 $this->
object->copy($this->sourceTheme, $this->targetTheme);
479 $this->assertEquals($expectedCopyEvents, $actualCopyEvents);
testCopyDatabaseCustomization()
testCopyFilesystemCustomization()