mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Fix SS4 AssetStore compat in FixtureContext
Correctly create published files, and delete them via the AssetStore API rather than unlink()
This commit is contained in:
parent
abb31cce69
commit
5728f8aabe
@ -36,6 +36,11 @@ class FixtureContext extends BehatContext
|
|||||||
*/
|
*/
|
||||||
protected $createdFilesPaths = array();
|
protected $createdFilesPaths = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array Stores the asset tuples.
|
||||||
|
*/
|
||||||
|
protected $createdAssets = array();
|
||||||
|
|
||||||
public function __construct(array $parameters) {
|
public function __construct(array $parameters) {
|
||||||
$this->context = $parameters;
|
$this->context = $parameters;
|
||||||
}
|
}
|
||||||
@ -99,14 +104,10 @@ class FixtureContext extends BehatContext
|
|||||||
* @AfterScenario
|
* @AfterScenario
|
||||||
*/
|
*/
|
||||||
public function afterResetAssets(ScenarioEvent $event) {
|
public function afterResetAssets(ScenarioEvent $event) {
|
||||||
if (is_array($this->createdFilesPaths)) {
|
$store = $this->getAssetStore();
|
||||||
$createdFiles = array_reverse($this->createdFilesPaths);
|
if (is_array($this->createdAssets)) {
|
||||||
foreach ($createdFiles as $path) {
|
foreach ($this->createdAssets as $asset) {
|
||||||
if (is_dir($path)) {
|
$store->delete($asset['Filename'], $asset['Hash']);
|
||||||
\Filesystem::removeFolder($path);
|
|
||||||
} else {
|
|
||||||
@unlink($path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -551,8 +552,10 @@ class FixtureContext extends BehatContext
|
|||||||
$parent = \Folder::find_or_make($relativeTargetPath);
|
$parent = \Folder::find_or_make($relativeTargetPath);
|
||||||
$targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath);
|
$targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath);
|
||||||
$data['ID'] = $parent->ID;
|
$data['ID'] = $parent->ID;
|
||||||
|
$this->createdAssets[] = $parent->File->getValue();
|
||||||
} else {
|
} else {
|
||||||
$parent = \Folder::find_or_make(dirname($relativeTargetPath));
|
$parent = \Folder::find_or_make(dirname($relativeTargetPath));
|
||||||
|
$this->createdAssets[] = $parent->File->getValue();
|
||||||
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"',
|
||||||
@ -568,7 +571,10 @@ class FixtureContext extends BehatContext
|
|||||||
$relativeTargetPath,
|
$relativeTargetPath,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
AssetStore::CONFLICT_OVERWRITE
|
array(
|
||||||
|
'conflict' => AssetStore::CONFLICT_OVERWRITE,
|
||||||
|
'visibility' => AssetStore::VISIBILITY_PUBLIC
|
||||||
|
)
|
||||||
);
|
);
|
||||||
$data['FileFilename'] = $asset['Filename'];
|
$data['FileFilename'] = $asset['Filename'];
|
||||||
$data['FileHash'] = $asset['Hash'];
|
$data['FileHash'] = $asset['Hash'];
|
||||||
@ -583,6 +589,7 @@ class FixtureContext extends BehatContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->createdFilesPaths[] = $targetPath;
|
$this->createdFilesPaths[] = $targetPath;
|
||||||
|
$this->createdAssets[] = $data;
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user