/** * Create a new subsite from the template and verify that all the template's pages are copied */ function testSubsiteCreation() { Subsite::$write_hostmap = false; // Create the instance $template = $this->objFromFixture('Subsite_Template', 'main'); // Test that changeSubsite is working Subsite::changeSubsite($template->ID); $tmplHome = DataObject::get_one('SiteTree', "\"URLSegment\" = 'home'"); // Publish all the pages in the template, testing that DataObject::get only returns pages from the chosen subsite $pages = DataObject::get("SiteTree"); $totalPages = $pages->TotalItems(); foreach ($pages as $page) { $this->assertEquals($template->ID, $page->SubsiteID); $page->publish('Stage', 'Live'); } // Create a new site $subsite = $template->createInstance('My Site', 'something.test.com'); // Check title $this->assertEquals($subsite->Title, 'My Site'); // Check that domain generation is working $this->assertEquals('something.test.com', $subsite->domain()); // Another test that changeSubsite is working $subsite->activate(); $siteHome = DataObject::get_one('SiteTree', "\"URLSegment\" = 'home'"); $this->assertNotNull($siteHome); $this->assertEquals($subsite->ID, $siteHome->SubsiteID, 'createInstance() copies existing pages retaining the same URLSegment'); $this->assertEquals($siteHome->MasterPageID, $tmplHome->ID, 'Check master page value'); // Check linking of child pages $tmplStaff = $this->objFromFixture('SiteTree', 'staff'); $siteStaff = DataObject::get_one('SiteTree', "\"URLSegment\" = '" . Convert::raw2sql($tmplStaff->URLSegment) . "'"); $this->assertEquals($siteStaff->MasterPageID, $tmplStaff->ID); Subsite::changeSubsite(0); }
/** * Create a new subsite from the template and verify that all the template's pages are copied */ function testSubsiteCreation() { Subsite::$write_hostmap = false; // Create the instance $template = $this->objFromFixture('Subsite', 'main'); // Test that changeSubsite is working Subsite::changeSubsite($template->ID); $tmplStaff = $this->objFromFixture('Page', 'staff'); $tmplHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'"); // Publish all the pages in the template, testing that DataObject::get only returns pages from the chosen subsite $pages = DataObject::get("SiteTree"); $totalPages = $pages->Count(); foreach ($pages as $page) { $this->assertEquals($template->ID, $page->SubsiteID); $page->publish('Stage', 'Live'); } // Create a new site $subsite = $template->duplicate(); // Check title $this->assertEquals($subsite->Title, $template->Title); // Another test that changeSubsite is working $subsite->activate(); $siteHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'"); $this->assertNotEquals($siteHome, false, 'Home Page for subsite not found'); $this->assertEquals($subsite->ID, $siteHome->SubsiteID, 'createInstance() copies existing pages retaining the same URLSegment'); Subsite::changeSubsite(0); }
/** * 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/{$subsite1ID}/edit", null, $this->adminLoggedInSession()); $this->assertTrue(strpos($response2->getBody(), 'id="Form_EditForm_ID"') !== false, "Testing Form_EditForm_ID exists"); $this->assertTrue(strpos($response2->getBody(), '<head') !== false, "Testing <head> exists"); }
/** * Test custom metadata. Reloading Content should not * obliterate our custom fields */ function testCustomMetadata() { Subsite::$write_hostmap = false; $subsite = $this->objFromFixture('Subsite_Template', 'main'); Subsite::changeSubsite($subsite->ID); $orig = $this->objFromFixture('SiteTree', 'linky'); $svp = new SubsitesVirtualPage(); $svp->CopyContentFromID = $orig->ID; $svp->SubsiteID = $subsite->ID; $svp->URLSegment = 'linky-' . rand(); $svp->write(); $this->assertEquals($svp->MetaTitle, 'Linky'); $svp->CustomMetaTitle = 'SVPTitle'; $svp->write(); $this->assertEquals($svp->MetaTitle, 'SVPTitle'); $svp->copyFrom($svp->CopyContentFrom()); $svp->write(); $this->assertEquals($svp->MetaTitle, 'SVPTitle'); }
/** * Similar to {@link SiteTreeSubsitesTest->testTwoPagesWithSameURLOnDifferentSubsites()} * and {@link SiteTreeSubsitesTest->testPagesInDifferentSubsitesCanShareURLSegment()}. */ function testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite() { Subsite::$write_hostmap = false; $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, $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'), // but linking to a page in subsite1 $subsite2Vp = new SubsitesVirtualPage(); $subsite2Vp->CopyContentFromID = $subsite1Page->ID; $subsite2Vp->SubsiteID = $subsite2->ID; $subsite2Vp->write(); $this->assertEquals($subsite2Vp->URLSegment, $subsite1Page->URLSegment, "Does allow explicit URLSegment overrides when only existing in a different subsite"); }