mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
Merge branch '2.3'
This commit is contained in:
commit
a4e99a2df5
@ -23,7 +23,7 @@ matrix:
|
|||||||
- php: 7.1
|
- php: 7.1
|
||||||
env: DB=MYSQL INSTALLER_VERSION=4.4.x-dev BEHAT_TEST=1
|
env: DB=MYSQL INSTALLER_VERSION=4.4.x-dev BEHAT_TEST=1
|
||||||
- php: 7.2
|
- php: 7.2
|
||||||
env: DB=MYSQL INSTALLER_VERSION=4.4.x-dev PHPUNIT_COVERAGE_TEST=1
|
env: DB=MYSQL INSTALLER_VERSION=4.4.x-dev PHPUNIT_TEST=1
|
||||||
- php: 7.2
|
- php: 7.2
|
||||||
env: DB=MYSQL INSTALLER_VERSION=4.x-dev BEHAT_TEST=1
|
env: DB=MYSQL INSTALLER_VERSION=4.x-dev BEHAT_TEST=1
|
||||||
- php: 7.3
|
- php: 7.3
|
||||||
|
@ -50,6 +50,7 @@ SilverStripe\Admin\SecurityAdmin:
|
|||||||
|
|
||||||
SilverStripe\CMS\Controllers\CMSMain:
|
SilverStripe\CMS\Controllers\CMSMain:
|
||||||
extensions:
|
extensions:
|
||||||
|
- SilverStripe\Subsites\Extensions\HintsCacheKeyExtension
|
||||||
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
|
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
|
||||||
|
|
||||||
SilverStripe\CMS\Controllers\CMSPagesController:
|
SilverStripe\CMS\Controllers\CMSPagesController:
|
||||||
|
@ -48,3 +48,14 @@ to speak to your website administrator or hosting provider to facilitate this.
|
|||||||
|
|
||||||
|
|
||||||
You can simulate subsite access without setting up virtual hosts by appending ?SubsiteID=<ID> to the request.
|
You can simulate subsite access without setting up virtual hosts by appending ?SubsiteID=<ID> to the request.
|
||||||
|
|
||||||
|
### How do Subsite domains work with Fluent domains?
|
||||||
|
|
||||||
|
The Subsites module and Fluent translation module both provide the concept of defining "domains" and let you
|
||||||
|
configure the host name for it. This functionality is essentially performing the same duty in both modules.
|
||||||
|
|
||||||
|
In the "URL segment" field for CMS pages, both Subsites and Fluent will add their context to the value. If you
|
||||||
|
have a Subsite domain configured but no Fluent domain, Fluent will respect the existing domain and add its
|
||||||
|
locale context to the value. If you have a Subsite domain configured and a Fluent domain configured, Fluent will
|
||||||
|
use its own domain host name value, and the Subsite domain value will be lost. For this reason, you will need
|
||||||
|
to ensure that you use the same host name in both Subsite and Fluent domain entries.
|
||||||
|
@ -47,13 +47,14 @@ en:
|
|||||||
SilverStripe\Subsites\Model\SubsiteDomain:
|
SilverStripe\Subsites\Model\SubsiteDomain:
|
||||||
DOMAIN: Domain
|
DOMAIN: Domain
|
||||||
DOMAIN_DESCRIPTION: 'Hostname of this subsite (exclude protocol). Allows wildcards (*).'
|
DOMAIN_DESCRIPTION: 'Hostname of this subsite (exclude protocol). Allows wildcards (*).'
|
||||||
|
ISPRIMARY_DESCRIPTION: 'Mark this as the default domain for this subsite'
|
||||||
IS_PRIMARY: 'Is Primary Domain?'
|
IS_PRIMARY: 'Is Primary Domain?'
|
||||||
PLURALNAME: 'Subsite Domains'
|
PLURALNAME: 'Subsite Domains'
|
||||||
PLURALS:
|
PLURALS:
|
||||||
one: 'A Subsite Domain'
|
one: 'A Subsite Domain'
|
||||||
other: '{count} Subsite Domains'
|
other: '{count} Subsite Domains'
|
||||||
PROTOCOL_AUTOMATIC: Automatic
|
PROTOCOL_AUTOMATIC: Automatic
|
||||||
PROTOCOL_DESCRIPTION: 'Mark this as the default domain for this subsite'
|
PROTOCOL_DESCRIPTION: 'When generating links to this subsite, use the selected protocol. <br />Selecting ''Automatic'' means subsite links will default to the current protocol.'
|
||||||
PROTOCOL_HTTP: 'http://'
|
PROTOCOL_HTTP: 'http://'
|
||||||
PROTOCOL_HTTPS: 'https://'
|
PROTOCOL_HTTPS: 'https://'
|
||||||
Protocol: Protocol
|
Protocol: Protocol
|
||||||
|
22
src/Extensions/HintsCacheKeyExtension.php
Normal file
22
src/Extensions/HintsCacheKeyExtension.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Subsites\Extensions;
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Controllers\CMSMain;
|
||||||
|
use SilverStripe\Core\Extension;
|
||||||
|
use SilverStripe\Subsites\State\SubsiteState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This extension adds the current Subsite ID as an additional factor to the Hints Cßache Key, which is used to cache
|
||||||
|
* the Site Tree Hints (which include allowed pagetypes).
|
||||||
|
*
|
||||||
|
* @package SilverStripe\Subsites\Extensions
|
||||||
|
* @see CMSMain::generateHintsCacheKey()
|
||||||
|
*/
|
||||||
|
class HintsCacheKeyExtension extends Extension
|
||||||
|
{
|
||||||
|
public function updateHintsCacheKey(&$baseKey)
|
||||||
|
{
|
||||||
|
$baseKey .= '_Subsite:' . SubsiteState::singleton()->getSubsiteId();
|
||||||
|
}
|
||||||
|
}
|
@ -215,11 +215,16 @@ class LeftAndMainSubsites extends LeftAndMainExtension
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the current controller is accessible for this user on this subsite.
|
* Check if the current controller is accessible for this user on this subsite.
|
||||||
|
*
|
||||||
|
* @param Member $member
|
||||||
*/
|
*/
|
||||||
public function canAccess()
|
public function canAccess(Member $member = null)
|
||||||
{
|
{
|
||||||
|
if (!$member) {
|
||||||
|
$member = Security::getCurrentUser();
|
||||||
|
}
|
||||||
|
|
||||||
// Admin can access everything, no point in checking.
|
// Admin can access everything, no point in checking.
|
||||||
$member = Security::getCurrentUser();
|
|
||||||
if ($member
|
if ($member
|
||||||
&& (Permission::checkMember($member, [
|
&& (Permission::checkMember($member, [
|
||||||
'ADMIN', // Full administrative rights
|
'ADMIN', // Full administrative rights
|
||||||
@ -238,10 +243,12 @@ class LeftAndMainSubsites extends LeftAndMainExtension
|
|||||||
/**
|
/**
|
||||||
* Prevent accessing disallowed resources. This happens after onBeforeInit has executed,
|
* Prevent accessing disallowed resources. This happens after onBeforeInit has executed,
|
||||||
* so all redirections should've already taken place.
|
* so all redirections should've already taken place.
|
||||||
|
*
|
||||||
|
* @param Member $member
|
||||||
*/
|
*/
|
||||||
public function alternateAccessCheck()
|
public function alternateAccessCheck(Member $member = null)
|
||||||
{
|
{
|
||||||
return $this->owner->canAccess();
|
return $this->owner->canAccess($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace SilverStripe\Subsites\Extensions;
|
namespace SilverStripe\Subsites\Extensions;
|
||||||
|
|
||||||
use Page;
|
use Page;
|
||||||
|
use SilverStripe\CMS\Forms\SiteTreeURLSegmentField;
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
@ -150,6 +151,7 @@ class SiteTreeSubsites extends DataExtension
|
|||||||
// replace readonly link prefix
|
// replace readonly link prefix
|
||||||
$subsite = $this->owner->Subsite();
|
$subsite = $this->owner->Subsite();
|
||||||
$nested_urls_enabled = Config::inst()->get(SiteTree::class, 'nested_urls');
|
$nested_urls_enabled = Config::inst()->get(SiteTree::class, 'nested_urls');
|
||||||
|
/** @var Subsite $subsite */
|
||||||
if ($subsite && $subsite->exists()) {
|
if ($subsite && $subsite->exists()) {
|
||||||
// Use baseurl from domain
|
// Use baseurl from domain
|
||||||
$baseLink = $subsite->absoluteBaseURL();
|
$baseLink = $subsite->absoluteBaseURL();
|
||||||
@ -163,7 +165,7 @@ class SiteTreeSubsites extends DataExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
$urlsegment = $fields->dataFieldByName('URLSegment');
|
$urlsegment = $fields->dataFieldByName('URLSegment');
|
||||||
if ($urlsegment) {
|
if ($urlsegment && $urlsegment instanceof SiteTreeURLSegmentField) {
|
||||||
$urlsegment->setURLPrefix($baseLink);
|
$urlsegment->setURLPrefix($baseLink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,12 +108,13 @@ class Subsite extends DataObject
|
|||||||
*/
|
*/
|
||||||
private static $check_is_public = true;
|
private static $check_is_public = true;
|
||||||
|
|
||||||
/*** @return array
|
/**
|
||||||
|
* @var array
|
||||||
*/
|
*/
|
||||||
private static $summary_fields = [
|
private static $summary_fields = [
|
||||||
'Title',
|
'Title',
|
||||||
'PrimaryDomain',
|
'PrimaryDomain',
|
||||||
'IsPublic'
|
'IsPublic.Nice'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -772,7 +773,7 @@ class Subsite extends DataObject
|
|||||||
$labels['DefaultSite'] = _t('Subsites.DefaultSiteFieldLabel', 'Default site');
|
$labels['DefaultSite'] = _t('Subsites.DefaultSiteFieldLabel', 'Default site');
|
||||||
$labels['Theme'] = _t('Subsites.ThemeFieldLabel', 'Theme');
|
$labels['Theme'] = _t('Subsites.ThemeFieldLabel', 'Theme');
|
||||||
$labels['Language'] = _t('Subsites.LanguageFieldLabel', 'Language');
|
$labels['Language'] = _t('Subsites.LanguageFieldLabel', 'Language');
|
||||||
$labels['IsPublic'] = _t('Subsites.IsPublicFieldLabel', 'Enable public access');
|
$labels['IsPublic.Nice'] = _t('Subsites.IsPublicFieldLabel', 'Enable public access');
|
||||||
$labels['PageTypeBlacklist'] = _t('Subsites.PageTypeBlacklistFieldLabel', 'Page Type Blacklist');
|
$labels['PageTypeBlacklist'] = _t('Subsites.PageTypeBlacklistFieldLabel', 'Page Type Blacklist');
|
||||||
$labels['Domains.Domain'] = _t('Subsites.DomainFieldLabel', 'Domain');
|
$labels['Domains.Domain'] = _t('Subsites.DomainFieldLabel', 'Domain');
|
||||||
$labels['PrimaryDomain'] = _t('Subsites.PrimaryDomainFieldLabel', 'Primary Domain');
|
$labels['PrimaryDomain'] = _t('Subsites.PrimaryDomainFieldLabel', 'Primary Domain');
|
||||||
|
@ -111,13 +111,14 @@ class SubsiteDomain extends DataObject
|
|||||||
self::PROTOCOL_HTTPS => _t(__CLASS__ . '.PROTOCOL_HTTPS', 'https://'),
|
self::PROTOCOL_HTTPS => _t(__CLASS__ . '.PROTOCOL_HTTPS', 'https://'),
|
||||||
self::PROTOCOL_AUTOMATIC => _t(__CLASS__ . '.PROTOCOL_AUTOMATIC', 'Automatic')
|
self::PROTOCOL_AUTOMATIC => _t(__CLASS__ . '.PROTOCOL_AUTOMATIC', 'Automatic')
|
||||||
];
|
];
|
||||||
$fields = new FieldList(
|
$fields = FieldList::create(
|
||||||
WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255)
|
WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255)
|
||||||
->setDescription(_t(
|
->setDescription(_t(
|
||||||
__CLASS__ . '.DOMAIN_DESCRIPTION',
|
__CLASS__ . '.DOMAIN_DESCRIPTION',
|
||||||
'Hostname of this subsite (exclude protocol). Allows wildcards (*).'
|
'Hostname of this subsite (exclude protocol). Allows wildcards (*).'
|
||||||
)),
|
)),
|
||||||
OptionsetField::create('Protocol', $this->fieldLabel('Protocol'), $protocols)
|
OptionsetField::create('Protocol', $this->fieldLabel('Protocol'), $protocols)
|
||||||
|
->setValue($this->Protocol ?: self::PROTOCOL_AUTOMATIC)
|
||||||
->setDescription(_t(
|
->setDescription(_t(
|
||||||
__CLASS__ . '.PROTOCOL_DESCRIPTION',
|
__CLASS__ . '.PROTOCOL_DESCRIPTION',
|
||||||
'When generating links to this subsite, use the selected protocol. <br />' .
|
'When generating links to this subsite, use the selected protocol. <br />' .
|
||||||
@ -125,7 +126,7 @@ class SubsiteDomain extends DataObject
|
|||||||
)),
|
)),
|
||||||
CheckboxField::create('IsPrimary', $this->fieldLabel('IsPrimary'))
|
CheckboxField::create('IsPrimary', $this->fieldLabel('IsPrimary'))
|
||||||
->setDescription(_t(
|
->setDescription(_t(
|
||||||
__CLASS__ . '.PROTOCOL_DESCRIPTION',
|
__CLASS__ . '.ISPRIMARY_DESCRIPTION',
|
||||||
'Mark this as the default domain for this subsite'
|
'Mark this as the default domain for this subsite'
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
@ -8,7 +8,6 @@ use SilverStripe\CMS\Model\VirtualPage;
|
|||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
use SilverStripe\Forms\LabelField;
|
|
||||||
use SilverStripe\Forms\LiteralField;
|
use SilverStripe\Forms\LiteralField;
|
||||||
use SilverStripe\Forms\TextareaField;
|
use SilverStripe\Forms\TextareaField;
|
||||||
use SilverStripe\Forms\TextField;
|
use SilverStripe\Forms\TextField;
|
||||||
@ -113,7 +112,7 @@ class SubsitesVirtualPage extends VirtualPage
|
|||||||
'Root.Main',
|
'Root.Main',
|
||||||
TextareaField::create(
|
TextareaField::create(
|
||||||
'CustomMetaKeywords',
|
'CustomMetaKeywords',
|
||||||
$this->fieldLabel('CustomMetaTitle')
|
$this->fieldLabel('CustomMetaKeywords')
|
||||||
)->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')),
|
)->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')),
|
||||||
'MetaKeywords'
|
'MetaKeywords'
|
||||||
);
|
);
|
||||||
@ -121,7 +120,7 @@ class SubsitesVirtualPage extends VirtualPage
|
|||||||
'Root.Main',
|
'Root.Main',
|
||||||
TextareaField::create(
|
TextareaField::create(
|
||||||
'CustomMetaDescription',
|
'CustomMetaDescription',
|
||||||
$this->fieldLabel('CustomMetaTitle')
|
$this->fieldLabel('CustomMetaDescription')
|
||||||
)->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')),
|
)->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')),
|
||||||
'MetaDescription'
|
'MetaDescription'
|
||||||
);
|
);
|
||||||
@ -129,7 +128,7 @@ class SubsitesVirtualPage extends VirtualPage
|
|||||||
'Root.Main',
|
'Root.Main',
|
||||||
TextField::create(
|
TextField::create(
|
||||||
'CustomExtraMeta',
|
'CustomExtraMeta',
|
||||||
$this->fieldLabel('CustomMetaTitle')
|
$this->fieldLabel('CustomExtraMeta')
|
||||||
)->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')),
|
)->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')),
|
||||||
'ExtraMeta'
|
'ExtraMeta'
|
||||||
);
|
);
|
||||||
@ -226,30 +225,20 @@ class SubsitesVirtualPage extends VirtualPage
|
|||||||
// Veto the validation rules if its false. In this case, some logic
|
// Veto the validation rules if its false. In this case, some logic
|
||||||
// needs to be duplicated from parent to find out the exact reason the validation failed.
|
// needs to be duplicated from parent to find out the exact reason the validation failed.
|
||||||
if (!$isValid) {
|
if (!$isValid) {
|
||||||
$IDFilter = $this->ID ? "AND \"SiteTree\".\"ID\" <> $this->ID" : null;
|
$filters = [
|
||||||
$parentFilter = null;
|
'URLSegment' => $this->URLSegment,
|
||||||
|
'ID:not' => $this->ID,
|
||||||
|
];
|
||||||
|
|
||||||
if (Config::inst()->get(SiteTree::class, 'nested_urls')) {
|
if (Config::inst()->get(SiteTree::class, 'nested_urls')) {
|
||||||
if ($this->ParentID) {
|
$filters['ParentID'] = $this->ParentID ?: 0;
|
||||||
$parentFilter = " AND \"SiteTree\".\"ParentID\" = $this->ParentID";
|
|
||||||
} else {
|
|
||||||
$parentFilter = ' AND "SiteTree"."ParentID" = 0';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
|
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
|
||||||
Subsite::$disable_subsite_filter = true;
|
Subsite::disable_subsite_filter();
|
||||||
$existingPage = DataObject::get_one(
|
$existingPage = SiteTree::get()->filter($filters)->first();
|
||||||
SiteTree::class,
|
Subsite::disable_subsite_filter($origDisableSubsiteFilter);
|
||||||
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter",
|
$existingPageInSubsite = SiteTree::get()->filter($filters)->first();
|
||||||
false // disable cache, it doesn't include subsite status in the key
|
|
||||||
);
|
|
||||||
Subsite::$disable_subsite_filter = $origDisableSubsiteFilter;
|
|
||||||
$existingPageInSubsite = DataObject::get_one(
|
|
||||||
SiteTree::class,
|
|
||||||
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter",
|
|
||||||
false // disable cache, it doesn't include subsite status in the key
|
|
||||||
);
|
|
||||||
|
|
||||||
// If URL has been vetoed because of an existing page,
|
// If URL has been vetoed because of an existing page,
|
||||||
// be more specific and allow same URLSegments in different subsites
|
// be more specific and allow same URLSegments in different subsites
|
||||||
|
@ -9,6 +9,7 @@ use SilverStripe\CMS\Controllers\CMSPageEditController;
|
|||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Dev\FunctionalTest;
|
use SilverStripe\Dev\FunctionalTest;
|
||||||
use SilverStripe\Security\Member;
|
use SilverStripe\Security\Member;
|
||||||
|
use SilverStripe\Subsites\Extensions\LeftAndMainSubsites;
|
||||||
use SilverStripe\Subsites\Model\Subsite;
|
use SilverStripe\Subsites\Model\Subsite;
|
||||||
use SilverStripe\Subsites\State\SubsiteState;
|
use SilverStripe\Subsites\State\SubsiteState;
|
||||||
|
|
||||||
@ -100,4 +101,14 @@ class LeftAndMainSubsitesTest extends FunctionalTest
|
|||||||
$this->assertTrue($l->shouldChangeSubsite(CMSPageEditController::class, 1, 5));
|
$this->assertTrue($l->shouldChangeSubsite(CMSPageEditController::class, 1, 5));
|
||||||
$this->assertFalse($l->shouldChangeSubsite(CMSPageEditController::class, 1, 1));
|
$this->assertFalse($l->shouldChangeSubsite(CMSPageEditController::class, 1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanAccessWithPassedMember()
|
||||||
|
{
|
||||||
|
$memberID = $this->logInWithPermission('ADMIN');
|
||||||
|
$member = Member::get()->byID($memberID);
|
||||||
|
|
||||||
|
/** @var LeftAndMain&LeftAndMainSubsites $leftAndMain */
|
||||||
|
$leftAndMain = new LeftAndMain();
|
||||||
|
$this->assertTrue($leftAndMain->canAccess($member));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ namespace SilverStripe\Subsites\Tests;
|
|||||||
use Page;
|
use Page;
|
||||||
use SilverStripe\CMS\Controllers\CMSMain;
|
use SilverStripe\CMS\Controllers\CMSMain;
|
||||||
use SilverStripe\CMS\Controllers\ModelAsController;
|
use SilverStripe\CMS\Controllers\ModelAsController;
|
||||||
|
use SilverStripe\CMS\Forms\SiteTreeURLSegmentField;
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Core\Convert;
|
|
||||||
use SilverStripe\ErrorPage\ErrorPage;
|
use SilverStripe\ErrorPage\ErrorPage;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Security\Member;
|
use SilverStripe\Security\Member;
|
||||||
@ -21,6 +21,7 @@ use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestClassB;
|
|||||||
use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestErrorPage;
|
use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestErrorPage;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
use SilverStripe\View\SSViewer;
|
use SilverStripe\View\SSViewer;
|
||||||
|
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
|
||||||
|
|
||||||
class SiteTreeSubsitesTest extends BaseSubsiteTest
|
class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||||
{
|
{
|
||||||
@ -33,7 +34,9 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
];
|
];
|
||||||
|
|
||||||
protected static $illegal_extensions = [
|
protected static $illegal_extensions = [
|
||||||
SiteTree::class => ['Translatable'] // @todo implement Translatable namespace
|
SiteTree::class => [
|
||||||
|
FluentSiteTreeExtension::class,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
@ -449,7 +452,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideAlternateAbsoluteLink
|
* @dataProvider provideAlternateAbsoluteLink
|
||||||
* @param name $pageFixtureName
|
* @param string $pageFixtureName
|
||||||
* @param string|null $action
|
* @param string|null $action
|
||||||
* @param string $expectedAbsoluteLink
|
* @param string $expectedAbsoluteLink
|
||||||
*/
|
*/
|
||||||
@ -465,4 +468,23 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
|
|
||||||
$this->assertEquals($expectedAbsoluteLink, $result);
|
$this->assertEquals($expectedAbsoluteLink, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testURLSegmentBaseIsSetToSubsiteBaseURL()
|
||||||
|
{
|
||||||
|
// This subsite has a domain with 'one.example.org' as the primary domain
|
||||||
|
/** @var Subsite $subsite */
|
||||||
|
$subsite = $this->objFromFixture(Subsite::class, 'domaintest1');
|
||||||
|
Subsite::changeSubsite($subsite);
|
||||||
|
|
||||||
|
$page = new SiteTree();
|
||||||
|
$page->SubsiteID = $subsite->ID;
|
||||||
|
$page->write();
|
||||||
|
$fields = $page->getCMSFields();
|
||||||
|
|
||||||
|
/** @var SiteTreeURLSegmentField $urlSegmentField */
|
||||||
|
$urlSegmentField = $fields->dataFieldByName('URLSegment');
|
||||||
|
$this->assertInstanceOf(SiteTreeURLSegmentField::class, $urlSegmentField);
|
||||||
|
|
||||||
|
$this->assertSame('http://one.example.org/', $urlSegmentField->getURLPrefix());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,4 +311,41 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
|
|||||||
Versioned::prepopulate_versionnumber_cache(SiteTree::class, 'Live', [$p->ID]);
|
Versioned::prepopulate_versionnumber_cache(SiteTree::class, 'Live', [$p->ID]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testValidURLSegmentWithUniquePageAndNestedURLs()
|
||||||
|
{
|
||||||
|
SiteTree::config()->set('nested_urls', true);
|
||||||
|
|
||||||
|
$newPage = new SubsitesVirtualPage();
|
||||||
|
$newPage->Title = 'My new page';
|
||||||
|
$newPage->URLSegment = 'my-new-page';
|
||||||
|
|
||||||
|
$this->assertTrue($newPage->validURLSegment());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testValidURLSegmentWithExistingPageInSubsite()
|
||||||
|
{
|
||||||
|
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
|
||||||
|
Subsite::changeSubsite($subsite1->ID);
|
||||||
|
|
||||||
|
SiteTree::config()->set('nested_urls', false);
|
||||||
|
|
||||||
|
$similarContactUsPage = new SubsitesVirtualPage();
|
||||||
|
$similarContactUsPage->Title = 'Similar to Contact Us in Subsite 1';
|
||||||
|
$similarContactUsPage->URLSegment = 'contact-us';
|
||||||
|
|
||||||
|
$this->assertFalse($similarContactUsPage->validURLSegment());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testValidURLSegmentWithExistingPageInAnotherSubsite()
|
||||||
|
{
|
||||||
|
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
|
||||||
|
Subsite::changeSubsite($subsite1->ID);
|
||||||
|
|
||||||
|
$similarStaffPage = new SubsitesVirtualPage();
|
||||||
|
$similarStaffPage->Title = 'Similar to Staff page in main site';
|
||||||
|
$similarStaffPage->URLSegment = 'staff';
|
||||||
|
|
||||||
|
$this->assertFalse($similarStaffPage->validURLSegment());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user