From 5728f8aabeb945bab17c08af95d7d65144cca085 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 24 Feb 2016 00:03:54 +1300 Subject: [PATCH] Fix SS4 AssetStore compat in FixtureContext Correctly create published files, and delete them via the AssetStore API rather than unlink() --- .../BehatExtension/Context/FixtureContext.php | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/SilverStripe/BehatExtension/Context/FixtureContext.php b/src/SilverStripe/BehatExtension/Context/FixtureContext.php index e365e8b..73dc127 100644 --- a/src/SilverStripe/BehatExtension/Context/FixtureContext.php +++ b/src/SilverStripe/BehatExtension/Context/FixtureContext.php @@ -36,6 +36,11 @@ class FixtureContext extends BehatContext */ protected $createdFilesPaths = array(); + /** + * @var array Stores the asset tuples. + */ + protected $createdAssets = array(); + public function __construct(array $parameters) { $this->context = $parameters; } @@ -99,14 +104,10 @@ class FixtureContext extends BehatContext * @AfterScenario */ public function afterResetAssets(ScenarioEvent $event) { - if (is_array($this->createdFilesPaths)) { - $createdFiles = array_reverse($this->createdFilesPaths); - foreach ($createdFiles as $path) { - if (is_dir($path)) { - \Filesystem::removeFolder($path); - } else { - @unlink($path); - } + $store = $this->getAssetStore(); + if (is_array($this->createdAssets)) { + foreach ($this->createdAssets as $asset) { + $store->delete($asset['Filename'], $asset['Hash']); } } } @@ -551,8 +552,10 @@ class FixtureContext extends BehatContext $parent = \Folder::find_or_make($relativeTargetPath); $targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath); $data['ID'] = $parent->ID; + $this->createdAssets[] = $parent->File->getValue(); } else { $parent = \Folder::find_or_make(dirname($relativeTargetPath)); + $this->createdAssets[] = $parent->File->getValue(); if(!file_exists($sourcePath)) { throw new \InvalidArgumentException(sprintf( 'Source file for "%s" cannot be found in "%s"', @@ -568,7 +571,10 @@ class FixtureContext extends BehatContext $relativeTargetPath, null, null, - AssetStore::CONFLICT_OVERWRITE + array( + 'conflict' => AssetStore::CONFLICT_OVERWRITE, + 'visibility' => AssetStore::VISIBILITY_PUBLIC + ) ); $data['FileFilename'] = $asset['Filename']; $data['FileHash'] = $asset['Hash']; @@ -583,6 +589,7 @@ class FixtureContext extends BehatContext } $this->createdFilesPaths[] = $targetPath; + $this->createdAssets[] = $data; return $data; }