Example #1
0
 /**
  * Check that changedData isn't populated with junk when clearing non-existent entries.
  */
 function testClearElementThatDoesntExist()
 {
     $s = new Session(array('something' => array('does' => 'exist')));
     $s->inst_clear('something.doesnt.exist');
     $this->assertEquals(array(), $s->inst_changedData());
     $s->inst_set('something-else', 'val');
     $s->inst_clear('something-new');
     $this->assertEquals(array('something-else' => 'val'), $s->inst_changedData());
 }
 /**
  * Choose the stage the site is currently on.
  *
  * If $_GET['stage'] is set, then it will use that stage, and store it in
  * the session.
  *
  * if $_GET['archiveDate'] is set, it will use that date, and store it in
  * the session.
  *
  * If neither of these are set, it checks the session, otherwise the stage
  * is set to 'Live'.
  *
  * @param Session $session Optional session within which to store the resulting stage
  */
 public static function choose_site_stage($session = null)
 {
     // Check any pre-existing session mode
     $preexistingMode = $session ? $session->inst_get('readingMode') : Session::get('readingMode');
     // Determine the reading mode
     if (isset($_GET['stage'])) {
         $stage = ucfirst(strtolower($_GET['stage']));
         if (!in_array($stage, array('Stage', 'Live'))) {
             $stage = 'Live';
         }
         $mode = 'Stage.' . $stage;
     } elseif (isset($_GET['archiveDate']) && strtotime($_GET['archiveDate'])) {
         $mode = 'Archive.' . $_GET['archiveDate'];
     } elseif ($preexistingMode) {
         $mode = $preexistingMode;
     } else {
         $mode = self::DEFAULT_MODE;
     }
     // Save reading mode
     Versioned::set_reading_mode($mode);
     // Try not to store the mode in the session if not needed
     if ($preexistingMode && $preexistingMode !== $mode || !$preexistingMode && $mode !== self::DEFAULT_MODE) {
         if ($session) {
             $session->inst_set('readingMode', $mode);
         } else {
             Session::set('readingMode', $mode);
         }
     }
     if (!headers_sent() && !Director::is_cli()) {
         if (Versioned::current_stage() == 'Live') {
             // clear the cookie if it's set
             if (!empty($_COOKIE['bypassStaticCache'])) {
                 Cookie::set('bypassStaticCache', null, 0, null, null, false, true);
                 unset($_COOKIE['bypassStaticCache']);
             }
         } else {
             // set the cookie if it's cleared
             if (empty($_COOKIE['bypassStaticCache'])) {
                 Cookie::set('bypassStaticCache', '1', 0, null, null, false, true);
                 $_COOKIE['bypassStaticCache'] = 1;
             }
         }
     }
 }