public function testMoveImageFromTmp()
 {
     $this->fileStorageDbMock->method('checkDbUsage')->willReturn(1);
     $this->fileStorageDbMock->expects($this->atLeastOnce())->method('getUniqueFilename')->willReturn('file___1');
     $this->fileStorageDbMock->method('renameFile')->will($this->returnSelf());
     $this->mediaDirectoryMock->expects($this->exactly(2))->method('delete')->will($this->returnSelf());
     $this->mediaHelperObject->moveImageFromTmp('file.tmp');
 }
Exemple #2
0
 public function testCopyQuoteToOrder()
 {
     $optionMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface')->disableOriginalConstructor()->setMethods(['getValue'])->getMockForAbstractClass();
     $quotePath = '/quote/path/path/uploaded.file';
     $orderPath = '/order/path/path/uploaded.file';
     $optionMock->expects($this->any())->method('getValue')->will($this->returnValue(['quote_path' => $quotePath, 'order_path' => $orderPath]));
     $this->rootDirectory->expects($this->any())->method('isFile')->with($this->equalTo($quotePath))->will($this->returnValue(true));
     $this->rootDirectory->expects($this->any())->method('isReadable')->with($this->equalTo($quotePath))->will($this->returnValue(true));
     $this->rootDirectory->expects($this->any())->method('getAbsolutePath')->will($this->returnValue('/file.path'));
     $this->coreFileStorageDatabase->expects($this->any())->method('copyFile')->will($this->returnValue('true'));
     $fileObject = $this->getFileObject();
     $fileObject->setData('configuration_item_option', $optionMock);
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Product\\Option\\Type\\File', $fileObject->copyQuoteToOrder());
 }
 /**
  * cover positive case for getFaviconFile and checkIsFile
  */
 public function testGetFaviconFile()
 {
     $scopeConfigValue = 'path';
     $urlToMediaDir = 'http://magento.url/pub/media/';
     $expectedFile = ImageFavicon::UPLOAD_DIR . '/' . $scopeConfigValue;
     $expectedUrl = $urlToMediaDir . $expectedFile;
     $this->scopeManager->expects($this->once())->method('getValue')->with('design/head/shortcut_icon', ScopeInterface::SCOPE_STORE)->willReturn($scopeConfigValue);
     $this->store->expects($this->once())->method('getBaseUrl')->with(UrlInterface::URL_TYPE_MEDIA)->willReturn($urlToMediaDir);
     $this->fileStorageDatabase->expects($this->once())->method('checkDbUsage')->willReturn(true);
     $this->fileStorageDatabase->expects($this->once())->method('saveFileToFilesystem')->willReturn(true);
     $this->mediaDir->expects($this->at(0))->method('isFile')->with($expectedFile)->willReturn(false);
     $this->mediaDir->expects($this->at(1))->method('isFile')->with($expectedFile)->willReturn(true);
     $results = $this->object->getFaviconFile();
     $this->assertEquals($expectedUrl, $results);
     $this->assertNotFalse($results);
 }
 public function testGetDirsCollectionCreateSubDirectories()
 {
     $directoryName = 'test1';
     $this->coreFileStorageMock->expects($this->once())->method('checkDbUsage')->willReturn(true);
     $this->directoryCollectionMock->expects($this->once())->method('getSubdirectories')->with(self::STORAGE_ROOT_DIR)->willReturn([['name' => $directoryName]]);
     $this->directoryDatabaseFactoryMock->expects($this->once())->method('create')->willReturn($this->directoryCollectionMock);
     $this->directoryMock->expects($this->once())->method('create')->with(rtrim(self::STORAGE_ROOT_DIR, '/') . '/' . $directoryName);
     $this->generalTestGetDirsCollection(self::STORAGE_ROOT_DIR);
 }
 public function testExecute()
 {
     $data = ['tmp_name' => 'tmp_name', 'path' => 'path', 'file' => 'file'];
     $uploader = $this->getMockBuilder('Magento\\MediaStorage\\Model\\File\\Uploader')->disableOriginalConstructor()->getMock();
     $resultJson = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->setMethods(['setData'])->getMock();
     $this->request->expects($this->once())->method('getParam')->with('type')->willReturn('samples');
     $this->sample->expects($this->once())->method('getBaseTmpPath')->willReturn('base_tmp_path');
     $this->uploaderFactory->expects($this->once())->method('create')->willReturn($uploader);
     $this->fileHelper->expects($this->once())->method('uploadFromTmp')->willReturn($data);
     $this->storageDatabase->expects($this->once())->method('saveFile');
     $this->session->expects($this->once())->method('getName')->willReturn('Name');
     $this->session->expects($this->once())->method('getSessionId')->willReturn('SessionId');
     $this->session->expects($this->once())->method('getCookieLifetime')->willReturn('CookieLifetime');
     $this->session->expects($this->once())->method('getCookiePath')->willReturn('CookiePath');
     $this->session->expects($this->once())->method('getCookieDomain')->willReturn('CookieDomain');
     $this->resultFactory->expects($this->once())->method('create')->willReturn($resultJson);
     $resultJson->expects($this->once())->method('setData')->willReturnSelf();
     $this->assertEquals($resultJson, $this->upload->execute());
 }
 public function testClearCache()
 {
     $this->coreFileHelper->expects($this->once())->method('deleteFolder')->will($this->returnValue(true));
     $this->image->clearCache();
 }