Merge pull request #145 from open-sausages/pulls/fix-file-fixture

BUG Prevent top-level files being created with incorrect parent folder
This commit is contained in:
Ingo Schommer 2017-02-27 11:41:45 +13:00 committed by GitHub
commit 8b0e0615f6

View File

@ -615,6 +615,8 @@ class FixtureContext extends BehatContext
if (!$data) { if (!$data) {
$data = array(); $data = array();
} }
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier; $relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;
$relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '\/?/', '', $relativeTargetPath); $relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '\/?/', '', $relativeTargetPath);
$sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath)); $sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath));
@ -624,7 +626,7 @@ class FixtureContext extends BehatContext
$parent = Folder::find_or_make($relativeTargetPath); $parent = Folder::find_or_make($relativeTargetPath);
$data['ID'] = $parent->ID; $data['ID'] = $parent->ID;
} else { } else {
$parent = Folder::find_or_make(dirname($relativeTargetPath)); // Check file exists
if (!file_exists($sourcePath)) { if (!file_exists($sourcePath)) {
throw new \InvalidArgumentException(sprintf( throw new \InvalidArgumentException(sprintf(
'Source file for "%s" cannot be found in "%s"', 'Source file for "%s" cannot be found in "%s"',
@ -632,7 +634,17 @@ class FixtureContext extends BehatContext
$sourcePath $sourcePath
)); ));
} }
$data['ParentID'] = $parent->ID;
// Get parent
$parentID = 0;
if (strstr($relativeTargetPath, '/')) {
$folderName = dirname($relativeTargetPath);
$parent = Folder::find_or_make($folderName);
if ($parent) {
$parentID = $parent->ID;
}
}
$data['ParentID'] = $parentID;
// Load file into APL and retrieve tuple // Load file into APL and retrieve tuple
$asset = $this->getAssetStore()->setFromLocalFile( $asset = $this->getAssetStore()->setFromLocalFile(