tests/SubsiteTest.php
/**
	 * Create a new subsite from the template and verify that all the template's pages are copied
	 */
Create a new subsite from the template and verify that all the template's pages are copied
Create a new subsite from the template and verify that all the template ' s pages are copied
function testSubsiteCreation() {
		Subsite::$write_hostmap = false;
		$template = $this->objFromFixture('Subsite_Template', 'main');
		Subsite::changeSubsite($template->ID);
		$tmplHome = DataObject::get_one('SiteTree', "\"URLSegment\" = 'home'");
		$pages = DataObject::get("SiteTree");
		$totalPages = $pages->TotalItems();
		foreach($pages as $page) {
			$this->assertEquals($template->ID, $page->SubsiteID);
			$page->publish('Stage', 'Live');
		}
		$subsite = $template->createInstance('My Site', 'something.test.com');
		$this->assertEquals($subsite->Title, 'My Site');
		$this->assertEquals('something.test.com', $subsite->domain());
		$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');
		$tmplStaff = $this->objFromFixture('SiteTree','staff');
		$siteStaff = DataObject::get_one('SiteTree', "\"URLSegment\" = '" . Convert::raw2sql($tmplStaff->URLSegment) . "'");
		$this->assertEquals($siteStaff->MasterPageID, $tmplStaff->ID);
		Subsite::changeSubsite(0);
	}
function testSubsiteCreation ( ) { Subsite :: $ write_hostmap = false ; $ template = $ this -> objFromFixture ( 'Subsite_Template' , 'main' ) ; Subsite :: changeSubsite ( $ template -> ID ) ; $ tmplHome = DataObject :: get_one ( 'SiteTree' , " \" URLSegment \"  = 'home' " ) ; $ pages = DataObject :: get ( " SiteTree " ) ; $ totalPages = $ pages -> TotalItems ( ) ; foreach ( $ pages as $ page ) { $ this -> assertEquals ( $ template -> ID , $ page -> SubsiteID ) ; $ page -> publish ( 'Stage' , 'Live' ) ; } $ subsite = $ template -> createInstance ( 'My Site' , 'something.test.com' ) ; $ this -> assertEquals ( $ subsite -> Title , 'My Site' ) ; $ this -> assertEquals ( 'something.test.com' , $ subsite -> domain ( ) ) ; $ 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' ) ; $ 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
Create a new subsite from the template and verify that all the template ' s pages are copied
// Create the instance // Test that changeSubsite is working // Publish all the pages in the template, testing that DataObject::get only returns pages from the chosen subsite // Create a new site // Check title // Check that domain generation is working // Another test that changeSubsite is working // Check linking of child pages