2011-03-18 04:17:04 +01:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
|
|
|
use SilverStripe\ORM\Versioning\Versioned;
|
|
|
|
|
2011-03-18 04:17:04 +01:00
|
|
|
/**
|
2011-03-22 10:47:26 +01:00
|
|
|
* @package cms
|
2011-03-18 04:17:04 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2011-07-21 11:49:55 +02:00
|
|
|
class ContentControllerPermissionsTest extends FunctionalTest {
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:17:04 +01:00
|
|
|
protected $usesDatabase = true;
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:17:04 +01:00
|
|
|
protected $autoFollowRedirection = false;
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:17:04 +01:00
|
|
|
public function testCanViewStage() {
|
2013-07-04 04:54:13 +02:00
|
|
|
// Create a new page
|
2011-03-18 04:17:04 +01:00
|
|
|
$page = new Page();
|
|
|
|
$page->URLSegment = 'testpage';
|
|
|
|
$page->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2013-07-04 04:54:13 +02:00
|
|
|
|
|
|
|
// Add a stage-only version
|
|
|
|
$page->Content = "Version2";
|
|
|
|
$page->write();
|
|
|
|
|
2011-03-18 04:17:04 +01:00
|
|
|
$response = $this->get('/testpage');
|
2015-12-22 05:46:07 +01:00
|
|
|
$this->assertEquals($response->getStatusCode(), 200, "Doesn't require login for implicit live stage");
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:17:04 +01:00
|
|
|
$response = $this->get('/testpage/?stage=Live');
|
2015-12-22 05:46:07 +01:00
|
|
|
$this->assertEquals($response->getStatusCode(), 200, "Doesn't require login for explicit live stage");
|
|
|
|
|
|
|
|
try {
|
|
|
|
$response = $this->get('/testpage/?stage=Stage');
|
|
|
|
} catch(SS_HTTPResponse_Exception $responseException) {
|
|
|
|
$response = $responseException->getResponse();
|
|
|
|
}
|
2011-03-18 04:17:04 +01:00
|
|
|
// should redirect to login
|
2011-05-19 11:26:09 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage');
|
2013-01-29 17:31:25 +01:00
|
|
|
$this->assertContains(
|
2016-06-23 01:51:20 +02:00
|
|
|
Config::inst()->get('SilverStripe\\Security\\Security', 'login_url'),
|
2013-01-29 17:31:25 +01:00
|
|
|
$response->getHeader('Location')
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:17:04 +01:00
|
|
|
$this->logInWithPermission('CMS_ACCESS_CMSMain');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:17:04 +01:00
|
|
|
$response = $this->get('/testpage/?stage=Stage');
|
2011-07-21 11:49:55 +02:00
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Doesnt redirect to login, but shows page for authenticated user');
|
2011-03-18 04:17:04 +01:00
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
|
|
|
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|