silverstripe-subsites/tests/php/SubsiteXHRControllerTest.php

51 lines
1.6 KiB
PHP
Raw Normal View History

2017-05-29 13:42:42 +02:00
<?php
namespace SilverStripe\Subsites\Tests;
2017-05-29 13:42:42 +02:00
use SilverStripe\Control\Session;
use SilverStripe\Dev\FunctionalTest;
/**
* Created by PhpStorm.
* User: dmooyman
* Date: 27/05/16
* Time: 3:10 PM
*/
class SubsiteXHRControllerTest extends FunctionalTest
{
2017-06-01 15:57:53 +02:00
protected static $fixture_file = 'SubsiteTest.yml';
2017-05-29 13:42:42 +02:00
2017-06-01 15:57:53 +02:00
public function testCanView()
{
// Test unauthenticated access
Session::clear('MemberID');
$result = $this->get('SubsiteXHRController', null, [
'X-Pjax' => 'SubsiteList',
'X-Requested-With' => 'XMLHttpRequest'
]);
$this->assertEquals(403, $result->getStatusCode());
2017-05-29 13:42:42 +02:00
2017-06-01 15:57:53 +02:00
// Login with NO permissions
$this->logInWithPermission('NOT_CMS_PERMISSION');
$result = $this->get('SubsiteXHRController', null, [
'X-Pjax' => 'SubsiteList',
'X-Requested-With' => 'XMLHttpRequest'
]);
$this->assertEquals(403, $result->getStatusCode());
2017-05-29 13:42:42 +02:00
2017-06-01 15:57:53 +02:00
// Test cms user
$this->logInWithPermission('CMS_ACCESS_CMSMain');
$result = $this->get('SubsiteXHRController', null, [
'X-Pjax' => 'SubsiteList',
'X-Requested-With' => 'XMLHttpRequest'
]);
$this->assertEquals(200, $result->getStatusCode());
$this->assertEquals('text/json', $result->getHeader('Content-Type'));
$body = $result->getBody();
static::assertContains('Main site', $body);
static::assertContains('Test 1', $body);
static::assertContains('Test 2', $body);
static::assertContains('Test 3', $body);
}
2017-05-29 13:42:42 +02:00
}