/**
  * cover update method when fileContent is empty
  */
 public function testUpdateWhenFileDelete()
 {
     $customCss = $this->getMockBuilder('Magento\\Framework\\View\\Design\\Theme\\FileInterface')->disableOriginalConstructor()->setMethods(['delete', 'save', 'getContent', 'getFileInfo', 'getFullPath', 'getFileName', 'setFileName', 'getTheme', 'setTheme', 'getCustomizationService', 'setCustomizationService', 'setData', 'getType', 'prepareFile'])->getMock();
     $fileContent = '';
     $customFiles = [$customCss];
     $fileType = 'png';
     $theme = $this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->setMethods(['getArea', 'getThemePath', 'getFullPath', 'getParentTheme', 'getCode', 'isPhysical', 'getInheritedThemes', 'getId', 'getCustomization'])->getMock();
     $customization = $this->getMockBuilder('Magento\\Framework\\View\\Design\\Theme\\CustomizationInterface')->getMock();
     $customCss->expects($this->once())->method('delete');
     $this->file->expects($this->once())->method('getType')->willReturn($fileType);
     $customization->expects($this->once())->method('getFilesByType')->with($fileType)->willReturn($customFiles);
     $theme->expects($this->once())->method('getCustomization')->willReturn($customization);
     /** @var \Magento\Framework\View\Design\ThemeInterface $theme */
     $this->assertInstanceOf('Magento\\Framework\\View\\Design\\Theme\\FileInterface', $this->object->update($theme, $fileContent));
 }
Example #2
0
 /**
  * Creates or updates custom single file which belong to a selected theme
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $themeModel
  * @param string $fileContent
  * @return \Magento\Framework\View\Design\Theme\FileInterface
  */
 public function update(\Magento\Framework\View\Design\ThemeInterface $themeModel, $fileContent)
 {
     $customFiles = $themeModel->getCustomization()->getFilesByType($this->_fileService->getType());
     $customCss = reset($customFiles);
     if (empty($fileContent) && $customCss) {
         $customCss->delete();
         return $customCss;
     }
     if (!$customCss) {
         $customCss = $this->_fileService->create();
     }
     $customCss->setData('content', $fileContent);
     $customCss->setTheme($themeModel);
     $customCss->save();
     return $customCss;
 }