2017-05-29 13:42:42 +02:00
|
|
|
<?php
|
|
|
|
|
2017-04-23 22:23:34 +02:00
|
|
|
namespace SilverStripe\Subsites\Tests;
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\Control\Session;
|
|
|
|
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
|
2017-08-29 07:22:32 +02:00
|
|
|
$this->logOut();
|
|
|
|
|
2017-08-30 05:29:13 +02:00
|
|
|
$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');
|
2017-08-30 05:29:13 +02:00
|
|
|
$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');
|
2017-08-30 05:29:13 +02:00
|
|
|
$result = $this->get('admin/subsite_xhr', null, [
|
2017-06-01 15:57:53 +02:00
|
|
|
'X-Pjax' => 'SubsiteList',
|
|
|
|
'X-Requested-With' => 'XMLHttpRequest'
|
|
|
|
]);
|
2017-08-30 05:29:13 +02:00
|
|
|
|
2017-06-01 15:57:53 +02:00
|
|
|
$this->assertEquals(200, $result->getStatusCode());
|
|
|
|
$this->assertEquals('text/json', $result->getHeader('Content-Type'));
|
2017-08-30 05:29:13 +02:00
|
|
|
|
2017-06-01 15:57:53 +02:00
|
|
|
$body = $result->getBody();
|
2017-08-29 07:30:22 +02:00
|
|
|
$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
|
|
|
}
|