Skip to content

Commit

Permalink
replace config::inst()->update() with config::modify->set()
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerkrauss committed May 24, 2017
1 parent a49189e commit ef602ab
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion code/extensions/SiteTreeSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static function contentcontrollerInit($controller) {
$subsite = Subsite::currentSubsite();

if($subsite && $subsite->Theme){
Config::inst()->update('SilverStripe\\View\\SSViewer', 'theme', Subsite::currentSubsite()->Theme);
Config::modify()->set('SilverStripe\\View\\SSViewer', 'theme', Subsite::currentSubsite()->Theme);
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/LeftAndMainSubsitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SilverStripe\Dev\FunctionalTest;

class LeftAndMainSubsitesTest extends FunctionalTest {

static $fixture_file = 'subsites/tests/SubsiteTest.yml';

/**
Expand Down Expand Up @@ -45,16 +45,16 @@ function testAccessChecksDontChangeCurrentSubsite() {
$admin = $this->objFromFixture("SilverStripe\\Security\\Member","admin");
$this->loginAs($admin);
$ids = array();

$subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
$subsite2 = $this->objFromFixture('Subsite', 'domaintest2');
$subsite3 = $this->objFromFixture('Subsite', 'domaintest3');

$ids[] = $subsite1->ID;
$ids[] = $subsite2->ID;
$ids[] = $subsite3->ID;
$ids[] = 0;

// Enable session-based subsite tracking.
Subsite::$use_session_subsiteid = true;

Expand All @@ -67,20 +67,20 @@ function testAccessChecksDontChangeCurrentSubsite() {
$this->assertEquals($id, Subsite::currentSubsiteID(),
"The current subsite has not been changed in the process of checking permissions for admin user.");
}

}

function testShouldChangeSubsite() {
$l = new LeftAndMain();
Config::inst()->nest();

Config::inst()->update('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', false);
Config::modify()->set('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', false);
$this->assertTrue($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 0, 5));
$this->assertFalse($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 0, 0));
$this->assertTrue($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 1, 5));
$this->assertFalse($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 1, 1));

Config::inst()->update('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', true);
Config::modify()->set('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', true);
$this->assertFalse($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 0, 5));
$this->assertFalse($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 0, 0));
$this->assertTrue($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 1, 5));
Expand Down
8 changes: 4 additions & 4 deletions tests/SubsiteAdminFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function testAnonymousIsForbiddenAdminAccess() {
function testAdminCanAccessAllSubsites() {
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
Session::set("loggedInAs", $member->ID);

$this->getAndFollowAll('admin/pages/?SubsiteID=0');
$this->assertEquals(Subsite::currentSubsiteID(), '0', 'Can access main site.');
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
Expand All @@ -63,19 +63,19 @@ function testAdminCanAccessAllSubsites() {
function testAdminIsRedirectedToObjectsSubsite() {
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
Session::set("loggedInAs", $member->ID);

$mainSubsitePage = $this->objFromFixture('Page', 'mainSubsitePage');
$subsite1Home = $this->objFromFixture('Page', 'subsite1_home');

Config::inst()->nest();

Config::inst()->update('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', false);
Config::modify()->set('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', false);
Subsite::changeSubsite(0);
$this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, 'Loading an object switches the subsite');
$this->assertRegExp("#^admin/pages.*#", $this->mainSession->lastUrl(), 'Lands on the correct section');

Config::inst()->update('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', true);
Config::modify()->set('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', true);
Subsite::changeSubsite(0);
$this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, 'Loading a non-main-site object still switches the subsite if configured with treats_subsite_0_as_global');
Expand Down
74 changes: 37 additions & 37 deletions tests/SubsitesVirtualPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ public function tearDown() {
AssetStoreTest_SpyStore::reset();
parent::tearDown();
}

// Attempt to bring main:linky to subsite2:linky
function testVirtualPageFromAnotherSubsite() {
Subsite::$write_hostmap = false;

$subsite = $this->objFromFixture('Subsite', 'subsite2');

Subsite::changeSubsite($subsite->ID);
Subsite::$disable_subsite_filter = false;

$linky = $this->objFromFixture('Page', 'linky');

$svp = new SubsitesVirtualPage();
$svp->CopyContentFromID = $linky->ID;
$svp->SubsiteID = $subsite->ID;
$svp->URLSegment = 'linky';

$svp->write();

$this->assertEquals($svp->SubsiteID, $subsite->ID);
$this->assertEquals($svp->Title, $linky->Title);
}
Expand All @@ -70,12 +70,12 @@ function testFileLinkRewritingOnVirtualPages() {
$svp->CopyContentFromID = $page->ID;
$svp->write();
$svp->doPublish();

// Rename the file
$file = $this->objFromFixture('SilverStripe\\Assets\\File', 'file1');
$file->Name = 'renamed-test-file.pdf';
$file->write();

// Verify that the draft and publish virtual pages both have the corrected link
$this->assertContains('<img src="/assets/SubsitesVirtualPageTest/464dedb70a/renamed-test-file.pdf"',
DB::query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = $svp->ID")->value());
Expand All @@ -99,27 +99,27 @@ function testSubsiteVirtualPagesArentInappropriatelyPublished() {
$p->doPublish();
$this->fixVersionNumberCache($vp);
$this->assertTrue($vp->IsAddedToStage);

// A new VP created after P's initial construction
$vp2 = new SubsitesVirtualPage();
$vp2->CopyContentFromID = $p->ID;
$vp2->write();
$this->assertTrue($vp2->IsAddedToStage);

// Also remains orange after a republish
$p->Content = "new content";
$p->write();
$p->doPublish();
$this->fixVersionNumberCache($vp2);
$this->assertTrue($vp2->IsAddedToStage);

// VP is now published
$vp->doPublish();

$this->fixVersionNumberCache($vp);
$this->assertTrue($vp->ExistsOnLive);
$this->assertFalse($vp->IsModifiedOnStage);

// P edited, VP and P both go green
$p->Content = "third content";
$p->write();
Expand All @@ -134,7 +134,7 @@ function testSubsiteVirtualPagesArentInappropriatelyPublished() {
$this->assertTrue($vp->ExistsOnLive);
$this->assertFalse($vp->IsModifiedOnStage);
}

/**
* This test ensures published Subsites Virtual Pages immediately reflect updates
* to their published target pages. Note - this has to happen when the virtual page
Expand All @@ -150,12 +150,12 @@ function testPublishedSubsiteVirtualPagesUpdateIfTargetPageUpdates()
$p->writeToStage('Stage');
$p->publish('Stage', 'Live');
$this->assertTrue($p->ExistsOnLive);

// change to subsite
$subsite = $this->objFromFixture('Subsite', 'subsite2');
Subsite::changeSubsite($subsite->ID);
Subsite::$disable_subsite_filter = false;

// create svp in subsite
$svp = new SubsitesVirtualPage();
$svp->CopyContentFromID = $p->ID;
Expand All @@ -164,64 +164,64 @@ function testPublishedSubsiteVirtualPagesUpdateIfTargetPageUpdates()
$svp->publish('Stage', 'Live');
$this->assertEquals($svp->SubsiteID, $subsite->ID);
$this->assertTrue($svp->ExistsOnLive);

// change back to original subsite ("Main site")
Subsite::changeSubsite(0);

// update original page
$p->Title = 'New Title';
// "save & publish"
$p->writeToStage('Stage');
$p->publish('Stage', 'Live');
$this->assertNotEquals($p->SubsiteID, $subsite->ID);

// reload SVP from database
// can't use DO::get by id because caches.
$svpdb = $svp->get()->byID($svp->ID);

// ensure title changed
$this->assertEquals($svpdb->Title, $p->Title);
$this->assertEquals($svpdb->Title, $p->Title);
}

function testUnpublishingParentPageUnpublishesSubsiteVirtualPages() {
Config::inst()->update('StaticPublisher', 'disable_realtime', true);
Config::modify()->set('StaticPublisher', 'disable_realtime', true);

// Go to main site, get parent page
$subsite = $this->objFromFixture('Subsite', 'main');
Subsite::changeSubsite($subsite->ID);
$page = $this->objFromFixture('Page', 'importantpage');

// Create two SVPs on other subsites
$subsite = $this->objFromFixture('Subsite', 'subsite1');
Subsite::changeSubsite($subsite->ID);
$vp1 = new SubsitesVirtualPage();
$vp1->CopyContentFromID = $page->ID;
$vp1->write();
$vp1->doPublish();

$subsite = $this->objFromFixture('Subsite', 'subsite2');
Subsite::changeSubsite($subsite->ID);
$vp2 = new SubsitesVirtualPage();
$vp2->CopyContentFromID = $page->ID;
$vp2->write();
$vp2->doPublish();

// Switch back to main site, unpublish source
$subsite = $this->objFromFixture('Subsite', 'main');
Subsite::changeSubsite($subsite->ID);
$page = $this->objFromFixture('Page', 'importantpage');
$page->doUnpublish();

Subsite::changeSubsite($vp1->SubsiteID);
$onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "\"SiteTree_Live\".\"ID\" = ".$vp1->ID);
$this->assertNull($onLive, 'SVP has been removed from live');

$subsite = $this->objFromFixture('Subsite', 'subsite2');
Subsite::changeSubsite($vp2->SubsiteID);
$onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "\"SiteTree_Live\".\"ID\" = ".$vp2->ID);
$this->assertNull($onLive, 'SVP has been removed from live');
}

/**
* Similar to {@link SiteTreeSubsitesTest->testTwoPagesWithSameURLOnDifferentSubsites()}
* and {@link SiteTreeSubsitesTest->testPagesInDifferentSubsitesCanShareURLSegment()}.
Expand All @@ -231,33 +231,33 @@ function testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite() {
$subsite1 = $this->objFromFixture('Subsite', 'subsite1');
$subsite2 = $this->objFromFixture('Subsite', 'subsite2');
Subsite::changeSubsite($subsite1->ID);

$subsite1Page = $this->objFromFixture('Page', 'subsite1_staff');
$subsite1Page->URLSegment = 'staff';
$subsite1Page->write();

// saving on subsite1, and linking to subsite1
$subsite1Vp = new SubsitesVirtualPage();
$subsite1Vp->CopyContentFromID = $subsite1Page->ID;
$subsite1Vp->SubsiteID = $subsite1->ID;
$subsite1Vp->write();
$this->assertNotEquals(
$subsite1Vp->URLSegment,
$subsite1Vp->URLSegment,
$subsite1Page->URLSegment,
"Doesn't allow explicit URLSegment overrides when already existing in same subsite"
);

//Change to subsite 2
Subsite::changeSubsite($subsite2->ID);

// saving in subsite2 (which already has a page with URLSegment 'contact-us'),
// saving in subsite2 (which already has a page with URLSegment 'contact-us'),
// but linking to a page in subsite1
$subsite2Vp = new SubsitesVirtualPage();
$subsite2Vp->CopyContentFromID = $subsite1Page->ID;
$subsite2Vp->SubsiteID = $subsite2->ID;
$subsite2Vp->SubsiteID = $subsite2->ID;
$subsite2Vp->write();
$this->assertEquals(
$subsite2Vp->URLSegment,
$subsite2Vp->URLSegment,
$subsite1Page->URLSegment,
"Does allow explicit URLSegment overrides when only existing in a different subsite"
);
Expand Down

0 comments on commit ef602ab

Please sign in to comment.