From c345f6fcc54e115315ff2e731b7d8a947167cd4a Mon Sep 17 00:00:00 2001 From: Kirk Mayo Date: Mon, 16 Jul 2012 11:14:13 +1200 Subject: [PATCH] BUG: Coding convention fixes BUG: more coding convention fixing --- code/extensions/SiteTreeSubsites.php | 22 +++--- code/model/RelatedPageLink.php | 2 +- code/model/Subsite.php | 19 ++--- css/LeftAndMain_Subsites.css | 8 +- templates/LeftAndMain_Menu.ss | 10 +-- tests/SubsiteAdminTest.php | 112 +++++++++++++-------------- tests/SubsiteTest.php | 4 +- tests/SubsitesVirtualPageTest.php | 8 +- 8 files changed, 93 insertions(+), 92 deletions(-) diff --git a/code/extensions/SiteTreeSubsites.php b/code/extensions/SiteTreeSubsites.php index cf46a69..edcf974 100644 --- a/code/extensions/SiteTreeSubsites.php +++ b/code/extensions/SiteTreeSubsites.php @@ -229,13 +229,13 @@ class SiteTreeSubsites extends DataExtension { $subsiteID = $subsite->ID; } else $subsite = DataObject::get_by_id('Subsite', $subsiteID); - $oldSubsite=Subsite::currentSubsiteID(); - if($subsiteID) { - Subsite::changeSubsite($subsiteID); - }else { - $subsiteID=$oldSubsite; - } - + $oldSubsite=Subsite::currentSubsiteID(); + if($subsiteID) { + Subsite::changeSubsite($subsiteID); + }else { + $subsiteID=$oldSubsite; + } + $page = $this->owner->duplicate(false); $page->CheckedPublicationDifferences = $page->AddedToStage = true; @@ -245,9 +245,9 @@ class SiteTreeSubsites extends DataExtension { if($isTemplate) $page->MasterPageID = $this->owner->ID; $page->write(); - - Subsite::changeSubsite($oldSubsite); - + + Subsite::changeSubsite($oldSubsite); + return $page; } @@ -331,4 +331,4 @@ class SiteTreeSubsites extends DataExtension { if(in_array($this->owner->class, $blacklisted)) return false; } } -} \ No newline at end of file +} diff --git a/code/model/RelatedPageLink.php b/code/model/RelatedPageLink.php index f86e382..cc0f20a 100644 --- a/code/model/RelatedPageLink.php +++ b/code/model/RelatedPageLink.php @@ -87,4 +87,4 @@ class RelatedPageLink extends DataObject { } } -?> \ No newline at end of file +?> diff --git a/code/model/Subsite.php b/code/model/Subsite.php index 455b198..abe41a0 100644 --- a/code/model/Subsite.php +++ b/code/model/Subsite.php @@ -661,17 +661,18 @@ class Subsite_Template extends Subsite { if($children) { foreach($children as $child) { $childClone = $child->duplicateToSubsite($intranet); - - //Change to destination subsite - self::changeSubsite($intranet->ID); - + + //Change to destination subsite + self::changeSubsite($intranet->ID); + $newTemplate = parent::duplicate($doWrite); + $childClone = $child->duplicateToSubsite($newTemplate, false); + $childClone->ParentID = $destParentID; $childClone->writeToStage('Stage'); $childClone->publish('Stage', 'Live'); - - //Change Back to this subsite - self::changeSubsite($this->ID); - + + //Change Back to this subsite + self::changeSubsite($this->ID); array_push($stack, array($child->ID, $childClone->ID)); } } @@ -682,4 +683,4 @@ class Subsite_Template extends Subsite { return $intranet; } } -?> \ No newline at end of file +?> diff --git a/css/LeftAndMain_Subsites.css b/css/LeftAndMain_Subsites.css index ec8983c..3eec4a8 100644 --- a/css/LeftAndMain_Subsites.css +++ b/css/LeftAndMain_Subsites.css @@ -25,7 +25,7 @@ } .cms-login-status.subsites { - padding-bottom: 7px; + padding-bottom: 7px; } #SubsitesSelect, @@ -33,7 +33,7 @@ font-size: 12px; } #SubsitesSelect { - width: 171px; + width: 171px; padding: 3px; } @@ -58,5 +58,5 @@ body.SubsiteAdmin .right form #URL .fieldgroup * { } .cms-add-form #PageType li .class-SubsitesVirtualPage, .class-SubsitesVirtualPage a .jstree-pageicon { - background-position: 0 -32px !important; -} \ No newline at end of file + background-position: 0 -32px !important; +} diff --git a/templates/LeftAndMain_Menu.ss b/templates/LeftAndMain_Menu.ss index 21fed4a..b6aee2a 100644 --- a/templates/LeftAndMain_Menu.ss +++ b/templates/LeftAndMain_Menu.ss @@ -18,10 +18,10 @@ <% end_control %> - -
- $SubsiteList -
+ +
+ $SubsiteList +
@@ -56,4 +56,4 @@ » «
- \ No newline at end of file + diff --git a/tests/SubsiteAdminTest.php b/tests/SubsiteAdminTest.php index b987114..419bde9 100644 --- a/tests/SubsiteAdminTest.php +++ b/tests/SubsiteAdminTest.php @@ -3,27 +3,27 @@ class SubsiteAdminTest extends SapphireTest { static $fixture_file = 'subsites/tests/SubsiteTest.yml'; - function adminLoggedInSession() { - return new Session(array( - 'loggedInAs' => $this->idFromFixture('Member', 'admin') - )); - } + function adminLoggedInSession() { + return new Session(array( + 'loggedInAs' => $this->idFromFixture('Member', 'admin') + )); + } - /** - * Test generation of the view - */ - function testBasicView() { + /** + * Test generation of the view + */ + function testBasicView() { Subsite::$write_hostmap = false; $subsite1ID = $this->objFromFixture('Subsite','domaintest1')->ID; - // Open the admin area logged in as admin - $response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession()); - - // Confirm that this URL gets you the entire page, with the edit form loaded - $response2 = Director::test("admin/subsites/Subsite/EditForm/field/Subsite/item/$subsite1ID/edit", null, $this->adminLoggedInSession()); - $this->assertTrue(strpos($response2->getBody(), 'id="Form_ItemEditForm_ID"') !== false, "Testing Form_ItemEditForm_ID exists"); - $this->assertTrue(strpos($response2->getBody(), ' exists"); - } + // Open the admin area logged in as admin + $response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession()); + + // Confirm that this URL gets you the entire page, with the edit form loaded + $response2 = Director::test("admin/subsites/Subsite/EditForm/field/Subsite/item/$subsite1ID/edit", null, $this->adminLoggedInSession()); + $this->assertTrue(strpos($response2->getBody(), 'id="Form_ItemEditForm_ID"') !== false, "Testing Form_ItemEditForm_ID exists"); + $this->assertTrue(strpos($response2->getBody(), ' exists"); + } /** * Test searching for an intranet @@ -31,7 +31,7 @@ class SubsiteAdminTest extends SapphireTest { function XXtestIntranetSearch() { $cont = new SubsiteAdmin(); $cont->pushCurrent(); - $cont->setSession($this->adminLoggedInSession()); + $cont->setSession($this->adminLoggedInSession()); // Check that the logged-in member has the correct permissions $this->assertTrue(Permission::check('ADMIN') ? true : false); @@ -44,49 +44,49 @@ class SubsiteAdminTest extends SapphireTest { foreach($searches as $search) { $response = $form->testAjaxSubmission('getResults', $search); - $links = $response->getLinks(); - foreach($links as $link) { - $this->assertTrue(preg_match('/^admin\/subsites\/show\/[0-9]+$/', $link['href']) == 1, "Search result links bad."); - } + $links = $response->getLinks(); + foreach($links as $link) { + $this->assertTrue(preg_match('/^admin\/subsites\/show\/[0-9]+$/', $link['href']) == 1, "Search result links bad."); + } } $cont->popCurrent(); } - - /** - * Test the intranet creation form. - */ - function XXtestIntranetCreation() { - $cont = new SubsiteAdmin(); - $cont->pushCurrent(); - $cont->setSession($this->adminLoggedInSession()); - - $form = $cont->AddSubsiteForm(); - $source = $form->dataFieldByName('TemplateID')->getSource(); - - $templateIDs = $this->allFixtureIDs('Subsite_Template'); - foreach($templateIDs as $templateID) { - $this->assertArrayHasKey($templateID, $source); - } - - $templateObj = $this->objFromFixture('Subsite_Template','main'); - $this->assertEquals($templateObj->Title, $source[$templateObj->ID], "Template dropdown isn't listing Title values"); - $response = $form->testSubmission('addintranet', array( - 'Name' => 'Test Intranet', - 'Domain' => 'test.example.com', - 'TemplateID' => 1, - 'AdminEmail' => '', - 'AdminName' => '', - )); + /** + * Test the intranet creation form. + */ + function XXtestIntranetCreation() { + $cont = new SubsiteAdmin(); + $cont->pushCurrent(); + $cont->setSession($this->adminLoggedInSession()); - $this->assertTrue(true == preg_match('/admin\/subsites\/show\/([0-9]+)/i', $response->getHeader('Location'), $matches), "Intranet creation dowsn't redirect to new view"); - - $newIntranet = DataObject::get_by_id("Subsite", $matches[1]); - $this->assertEquals('Test Intranet', $newIntranet->Title, "New intranet not created properly."); - - $cont->popCurrent(); - } + $form = $cont->AddSubsiteForm(); + $source = $form->dataFieldByName('TemplateID')->getSource(); + + $templateIDs = $this->allFixtureIDs('Subsite_Template'); + foreach($templateIDs as $templateID) { + $this->assertArrayHasKey($templateID, $source); + } + + $templateObj = $this->objFromFixture('Subsite_Template','main'); + $this->assertEquals($templateObj->Title, $source[$templateObj->ID], "Template dropdown isn't listing Title values"); + + $response = $form->testSubmission('addintranet', array( + 'Name' => 'Test Intranet', + 'Domain' => 'test.example.com', + 'TemplateID' => 1, + 'AdminEmail' => '', + 'AdminName' => '', + )); + + $this->assertTrue(true == preg_match('/admin\/subsites\/show\/([0-9]+)/i', $response->getHeader('Location'), $matches), "Intranet creation dowsn't redirect to new view"); + + $newIntranet = DataObject::get_by_id("Subsite", $matches[1]); + $this->assertEquals('Test Intranet', $newIntranet->Title, "New intranet not created properly."); + + $cont->popCurrent(); + } /** @@ -112,4 +112,4 @@ class SubsiteAdminTest extends SapphireTest { } -?> \ No newline at end of file +?> diff --git a/tests/SubsiteTest.php b/tests/SubsiteTest.php index bce3a61..c8ced5f 100644 --- a/tests/SubsiteTest.php +++ b/tests/SubsiteTest.php @@ -52,7 +52,7 @@ class SubsiteTest extends SapphireTest { $subsite->activate(); $siteHome = DataObject::get_one('SiteTree', "\"URLSegment\" = 'home'"); - $this->assertNotEquals($siteHome, false, 'Home Page for subsite not found'); + $this->assertNotEquals($siteHome, false, 'Home Page for subsite not found'); $this->assertEquals($subsite->ID, $siteHome->SubsiteID, 'createInstance() copies existing pages retaining the same URLSegment' ); @@ -342,4 +342,4 @@ class SubsiteTest extends SapphireTest { $subsite2->activate(); $this->assertEquals('MyNewAwesomePage', DataObject::get_by_id('Page', $page2->ID)->Title); } -} \ No newline at end of file +} diff --git a/tests/SubsitesVirtualPageTest.php b/tests/SubsitesVirtualPageTest.php index 5944fee..244a416 100644 --- a/tests/SubsitesVirtualPageTest.php +++ b/tests/SubsitesVirtualPageTest.php @@ -232,9 +232,9 @@ class SubsitesVirtualPageTest extends SapphireTest { "Doesn't allow explicit URLSegment overrides when already existing in same subsite" ); - //Change to subsite 2 - Subsite::changeSubsite($subsite2->ID); - + //Change to subsite 2 + Subsite::changeSubsite($subsite2->ID); + // saving in subsite2 (which already has a page with URLSegment 'contact-us'), // but linking to a page in subsite1 $subsite2Vp = new SubsitesVirtualPage(); @@ -256,4 +256,4 @@ class SubsitesVirtualPageTest extends SapphireTest { } } -} \ No newline at end of file +}