mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
Merge branch '2.1'
This commit is contained in:
commit
e4fe534f10
@ -548,7 +548,7 @@ class SiteTreeSubsites extends DataExtension
|
|||||||
$subsite = Subsite::currentSubsite();
|
$subsite = Subsite::currentSubsite();
|
||||||
if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) {
|
if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) {
|
||||||
// SS 4.1: JSON encoded. SS 4.0, comma delimited
|
// SS 4.1: JSON encoded. SS 4.0, comma delimited
|
||||||
$blacklist = Convert::json2array($subsite->PageTypeBlacklist);
|
$blacklist = json_decode($subsite->PageTypeBlacklist, true);
|
||||||
if ($blacklist === false) {
|
if ($blacklist === false) {
|
||||||
$blacklist = explode(',', $subsite->PageTypeBlacklist);
|
$blacklist = explode(',', $subsite->PageTypeBlacklist);
|
||||||
}
|
}
|
||||||
|
@ -257,6 +257,10 @@ class Subsite extends DataObject
|
|||||||
$host = $_SERVER['HTTP_HOST'];
|
$host = $_SERVER['HTTP_HOST'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove ports, we aren't concerned with them in terms of detecting subsites via domains
|
||||||
|
$hostParts = explode(':', $host, 2);
|
||||||
|
$host = reset($hostParts);
|
||||||
|
|
||||||
$matchingDomains = null;
|
$matchingDomains = null;
|
||||||
$cacheKey = null;
|
$cacheKey = null;
|
||||||
if ($host) {
|
if ($host) {
|
||||||
|
@ -268,7 +268,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
|
|
||||||
Subsite::changeSubsite($s1);
|
Subsite::changeSubsite($s1);
|
||||||
$cmsmain = CMSMain::create();
|
$cmsmain = CMSMain::create();
|
||||||
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
$hints = json_decode($cmsmain->SiteTreeHints(), true);
|
||||||
$classes = $hints['Root']['disallowedChildren'];
|
$classes = $hints['Root']['disallowedChildren'];
|
||||||
$this->assertContains(ErrorPage::class, $classes);
|
$this->assertContains(ErrorPage::class, $classes);
|
||||||
$this->assertContains(TestClassA::class, $classes);
|
$this->assertContains(TestClassA::class, $classes);
|
||||||
@ -279,7 +279,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
if ($cmsmain->hasMethod('getHintsCache')) {
|
if ($cmsmain->hasMethod('getHintsCache')) {
|
||||||
$cmsmain->getHintsCache()->clear();
|
$cmsmain->getHintsCache()->clear();
|
||||||
}
|
}
|
||||||
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
$hints = json_decode($cmsmain->SiteTreeHints(), true);
|
||||||
|
|
||||||
$classes = $hints['Root']['disallowedChildren'];
|
$classes = $hints['Root']['disallowedChildren'];
|
||||||
$this->assertNotContains(ErrorPage::class, $classes);
|
$this->assertNotContains(ErrorPage::class, $classes);
|
||||||
|
@ -191,12 +191,23 @@ class SubsiteTest extends BaseSubsiteTest
|
|||||||
Subsite::getSubsiteIDForDomain('example.org'),
|
Subsite::getSubsiteIDForDomain('example.org'),
|
||||||
'Exact matches without strict checking when not using www prefix'
|
'Exact matches without strict checking when not using www prefix'
|
||||||
);
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$subsite1->ID,
|
||||||
|
Subsite::getSubsiteIDForDomain('example.org:1123'),
|
||||||
|
'Exact matches without strict checking when not using www prefix and ignores port'
|
||||||
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$subsite1->ID,
|
$subsite1->ID,
|
||||||
Subsite::getSubsiteIDForDomain('www.example.org'),
|
Subsite::getSubsiteIDForDomain('www.example.org'),
|
||||||
'Matches without strict checking when using www prefix, '
|
'Matches without strict checking when using www prefix, '
|
||||||
.'still matching first domain regardless of www prefix (falling back to subsite primary key ordering)'
|
.'still matching first domain regardless of www prefix (falling back to subsite primary key ordering)'
|
||||||
);
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$subsite1->ID,
|
||||||
|
Subsite::getSubsiteIDForDomain('www.example.org:9923'),
|
||||||
|
'Matches without strict checking when using www prefix, '
|
||||||
|
.'still matching first domain without prefix (falling back to primary key ordering and ignoring port)'
|
||||||
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$subsite1->ID,
|
$subsite1->ID,
|
||||||
Subsite::getSubsiteIDForDomain('www.example.com'),
|
Subsite::getSubsiteIDForDomain('www.example.com'),
|
||||||
@ -215,6 +226,11 @@ class SubsiteTest extends BaseSubsiteTest
|
|||||||
Subsite::getSubsiteIDForDomain('example.org'),
|
Subsite::getSubsiteIDForDomain('example.org'),
|
||||||
'Matches with strict checking when not using www prefix'
|
'Matches with strict checking when not using www prefix'
|
||||||
);
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$subsite1->ID,
|
||||||
|
Subsite::getSubsiteIDForDomain('example.org:123'),
|
||||||
|
'Matches with strict checking when not using www prefix and ignores port'
|
||||||
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$subsite2->ID, // not 1
|
$subsite2->ID, // not 1
|
||||||
Subsite::getSubsiteIDForDomain('www.example.org'),
|
Subsite::getSubsiteIDForDomain('www.example.org'),
|
||||||
@ -291,46 +307,42 @@ class SubsiteTest extends BaseSubsiteTest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that Subsite and SubsiteDomain both respect http protocol correctly
|
* Tests that Subsite and SubsiteDomain both respect http protocol correctly
|
||||||
|
*
|
||||||
|
* @param string $class Fixture class name
|
||||||
|
* @param string $identifier Fixture identifier
|
||||||
|
* @param bool $currentIsSecure Whether the current base URL should be secure
|
||||||
|
* @param string $expected The expected base URL for the subsite or subsite domain
|
||||||
|
* @dataProvider domainProtocolProvider
|
||||||
*/
|
*/
|
||||||
public function testDomainProtocol()
|
public function testDomainProtocol($class, $identifier, $currentIsSecure, $expected)
|
||||||
{
|
{
|
||||||
// domaintest2 has 'protocol'
|
/** @var Subsite|SubsiteDomain $model */
|
||||||
$subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
$model = $this->objFromFixture($class, $identifier);
|
||||||
$domain2a = $this->objFromFixture(SubsiteDomain::class, 'dt2a');
|
$protocol = $currentIsSecure ? 'https' : 'http';
|
||||||
$domain2b = $this->objFromFixture(SubsiteDomain::class, 'dt2b');
|
Config::modify()->set(Director::class, 'alternate_base_url', $protocol . '://www.mysite.com');
|
||||||
|
$this->assertSame($expected, $model->absoluteBaseURL());
|
||||||
|
}
|
||||||
|
|
||||||
// domaintest4 is 'https' (primary only)
|
public function domainProtocolProvider()
|
||||||
$subsite4 = $this->objFromFixture(Subsite::class, 'domaintest4');
|
{
|
||||||
$domain4a = $this->objFromFixture(SubsiteDomain::class, 'dt4a');
|
return [
|
||||||
$domain4b = $this->objFromFixture(SubsiteDomain::class, 'dt4b'); // secondary domain is http only though
|
[Subsite::class, 'domaintest2', false, 'http://two.mysite.com/'],
|
||||||
|
[SubsiteDomain::class, 'dt2a', false, 'http://two.mysite.com/'],
|
||||||
// domaintest5 is 'http'
|
[SubsiteDomain::class, 'dt2b', false, 'http://subsite.mysite.com/'],
|
||||||
$subsite5 = $this->objFromFixture(Subsite::class, 'domaintest5');
|
[Subsite::class, 'domaintest4', false, 'https://www.primary.com/'],
|
||||||
$domain5a = $this->objFromFixture(SubsiteDomain::class, 'dt5');
|
[SubsiteDomain::class, 'dt4a', false, 'https://www.primary.com/'],
|
||||||
|
[SubsiteDomain::class, 'dt4b', false, 'http://www.secondary.com/'],
|
||||||
// Check protocol when current protocol is http://
|
[Subsite::class, 'domaintest5', false, 'http://www.tertiary.com/'],
|
||||||
Config::modify()->set(Director::class, 'alternate_base_url', 'http://www.mysite.com');
|
[SubsiteDomain::class, 'dt5', false, 'http://www.tertiary.com/'],
|
||||||
|
[Subsite::class, 'domaintest2', true, 'https://two.mysite.com/'],
|
||||||
$this->assertEquals('http://two.mysite.com/', $subsite2->absoluteBaseURL());
|
[SubsiteDomain::class, 'dt2a', true, 'https://two.mysite.com/'],
|
||||||
$this->assertEquals('http://two.mysite.com/', $domain2a->absoluteBaseURL());
|
[SubsiteDomain::class, 'dt2b', true, 'https://subsite.mysite.com/'],
|
||||||
$this->assertEquals('http://subsite.mysite.com/', $domain2b->absoluteBaseURL());
|
[Subsite::class, 'domaintest4', true, 'https://www.primary.com/'],
|
||||||
$this->assertEquals('https://www.primary.com/', $subsite4->absoluteBaseURL());
|
[SubsiteDomain::class, 'dt4a', true, 'https://www.primary.com/'],
|
||||||
$this->assertEquals('https://www.primary.com/', $domain4a->absoluteBaseURL());
|
[SubsiteDomain::class, 'dt4b', true, 'http://www.secondary.com/'],
|
||||||
$this->assertEquals('http://www.secondary.com/', $domain4b->absoluteBaseURL());
|
[Subsite::class, 'domaintest5', true, 'http://www.tertiary.com/'],
|
||||||
$this->assertEquals('http://www.tertiary.com/', $subsite5->absoluteBaseURL());
|
[SubsiteDomain::class, 'dt5', true, 'http://www.tertiary.com/'],
|
||||||
$this->assertEquals('http://www.tertiary.com/', $domain5a->absoluteBaseURL());
|
];
|
||||||
|
|
||||||
// Check protocol when current protocol is https://
|
|
||||||
Config::modify()->set(Director::class, 'alternate_base_url', 'https://www.mysite.com');
|
|
||||||
|
|
||||||
$this->assertEquals('https://two.mysite.com/', $subsite2->absoluteBaseURL());
|
|
||||||
$this->assertEquals('https://two.mysite.com/', $domain2a->absoluteBaseURL());
|
|
||||||
$this->assertEquals('https://subsite.mysite.com/', $domain2b->absoluteBaseURL());
|
|
||||||
$this->assertEquals('https://www.primary.com/', $subsite4->absoluteBaseURL());
|
|
||||||
$this->assertEquals('https://www.primary.com/', $domain4a->absoluteBaseURL());
|
|
||||||
$this->assertEquals('http://www.secondary.com/', $domain4b->absoluteBaseURL());
|
|
||||||
$this->assertEquals('http://www.tertiary.com/', $subsite5->absoluteBaseURL());
|
|
||||||
$this->assertEquals('http://www.tertiary.com/', $domain5a->absoluteBaseURL());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAllSites()
|
public function testAllSites()
|
||||||
|
Loading…
Reference in New Issue
Block a user