mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
e7a683c0c4
commit
f88a481026
@ -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;
|
||||
|
42
tests/control/RootURLControllerTest.php
Normal file
42
tests/control/RootURLControllerTest.php
Normal 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;
|
||||
}
|
||||
}
|
15
tests/control/RootURLControllerTest.yml
Normal file
15
tests/control/RootURLControllerTest.yml
Normal 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
|
Loading…
Reference in New Issue
Block a user