silverstripe-cms/tests/controller/ContentControllerPermissionsTest.php

56 lines
1.6 KiB
PHP
Raw Normal View History

<?php
use SilverStripe\ORM\Versioning\Versioned;
2016-09-09 01:26:24 +02:00
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
/**
* @package cms
* @subpackage tests
*/
class ContentControllerPermissionsTest extends FunctionalTest {
2016-03-08 21:50:55 +01:00
protected $usesDatabase = true;
2016-03-08 21:50:55 +01:00
protected $autoFollowRedirection = false;
2016-03-08 21:50:55 +01:00
public function testCanViewStage() {
// Create a new page
$page = new Page();
$page->URLSegment = 'testpage';
$page->write();
2016-04-01 05:17:37 +02:00
$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");
2016-03-08 21:50:55 +01:00
$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');
2016-09-09 01:26:24 +02:00
} catch(HTTPResponse_Exception $responseException) {
$response = $responseException->getResponse();
}
// should redirect to login
$this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage');
$this->assertContains(
Config::inst()->get('SilverStripe\\Security\\Security', 'login_url'),
$response->getHeader('Location')
);
2016-03-08 21:50:55 +01:00
$this->logInWithPermission('CMS_ACCESS_CMSMain');
2016-03-08 21:50:55 +01:00
$response = $this->get('/testpage/?stage=Stage');
$this->assertEquals($response->getStatusCode(), 200, 'Doesnt redirect to login, but shows page for authenticated user');
}
2016-03-08 21:50:55 +01:00
}