Last active
August 29, 2015 14:03
-
-
Save Konafets/ad0cd3bfe0269993bb47 to your computer and use it in GitHub Desktop.
createUploadFolder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates the upload folder of an extension. | |
* | |
* @param string $key The extension key | |
* | |
* @return void | |
*/ | |
public function createUploadFoldersCommand($key) { | |
try { | |
$messages = $this->extensionApiService->createUploadFolders($key); | |
if (sizeof($messages) > 1) { | |
foreach ($messages as $message) { | |
$this->outputLine($message); | |
} | |
} else { | |
$this->outputLine($messages[0]); | |
} | |
} catch (Exception $e) { | |
$this->outputLine($e->getMessage()); | |
$this->quit(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates the upload folders of an extension. | |
* | |
* @param string $extensionKey The extension key | |
* | |
* @throws \InvalidArgumentException | |
* @return array | |
*/ | |
public function createUploadFolders($extensionKey) { | |
$this->checkExtensionExists($extensionKey); | |
$extensions = $this->listExtensions(); | |
$extension = $extensions[$extensionKey]; | |
$extension['key'] = $extensionKey; | |
$folders = $this->fileHandlingUtility->getAbsolutePathsToConfiguredDirectories($extension); | |
$result = array(); | |
if (is_array($folders) && sizeof($folders) > 0) { | |
$result = $this->fileHandlingUtility->ensureConfiguredDirectoriesExist($extension); | |
} else { | |
$result[] = sprintf('No upload folders configured for "%s".', $extensionKey); | |
} | |
return $result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Tests for createUpdateFolders() | |
// | |
/** | |
* Provides the array which is return value from ExtensionServiceApi::getInstalledExtensions() | |
* | |
* @return array | |
*/ | |
public function getExtensionArrayForCreateUploadFolders() { | |
return array( | |
'about' => array( | |
'title' => 'Help>About', | |
'description' => 'Shows info about TYPO3 and installed extensions', | |
'category' => 'module', | |
'shy' => 1, | |
'dependencies' => '', | |
'conflicts' => '', | |
'priority' => '', | |
'loadOrder' => '', | |
'module' => 'mod', | |
'state' => 'stable', | |
'internal' => 0, | |
'uploadfolder' => 0, | |
'createDirs' => '', | |
'modify_tables' => '', | |
'clearCacheOnLoad' => '', | |
'lockType' => '', | |
'author' => 'Kasper Skaarhoj', | |
'author_email' => '[email protected]', | |
'author_company' => 'Curby Soft Multimedia', | |
'CGLcompilance' => '', | |
'CGLcompilance_note' => '', | |
'version' => '6.2.0', | |
'_md5_values_when_last_written' => '', | |
'constraints' => array(), | |
'suggests' => array(), | |
'key' => 'about' | |
), | |
'backend' => array( | |
'title' => 'TYPO3 Backend', | |
'description' => 'Classes for the TYPO3 backend.', | |
'category' => 'be', | |
'shy' => 1, | |
'dependencies' => '', | |
'conflicts' => '', | |
'priority' => 'top', | |
'loadOrder' => '', | |
'module' => '', | |
'state' => 'stable', | |
'internal' => 1, | |
'uploadfolder' => 0, | |
'createDirs' => '', | |
'modify_tables' => '', | |
'clearCacheOnLoad' => 0, | |
'lockType' => 'S', | |
'author' => 'Kasper Skaarhoj', | |
'author_email' => '[email protected]', | |
'author_company' => 'Curby Soft Multimedia', | |
'CGLcompilance' => '', | |
'CGLcompilance_note' => '', | |
'version' => '6.2.0', | |
'_md5_values_when_last_written' => '', | |
'constraints' => array(), | |
'suggests' => array(), | |
'key' => 'about' | |
), | |
'core' => array( | |
'title' => 'TYPO3 Core', | |
'description' => 'Classes for the TYPO3 backend.', | |
'category' => 'be', | |
'shy' => 1, | |
'dependencies' => '', | |
'conflicts' => '', | |
'priority' => 'top', | |
'loadOrder' => '', | |
'module' => '', | |
'state' => 'stable', | |
'internal' => 1, | |
'uploadfolder' => 0, | |
'createDirs' => '', | |
'modify_tables' => '', | |
'clearCacheOnLoad' => 0, | |
'lockType' => 'S', | |
'author' => 'Kasper Skaarhoj', | |
'author_email' => '[email protected]', | |
'author_company' => 'Curby Soft Multimedia', | |
'CGLcompilance' => '', | |
'CGLcompilance_note' => '', | |
'version' => '6.2.0', | |
'_md5_values_when_last_written' => '', | |
'constraints' => array(), | |
'suggests' => array(), | |
'key' => 'about' | |
), | |
'dummy' => array( | |
'title' => 'Dummy Extension for testing', | |
'description' => 'This is just a dummy extension', | |
'category' => 'experimental', | |
'shy' => 1, | |
'dependencies' => '', | |
'conflicts' => '', | |
'priority' => '', | |
'loadOrder' => '', | |
'module' => 'mod', | |
'state' => 'stable', | |
'internal' => 0, | |
'uploadfolder' => 0, | |
'createDirs' => '', | |
'modify_tables' => '', | |
'clearCacheOnLoad' => '', | |
'lockType' => '', | |
'author' => 'Stefano Kowalke', | |
'author_email' => '[email protected]', | |
'author_company' => 'Arroba IT', | |
'CGLcompilance' => '', | |
'CGLcompilance_note' => '', | |
'version' => '6.2.0', | |
'_md5_values_when_last_written' => '', | |
'constraints' => array(), | |
'suggests' => array(), | |
'key' => 'about' | |
) | |
); | |
} | |
/** | |
* @test | |
* @covers ::createUploadFolders | |
* @expectedException \InvalidArgumentException | |
* @expectedExceptionMessage Extension "dummy" does not exist! | |
*/ | |
public function createUploadFoldersForNonexistentExtensionThrowsException() { | |
$installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('isAvailable')); | |
$installUtilityMock->expects($this->once())->method('isAvailable')->with('dummy')->will($this->returnValue(FALSE)); | |
$this->subject->injectInstallUtility($installUtilityMock); | |
$this->subject->createUploadFolders('dummy'); | |
} | |
/** | |
* @test | |
* @covers ::createUploadFolders | |
*/ | |
public function createUploadFoldersNoUploadFoldersConfigured() { | |
$this->subject = $this->getAccessibleMock( | |
'Etobi\\CoreApi\\Service\\ExtensionApiService', array('getInstalledExtensions', 'listExtensions') | |
); | |
$installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('isAvailable')); | |
$installUtilityMock->expects($this->once())->method('isAvailable')->with('about')->will($this->returnValue(TRUE)); | |
$extensions = $this->getFakeInstalledExtensionArray(); | |
$this->subject->expects($this->once())->method('listExtensions')->will($this->returnValue($extensions)); | |
$extensions['about']['key'] = 'about'; | |
$fileHandlingUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility'); | |
$fileHandlingUtilityMock | |
->expects($this->once()) | |
->method('getAbsolutePathsToConfiguredDirectories') | |
->with($extensions['about']) | |
->will($this->returnValue(array()) | |
); | |
$fileHandlingUtilityMock->expects($this->never())->method('ensureConfiguredDirectoriesExist'); | |
$this->subject->injectInstallUtility($installUtilityMock); | |
$this->subject->injectFileHandlingUtility($fileHandlingUtilityMock); | |
$this->assertSame(array('No upload folders configured for "about".'), $this->subject->createUploadFolders('about')); | |
} | |
/** | |
* @test | |
* @covers ::createUploadFolders | |
*/ | |
public function createUploadFoldersFolderAlreadyExist() { | |
$this->subject = $this->getAccessibleMock( | |
'Etobi\\CoreApi\\Service\\ExtensionApiService', | |
array('getInstalledExtensions', 'listExtensions') | |
); | |
$installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('isAvailable')); | |
$installUtilityMock->expects($this->once())->method('isAvailable')->with('about')->will($this->returnValue(TRUE)); | |
$extensions = $this->getFakeInstalledExtensionArray(); | |
$this->subject->expects($this->once())->method('listExtensions')->will($this->returnValue($extensions)); | |
$this->subject->expects($this->once())->method('listExtensions')->will($this->returnValue($extensions)); | |
$extensions['about']['key'] = 'about'; | |
$fileHandlingUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility'); | |
$fileHandlingUtilityMock | |
->expects($this->once()) | |
->method('getAbsolutePathsToConfiguredDirectories') | |
->with($extensions['about']) | |
->will($this->returnValue(array('test/', 'test/two')) | |
); | |
$fileHandlingUtilityMock | |
->expects($this->once()) | |
->method('ensureConfiguredDirectoriesExist') | |
->with($extensions['about']) | |
->will($this->returnValue(array('Did not created directory "/path/to/uploadfolder". Already exists.')) | |
); | |
$this->subject->injectInstallUtility($installUtilityMock); | |
$this->subject->injectFileHandlingUtility($fileHandlingUtilityMock); | |
$this->assertSame(array('Did not created directory "/path/to/uploadfolder". Already exists.'), $this->subject->createUploadFolders('about')); | |
} | |
/** | |
* @test | |
* @covers ::createUploadFolders | |
*/ | |
public function createUploadFoldersCreateUploadFolders() { | |
$this->subject = $this->getAccessibleMock( | |
'Etobi\\CoreApi\\Service\\ExtensionApiService', | |
array('getInstalledExtensions', 'listExtensions') | |
); | |
$installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('isAvailable')); | |
$installUtilityMock->expects($this->once())->method('isAvailable')->with('about')->will($this->returnValue(TRUE)); | |
$extensions = $this->getExtensionArrayForCreateUploadFolders(); | |
$this->subject->expects($this->once())->method('listExtensions')->will($this->returnValue($extensions)); | |
$this->subject->injectInstallUtility($installUtilityMock); | |
$extensions['about']['key'] = 'about'; | |
$fileHandlingUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility'); | |
$fileHandlingUtilityMock | |
->expects($this->once()) | |
->method('getAbsolutePathsToConfiguredDirectories') | |
->with($extensions['about']) | |
->will($this->returnValue(array('test/', 'test/two')) | |
); | |
$fileHandlingUtilityMock | |
->expects($this->once()) | |
->method('ensureConfiguredDirectoriesExist') | |
->with($extensions['about']) | |
->will($this->returnValue(array('Directory "/path/to/uploadfolder" created.')) | |
); | |
$this->subject->injectFileHandlingUtility($fileHandlingUtilityMock); | |
$this->assertSame(array('Directory "/path/to/uploadfolder" created.'), $this->subject->createUploadFolders('about')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment