silverstripe-subsites/tests/php/SubsiteXHRControllerTest.php

48 lines
1.5 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());
// 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-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
}