2011-03-18 04:17:04 +01:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2017-08-09 04:53:38 +02:00
|
|
|
namespace SilverStripe\CMS\Tests\Controllers;
|
2017-08-09 03:25:12 +02:00
|
|
|
|
2017-03-21 05:26:46 +01:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2016-09-09 01:26:24 +02:00
|
|
|
use SilverStripe\Control\HTTPResponse_Exception;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
2018-05-04 03:04:18 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2017-08-09 03:25:12 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
class ContentControllerPermissionsTest extends FunctionalTest
|
|
|
|
{
|
|
|
|
protected $usesDatabase = true;
|
|
|
|
|
|
|
|
protected $autoFollowRedirection = false;
|
|
|
|
|
|
|
|
public function testCanViewStage()
|
|
|
|
{
|
|
|
|
// Create a new page
|
2018-05-04 03:04:18 +02:00
|
|
|
$page = new SiteTree();
|
2017-01-25 21:59:25 +01:00
|
|
|
$page->URLSegment = 'testpage';
|
|
|
|
$page->write();
|
|
|
|
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
|
|
|
|
|
|
|
// Add a stage-only version
|
|
|
|
$page->Content = "Version2";
|
|
|
|
$page->write();
|
|
|
|
|
|
|
|
$response = $this->get('/testpage');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, "Doesn't require login for implicit live stage");
|
|
|
|
|
|
|
|
$response = $this->get('/testpage/?stage=Live');
|
|
|
|
$this->assertEquals($response->getStatusCode(), 200, "Doesn't require login for explicit live stage");
|
|
|
|
|
|
|
|
try {
|
|
|
|
$response = $this->get('/testpage/?stage=Stage');
|
|
|
|
} catch (HTTPResponse_Exception $responseException) {
|
|
|
|
$response = $responseException->getResponse();
|
|
|
|
}
|
|
|
|
// should redirect to login
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
$response->getStatusCode(),
|
|
|
|
302,
|
|
|
|
'Redirects to login page when not logged in for draft stage'
|
|
|
|
);
|
2021-10-27 23:40:52 +02:00
|
|
|
$this->assertStringContainsString(
|
2017-01-25 21:59:25 +01:00
|
|
|
Config::inst()->get('SilverStripe\\Security\\Security', 'login_url'),
|
|
|
|
$response->getHeader('Location')
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->logInWithPermission('CMS_ACCESS_CMSMain');
|
|
|
|
|
|
|
|
$response = $this->get('/testpage/?stage=Stage');
|
2018-05-04 03:04:18 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
$response->getStatusCode(),
|
|
|
|
200,
|
|
|
|
'Doesnt redirect to login, but shows page for authenticated user'
|
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|