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
This commit is contained in:
Sam Minnee 2008-03-19 20:38:41 +00:00
parent e7a683c0c4
commit f88a481026
3 changed files with 59 additions and 2 deletions

View File

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

View File

@ -0,0 +1,42 @@
<?php
class RootURLControllerTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/control/RootURLControllerTest.yml';
function testHomepageForDomain() {
$originalHost = $_SERVER['HTTP_HOST'];
// Tests matching an HTTP_HOST value to URLSegment homepage values
$tests = array(
'page.co.nz' => '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;
}
}

View File

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