2011-03-18 04:17:04 +01:00
|
|
|
<?php
|
|
|
|
/**
|
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 {
|
2011-03-18 04:17:04 +01:00
|
|
|
|
|
|
|
protected $usesDatabase = true;
|
|
|
|
|
|
|
|
protected $autoFollowRedirection = false;
|
|
|
|
|
|
|
|
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();
|
|
|
|
$page->publish('Stage', '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");
|
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-01-06 00:42:07 +01:00
|
|
|
Config::inst()->get('Security', 'login_url'),
|
2013-01-29 17:31:25 +01:00
|
|
|
$response->getHeader('Location')
|
|
|
|
);
|
2011-03-18 04:17:04 +01:00
|
|
|
|
|
|
|
$this->logInWithPermission('CMS_ACCESS_CMSMain');
|
|
|
|
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|