@@ -11,45 +11,45 @@ |
||
| 11 | 11 | |
| 12 | 12 | class SiteMap_Controller extends Page_Controller |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * This function will return a unordered list of all pages on the site. |
|
| 16 | - * Watch for the switch between $page and $child in the second line of the |
|
| 17 | - * foreach(). |
|
| 18 | - * |
|
| 19 | - * Note that this will only skip ErrorPage's at the top/root level of the site. |
|
| 20 | - * If you have an ErrorPage class somewhere else in the hierarchy, it will be |
|
| 21 | - * displayed. |
|
| 22 | - */ |
|
| 23 | - public function SiteMap() |
|
| 24 | - { |
|
| 25 | - // Pages at the root level only |
|
| 26 | - $rootLevel = Page::get()->filter('ParentID', 0); |
|
| 27 | - $output = ''; |
|
| 28 | - $output = $this->makeList($rootLevel); |
|
| 29 | - return $output; |
|
| 30 | - } |
|
| 14 | + /** |
|
| 15 | + * This function will return a unordered list of all pages on the site. |
|
| 16 | + * Watch for the switch between $page and $child in the second line of the |
|
| 17 | + * foreach(). |
|
| 18 | + * |
|
| 19 | + * Note that this will only skip ErrorPage's at the top/root level of the site. |
|
| 20 | + * If you have an ErrorPage class somewhere else in the hierarchy, it will be |
|
| 21 | + * displayed. |
|
| 22 | + */ |
|
| 23 | + public function SiteMap() |
|
| 24 | + { |
|
| 25 | + // Pages at the root level only |
|
| 26 | + $rootLevel = Page::get()->filter('ParentID', 0); |
|
| 27 | + $output = ''; |
|
| 28 | + $output = $this->makeList($rootLevel); |
|
| 29 | + return $output; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - private function makeList($pages) |
|
| 33 | - { |
|
| 34 | - $output = ''; |
|
| 35 | - if (count($pages)) { |
|
| 36 | - $output = ' |
|
| 32 | + private function makeList($pages) |
|
| 33 | + { |
|
| 34 | + $output = ''; |
|
| 35 | + if (count($pages)) { |
|
| 36 | + $output = ' |
|
| 37 | 37 | <ul class="sitemap-list">'; |
| 38 | - foreach ($pages as $page) { |
|
| 39 | - if (!($page instanceof ErrorPage) && $page->ShowInMenus && $page->Title != $this->Title) { |
|
| 40 | - $output .= ' |
|
| 38 | + foreach ($pages as $page) { |
|
| 39 | + if (!($page instanceof ErrorPage) && $page->ShowInMenus && $page->Title != $this->Title) { |
|
| 40 | + $output .= ' |
|
| 41 | 41 | <li><a href="'.$page->URLSegment.'" title="Go to the '.Convert::raw2xml($page->Title).' page">'.Convert::raw2xml($page->MenuTitle).'</a>'; |
| 42 | - $whereStatement = 'ParentID = '.$page->ID; |
|
| 43 | - //$childPages = new DataObjectSet(); |
|
| 44 | - $childPages = DataObject::get('Page', $whereStatement); |
|
| 45 | - $output .= $this->makeList($childPages); |
|
| 46 | - $output .= ' |
|
| 42 | + $whereStatement = 'ParentID = '.$page->ID; |
|
| 43 | + //$childPages = new DataObjectSet(); |
|
| 44 | + $childPages = DataObject::get('Page', $whereStatement); |
|
| 45 | + $output .= $this->makeList($childPages); |
|
| 46 | + $output .= ' |
|
| 47 | 47 | </li>'; |
| 48 | - } |
|
| 49 | - } |
|
| 50 | - $output .= ' |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + $output .= ' |
|
| 51 | 51 | </ul>'; |
| 52 | - } |
|
| 53 | - return $output; |
|
| 54 | - } |
|
| 52 | + } |
|
| 53 | + return $output; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -8,23 +8,23 @@ |
||
| 8 | 8 | { |
| 9 | 9 | $this->logInWithPermission('ADMIN'); |
| 10 | 10 | // pages need published, fixtures are not |
| 11 | - foreach (Page::get() as $page) { |
|
| 12 | - $page->doPublish(); |
|
| 13 | - } |
|
| 14 | - $response = $this->get('/sitemap/'); |
|
| 11 | + foreach (Page::get() as $page) { |
|
| 12 | + $page->doPublish(); |
|
| 13 | + } |
|
| 14 | + $response = $this->get('/sitemap/'); |
|
| 15 | 15 | $this->assertEquals(200, $response->getStatusCode()); |
| 16 | 16 | $positions = array(); |
| 17 | 17 | $body = $response->getBody(); |
| 18 | 18 | |
| 19 | 19 | // assert is a sitemap |
| 20 | 20 | $count = substr_count($body, '<ul class="sitemap-list">'); |
| 21 | - $this->assertEquals(2, $count); |
|
| 21 | + $this->assertEquals(2, $count); |
|
| 22 | 22 | |
| 23 | - // assert root level pages |
|
| 23 | + // assert root level pages |
|
| 24 | 24 | for ($i=1; $i <= 4; $i++) { |
| 25 | - $row = '<li><a href="page-' . $i . '" title="Go to the Page ' . $i . ' page">Page ' . $i . '</a>'; |
|
| 26 | - $this->assertContains($row, $body); |
|
| 27 | - $positions["{$i}"] = strpos($body, $row); |
|
| 25 | + $row = '<li><a href="page-' . $i . '" title="Go to the Page ' . $i . ' page">Page ' . $i . '</a>'; |
|
| 26 | + $this->assertContains($row, $body); |
|
| 27 | + $positions["{$i}"] = strpos($body, $row); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | //assert order |
@@ -21,8 +21,8 @@ |
||
| 21 | 21 | $this->assertEquals(2, $count); |
| 22 | 22 | |
| 23 | 23 | // assert root level pages |
| 24 | - for ($i=1; $i <= 4; $i++) { |
|
| 25 | - $row = '<li><a href="page-' . $i . '" title="Go to the Page ' . $i . ' page">Page ' . $i . '</a>'; |
|
| 24 | + for ($i = 1; $i <= 4; $i++) { |
|
| 25 | + $row = '<li><a href="page-'.$i.'" title="Go to the Page '.$i.' page">Page '.$i.'</a>'; |
|
| 26 | 26 | $this->assertContains($row, $body); |
| 27 | 27 | $positions["{$i}"] = strpos($body, $row); |
| 28 | 28 | } |