/**
  * New tests require nested urls to be enabled, but the site might not 
  * support nested URLs. 
  * This setup will enable nested-urls for this test and resets the state
  * after the tests have been performed.
  */
 function tearDown()
 {
     if (isset($this->orig['nested_urls']) && !$this->orig['nested_urls']) {
         SiteTree::disable_nested_urls();
     }
     parent::tearDown();
 }
	public function testGetHomepageLink() {
		$default = $this->objFromFixture('Page', 'home');
		
		SiteTree::disable_nested_urls();
		$this->assertEquals('home', RootURLController::get_homepage_link());
		SiteTree::enable_nested_urls();
		$this->assertEquals('home', RootURLController::get_homepage_link());
	}
 public function testDeepNestedURLs()
 {
     SiteTree::enable_nested_urls();
     $page = new Page();
     $page->URLSegment = 'base-page';
     $page->write();
     for ($i = 0; $i < 10; $i++) {
         $parentID = $page->ID;
         $page = new ContentControllerTest_Page();
         $page->ParentID = $parentID;
         $page->Title = "Page Level {$i}";
         $page->URLSegment = "level-{$i}";
         $page->write();
         $relativeLink = Director::makeRelative($page->Link());
         $this->assertEquals($page->Title, $this->get($relativeLink)->getBody());
     }
     SiteTree::disable_nested_urls();
 }
 public function testGetHomepageLink()
 {
     $default = $this->objFromFixture('Page', 'home');
     $nested = $this->objFromFixture('Page', 'nested');
     SiteTree::disable_nested_urls();
     $this->assertEquals('home', RootURLController::get_homepage_link());
     SiteTree::enable_nested_urls();
     $this->assertEquals('home', RootURLController::get_homepage_link());
     $nested->HomepageForDomain = str_replace('www.', null, $_SERVER['HTTP_HOST']);
     $nested->write();
     RootURLController::reset();
     SiteTree::disable_nested_urls();
     $this->assertEquals('nested-home', RootURLController::get_homepage_link());
     RootURLController::reset();
     SiteTree::enable_nested_urls();
     $this->assertEquals('home/nested-home', RootURLController::get_homepage_link());
     $nested->HomepageForDomain = null;
     $nested->write();
 }
 function tearDown()
 {
     // Preserve memory settings
     ini_set('memory_limit', $this->originalMemoryLimit ? $this->originalMemoryLimit : -1);
     // Restore email configuration
     Email::set_mailer($this->originalMailer);
     $this->originalMailer = null;
     $this->mailer = null;
     // Restore password validation
     Member::set_password_validator($this->originalMemberPasswordValidator);
     // Restore requirements
     Requirements::set_backend($this->originalRequirements);
     // Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls
     self::$is_running_test = $this->originalIsRunningTest;
     $this->originalIsRunningTest = null;
     // Reset theme setting
     SSViewer::set_theme($this->originalTheme);
     // Reset mocked datetime
     SS_Datetime::clear_mock_now();
     // Restore nested_urls state
     if ($this->originalNestedURLsState) {
         SiteTree::enable_nested_urls();
     } else {
         SiteTree::disable_nested_urls();
     }
     // Stop the redirection that might have been requested in the test.
     // Note: Ideally a clean Controller should be created for each test.
     // Now all tests executed in a batch share the same controller.
     $controller = Controller::has_curr() ? Controller::curr() : null;
     if ($controller && $controller->response && $controller->response->getHeader('Location')) {
         $controller->response->setStatusCode(200);
         $controller->response->removeHeader('Location');
     }
 }
 /**
  * @covers SiteTree::validURLSegment
  */
 public function testValidURLSegmentURLSegmentConflicts()
 {
     $sitetree = new SiteTree();
     SiteTree::disable_nested_urls();
     $sitetree->URLSegment = 'home';
     $this->assertFalse($sitetree->validURLSegment(), 'URLSegment conflicts are recognised');
     $sitetree->URLSegment = 'home-noconflict';
     $this->assertTrue($sitetree->validURLSegment());
     $sitetree->ParentID = $this->idFromFixture('Page', 'about');
     $sitetree->URLSegment = 'home';
     $this->assertFalse($sitetree->validURLSegment(), 'Conflicts are still recognised with a ParentID value');
     SiteTree::enable_nested_urls();
     $sitetree->ParentID = 0;
     $sitetree->URLSegment = 'home';
     $this->assertFalse($sitetree->validURLSegment(), 'URLSegment conflicts are recognised');
     $sitetree->ParentID = $this->idFromFixture('Page', 'about');
     $this->assertTrue($sitetree->validURLSegment(), 'URLSegments can be the same across levels');
     $sitetree->URLSegment = 'my-staff';
     $this->assertFalse($sitetree->validURLSegment(), 'Nested URLSegment conflicts are recognised');
     $sitetree->URLSegment = 'my-staff-noconflict';
     $this->assertTrue($sitetree->validURLSegment());
 }