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