Skip to content

Commit

Permalink
Add Subsite theme as main theme; allow cascading of themes
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerkrauss committed Jun 7, 2017
1 parent a4a1ab6 commit 877f4f5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/extensions/SiteTreeSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static function contentcontrollerInit($controller)
$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()));
}
}

Expand Down
28 changes: 28 additions & 0 deletions tests/php/SiteTreeSubsitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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;
Expand All @@ -18,6 +19,7 @@
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\SSViewer;

class SiteTreeSubsitesTest extends BaseSubsiteTest
{
Expand Down Expand Up @@ -337,6 +339,32 @@ public function testCopySubsiteWithoutChildren()
$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');

}
}


Expand Down
38 changes: 38 additions & 0 deletions tests/php/SubsiteFunctionalTest.php
Original file line number Diff line number Diff line change
@@ -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');

}
}
1 change: 1 addition & 0 deletions tests/php/SubsiteTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SilverStripe\Subsites\Model\Subsite:
Title: Template
subsite1:
Title: Subsite1 Template
Theme: subsiteTheme
subsite2:
Title: Subsite2 Template
domaintest1:
Expand Down

0 comments on commit 877f4f5

Please sign in to comment.