silverstripe-subsites/tests/php/SubsiteXHRControllerTest.php

47 lines
1.4 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\Dev\FunctionalTest;
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
$this->logOut();
$result = $this->get('admin/subsite_xhr', null, [
2017-06-01 15:57:53 +02:00
'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('admin/subsite_xhr', null, [
2017-06-01 15:57:53 +02:00
'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('admin/subsite_xhr', null, [
2017-06-01 15:57:53 +02:00
'X-Pjax' => 'SubsiteList',
'X-Requested-With' => 'XMLHttpRequest'
]);
2017-06-01 15:57:53 +02:00
$this->assertEquals(200, $result->getStatusCode());
$this->assertEquals('text/json', $result->getHeader('Content-Type'));
2017-06-01 15:57:53 +02:00
$body = $result->getBody();
$this->assertContains('Main site', $body);
$this->assertContains('Test 1', $body);
$this->assertContains('Test 2', $body);
$this->assertContains('Test 3', $body);
2017-06-01 15:57:53 +02:00
}
2017-05-29 13:42:42 +02:00
}