From f88a4810261a8108d7c70bf9c5c6383cdf75f5d5 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 19 Mar 2008 20:38:41 +0000 Subject: [PATCH] Merged revisions 51436 via svnmerge from svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.2.2 ........ r51436 | sminnee | 2008-03-19 15:58:05 +1300 (Wed, 19 Mar 2008) | 2 lines Fixed HomepageForDomain behaviour when entering multiple domains ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@51464 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/RootURLController.php | 4 +-- tests/control/RootURLControllerTest.php | 42 +++++++++++++++++++++++++ tests/control/RootURLControllerTest.yml | 15 +++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 tests/control/RootURLControllerTest.php create mode 100644 tests/control/RootURLControllerTest.yml diff --git a/core/control/RootURLController.php b/core/control/RootURLController.php index 2a4961d9c..a5ac38aa7 100755 --- a/core/control/RootURLController.php +++ b/core/control/RootURLController.php @@ -36,8 +36,8 @@ class RootURLController extends Controller { static function get_homepage_urlsegment() { $host = $_SERVER['HTTP_HOST']; $host = str_replace('www.','',$host); - $SQL_host = Convert::raw2sql($host); - $homePageOBJ = DataObject::get_one("SiteTree", "HomepageForDomain = '$SQL_host'"); + $SQL_host = str_replace('.','\\.',Convert::raw2sql($host)); + $homePageOBJ = DataObject::get_one("SiteTree", "HomepageForDomain REGEXP '(,|^) *$SQL_host *(,|\$)'"); if($homePageOBJ) { return $homePageOBJ->URLSegment; diff --git a/tests/control/RootURLControllerTest.php b/tests/control/RootURLControllerTest.php new file mode 100644 index 000000000..9eb0e88b4 --- /dev/null +++ b/tests/control/RootURLControllerTest.php @@ -0,0 +1,42 @@ + 'page1', + 'www.page.co.nz' => 'page1', + 'help.com' => 'page1', + 'www.help.com' => 'page1', + 'something.com' => 'page1', + 'www.something.com' => 'page1', + + 'other.co.nz' => 'page2', + 'www.other.co.nz' => 'page2', + 'right' => 'page2', + 'www. right' => 'page2', + + 'only.com' => 'page3', + 'www.only.com' => 'page3', + + 'www.somethingelse.com' => 'home', + 'somethingelse.com' => 'home', + + // Test some potential false matches to page2 and page3 + 'alternate.only.com' => 'home', + 'www.alternate.only.com' => 'home', + 'alternate.something.com' => 'home', + ); + + foreach($tests as $domain => $urlSegment) { + $_SERVER['HTTP_HOST'] = $domain; + $this->assertEquals($urlSegment, RootURLController::get_homepage_urlsegment(), "Testing $domain matches $urlSegment"); + } + + $_SERVER['HTTP_HOST'] = $originalHost; + } +} \ No newline at end of file diff --git a/tests/control/RootURLControllerTest.yml b/tests/control/RootURLControllerTest.yml new file mode 100644 index 000000000..6ca1978f4 --- /dev/null +++ b/tests/control/RootURLControllerTest.yml @@ -0,0 +1,15 @@ +Page: + home: + Title: Home + page1: + Title: First Page + URLSegment: page1 + HomepageForDomain: page.co.nz, help.com,something.com, www.something.com + page2: + Title: Second Page + URLSegment: page2 + HomepageForDomain: other.co.nz, right + page3: + Title: Third Page + URLSegment: page3 + HomepageForDomain: only.com \ No newline at end of file