BUG Fix regression in canViewStage

This commit is contained in:
Damian Mooyman 2015-12-09 14:53:21 +13:00
parent 1eda9151a4
commit fa0160a874
2 changed files with 36 additions and 2 deletions

View File

@ -815,7 +815,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
$oldMode = Versioned::get_reading_mode(); $oldMode = Versioned::get_reading_mode();
Versioned::reading_stage($stage); Versioned::reading_stage($stage);
$versionFromStage = DataObject::get($this->class)->byID($this->ID); $versionFromStage = DataObject::get($this->owner->class)->byID($this->owner->ID);
Versioned::set_reading_mode($oldMode); Versioned::set_reading_mode($oldMode);
return $versionFromStage ? $versionFromStage->canView($member) : false; return $versionFromStage ? $versionFromStage->canView($member) : false;

View File

@ -33,7 +33,7 @@ class VersionedTest extends SapphireTest {
'VersionedTest_WithIndexes_Live' => 'VersionedTest_WithIndexes_Live' =>
array('value' => false, 'message' => 'Unique indexes are no longer unique in _Live table'), array('value' => false, 'message' => 'Unique indexes are no longer unique in _Live table'),
); );
// Test each table's performance // Test each table's performance
foreach ($tableExpectations as $tableName => $expectation) { foreach ($tableExpectations as $tableName => $expectation) {
$indexes = DB::get_schema()->indexList($tableName); $indexes = DB::get_schema()->indexList($tableName);
@ -800,6 +800,40 @@ class VersionedTest extends SapphireTest {
$this->assertTrue($public2->canView()); $this->assertTrue($public2->canView());
$this->assertTrue($private->canView()); $this->assertTrue($private->canView());
} }
public function testCanViewStage() {
$public = $this->objFromFixture('VersionedTest_PublicStage', 'public1');
$private = $this->objFromFixture('VersionedTest_DataObject', 'page1');
Session::clear("loggedInAs");
Versioned::reading_stage('Stage');
// Test that all (and only) public pages are viewable in stage mode
// Unpublished records are not viewable in live regardless of permissions
$this->assertTrue($public->canViewStage('Stage'));
$this->assertFalse($private->canViewStage('Stage'));
$this->assertFalse($public->canViewStage('Live'));
$this->assertFalse($private->canViewStage('Live'));
// Writing records to live should make both stage and live modes viewable
$private->publish("Stage", "Live");
$public->publish("Stage", "Live");
$this->assertTrue($public->canViewStage('Stage'));
$this->assertTrue($private->canViewStage('Stage'));
$this->assertTrue($public->canViewStage('Live'));
$this->assertTrue($private->canViewStage('Live'));
// If the draft mode changes, the live mode remains public, although the updated
// draft mode is secured for non-public records.
$private->Title = 'Secret Title';
$private->write();
$public->Title = 'Public Title';
$public->write();
$this->assertTrue($public->canViewStage('Stage'));
$this->assertFalse($private->canViewStage('Stage'));
$this->assertTrue($public->canViewStage('Live'));
$this->assertTrue($private->canViewStage('Live'));
}
} }