2009-05-06 08:36:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class VersionedTest extends SapphireTest {
|
|
|
|
static $fixture_file = 'sapphire/tests/model/VersionedTest.yml';
|
2010-01-13 00:16:14 +01:00
|
|
|
|
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'VersionedTest_DataObject',
|
|
|
|
);
|
2009-05-06 08:36:16 +02:00
|
|
|
|
2009-05-27 02:09:23 +02:00
|
|
|
function testForceChangeUpdatesVersion() {
|
2010-03-16 23:08:33 +01:00
|
|
|
$obj = new VersionedTest_DataObject();
|
|
|
|
$obj->Name = "test";
|
|
|
|
$obj->write();
|
|
|
|
|
|
|
|
$oldVersion = $obj->Version;
|
|
|
|
$obj->forceChange();
|
|
|
|
$obj->write();
|
2009-05-27 02:09:23 +02:00
|
|
|
|
|
|
|
$this->assertTrue(
|
2010-03-16 23:08:33 +01:00
|
|
|
($obj->Version > $oldVersion),
|
2009-05-27 02:09:23 +02:00
|
|
|
"A object Version is increased when just calling forceChange() without any other changes"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-05-06 08:36:16 +02:00
|
|
|
/**
|
|
|
|
* Test Versioned::get_including_deleted()
|
|
|
|
*/
|
|
|
|
function testGetIncludingDeleted() {
|
|
|
|
// Delete a page
|
|
|
|
$this->objFromFixture('Page', 'page3')->delete();
|
|
|
|
|
|
|
|
// Get all items, ignoring deleted
|
2009-09-30 23:54:49 +02:00
|
|
|
$remainingPages = DataObject::get("SiteTree", "\"ParentID\" = 0", "\"SiteTree\".\"ID\" ASC");
|
2009-05-06 08:36:16 +02:00
|
|
|
// Check that page 3 has gone
|
2009-05-14 07:26:47 +02:00
|
|
|
$this->assertNotNull($remainingPages);
|
2009-05-06 08:36:16 +02:00
|
|
|
$this->assertEquals(array("Page 1", "Page 2"), $remainingPages->column('Title'));
|
|
|
|
|
|
|
|
// Get all including deleted
|
2009-09-30 23:54:49 +02:00
|
|
|
$allPages = Versioned::get_including_deleted("SiteTree", "\"ParentID\" = 0", "\"SiteTree\".\"ID\" ASC");
|
2009-05-06 08:36:16 +02:00
|
|
|
// Check that page 3 is still there
|
|
|
|
$this->assertEquals(array("Page 1", "Page 2", "Page 3"), $allPages->column('Title'));
|
|
|
|
|
|
|
|
// Check that this still works if we switch to reading the other stage
|
|
|
|
Versioned::reading_stage("Live");
|
2009-09-30 23:54:49 +02:00
|
|
|
$allPages = Versioned::get_including_deleted("SiteTree", "\"ParentID\" = 0", "\"SiteTree\".\"ID\" ASC");
|
2009-05-06 08:36:16 +02:00
|
|
|
$this->assertEquals(array("Page 1", "Page 2", "Page 3"), $allPages->column('Title'));
|
|
|
|
|
|
|
|
}
|
2009-06-22 04:42:42 +02:00
|
|
|
|
|
|
|
function testVersionedFieldsAdded() {
|
|
|
|
$obj = new VersionedTest_DataObject();
|
|
|
|
// Check that the Version column is added as a full-fledged column
|
|
|
|
$this->assertType('Int', $obj->dbObject('Version'));
|
|
|
|
|
|
|
|
$obj2 = new VersionedTest_Subclass();
|
|
|
|
// Check that the Version column is added as a full-fledged column
|
|
|
|
$this->assertType('Int', $obj2->dbObject('Version'));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-01-13 00:16:14 +01:00
|
|
|
class VersionedTest_DataObject extends DataObject implements TestOnly {
|
2009-06-22 04:42:42 +02:00
|
|
|
static $db = array(
|
|
|
|
"Name" => "Varchar",
|
|
|
|
);
|
|
|
|
|
|
|
|
static $extensions = array(
|
|
|
|
"Versioned('Stage', 'Live')"
|
|
|
|
);
|
|
|
|
}
|
2009-05-06 08:36:16 +02:00
|
|
|
|
2010-01-13 00:16:14 +01:00
|
|
|
class VersionedTest_Subclass extends VersionedTest_DataObject implements TestOnly {
|
2009-06-22 04:42:42 +02:00
|
|
|
static $db = array(
|
|
|
|
"ExtraField" => "Varchar",
|
|
|
|
);
|
|
|
|
}
|