mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Merge pull request #117 from open-sausages/pulls/4.0/namespace-orm
Update to support new namespace SilverStripe\ORM
This commit is contained in:
commit
6ea51d4f95
@ -7,6 +7,10 @@ use Behat\Behat\Context\BehatContext,
|
||||
Behat\Gherkin\Node\PyStringNode,
|
||||
Behat\Gherkin\Node\TableNode,
|
||||
SilverStripe\Filesystem\Storage\AssetStore;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\Versioning\Versioned;
|
||||
|
||||
|
||||
// PHPUnit
|
||||
require_once BASE_PATH . '/vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';
|
||||
@ -84,17 +88,17 @@ class FixtureContext extends BehatContext
|
||||
*/
|
||||
public function beforeDatabaseDefaults(ScenarioEvent $event) {
|
||||
\SapphireTest::empty_temp_db();
|
||||
\DB::getConn()->quiet();
|
||||
$dataClasses = \ClassInfo::subclassesFor('DataObject');
|
||||
DB::get_conn()->quiet();
|
||||
$dataClasses = \ClassInfo::subclassesFor('SilverStripe\\ORM\\DataObject');
|
||||
array_shift($dataClasses);
|
||||
foreach ($dataClasses as $dataClass) {
|
||||
\singleton($dataClass)->requireDefaultRecords();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @AfterScenario
|
||||
*/
|
||||
/**
|
||||
* @AfterScenario
|
||||
*/
|
||||
public function afterResetDatabase(ScenarioEvent $event) {
|
||||
\SapphireTest::empty_temp_db();
|
||||
}
|
||||
@ -295,7 +299,7 @@ class FixtureContext extends BehatContext
|
||||
else $field = "ID";
|
||||
|
||||
// Check if the fixture object exists - if not, we create it
|
||||
$obj = \DataObject::get($class)->filter($field, $value)->first();
|
||||
$obj = DataObject::get($class)->filter($field, $value)->first();
|
||||
if(!$obj) $obj = $this->fixtureFactory->createObject($class, $value);
|
||||
// If has_many or many_many, add this fixture object to the relation object
|
||||
// If has_one, set value to the joint field with this fixture object's ID
|
||||
@ -332,11 +336,11 @@ class FixtureContext extends BehatContext
|
||||
break;
|
||||
case 'not published':
|
||||
case 'unpublished':
|
||||
$oldMode = \Versioned::get_reading_mode();
|
||||
\Versioned::set_stage(\Versioned::LIVE);
|
||||
$oldMode = Versioned::get_reading_mode();
|
||||
Versioned::set_stage(Versioned::LIVE);
|
||||
$clone = clone $obj;
|
||||
$clone->delete();
|
||||
\Versioned::set_reading_mode($oldMode);
|
||||
Versioned::set_reading_mode($oldMode);
|
||||
break;
|
||||
case 'deleted':
|
||||
$obj->delete();
|
||||
@ -517,7 +521,7 @@ class FixtureContext extends BehatContext
|
||||
$date = date("Y-m-d H:i:s",strtotime($time));
|
||||
$table = \ClassInfo::baseDataClass(get_class($record));
|
||||
$field = ($mod == 'created') ? 'Created' : 'LastEdited';
|
||||
\DB::query(sprintf(
|
||||
DB::query(sprintf(
|
||||
'UPDATE "%s" SET "%s" = \'%s\' WHERE "ID" = \'%d\'',
|
||||
$table,
|
||||
$field,
|
||||
@ -525,8 +529,8 @@ class FixtureContext extends BehatContext
|
||||
$record->ID
|
||||
));
|
||||
// Support for Versioned extension, by checking for a "Live" stage
|
||||
if(\DB::getConn()->hasTable($table . '_Live')) {
|
||||
\DB::query(sprintf(
|
||||
if(DB::getConn()->hasTable($table . '_Live')) {
|
||||
DB::query(sprintf(
|
||||
'UPDATE "%s_Live" SET "%s" = \'%s\' WHERE "ID" = \'%d\'',
|
||||
$table,
|
||||
$field,
|
||||
@ -620,13 +624,15 @@ class FixtureContext extends BehatContext
|
||||
|
||||
// Try direct mapping
|
||||
$class = str_replace(' ', '', ucwords($type));
|
||||
if(class_exists($class) || !($class == 'DataObject' || is_subclass_of($class, 'DataObject'))) {
|
||||
return $class;
|
||||
if(class_exists($class) && is_subclass_of($class, 'SilverStripe\\ORM\\DataObject')) {
|
||||
return \ClassInfo::class_name($class);
|
||||
}
|
||||
|
||||
// Fall back to singular names
|
||||
foreach(array_values(\ClassInfo::subclassesFor('DataObject')) as $candidate) {
|
||||
if(singleton($candidate)->singular_name() == $type) return $candidate;
|
||||
foreach(array_values(\ClassInfo::subclassesFor('SilverStripe\\ORM\\DataObject')) as $candidate) {
|
||||
if(strcasecmp(singleton($candidate)->singular_name(), $type) === 0) {
|
||||
return $candidate;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
@ -639,9 +645,9 @@ class FixtureContext extends BehatContext
|
||||
* Updates an object with values, resolving aliases set through
|
||||
* {@link DataObject->fieldLabels()}.
|
||||
*
|
||||
* @param String Class name
|
||||
* @param Array Map of field names or aliases to their values.
|
||||
* @return Array Map of actual object properties to their values.
|
||||
* @param string $class Class name
|
||||
* @param array $fields Map of field names or aliases to their values.
|
||||
* @return array Map of actual object properties to their values.
|
||||
*/
|
||||
protected function convertFields($class, $fields) {
|
||||
$labels = singleton($class)->fieldLabels();
|
||||
|
@ -9,6 +9,8 @@ Behat\Behat\Context\Step,
|
||||
Behat\Behat\Exception\PendingException;
|
||||
use Behat\Gherkin\Node\PyStringNode,
|
||||
Behat\Gherkin\Node\TableNode;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
|
||||
// PHPUnit
|
||||
require_once BASE_PATH . '/vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';
|
||||
@ -86,7 +88,7 @@ class LoginContext extends BehatContext
|
||||
$permission->write();
|
||||
$group->Permissions()->add($permission);
|
||||
|
||||
$member = \DataObject::get_one('Member', sprintf('"Email" = \'%s\'', "$permCode@example.org"));
|
||||
$member = DataObject::get_one('Member', sprintf('"Email" = \'%s\'', "$permCode@example.org"));
|
||||
if (!$member) {
|
||||
$member = \Injector::inst()->create('Member');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user