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

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@111961 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-12 21:42:45 +00:00
parent e09cc66e94
commit 79459d72ad
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"
);
}