From 0ffc6ac2bec36281b7e7a0dda9ed0dd264aa8c57 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Mon, 27 Jul 2015 00:21:54 +0100 Subject: [PATCH] Allow URLs to be case insensitive --- code/GoogleSitemap.php | 9 +++++++++ tests/GoogleSitemapTest.php | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/code/GoogleSitemap.php b/code/GoogleSitemap.php index 9fe456f..8217dfa 100644 --- a/code/GoogleSitemap.php +++ b/code/GoogleSitemap.php @@ -182,6 +182,15 @@ class GoogleSitemap { * @return ArrayList */ public static function get_items($class, $page = 1) { + //normalise the class name + try { + $reflectionClass = new ReflectionClass($class); + $class = $reflectionClass->getName(); + } catch (ReflectionException $e) { + // this can happen when $class is GoogleSitemapRoute + //we should try to carry on + } + $output = new ArrayList(); $count = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap'); $filter = Config::inst()->get('GoogleSitemap', 'use_show_in_search'); diff --git a/tests/GoogleSitemapTest.php b/tests/GoogleSitemapTest.php index ff2b313..808c7e9 100644 --- a/tests/GoogleSitemapTest.php +++ b/tests/GoogleSitemapTest.php @@ -89,7 +89,7 @@ class GoogleSitemapTest extends FunctionalTest { $expected = "". Director::absoluteURL("sitemap.xml/sitemap/GoogleSitemapTest_UnviewableDataObject/2") .""; $this->assertEquals(0, substr_count($body, $expected) , 'A link to a GoogleSitemapTest_UnviewableDataObject does not exist'); - } + } public function testLastModifiedDateOnRootXML() { Config::inst()->update('GoogleSitemap', 'enabled', true); @@ -161,6 +161,19 @@ class GoogleSitemapTest extends FunctionalTest { Config::inst()->update('GoogleSitemap', 'objects_per_sitemap', $original); } + public function testAccessingNestedSiteMapCaseInsensitive() { + $original = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap'); + Config::inst()->update('GoogleSitemap', 'objects_per_sitemap', 1); + GoogleSitemap::register_dataobject("GoogleSitemapTest_DataObject"); + + $response = $this->get('sitemap.xml/sitemap/googlesitemaptest_dataobject/1'); + $body = $response->getBody(); + + $this->assertEquals(200, $response->getStatusCode(), 'successful loaded nested sitemap'); + + Config::inst()->update('GoogleSitemap', 'objects_per_sitemap', $original); + } + public function testGetItemsWithPages() { if(!class_exists('Page')) { $this->markTestIncomplete('No cms module installed, page related test skipped');