mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Save ParentID alongside first record write to avoid validation errors
This commit is contained in:
parent
4dece01c34
commit
7e8eaae73a
@ -197,22 +197,31 @@ class FixtureContext extends BehatContext
|
|||||||
*/
|
*/
|
||||||
public function stepUpdateRecordRelation($type, $id, $relation, $relationType, $relationId) {
|
public function stepUpdateRecordRelation($type, $id, $relation, $relationType, $relationId) {
|
||||||
$class = $this->convertTypeToClass($type);
|
$class = $this->convertTypeToClass($type);
|
||||||
|
|
||||||
$relationClass = $this->convertTypeToClass($relationType);
|
$relationClass = $this->convertTypeToClass($relationType);
|
||||||
|
|
||||||
$obj = $this->fixtureFactory->get($class, $id);
|
|
||||||
if(!$obj) $obj = $this->fixtureFactory->createObject($class, $id);
|
|
||||||
|
|
||||||
$relationObj = $this->fixtureFactory->get($relationClass, $relationId);
|
$relationObj = $this->fixtureFactory->get($relationClass, $relationId);
|
||||||
if(!$relationObj) $relationObj = $this->fixtureFactory->createObject($relationClass, $relationId);
|
if(!$relationObj) $relationObj = $this->fixtureFactory->createObject($relationClass, $relationId);
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
if($relation == 'child') {
|
||||||
|
$data['ParentID'] = $relationObj->ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
$obj = $this->fixtureFactory->get($class, $id);
|
||||||
|
if($obj) {
|
||||||
|
$obj->update($data);
|
||||||
|
$obj->write();
|
||||||
|
} else {
|
||||||
|
$obj = $this->fixtureFactory->createObject($class, $id, $data);
|
||||||
|
}
|
||||||
|
|
||||||
switch($relation) {
|
switch($relation) {
|
||||||
case 'parent':
|
case 'parent':
|
||||||
$relationObj->ParentID = $obj->ID;
|
$relationObj->ParentID = $obj->ID;
|
||||||
$relationObj->write();
|
$relationObj->write();
|
||||||
break;
|
break;
|
||||||
case 'child':
|
case 'child':
|
||||||
$obj->ParentID = $relationObj->ID;
|
// already written through $data above
|
||||||
$obj->write();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
|
Loading…
Reference in New Issue
Block a user