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\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());
|
2018-08-19 23:19:52 +02:00
|
|
|
// SilverStripe 4.0-4.2: text/json. >=4.3: application/json
|
2021-10-27 07:24:03 +02:00
|
|
|
$this->assertStringContainsString('json', $result->getHeader('Content-Type'));
|
2017-08-30 05:29:13 +02:00
|
|
|
|
2017-06-01 15:57:53 +02:00
|
|
|
$body = $result->getBody();
|
2021-10-27 07:24:03 +02:00
|
|
|
$this->assertStringContainsString('Main site', $body);
|
|
|
|
$this->assertStringContainsString('Test 1', $body);
|
|
|
|
$this->assertStringContainsString('Test 2', $body);
|
|
|
|
$this->assertStringContainsString('Test 3', $body);
|
2017-06-01 15:57:53 +02:00
|
|
|
}
|
2017-05-29 13:42:42 +02:00
|
|
|
}
|