mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 09:05:55 +00:00
MINOR Clearer testing and documentation around wildcard usage for domain matching
This commit is contained in:
parent
fbe9eec50b
commit
32d51ed986
@ -162,7 +162,7 @@ class Subsite extends DataObject implements PermissionProvider {
|
|||||||
*/
|
*/
|
||||||
function getCMSFields() {
|
function getCMSFields() {
|
||||||
$domainTable = new TableField("Domains", "SubsiteDomain",
|
$domainTable = new TableField("Domains", "SubsiteDomain",
|
||||||
array("Domain" => "Domain (use * as a wildcard)", "IsPrimary" => "Primary domain?"),
|
array("Domain" => "Domain <small>(use * as a wildcard)</small>", "IsPrimary" => "Primary domain?"),
|
||||||
array("Domain" => "TextField", "IsPrimary" => "CheckboxField"),
|
array("Domain" => "TextField", "IsPrimary" => "CheckboxField"),
|
||||||
"SubsiteID", $this->ID);
|
"SubsiteID", $this->ID);
|
||||||
|
|
||||||
@ -310,10 +310,11 @@ JS;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a matching subsite for the given host, or for the current HTTP_HOST.
|
* Get a matching subsite for the given host, or for the current HTTP_HOST.
|
||||||
|
* Supports "fuzzy" matching of domains by placing an asterisk at the start of end of the string,
|
||||||
|
* for example matching all subdomains on *.example.com with one subsite,
|
||||||
|
* and all subdomains on *.example.org on another.
|
||||||
*
|
*
|
||||||
* @param $host The host to find the subsite for. If not specified, $_SERVER['HTTP_HOST']
|
* @param $host The host to find the subsite for. If not specified, $_SERVER['HTTP_HOST'] is used.
|
||||||
* is used.
|
|
||||||
*
|
|
||||||
* @return int Subsite ID
|
* @return int Subsite ID
|
||||||
*/
|
*/
|
||||||
static function getSubsiteIDForDomain($host = null, $returnMainIfNotFound = true) {
|
static function getSubsiteIDForDomain($host = null, $returnMainIfNotFound = true) {
|
||||||
|
@ -59,26 +59,33 @@ class SubsiteTest extends SapphireTest {
|
|||||||
function testDomainLookup() {
|
function testDomainLookup() {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->idFromFixture('Subsite','domaintest1'),
|
$this->idFromFixture('Subsite','domaintest1'),
|
||||||
Subsite::getSubsiteIDForDomain('one.example.org')
|
Subsite::getSubsiteIDForDomain('one.example.org'),
|
||||||
|
'Full match'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->idFromFixture('Subsite','domaintest1'),
|
$this->idFromFixture('Subsite','domaintest1'),
|
||||||
Subsite::getSubsiteIDForDomain('one.localhost')
|
Subsite::getSubsiteIDForDomain('one.localhost'),
|
||||||
);
|
'Fuzzy match suffixed with asterisk (rule "one.*")'
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
$this->idFromFixture('Subsite','domaintest2'),
|
|
||||||
Subsite::getSubsiteIDForDomain('two.mysite.com')
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->idFromFixture('Subsite','domaintest2'),
|
$this->idFromFixture('Subsite','domaintest2'),
|
||||||
Subsite::getSubsiteIDForDomain('other.mysite.com')
|
Subsite::getSubsiteIDForDomain('two.mysite.com'),
|
||||||
|
'Matches correct subsite for rule'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->idFromFixture('Subsite','domaintest2'),
|
||||||
|
Subsite::getSubsiteIDForDomain('other.mysite.com'),
|
||||||
|
'Fuzzy match prefixed with asterisk (rule "*.mysite.com")'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(0, Subsite::getSubsiteIDForDomain('other.example.com'));
|
$this->assertEquals(
|
||||||
$this->assertEquals(0, Subsite::getSubsiteIDForDomain('two.example.com'));
|
0,
|
||||||
|
Subsite::getSubsiteIDForDomain('unknown.madeup.com'),
|
||||||
|
"Doesn't match unknown subsite"
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user