/** * test get storage data */ public function testGetStorageData() { $this->filesystemMock->expects($this->once())->method('getDirectoryRead')->with($this->equalTo(DirectoryList::MEDIA))->will($this->returnValue($this->directoryReadMock)); $this->directoryReadMock->expects($this->any())->method('isDirectory')->will($this->returnValueMap([['/', true], ['folder_one', true], ['file_three.txt', false], ['folder_one/.svn', false], ['folder_one/file_one.txt', false], ['folder_one/folder_two', true], ['folder_one/folder_two/.htaccess', false], ['folder_one/folder_two/file_two.txt', false]])); $paths = ['folder_one', 'file_three.txt', 'folder_one/.svn', 'folder_one/file_one.txt', 'folder_one/folder_two', 'folder_one/folder_two/.htaccess', 'folder_one/folder_two/file_two.txt']; sort($paths); $this->directoryReadMock->expects($this->once())->method('readRecursively')->with($this->equalTo('/'))->will($this->returnValue($paths)); $expected = ['files' => ['file_three.txt', 'folder_one/file_one.txt', 'folder_one/folder_two/file_two.txt'], 'directories' => [['name' => 'folder_one', 'path' => '/'], ['name' => 'folder_two', 'path' => 'folder_one']]]; $actual = $this->storageFile->getStorageData(); $this->assertEquals($expected, $actual); }
/** * @param string $fileUrl * @param string $localFilePath * @return bool|void */ protected function retrieveRemoteImage($fileUrl, $localFilePath) { $this->curl->setConfig(['header' => false]); $this->curl->write('GET', $fileUrl); $image = $this->curl->read(); $this->fileUtility->saveFile($localFilePath, $image); }
/** * Extend the original functionality of this method by also uploading the * requested file to S3. * * @param string $filePath * @param string $content * @param bool $overwrite * @return bool * @throws \Magento\Framework\Exception\LocalizedException */ public function saveFile($filePath, $content, $overwrite = false) { $result = parent::saveFile($filePath, $content, $overwrite); if ($result) { $this->fileStorageDb->saveFile($filePath); } return $result; }
/** * @param string $fileUrl * @param string $localFilePath * @return void * @throws \Magento\Framework\Exception\LocalizedException */ protected function retrieveRemoteImage($fileUrl, $localFilePath) { $this->curl->setConfig(['header' => false]); $this->curl->write('GET', $fileUrl); $image = $this->curl->read(); if (empty($image)) { throw new \Magento\Framework\Exception\LocalizedException(__('Could not get preview image information. Please check your connection and try again.')); } $this->fileUtility->saveFile($localFilePath, $image); }
public function testCollectDataFailureEmptyDataWasGiven() { $this->_fileUtilityMock->expects($this->any())->method('getStorageData')->will($this->returnValue(['files' => []])); $this->assertFalse($this->_model->collectData(0, 1)); }