mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
API Update for filesystem refactor
This commit is contained in:
parent
2a1e1e29d6
commit
15b491ed74
@ -32,7 +32,7 @@
|
|||||||
"symfony/yaml": "~2.0",
|
"symfony/yaml": "~2.0",
|
||||||
"symfony/finder": "~2.0",
|
"symfony/finder": "~2.0",
|
||||||
"silverstripe/testsession": "*",
|
"silverstripe/testsession": "*",
|
||||||
"silverstripe/framework": ">=3.1.0"
|
"silverstripe/framework": "^4.0.0"
|
||||||
},
|
},
|
||||||
|
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
@ -2,13 +2,10 @@
|
|||||||
|
|
||||||
namespace SilverStripe\BehatExtension\Context;
|
namespace SilverStripe\BehatExtension\Context;
|
||||||
|
|
||||||
use Behat\Behat\Context\ClosuredContextInterface,
|
use Behat\Behat\Context\BehatContext,
|
||||||
Behat\Behat\Context\TranslatedContextInterface,
|
|
||||||
Behat\Behat\Context\BehatContext,
|
|
||||||
Behat\Behat\Context\Step,
|
Behat\Behat\Context\Step,
|
||||||
Behat\Behat\Event\StepEvent,
|
Behat\Behat\Event\StepEvent,
|
||||||
Behat\Behat\Event\ScenarioEvent,
|
Behat\Behat\Event\ScenarioEvent;
|
||||||
Behat\Behat\Exception\PendingException;
|
|
||||||
|
|
||||||
use Behat\Mink\Driver\Selenium2Driver;
|
use Behat\Mink\Driver\Selenium2Driver;
|
||||||
|
|
||||||
@ -268,8 +265,9 @@ JS;
|
|||||||
*/
|
*/
|
||||||
public function cleanAssetsAfterScenario(ScenarioEvent $event) {
|
public function cleanAssetsAfterScenario(ScenarioEvent $event) {
|
||||||
foreach(\File::get() as $file) {
|
foreach(\File::get() as $file) {
|
||||||
if(file_exists($file->getFullPath())) $file->delete();
|
$file->delete();
|
||||||
}
|
}
|
||||||
|
\Filesystem::removeFolder(ASSETS_PATH, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function takeScreenshot(StepEvent $event) {
|
public function takeScreenshot(StepEvent $event) {
|
||||||
|
@ -2,17 +2,11 @@
|
|||||||
|
|
||||||
namespace SilverStripe\BehatExtension\Context;
|
namespace SilverStripe\BehatExtension\Context;
|
||||||
|
|
||||||
use Behat\Behat\Context\ClosuredContextInterface,
|
use Behat\Behat\Context\BehatContext,
|
||||||
Behat\Behat\Context\TranslatedContextInterface,
|
|
||||||
Behat\Behat\Context\BehatContext,
|
|
||||||
Behat\Behat\Context\Step,
|
|
||||||
Behat\Behat\Event\StepEvent,
|
|
||||||
Behat\Behat\Event\FeatureEvent,
|
|
||||||
Behat\Behat\Event\ScenarioEvent,
|
Behat\Behat\Event\ScenarioEvent,
|
||||||
Behat\Behat\Exception\PendingException,
|
|
||||||
Behat\Mink\Driver\Selenium2Driver,
|
|
||||||
Behat\Gherkin\Node\PyStringNode,
|
Behat\Gherkin\Node\PyStringNode,
|
||||||
Behat\Gherkin\Node\TableNode;
|
Behat\Gherkin\Node\TableNode,
|
||||||
|
SilverStripe\Filesystem\Storage\AssetStore;
|
||||||
|
|
||||||
// PHPUnit
|
// PHPUnit
|
||||||
require_once 'PHPUnit/Autoload.php';
|
require_once 'PHPUnit/Autoload.php';
|
||||||
@ -548,13 +542,13 @@ class FixtureContext extends BehatContext
|
|||||||
protected function prepareAsset($class, $identifier, $data = null) {
|
protected function prepareAsset($class, $identifier, $data = null) {
|
||||||
if(!$data) $data = array();
|
if(!$data) $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);
|
||||||
$targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath);
|
|
||||||
$sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath));
|
$sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath));
|
||||||
|
|
||||||
// Create file or folder on filesystem
|
// Create file or folder on filesystem
|
||||||
|
$parent = \Folder::find_or_make(dirname($relativeTargetPath));
|
||||||
if($class == 'Folder' || is_subclass_of($class, 'Folder')) {
|
if($class == 'Folder' || is_subclass_of($class, 'Folder')) {
|
||||||
$parent = \Folder::find_or_make($relativeTargetPath);
|
$targetPath = $this->joinPaths(ASSETS_PATH, $relativeTargetPath);
|
||||||
} else {
|
} else {
|
||||||
if(!file_exists($sourcePath)) {
|
if(!file_exists($sourcePath)) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
@ -563,18 +557,43 @@ class FixtureContext extends BehatContext
|
|||||||
$sourcePath
|
$sourcePath
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
$parent = \Folder::find_or_make(dirname($relativeTargetPath));
|
// Load file into APL and retrieve tuple
|
||||||
copy($sourcePath, $targetPath);
|
$asset = $this->getAssetStore()->setFromLocalFile(
|
||||||
|
$sourcePath,
|
||||||
|
$relativeTargetPath,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
AssetStore::CONFLICT_OVERWRITE
|
||||||
|
);
|
||||||
|
$data['FileFilename'] = $asset['Filename'];
|
||||||
|
$data['FileHash'] = $asset['Hash'];
|
||||||
|
$data['FileVariant'] = $asset['Variant'];
|
||||||
|
|
||||||
|
// Strip base from url to get dir relative to base
|
||||||
|
$url = $this->getAssetStore()->getAsURL($asset['Filename'], $asset['Hash'], $asset['Variant']);
|
||||||
|
$targetPath = $this->joinPaths(BASE_PATH, substr($url, strlen(\Director::baseURL())));
|
||||||
|
}
|
||||||
|
unset($data['Filename']);
|
||||||
|
if(!isset($data['Name'])) {
|
||||||
|
$data['Name'] = basename($relativeTargetPath);
|
||||||
|
}
|
||||||
|
if($parent) {
|
||||||
|
$data['ParentID'] = $parent->ID;
|
||||||
}
|
}
|
||||||
$data['Filename'] = $this->joinPaths(ASSETS_DIR, $relativeTargetPath);
|
|
||||||
if(!isset($data['Name'])) $data['Name'] = basename($relativeTargetPath);
|
|
||||||
if($parent) $data['ParentID'] = $parent->ID;
|
|
||||||
|
|
||||||
$this->createdFilesPaths[] = $targetPath;
|
$this->createdFilesPaths[] = $targetPath;
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return AssetStore
|
||||||
|
*/
|
||||||
|
protected function getAssetStore() {
|
||||||
|
return singleton('AssetStore');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a natural language class description to an actual class name.
|
* Converts a natural language class description to an actual class name.
|
||||||
* Respects {@link DataObject::$singular_name} variations.
|
* Respects {@link DataObject::$singular_name} variations.
|
||||||
|
Loading…
Reference in New Issue
Block a user