Beispiel #1
0
 /**
  * @expectedException \Magento\Framework\Model\Exception
  */
 public function testUploadInvalidJsFile()
 {
     $fileName = 'file.name';
     $this->_service = new \Magento\Theme\Model\Uploader\Service($this->_filesystemMock, $this->_fileSizeMock, $this->_uploaderFactory, ['js' => '100M']);
     $this->_uploader->expects($this->once())->method('getFileSize')->will($this->returnValue(499 * self::MB_MULTIPLIER));
     $this->_service->uploadJsFile($fileName);
 }
 public function testExecute()
 {
     $themeId = 23;
     $theme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface', [], '', false);
     $jsFile = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\Theme\\FileInterface', [], '', false, true, true, ['setTheme', 'setFileName', 'setData', 'save']);
     $this->_request->expects($this->at(0))->method('getParam')->with('id')->willReturn($themeId);
     $this->_objectManagerMock->expects($this->at(0))->method('get')->with('Magento\\Theme\\Model\\Uploader\\Service')->WillReturn($this->serviceModel);
     $this->_objectManagerMock->expects($this->at(1))->method('get')->with('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory')->WillReturn($this->themeFactory);
     $this->_objectManagerMock->expects($this->at(2))->method('get')->with('Magento\\Framework\\View\\Design\\Theme\\Customization\\File\\Js')->WillReturn($this->customizationJs);
     $this->_objectManagerMock->expects($this->at(4))->method('get')->with('Magento\\Framework\\Json\\Helper\\Data')->WillReturn($this->jsonHelper);
     $this->themeFactory->expects($this->once())->method('create')->willReturn($theme);
     $this->serviceModel->expects($this->once())->method('uploadJsFile')->with('js_files_uploader')->willReturn(['filename' => 'filename', 'content' => 'content']);
     $this->customizationJs->expects($this->once())->method('create')->willReturn($jsFile);
     $jsFile->expects($this->once())->method('setTheme')->with($theme);
     $jsFile->expects($this->once())->method('setFileName')->with('filename');
     $jsFile->expects($this->once())->method('setData')->with('content', 'content');
     $jsFile->expects($this->once())->method('save');
     $this->_objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\View\\Design\\Theme\\CustomizationInterface', ['theme' => $theme])->willReturn($this->themeCustomization);
     $this->themeCustomization->expects($this->once())->method('getFilesByType')->with(\Magento\Framework\View\Design\Theme\Customization\File\Js::TYPE)->willReturn([$jsFile]);
     $this->themeCustomization->expects($this->once())->method('generateFileInfo')->with([$jsFile])->willReturn(['fileOne' => ['name' => 'name']]);
     $this->jsonHelper->expects($this->once())->method('jsonEncode')->with(['error' => false, 'files' => ['fileOne' => ['name' => 'name']]])->willReturn('{"error":false,"files":{"fileOne":{"name":"name"}}}');
     $this->response->expects($this->once())->method('representJson')->with('{"error":false,"files":{"fileOne":{"name":"name"}}}');
     $this->_model->execute();
 }