SubsiteXHRControllerTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testCanView() 0 35 1
1
<?php
2
3
namespace SilverStripe\Subsites\Tests;
4
5
use SilverStripe\Dev\FunctionalTest;
6
7
class SubsiteXHRControllerTest extends FunctionalTest
8
{
9
    protected static $fixture_file = 'SubsiteTest.yml';
10
11
    public function testCanView()
12
    {
13
        // Test unauthenticated access
14
        $this->logOut();
15
16
        $result = $this->get('admin/subsite_xhr', null, [
17
            'X-Pjax' => 'SubsiteList',
18
            'X-Requested-With' => 'XMLHttpRequest'
19
        ]);
20
        $this->assertEquals(403, $result->getStatusCode());
21
22
        // Login with NO permissions
23
        $this->logInWithPermission('NOT_CMS_PERMISSION');
24
        $result = $this->get('admin/subsite_xhr', null, [
25
            'X-Pjax' => 'SubsiteList',
26
            'X-Requested-With' => 'XMLHttpRequest'
27
        ]);
28
        $this->assertEquals(403, $result->getStatusCode());
29
30
        // Test cms user
31
        $this->logInWithPermission('CMS_ACCESS_CMSMain');
32
        $result = $this->get('admin/subsite_xhr', null, [
33
            'X-Pjax' => 'SubsiteList',
34
            'X-Requested-With' => 'XMLHttpRequest'
35
        ]);
36
37
        $this->assertEquals(200, $result->getStatusCode());
38
        // SilverStripe 4.0-4.2: text/json. >=4.3: application/json
39
        $this->assertContains('json', $result->getHeader('Content-Type'));
40
41
        $body = $result->getBody();
42
        $this->assertContains('Main site', $body);
43
        $this->assertContains('Test 1', $body);
44
        $this->assertContains('Test 2', $body);
45
        $this->assertContains('Test 3', $body);
46
    }
47
}
48