From e4ca69dc3f3d987d92f36e963f5c9887018cc357 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 24 Aug 2009 07:35:05 +0000 Subject: [PATCH] BUGFIX #4463: Set AuthorID and PublisherID correctly git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@85086 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/Versioned.php | 2 +- tests/SiteTreeTest.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/core/model/Versioned.php b/core/model/Versioned.php index 9b62dc4cd..2d083730d 100755 --- a/core/model/Versioned.php +++ b/core/model/Versioned.php @@ -309,7 +309,7 @@ class Versioned extends DataObjectDecorator { foreach($tables as $table) { $baseDataClass = ClassInfo::baseDataClass($table); - $isRootClass = ($this->owner->class == ClassInfo::baseDataClass($this->owner->class)); + $isRootClass = ($table == $baseDataClass); // Make sure that the augmented write is being applied to a table that can be versioned if( !$this->canBeVersioned($table) ) { diff --git a/tests/SiteTreeTest.php b/tests/SiteTreeTest.php index 9247b79ab..1613f64db 100644 --- a/tests/SiteTreeTest.php +++ b/tests/SiteTreeTest.php @@ -305,6 +305,38 @@ class SiteTreeTest extends SapphireTest { $this->assertFalse($product4->canEdit($editor)); } + function testAuthorIDAndPublisherIDFilledOutOnPublish() { + // Ensure that we have a member ID who is doing all this work + $member = Member::currentUser(); + if($member) { + $memberID = $member->ID; + } else { + $memberID = $this->idFromFixture("Member", "admin"); + Session::set("loggedInAs", $memberID); + } + + // Write the page + $about = $this->objFromFixture('Page','about'); + $about->Title = "Another title"; + $about->write(); + + // Check the version created + $savedVersion = DB::query("SELECT AuthorID, PublisherID FROM SiteTree_versions + WHERE RecordID = $about->ID ORDER BY Version DESC LIMIT 1")->record(); + $this->assertEquals($memberID, $savedVersion['AuthorID']); + $this->assertEquals(0, $savedVersion['PublisherID']); + + // Publish the page + $about->doPublish(); + $publishedVersion = DB::query("SELECT AuthorID, PublisherID FROM SiteTree_versions + WHERE RecordID = $about->ID ORDER BY Version DESC LIMIT 1")->record(); + + // Check the version created + $this->assertEquals($memberID, $publishedVersion['AuthorID']); + $this->assertEquals($memberID, $publishedVersion['PublisherID']); + + } + } // We make these extend page since that's what all page types are expected to do