BUGFIX: Ensure that Versioned works on classes with underscores in the names. (from r100905)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@101153 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-03-16 22:08:33 +00:00
parent f3a666b89f
commit f2bb6baa9f
2 changed files with 15 additions and 8 deletions

View File

@ -410,9 +410,13 @@ class Versioned extends DataObjectDecorator {
* @return boolean Returns false if the field isn't in the table, true otherwise
*/
function hasVersionField($table) {
$tableParts = explode('_',$table);
return ('DataObject' == get_parent_class($tableParts[0]));
$rPos = strrpos($table,'_');
if(($rPos !== false) && in_array(substr($table,$rPos), $this->stages)) {
$tableWithoutStage = substr($table,0,$rPos);
} else {
$tableWithoutStage = $table;
}
return ('DataObject' == get_parent_class($tableWithoutStage));
}
function extendWithSuffix($table) {
foreach (Versioned::$versionableExtensions as $versionableExtension => $suffixes) {

View File

@ -8,13 +8,16 @@ class VersionedTest extends SapphireTest {
);
function testForceChangeUpdatesVersion() {
$page = $this->objFromFixture('Page', 'page3');
$oldVersion = $page->Version;
$page->forceChange();
$page->write();
$obj = new VersionedTest_DataObject();
$obj->Name = "test";
$obj->write();
$oldVersion = $obj->Version;
$obj->forceChange();
$obj->write();
$this->assertTrue(
($page->Version > $oldVersion),
($obj->Version > $oldVersion),
"A object Version is increased when just calling forceChange() without any other changes"
);
}