mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #4220 from gregsmirnov/pulls/fix-setting-Page-LastEdited-from-fixture-2
BUG Fixed setting LastEdited for DataObject with class ancestry
This commit is contained in:
commit
d43115e320
@ -183,14 +183,8 @@ class FixtureBlueprint {
|
|||||||
|
|
||||||
// If LastEdited was set in the fixture, set it here
|
// If LastEdited was set in the fixture, set it here
|
||||||
if($data && array_key_exists('LastEdited', $data)) {
|
if($data && array_key_exists('LastEdited', $data)) {
|
||||||
$edited = $this->parseValue($data['LastEdited'], $fixtures);
|
$this->overrideField($obj, 'LastEdited', $data['LastEdited'], $fixtures);
|
||||||
DB::manipulate(array(
|
}
|
||||||
$class => array(
|
|
||||||
"command" => "update", "id" => $obj->id,
|
|
||||||
"fields" => array("LastEdited" => "'".$edited."'")
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
Config::inst()->update('DataObject', 'validation_enabled', $validationenabled);
|
Config::inst()->update('DataObject', 'validation_enabled', $validationenabled);
|
||||||
throw $e;
|
throw $e;
|
||||||
@ -288,4 +282,17 @@ class FixtureBlueprint {
|
|||||||
$obj->$name = $this->parseValue($value, $fixtures);
|
$obj->$name = $this->parseValue($value, $fixtures);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function overrideField($obj, $fieldName, $value, $fixtures = null) {
|
||||||
|
$table = ClassInfo::table_for_object_field(get_class($obj), $fieldName);
|
||||||
|
$value = $this->parseValue($value, $fixtures);
|
||||||
|
|
||||||
|
DB::manipulate(array(
|
||||||
|
$table => array(
|
||||||
|
"command" => "update", "id" => $obj->ID,
|
||||||
|
"fields" => array($fieldName => is_string($value) ? "'$value'" : $value)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$obj->$fieldName = $value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -9,7 +9,9 @@ class FixtureBlueprintTest extends SapphireTest {
|
|||||||
|
|
||||||
protected $extraDataObjects = array(
|
protected $extraDataObjects = array(
|
||||||
'FixtureFactoryTest_DataObject',
|
'FixtureFactoryTest_DataObject',
|
||||||
'FixtureFactoryTest_DataObjectRelation'
|
'FixtureFactoryTest_DataObjectRelation',
|
||||||
|
'FixtureBlueprintTest_SiteTree',
|
||||||
|
'FixtureBlueprintTest_Page'
|
||||||
);
|
);
|
||||||
|
|
||||||
public function testCreateWithRelationshipExtraFields() {
|
public function testCreateWithRelationshipExtraFields() {
|
||||||
@ -180,6 +182,40 @@ class FixtureBlueprintTest extends SapphireTest {
|
|||||||
$this->assertEquals(99, $obj->ID);
|
$this->assertEquals(99, $obj->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCreateWithLastEdited() {
|
||||||
|
$extpectedDate = '2010-12-14 16:18:20';
|
||||||
|
$blueprint = new FixtureBlueprint('FixtureFactoryTest_DataObject');
|
||||||
|
$obj = $blueprint->createObject('lastedited', array('LastEdited' => $extpectedDate));
|
||||||
|
$this->assertNotNull($obj);
|
||||||
|
$this->assertEquals($extpectedDate, $obj->LastEdited);
|
||||||
|
|
||||||
|
$obj = FixtureFactoryTest_DataObject::get()->byID($obj->ID);
|
||||||
|
$this->assertEquals($extpectedDate, $obj->LastEdited);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateWithClassAncestry() {
|
||||||
|
$data = array(
|
||||||
|
'Title' => 'My Title',
|
||||||
|
'Created' => '2010-12-14 16:18:20',
|
||||||
|
'LastEdited' => '2010-12-14 16:18:20',
|
||||||
|
'PublishDate' => '2015-12-09 06:03:00'
|
||||||
|
);
|
||||||
|
$blueprint = new FixtureBlueprint('FixtureBlueprintTest_Article');
|
||||||
|
$obj = $blueprint->createObject('home', $data);
|
||||||
|
$this->assertNotNull($obj);
|
||||||
|
$this->assertEquals($data['Title'], $obj->Title);
|
||||||
|
$this->assertEquals($data['Created'], $obj->Created);
|
||||||
|
$this->assertEquals($data['LastEdited'], $obj->LastEdited);
|
||||||
|
$this->assertEquals($data['PublishDate'], $obj->PublishDate);
|
||||||
|
|
||||||
|
$obj = FixtureBlueprintTest_Article::get()->byID($obj->ID);
|
||||||
|
$this->assertNotNull($obj);
|
||||||
|
$this->assertEquals($data['Title'], $obj->Title);
|
||||||
|
$this->assertEquals($data['Created'], $obj->Created);
|
||||||
|
$this->assertEquals($data['LastEdited'], $obj->LastEdited);
|
||||||
|
$this->assertEquals($data['PublishDate'], $obj->PublishDate);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCallbackOnBeforeCreate() {
|
public function testCallbackOnBeforeCreate() {
|
||||||
$blueprint = new FixtureBlueprint('FixtureFactoryTest_DataObject');
|
$blueprint = new FixtureBlueprint('FixtureFactoryTest_DataObject');
|
||||||
$this->_called = 0;
|
$this->_called = 0;
|
||||||
@ -231,4 +267,33 @@ class FixtureBlueprintTest extends SapphireTest {
|
|||||||
$this->assertEquals('Override Name', $obj2->Name);
|
$this->assertEquals('Override Name', $obj2->Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package framework
|
||||||
|
* @subpackage tests
|
||||||
|
*/
|
||||||
|
class FixtureBlueprintTest_SiteTree extends DataObject implements TestOnly {
|
||||||
|
|
||||||
|
private static $db = array(
|
||||||
|
"Title" => "Varchar"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package framework
|
||||||
|
* @subpackage tests
|
||||||
|
*/
|
||||||
|
class FixtureBlueprintTest_Page extends FixtureBlueprintTest_SiteTree {
|
||||||
|
|
||||||
|
private static $db = array(
|
||||||
|
'PublishDate' => 'SS_DateTime'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package framework
|
||||||
|
* @subpackage tests
|
||||||
|
*/
|
||||||
|
class FixtureBlueprintTest_Article extends FixtureBlueprintTest_Page {
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user