Passed
Pull Request — master (#326)
by Robbie
04:32
created

SubsiteXHRControllerTest::testCanView()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 21
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 34
rs 8.8571
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
        $this->assertEquals('text/json', $result->getHeader('Content-Type'));
39
40
        $body = $result->getBody();
41
        $this->assertContains('Main site', $body);
42
        $this->assertContains('Test 1', $body);
43
        $this->assertContains('Test 2', $body);
44
        $this->assertContains('Test 3', $body);
45
    }
46
}
47