mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
Add Subsite theme as main theme; allow cascading of themes
This commit is contained in:
parent
a4a1ab6a78
commit
877f4f5f9d
@ -297,7 +297,7 @@ class SiteTreeSubsites extends DataExtension
|
||||
$subsite = Subsite::currentSubsite();
|
||||
|
||||
if ($subsite && $subsite->Theme) {
|
||||
Config::modify()->set(SSViewer::class, 'theme', Subsite::currentSubsite()->Theme);
|
||||
SSViewer::set_themes(array_merge([$subsite->Theme], SSViewer::get_themes()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use Page;
|
||||
use SilverStripe\CMS\Controllers\CMSMain;
|
||||
use SilverStripe\CMS\Controllers\ModelAsController;
|
||||
use SilverStripe\CMS\Model\ErrorPage;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Director;
|
||||
@ -18,6 +19,7 @@ use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\View\SSViewer;
|
||||
|
||||
class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
{
|
||||
@ -337,6 +339,32 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
$this->assertEquals($moved->SubsiteID, $newSubsite->ID, 'Ensure returned records are on new subsite');
|
||||
$this->assertEquals($moved->AllChildren()->count(), 0, 'All pages are copied across');
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo: move to a functional test?
|
||||
*/
|
||||
public function testIfSubsiteThemeIsSetToThemeList()
|
||||
{
|
||||
$defaultThemes = ['default'];
|
||||
SSViewer::set_themes($defaultThemes);
|
||||
|
||||
$subsitePage = $this->objFromFixture(Page::class, 'home');
|
||||
Subsite::changeSubsite($subsitePage->SubsiteID);
|
||||
$controller = ModelAsController::controller_for($subsitePage);
|
||||
SiteTree::singleton()->extend('contentcontrollerInit', $controller);
|
||||
|
||||
$this->assertEquals(SSViewer::get_themes(), $defaultThemes,
|
||||
'Themes should not be modified when Subsite has no theme defined');
|
||||
|
||||
$pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_home');
|
||||
Subsite::changeSubsite($pageWithTheme->SubsiteID);
|
||||
$controller = ModelAsController::controller_for($pageWithTheme);
|
||||
SiteTree::singleton()->extend('contentcontrollerInit', $controller);
|
||||
$subsiteTheme = $pageWithTheme->Subsite()->Theme;
|
||||
$this->assertEquals(SSViewer::get_themes(), array_merge([$subsiteTheme], $defaultThemes),
|
||||
'Themes should be modified when Subsite has theme defined');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
38
tests/php/SubsiteFunctionalTest.php
Normal file
38
tests/php/SubsiteFunctionalTest.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace subsites\tests\php;
|
||||
|
||||
|
||||
use Page;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\View\SSViewer;
|
||||
|
||||
class SubsiteFunctionalTest extends FunctionalTest
|
||||
{
|
||||
public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
|
||||
|
||||
/**
|
||||
* @todo: remove test from SiteTreeSubsitesTest when this one works. Seems domain lookup is broken atm
|
||||
*/
|
||||
public function testIfSubsiteThemeIsSetToThemeList()
|
||||
{
|
||||
$this->markTestSkipped('doesn\'t work somehow - refactor when domain lookup is working');
|
||||
$defaultThemes = ['default'];
|
||||
SSViewer::set_themes($defaultThemes);
|
||||
|
||||
$subsitePage = $this->objFromFixture(Page::class, 'contact');
|
||||
$this->get($subsitePage->AbsoluteLink());
|
||||
$this->assertEquals($subsitePage->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed');
|
||||
$this->assertEquals(SSViewer::get_themes(), $defaultThemes,
|
||||
'Themes should not be modified when Subsite has no theme defined');
|
||||
|
||||
$pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_contactus');
|
||||
$this->get($pageWithTheme->AbsoluteLink());
|
||||
$subsiteTheme = $pageWithTheme->Subsite()->Theme;
|
||||
$this->assertEquals($pageWithTheme->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed');
|
||||
$this->assertEquals(SSViewer::get_themes(), array_merge([$subsiteTheme], $defaultThemes),
|
||||
'Themes should be modified when Subsite has theme defined');
|
||||
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ SilverStripe\Subsites\Model\Subsite:
|
||||
Title: Template
|
||||
subsite1:
|
||||
Title: Subsite1 Template
|
||||
Theme: subsiteTheme
|
||||
subsite2:
|
||||
Title: Subsite2 Template
|
||||
domaintest1:
|
||||
|
Loading…
Reference in New Issue
Block a user