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
|
|
|
|