SiteMapTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 43
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testSiteMap() 0 38 3
1
<?php
2
namespace Suilven\PageSiteMap\Tests;
3
4
use SilverStripe\Dev\FunctionalTest;
5
6
class SiteMapTest extends FunctionalTest
7
{
8
    protected static $fixture_file = 'SiteMapTest.yml';
9
10
    public function testSiteMap()
11
    {
12
        $this->logInWithPermission('ADMIN');
13
        // pages need published, fixtures are not
14
        foreach (Page::get() as $page) {
15
            $page->doPublish();
16
        }
17
        $response = $this->get('/sitemap/');
18
        $this->assertEquals(200, $response->getStatusCode());
19
        $positions = array();
20
        $body = $response->getBody();
21
22
        // assert is a sitemap
23
        $count = substr_count($body, '<ul class="sitemap-list">');
24
        $this->assertEquals(2, $count);
25
26
        // assert root level pages
27
        for ($i=1; $i <= 4; $i++) {
28
            $row = '<li><a href="page-' . $i . '" title="Go to the Page ' . $i . ' page">Page ' . $i . '</a>';
29
            $this->assertContains($row, $body);
30
            $positions["{$i}"] = strpos($body, $row);
31
        }
32
33
        //assert order
34
        $this->assertGreaterThan($positions['3'], $positions['4']);
35
        $this->assertGreaterThan($positions['2'], $positions['3']);
36
        $this->assertGreaterThan($positions['1'], $positions['2']);
37
38
        // check sub pages
39
        $sub1 = '<li><a href="page-11" title="Go to the Page 1/1 page">Page 1/1</a>';
40
        $sub2 = '<li><a href="page-12" title="Go to the Page 1/2 page">Page 1/2</a>';
41
        $sub1pos = strpos($body, $sub1);
42
        $sub2pos = strpos($body, $sub2);
43
        $this->assertContains($sub1, $body);
44
        $this->assertContains($sub2, $body);
45
        $this->assertGreaterThan($positions[1], $sub1pos);
46
        $this->assertGreaterThan($sub1pos, $sub2pos);
47
    }
48
}
49