Development

Changeset 10594

You must first sign up to be able to contribute.

Changeset 10594

Show
Ignore:
Timestamp:
08/01/08 18:50:33 (5 months ago)
Author:
dwhittle
Message:

dwhittle: merged changes to branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dwhittle/1.1/lib/routing/sfPatternRouting.class.php

    r10218 r10594  
    560560    // replace variables 
    561561    $realUrl = $url; 
    562     foreach ($variables as $variable => $value) 
     562 
     563    $tmp = $variables; 
     564    uasort($tmp, create_function('$a, $b', 'return strlen($a) < strlen($b);')); 
     565    foreach ($tmp as $variable => $value) 
    563566    { 
    564567      $realUrl = str_replace($value, urlencode($tparams[$variable]), $realUrl); 
  • branches/dwhittle/1.1/lib/storage/sfDatabaseSessionStorage.class.php

    r10431 r10594  
    177177 
    178178    $newId = session_id(); 
     179    $this->sessionRead($newId); 
    179180 
    180     $this->updateSessionId($currentId, $newId); 
     181    return $this->sessionWrite($newId, $this->sessionRead($currentId)); 
    181182  } 
    182  
    183   /** 
    184    * Updates the session id. 
    185    * 
    186    * @param  string   $currentId The current session id 
    187    * @param  string   $newId     The new current id 
    188    *  
    189    * @return Boolean  True if the session id was successfully regenerated 
    190    * @throws sfDatabaseException if an error occured while regenrating the session id 
    191    */ 
    192   abstract protected function updateSessionId($currentId, $newId); 
    193183 
    194184  /** 
  • branches/dwhittle/1.1/lib/storage/sfMySQLSessionStorage.class.php

    r10431 r10594  
    162162 
    163163  /** 
    164    * Updates the session id. 
    165    * 
    166    * @param  string   $currentId The current session id 
    167    * @param  string   $newId     The new current id 
    168    *  
    169    * @return Boolean  True if the session id was successfully regenerated 
    170    * @throws sfDatabaseException if an error occured while regenrating the session id 
    171    */ 
    172   protected function updateSessionId($currentId, $newId) 
    173   { 
    174     // get table/column 
    175     $db_table    = $this->options['db_table']; 
    176     $db_id_col   = $this->options['db_id_col']; 
    177  
    178     // cleanup the session ids, just in case 
    179     $newId     = $this->db_escape($newId); 
    180     $currentId = $this->db_escape($currentId); 
    181  
    182     // update the session id 
    183     $sql = "UPDATE $db_table SET $db_id_col='$newId' WHERE $db_id_col='$currentId'"; 
    184  
    185     if ($this->db_query($sql)) 
    186     { 
    187       return true; 
    188     } 
    189  
    190     // failed to write session data 
    191     throw new sfDatabaseException(sprintf('%s cannot update session id from "%s" to "%s" (%s).', get_class($this), $currentId, $newId, mysql_error())); 
    192   } 
    193  
    194   /** 
    195164   * Executes an SQL Query 
    196165   * 
  • branches/dwhittle/1.1/lib/storage/sfPDOSessionStorage.class.php

    r10562 r10594  
    170170    return true; 
    171171  } 
    172  
    173   /** 
    174    * Updates the session id. 
    175    * 
    176    * @param  string   $currentId The current session id 
    177    * @param  string   $newId     The new current id 
    178    *  
    179    * @return Boolean  True if the session id was successfully regenerated 
    180    * @throws sfDatabaseException if an error occured while regenrating the session id 
    181    */ 
    182   protected function updateSessionId($currentId, $newId) 
    183   { 
    184     // get table/column 
    185     $db_table    = $this->options['db_table']; 
    186     $db_id_col   = $this->options['db_id_col']; 
    187  
    188     // update the session id 
    189     $sql = "UPDATE $db_table SET $db_id_col=? WHERE $db_id_col=?"; 
    190  
    191     try 
    192     { 
    193       $stmt = $this->db->prepare($sql); 
    194       $stmt->bindParam(1, $newId, PDO::PARAM_STR); 
    195       $stmt->bindParam(2, $currentId, PDO::PARAM_STR); 
    196       $stmt->execute(); 
    197     } 
    198     catch (PDOException $e) 
    199     { 
    200       throw new sfDatabaseException(sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage())); 
    201     } 
    202  
    203     return true; 
    204   } 
    205172} 
  • branches/dwhittle/1.1/lib/storage/sfPostgreSQLSessionStorage.class.php

    r10431 r10594  
    159159    throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot write session data for id "%s".', $id)); 
    160160  } 
    161  
    162   /** 
    163    * Updates the session id. 
    164    * 
    165    * @param  string   $currentId The current session id 
    166    * @param  string   $newId     The new current id 
    167    *  
    168    * @return Boolean  True if the session id was successfully regenerated 
    169    * @throws sfDatabaseException if an error occured while regenrating the session id 
    170    */ 
    171   protected function updateSessionId($currentId, $newId) 
    172   { 
    173     // get table/column 
    174     $db_table    = $this->options['db_table']; 
    175     $db_id_col   = $this->options['db_id_col']; 
    176  
    177     // cleanup the session id and data, just in case 
    178     $currentId = addslashes($currentId); 
    179     $newId     = addslashes($newId); 
    180  
    181     // update the session id 
    182     $sql = "UPDATE $db_table SET $db_id_col=? WHERE $db_id_col=?"; 
    183  
    184     if (@pg_query($this->db, $sql)) 
    185     { 
    186       return true; 
    187     } 
    188  
    189     // failed to write session data 
    190     throw new sfDatabaseException(sprintf('% cannot update session id from "%s" to "%s".', get_class($this), $currentId, $newId)); 
    191   } 
    192161} 
  • branches/dwhittle/1.1/lib/task/project/sfProjectClearControllersTask.class.php

    r8154 r10594  
    6767      $content = file_get_contents($controller); 
    6868 
    69       if (preg_match('/new (.*?)Configuration\(\'(.*?)\'/', $content, $match)) 
     69      if (preg_match('/ProjectConfiguration::getApplicationConfiguration\(\'(.*?)\', \'(.*?)\'/', $content, $match)) 
    7070      { 
    7171        // Remove file if it has found an application and the environment is not production 
  • branches/dwhittle/1.1/lib/yaml/sfYamlDumper.class.php

    r8490 r10594  
    4141    else 
    4242    { 
    43       $isAHash = count(array_diff_key($input, array_fill(0, count($input), true))); 
     43      $isAHash = array_keys($input) !== range(0, count($input) - 1); 
    4444 
    4545      foreach ($input as $key => $value) 
  • branches/dwhittle/1.1/test/unit/routing/sfPatternRoutingTest.php

    r8851 r10594  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13  
    14 $t = new lime_test(142, new lime_output_color()); 
     13$t = new lime_test(143, new lime_output_color()); 
    1514 
    1615class sfPatternRoutingTest extends sfPatternRouting 
     
    584583$params = array('module' => 'default', 'action' => 'action', 'param1' => 'param1'); 
    585584$t->is($r->parse($url), $params, 'parse /customer/:param1/:action/* route'); 
     585 
     586$r->clearRoutes(); 
     587$r->connect('test', '/customer/:id/:id_name', array('module' => 'default')); 
     588$t->is($r->generate('', array('id' => 2, 'id_name' => 'fabien')), '/customer/2/fabien', '->generate() first replaces the longest variable names'); 
  • branches/dwhittle/1.1/test/unit/storage/sfMySQLStorageTest.php

    r9169 r10594  
    33/* 
    44 * This file is part of the symfony package. 
     5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 
    56 * (c) 2008 Dejan Spasic <spasic.dejan@yahoo.de> 
    67 * 
     
    1112require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1213 
     14ob_start(); 
     15$plan = 16; 
     16$t = new lime_test($plan, new lime_output_color()); 
     17 
    1318if (!extension_loaded('mysql')) 
    1419{ 
    15   return false; 
     20  $t->skip('Mysql extension must be loaded', $plan); 
     21  exit(0); 
    1622} 
    1723 
    18 /* 
    19 $sfTestMysqlSessionStorage_DatabaseName = 'sf_unit_test'; 
    20 $sfTestMysqlSessionStorage_MysqlParameters = array( 
    21   'database' => $sfTestMysqlSessionStorage_DatabaseName, 
    22     'username' => 'root', 'password' => '', 'method' => 'normal'); 
    23 */ 
     24// Configure your database with the settings below in order to run the test 
     25$mysql_config = array( 
     26  'host'     => 'localhost', 
     27  'username' => 'root',  
     28  'password' => '',  
     29); 
    2430 
    25 ob_start(); 
    26 $t = new lime_test(5, new lime_output_color()); 
     31if (!isset($mysql_config)) 
     32
     33  $t->skip('Mysql credentials needed to run these tests', $plan); 
     34  exit(0); 
     35
    2736 
    28 if(isset($sfTestMysqlSessionStorage_DatabaseName, $sfTestMysqlSessionStorage_MysqlParameters)) 
     37try 
    2938{ 
    30   $connection = mysql_connect('localhost', 
    31     $sfTestMysqlSessionStorage_MysqlParameters['username'], 
    32     $sfTestMysqlSessionStorage_MysqlParameters['password']) 
    33     or $t->fail('Can not connect to mysql server'); 
     39  // Creating mysql database connection 
     40  $database = new sfMySQLDatabase($mysql_config); 
     41  $connection = $database->getResource(); 
     42
     43catch (sfDatabaseException $e) 
     44
     45  $t->diag($e->getMessage()); 
     46  $t->skip('Unable to connect to MySQL database, skipping', $plan); 
     47  exit(0); 
     48
    3449 
    35   mysql_query('DROP DATABASE ' . $sfTestMysqlSessionStorage_DatabaseName, $connection); 
    36   mysql_query('CREATE DATABASE ' . $sfTestMysqlSessionStorage_DatabaseName, $connection) 
    37     or $t->fail('Can not create database ' . $sfTestMysqlSessionStorage_DatabaseName); 
     50// Creates test database 
     51mysql_query('DROP DATABASE IF EXISTS sf_mysql_storage_unit_test', $connection); 
     52mysql_query('CREATE DATABASE sf_mysql_storage_unit_test', $connection) or $t->fail('Cannot create database sf_mysql_storage_unit_test'); 
     53mysql_select_db('sf_mysql_storage_unit_test', $connection); 
     54mysql_query("CREATE TABLE `session` ( 
     55  `sess_id` varchar(40) NOT NULL PRIMARY KEY, 
     56  `sess_time` int(10) unsigned NOT NULL default '0', 
     57  `sess_data` text collate utf8_unicode_ci 
     58) ENGINE=MyISAM", $connection)  
     59  or $t->fail('Can not create table session'); 
    3860 
    39   mysql_select_db($sfTestMysqlSessionStorage_DatabaseName, $connection); 
    40   mysql_close($connection)
     61ini_set('session.use_cookies', 0); 
     62$session_id = "1"
    4163 
    42   unset($connection); 
     64$storage = new sfMySQLSessionStorage(array( 
     65  'db_table'   => 'session', 
     66  'session_id' => $session_id, 
     67  'database'   => $database) 
     68); 
    4369 
    44   // initialize the storage 
    45   $database = new sfMySQLDatabase($sfTestMysqlSessionStorage_MysqlParameters); 
     70$t->ok($storage instanceof sfStorage, 'sfMySQLSessionStorage is an instance of sfStorage'); 
     71$t->ok($storage instanceof sfDatabaseSessionStorage, 'sfMySQLSessionStorage is an instance of sfDatabaseSessionStorage'); 
    4672 
    47   mysql_query("CREATE TABLE `session` ( 
    48     `sess_id` varchar(40) NOT NULL PRIMARY KEY, 
    49     `sess_time` int(10) unsigned NOT NULL default '0', 
    50     `sess_data` text collate utf8_unicode_ci 
    51   ) ENGINE=MyISAM", $database->getResource()) 
    52     or $t->fail('Can not create table session'); 
     73// regenerate() 
     74$oldSessionData = 'foo:bar'; 
     75$storage->sessionWrite($session_id, $oldSessionData); 
     76$storage->regenerate(false); 
    5377 
    54   ini_set('session.use_cookies', 0); 
    55   $sessionId = "1"; 
     78$newSessionData = 'foo:bar:baz'; 
     79$storage->sessionWrite(session_id(), $newSessionData); 
     80$t->isnt(session_id(), $session_id, 'regenerate() regenerated the session with a different session id'); 
    5681 
    57   $storage = new sfMySQLSessionStorage(array('db_table' => 'session', 
    58                                              'session_id' => $sessionId, 
    59                                              'database' => $database)); 
     82// checking if the old session record still exists 
     83$result = mysql_query(sprintf('SELECT sess_data FROM session WHERE sess_id = "%s"', $session_id), $connection); 
     84$t->is(mysql_num_rows($result), 1, 'regenerate() has kept destroyed old session'); 
     85$rSessionData = list($thisSessData) = mysql_fetch_row($result); 
     86$t->is($rSessionData[0], $oldSessionData, 'regenerate() has kept destroyed old session data'); 
    6087 
    61   $t->ok($storage instanceof sfStorage, 'sfMySQLSessionStorage is an instance of sfStorage'); 
    62   $t->ok($storage instanceof sfDatabaseSessionStorage, 'sfMySQLSessionStorage is an instance of sfDatabaseSessionStorage'); 
     88// checking if the new session record has been created 
     89$result = mysql_query(sprintf('SELECT sess_data FROM session WHERE sess_id = "%s"', session_id()), $connection); 
     90$t->is(mysql_num_rows($result), 1, 'regenerate() has created a new session record'); 
     91$rSessionData = list($thisSessData) = mysql_fetch_row($result); 
     92$t->is($rSessionData[0], $newSessionData, 'regenerate() has created a new record with correct data'); 
    6393 
    64   // do some session operations 
    65   $_SESSION['foo'] = 'bar'; 
    66   $_SESSION['bar'] = 'foo'; 
    67   unset($_SESSION['foo']); 
    68   $sessionData = session_encode(); 
     94$session_id = session_id(); 
    6995 
    70   // end of session 
    71   session_write_close(); 
     96// check session data in the database 
     97$result = mysql_query(sprintf('SELECT sess_data FROM session WHERE sess_id = "%s"', $session_id), $connection); 
     98list($thisSessData) = mysql_fetch_row($result); 
     99$t->is(mysql_num_rows($result), 1, 'session is stored in the database'); 
     100$t->is($thisSessData, $newSessionData, 'session variables are stored in the database'); 
    72101 
    73   // check session data in the database 
    74   $result = mysql_query(sprintf('SELECT sess_data FROM session WHERE sess_id = "%s"', $sessionId), $database->getResource()); 
    75   list($thisSessData) = mysql_fetch_row($result); 
    76   $t->is(mysql_num_rows($result), 1, 'session is stored in the database'); 
    77   $t->is($thisSessData, $sessionData, 'session variables are stored in the database'); 
     102mysql_free_result($result); 
     103unset($thisSessData, $result); 
    78104 
    79   mysql_free_result($result); 
    80   unset($thisSessData, $result); 
     105// sessionRead() 
     106try 
     107
     108  $retrieved_data = $storage->sessionRead($session_id); 
     109  $t->pass('sessionRead() does not throw an exception'); 
     110
     111catch (Exception $e) 
     112
     113  $t->fail('sessionRead() does not throw an exception'); 
     114
     115$t->is($retrieved_data, $newSessionData, 'sessionRead() reads session data'); 
    81116 
    82   // destroy the session 
    83   $storage->sessionDestroy($sessionId); 
    84   $result = mysql_query(sprintf('SELECT COUNT(sess_id) FROM session WHERE sess_id = "%s"', $sessionId), $database->getResource()); 
     117// sessionWrite() 
     118$otherSessionData = 'foo:foo:foo'; 
     119try 
     120
     121  $write = $storage->sessionWrite($session_id, $otherSessionData); 
     122  $t->pass('sessionWrite() does not throw an exception'); 
     123
     124catch (Exception $e) 
     125
     126  $t->fail('sessionWrite() does not throw an exception'); 
     127
    85128 
    86   list($count) = mysql_fetch_row($result); 
    87   $t->is($count, 0, 'session is removed from the database'); 
     129$t->ok($write, 'sessionWrite() returns true'); 
     130$t->is($storage->sessionRead($session_id), $otherSessionData, 'sessionWrite() wrote session data'); 
    88131 
    89   mysql_free_result($result); 
    90   unset($count, $result); 
     132// sessionDestroy() 
     133try 
     134
     135  $storage->sessionDestroy($session_id); 
     136  $t->pass('sessionDestroy() does not throw an exception'); 
     137
     138catch (Exception $e) 
     139
     140  $t->fail('sessionDestroy() does not throw an exception'); 
     141
    91142 
    92   mysql_query('DROP DATABASE ' . $sfTestMysqlSessionStorage_DatabaseName, $database->getResource()); 
     143$result = mysql_query(sprintf('SELECT COUNT(sess_id) FROM session WHERE sess_id = "%s"', $session_id), $connection); 
    93144 
    94   // shutdown the storage 
    95   $storage->shutdown(); 
     145list($count) = mysql_fetch_row($result); 
     146$t->is($count, 0, 'session is removed from the database'); 
    96147 
    97   // shutdown the database 
    98   $database->shutdown(); 
    99  
    100   unset($sfTestMysqlSessionStorage_DatabaseName, $sfTestMysqlSessionStorage_MysqlParameters); 
    101 
    102 else 
    103 
    104   $t->skip('Mysql credentials needed to run these tests', 5); 
    105 
     148mysql_free_result($result); 
     149unset($count, $result); 
  • branches/dwhittle/1.1/test/unit/storage/sfMySQLiStorageTest.php

    r9169 r10594  
    33/* 
    44 * This file is part of the symfony package. 
     5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 
    56 * (c) 2008 Dejan Spasic <spasic.dejan@yahoo.de> 
    67 * 
     
    1112require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1213 
     14ob_start(); 
     15$plan = 12; 
     16$t = new lime_test($plan, new lime_output_color()); 
     17 
    1318if (!extension_loaded('mysqli')) 
    1419{ 
    15   return false; 
     20  $t->skip('Mysqli extension must be loaded', $plan); 
     21  exit(0); 
    1622} 
    1723 
    18 /* 
    19 $sfTestMysqlSessionStorage_DatabaseName = 'sf_unit_test'; 
    20 $sfTestMysqlSessionStorage_MysqlParameters = array( 
    21   'database' => $sfTestMysqlSessionStorage_DatabaseName, 
    22     'username' => 'root', 'password' => '', 'method' => 'normal'); 
    23 */ 
     24// Configure your database with the settings below in order to run the test 
     25$mysqli_config = array( 
     26  'host'     => 'localhost', 
     27  'username' => 'root',  
     28  'password' => '',  
     29); 
    2430 
    25 ob_start(); 
    26 $t = new lime_test(5, new lime_output_color()); 
     31if (!isset($mysqli_config)) 
     32
     33  $t->skip('Mysql credentials needed to run these tests', $plan); 
     34  exit(0); 
     35
    2736 
    28 if(isset($sfTestMysqlSessionStorage_DatabaseName, $sfTestMysqlSessionStorage_MysqlParameters)) 
     37try 
    2938{ 
    30   $connection = mysqli_connect('localhost', 
    31     $sfTestMysqlSessionStorage_MysqlParameters['username'], 
    32     $sfTestMysqlSessionStorage_MysqlParameters['password']) 
    33     or $t->fail('Can not connect to mysql server'); 
     39  // Creating mysql database connection 
     40  $database = new sfMySQLiDatabase($mysqli_config); 
     41  $connection = $database->getResource(); 
     42
     43catch (sfDatabaseException $e) 
     44
     45  $t->diag($e->getMessage()); 
     46  $t->skip('Unable to connect to MySQL database, skipping', $plan); 
     47  exit(0); 
     48
    3449 
    35   mysqli_query($connection, 'DROP DATABASE ' . $sfTestMysqlSessionStorage_DatabaseName); 
    36   mysqli_query($connection, 'CREATE DATABASE ' . $sfTestMysqlSessionStorage_DatabaseName) 
    37     or $t->fail('Can not create database ' . $sfTestMysqlSessionStorage_DatabaseName); 
     50// Creates test database 
     51mysqli_query($connection, 'DROP DATABASE IF EXISTS sf_mysqli_storage_unit_test'); 
     52mysqli_query($connection, 'CREATE DATABASE sf_mysqli_storage_unit_test') or $t->fail('Cannot create database sf_mysqli_storage_unit_test'); 
     53mysqli_select_db($connection, 'sf_mysqli_storage_unit_test'); 
     54mysqli_query($connection, "CREATE TABLE `session` ( 
     55  `sess_id` varchar(40) NOT NULL PRIMARY KEY, 
     56  `sess_time` int(10) unsigned NOT NULL default '0', 
     57  `sess_data` text collate utf8_unicode_ci 
     58) ENGINE=MyISAM")  
     59  or $t->fail('Can not create table session'); 
    3860 
    39   mysqli_select_db($connection,$sfTestMysqlSessionStorage_DatabaseName); 
    40   mysqli_close($connection)
     61ini_set('session.use_cookies', 0); 
     62$session_id = "1"
    4163 
    42   unset($connection); 
     64$storage = new sfMySQLiSessionStorage(array( 
     65  'db_table'   => 'session', 
     66  'session_id' => $session_id, 
     67  'database'   => $database) 
     68); 
    4369 
    44   // initialize the storage 
    45   $database = new sfMySQLiDatabase($sfTestMysqlSessionStorage_MysqlParameters); 
     70$t->ok($storage instanceof sfStorage, 'sfMySQLSessionStorage is an instance of sfStorage'); 
     71$t->ok($storage instanceof sfDatabaseSessionStorage, 'sfMySQLSessionStorage is an instance of sfDatabaseSessionStorage'); 
    4672 
    47   mysqli_query($database->getResource(), 
    48   "CREATE TABLE `session` ( 
    49     `sess_id` varchar(40) NOT NULL PRIMARY KEY, 
    50     `sess_time` int(10) unsigned NOT NULL default '0', 
    51     `sess_data` text collate utf8_unicode_ci 
    52   ) ENGINE=MyISAM") 
    53     or $t->fail('Can not create table session'); 
     73// regenerate() 
     74$storage->regenerate(false); 
     75$t->isnt(session_id(), $session_id, 'regenerate() regenerated the session id'); 
     76$session_id = session_id(); 
    5477 
    55   ini_set('session.use_cookies', 0); 
    56   $sessionId = "1"; 
     78// do some session operations 
     79$_SESSION['foo'] = 'bar'; 
     80$_SESSION['bar'] = 'foo'; 
     81unset($_SESSION['foo']); 
     82$session_data = session_encode(); 
    5783 
    58   $storage = new sfMySQLiSessionStorage(array('db_table' => 'session', 
    59                                              'session_id' => $sessionId, 
    60                                              'database' => $database)); 
     84// end of session 
     85session_write_close(); 
    6186 
    62   $t->ok($storage instanceof sfStorage, 'sfMySQLSessionStorage is an instance of sfStorage'); 
    63   $t->ok($storage instanceof sfDatabaseSessionStorage, 'sfMySQLSessionStorage is an instance of sfDatabaseSessionStorage'); 
     87// check session data in the database 
     88$result = mysqli_query($connection, sprintf('SELECT sess_data FROM session WHERE sess_id = "%s"', $session_id)); 
     89list($thisSessData) = mysqli_fetch_row($result); 
     90$t->is(mysqli_num_rows($result), 1, 'session is stored in the database'); 
     91$t->is($thisSessData, $session_data, 'session variables are stored in the database'); 
    6492 
    65   // do some session operations 
    66   $_SESSION['foo'] = 'bar'; 
    67   $_SESSION['bar'] = 'foo'; 
    68   unset($_SESSION['foo']); 
    69   $sessionData = session_encode(); 
     93mysqli_free_result($result); 
     94unset($thisSessData, $result); 
    7095 
    71   // end of session 
    72   session_write_close(); 
     96// sessionRead() 
     97try 
     98
     99  $retrieved_data = $storage->sessionRead($session_id); 
     100  $t->pass('sessionRead() does not throw an exception'); 
     101
     102catch (Exception $e) 
     103
     104  $t->fail('sessionRead() does not throw an exception'); 
     105
     106$t->is($retrieved_data, $session_data, 'sessionRead() reads session data'); 
    73107 
    74   // check session data in the database 
    75   $result = mysqli_query($database->getResource(), sprintf('SELECT sess_data FROM session WHERE sess_id = "%s"', $sessionId)); 
    76   list($thisSessData) = mysqli_fetch_row($result); 
    77   $t->is(mysqli_num_rows($result), 1, 'session is stored in the database'); 
    78   $t->is($thisSessData, $sessionData, 'session variables are stored in the database'); 
     108// sessionWrite() 
     109$_SESSION['baz'] = 'woo'; 
     110$session_data = session_encode(); 
     111try 
     112
     113  $write = $storage->sessionWrite($session_id, $session_data); 
     114  $t->pass('sessionWrite() does not throw an exception'); 
     115
     116catch (Exception $e) 
     117
     118  $t->fail('sessionWrite() does not throw an exception'); 
     119
    79120 
    80   mysqli_free_result($result); 
    81   unset($thisSessData, $result); 
     121$t->ok($write, 'sessionWrite() returns true'); 
     122$t->is($storage->sessionRead($session_id), $session_data, 'sessionWrite() wrote session data'); 
    82123 
    83   // destroy the session 
    84   $storage->sessionDestroy($sessionId); 
    85   $result = mysqli_query($database->getResource(), sprintf('SELECT COUNT(sess_id) FROM session WHERE sess_id = "%s"', $sessionId)); 
     124// sessionDestroy() 
     125try 
     126
     127  $storage->sessionDestroy($session_id); 
     128  $t->pass('sessionDestroy() does not throw an exception'); 
     129
     130catch (Exception $e) 
     131
     132  $t->fail('sessionDestroy() does not throw an exception'); 
     133
    86134 
    87   list($count) = mysqli_fetch_row($result); 
    88   $t->is($count, 0, 'session is removed from the database'); 
     135$result = mysqli_query($connection, sprintf('SELECT COUNT(sess_id) FROM session WHERE sess_id = "%s"', $session_id)); 
    89136 
    90   mysqli_free_result($result); 
    91   unset($count, $result); 
     137list($count) = mysqli_fetch_row($result); 
     138$t->is($count, 0, 'session is removed from the database'); 
    92139 
    93   mysqli_query($database->getResource(), 'DROP DATABASE ' . $sfTestMysqlSessionStorage_DatabaseName); 
     140mysqli_free_result($result); 
     141unset($count, $result); 
    94142 
    95   // shutdown the storage 
    96   $storage->shutdown(); 
     143mysqli_query($connection, 'DROP DATABASE sf_mysqli_storage_unit_test'); 
    97144 
    98   // shutdown the databas
    99   $database->shutdown(); 
     145// shutdown the storag
     146$storage->shutdown(); 
    100147 
    101   unset($sfTestMysqlSessionStorage_DatabaseName, $sfTestMysqlSessionStorage_MysqlParameters); 
    102 
    103 else 
    104 
    105   $t->skip('Mysql credentials needed to run these tests', 5); 
    106 
     148// shutdown the database 
     149$database->shutdown(); 
     150 
     151unset($mysqli_config); 
  • branches/dwhittle/1.1/test/unit/storage/sfPDOSessionStorageTest.php

    r9683 r10594  
    1212 
    1313ob_start(); 
    14 $t = new lime_test(5, new lime_output_color()); 
     14$t = new lime_test(15, new lime_output_color()); 
    1515 
    1616if (!extension_loaded('SQLite')) 
    1717{ 
    1818  $t->skip('SQLite needed to run these tests', 5); 
     19  exit(0); 
    1920} 
    20 else 
     21 
     22// initialize the storage 
     23$database = new sfPDODatabase(array('dsn' => 'sqlite::memory:')); 
     24$connection = $database->getConnection(); 
     25$connection->exec('CREATE TABLE session (sess_id, sess_data, sess_time)'); 
     26 
     27ini_set('session.use_cookies', 0); 
     28$session_id = "1"; 
     29 
     30$storage = new sfPDOSessionStorage(array('db_table' => 'session', 'session_id' => $session_id, 'database' => $database)); 
     31$t->ok($storage instanceof sfStorage, 'sfPDOSessionStorage is an instance of sfStorage'); 
     32$t->ok($storage instanceof sfDatabaseSessionStorage, 'sfPDOSessionStorage is an instance of sfDatabaseSessionStorage'); 
     33 
     34// regenerate() 
     35$oldSessionData = 'foo:bar'; 
     36$storage->sessionWrite($session_id, $oldSessionData); 
     37$storage->regenerate(false); 
     38 
     39$newSessionData = 'foo:bar:baz'; 
     40$storage->sessionWrite(session_id(), $newSessionData); 
     41$t->isnt(session_id(), $session_id, 'regenerate() regenerated the session with a different session id'); 
     42 
     43// checking if the old session record still exists 
     44$result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', $session_id)); 
     45$data = $result->fetchAll(); 
     46$t->is(count($data), 1, 'regenerate() has kept destroyed old session'); 
     47$t->is($data[0]['sess_data'], $oldSessionData, 'regenerate() has kept destroyed old session data'); 
     48 
     49// checking if the new session record has been created 
     50$result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', session_id())); 
     51$data = $result->fetchAll(); 
     52$t->is(count($data), 1, 'regenerate() has created a new session record'); 
     53$t->is($data[0]['sess_data'], $newSessionData, 'regenerate() has created a new record with correct data'); 
     54 
     55$session_id = session_id(); 
     56 
     57// sessionRead() 
     58try 
    2159{ 
    22   // initialize the storage 
    23   $database = new sfPDODatabase(array('dsn' => 'sqlite::memory:')); 
    24   $connection = $database->getConnection(); 
    25   $connection->exec('CREATE TABLE session (sess_id, sess_data, sess_time)'); 
     60  $retrieved_data = $storage->sessionRead($session_id); 
     61  $t->pass('sessionRead() does not throw an exception'); 
     62
     63catch (Exception $e) 
     64
     65  $t->fail('sessionRead() does not throw an exception'); 
     66
     67$t->is($retrieved_data, $newSessionData, 'sessionRead() reads session data'); 
    2668 
    27   ini_set('session.use_cookies', 0); 
    28   $session_id = "1"; 
     69// sessionWrite() 
     70$otherSessionData = 'foo:foo:foo'; 
     71try 
     72
     73  $write = $storage->sessionWrite($session_id, $otherSessionData); 
     74  $t->pass('sessionWrite() does not throw an exception'); 
     75
     76catch (Exception $e) 
     77
     78  $t->fail('sessionWrite() does not throw an exception'); 
     79
    2980 
    30   $storage = new sfPDOSessionStorage(array('db_table' => 'session', 'session_id' => $session_id, 'database' => $database)); 
    31   $t->ok($storage instanceof sfStorage, 'sfPDOSessionStorage is an instance of sfStorage'); 
    32   $t->ok($storage instanceof sfDatabaseSessionStorage, 'sfPDOSessionStorage is an instance of sfDatabaseSessionStorage'); 
     81$t->ok($write, 'sessionWrite() returns true'); 
     82$t->is($storage->sessionRead($session_id), $otherSessionData, 'sessionWrite() wrote session data'); 
    3383 
    34   // do some session operations 
    35   $_SESSION['foo'] = 'bar'; 
    36   $_SESSION['bar'] = 'foo'; 
    37   unset($_SESSION['foo']); 
    38   $session_data = session_encode(); 
     84// sessionGC() 
     85try 
     86
     87  $storage->sessionGC(0); 
     88  $t->pass('sessionGC() does not throw an exception'); 
     89
     90catch (Exception $e) 
     91
     92  $t->fail('sessionGC() does not throw an exception'); 
     93
    3994 
    40   // end of session 
    41   session_write_close(); 
     95// destroy the session 
     96try 
     97
     98  $storage->sessionDestroy($session_id); 
     99  $t->pass('sessionDestroy() does not throw an exception'); 
     100
     101catch (Exception $e) 
     102
     103  $t->fail('sessionClose() does not throw an exception'); 
     104
     105$result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', $session_id)); 
     106$data = $result->fetchAll(); 
     107$t->is(count($data), 0, 'session is removed from the database'); 
    42108 
    43   // check session data in the database 
    44   $result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', $session_id)); 
    45   $data = $result->fetchAll(); 
    46   $t->is(count($data), 1, 'session is stored in the database'); 
    47   $t->is($data[0]['sess_data'], $session_data, 'session variables are stored in the database'); 
    48  
    49   // destroy the session 
    50   $storage->sessionDestroy($session_id); 
    51   $result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', $session_id)); 
    52   $data = $result->fetchAll(); 
    53   $t->is(count($data), 0, 'session is removed from the database'); 
    54  
    55   // shutdown the storage 
    56   $storage->shutdown(); 
    57 
     109// shutdown the storage 
     110$storage->shutdown(); 
  • branches/dwhittle/1.1/test/unit/yaml/fixtures/sfTests.yml

    r8868 r10594  
    9292php: | 
    9393  array('foo', array('bar' => array('bar' => 'foo'))) 
     94--- 
     95test: A sequence with an unordered array 
     96brief: > 
     97  A sequence with an unordered array 
     98yaml: | 
     99  1: foo 
     100  0: bar 
     101php: | 
     102  array(1 => 'foo', 0 => 'bar') 
  • branches/dwhittle/1.1/test/unit/yaml/sfYamlDumperTest.php

    r8932 r10594  
    1313require_once(dirname(__FILE__).'/../../../lib/yaml/sfYamlDumper.class.php'); 
    1414 
    15 $t = new lime_test(140, new lime_output_color()); 
     15$t = new lime_test(141, new lime_output_color()); 
    1616 
    1717$parser = new sfYamlParser(); 
  • branches/dwhittle/1.1/test/unit/yaml/sfYamlParserTest.php

    r8932 r10594  
    1212require_once(dirname(__FILE__).'/../../../lib/yaml/sfYamlParser.class.php'); 
    1313 
    14 $t = new lime_test(140, new lime_output_color()); 
     14$t = new lime_test(141, new lime_output_color()); 
    1515 
    1616$parser = new sfYamlParser(); 
  • branches/dwhittle/1.2/lib/routing/sfPatternRouting.class.php

    r10218 r10594  
    559559    // replace variables 
    560560    $realUrl = $url; 
    561     foreach ($variables as $variable => $value) 
     561 
     562    $tmp = $variables; 
     563    uasort($tmp, create_function('$a, $b', 'return strlen($a) < strlen($b);')); 
     564    foreach ($tmp as $variable => $value) 
    562565    { 
    563566      $realUrl = str_replace($value, urlencode($tparams[$variable]), $realUrl); 
  • branches/dwhittle/1.2/lib/storage/sfDatabaseSessionStorage.class.php

    r10431 r10594  
    177177 
    178178    $newId = session_id(); 
     179    $this->sessionRead($newId); 
    179180 
    180     $this->updateSessionId($currentId, $newId); 
     181    return $this->sessionWrite($newId, $this->sessionRead($currentId)); 
    181182  } 
    182  
    183   /** 
    184    * Updates the session id. 
    185    * 
    186    * @param  string   $currentId The current session id 
    187    * @param  string   $newId     The new current id 
    188    *  
    189    * @return Boolean  True if the session id was successfully regenerated 
    190    * @throws sfDatabaseException if an error occured while regenrating the session id 
    191    */ 
    192   abstract protected function updateSessionId($currentId, $newId); 
    193183 
    194184  /** 
  • branches/dwhittle/1.2/lib/storage/sfMySQLSessionStorage.class.php

    r10431 r10594  
    162162 
    163163  /** 
    164    * Updates the session id. 
    165    * 
    166    * @param  string   $currentId The current session id 
    167    * @param  string   $newId     The new current id 
    168    *  
    169    * @return Boolean  True if the session id was successfully regenerated 
    170    * @throws sfDatabaseException if an error occured while regenrating the session id 
    171    */ 
    172   protected function updateSessionId($currentId, $newId) 
    173   { 
    174     // get table/column 
    175     $db_table    = $this->options['db_table']; 
    176     $db_id_col   = $this->options['db_id_col']; 
    177  
    178     // cleanup the session ids, just in case 
    179     $newId     = $this->db_escape($newId); 
    180     $currentId = $this->db_escape($currentId); 
    181  
    182     // update the session id 
    183     $sql = "UPDATE $db_table SET $db_id_col='$newId' WHERE $db_id_col='$currentId'"; 
    184  
    185     if ($this->db_query($sql)) 
    186     { 
    187       return true; 
    188     } 
    189  
    190     // failed to write session data 
    191     throw new sfDatabaseException(sprintf('%s cannot update session id from "%s" to "%s" (%s).', get_class($this), $currentId, $newId, mysql_error())); 
    192   } 
    193  
    194   /** 
    195164   * Executes an SQL Query 
    196165   * 
  • branches/dwhittle/1.2/lib/storage/sfPDOSessionStorage.class.php

    r10562 r10594  
    169169    return true; 
    170170  } 
    171  
    172   /** 
    173    * Updates the session id. 
    174    * 
    175    * @param  string   $currentId The current session id 
    176    * @param  string   $newId     The new current id 
    177    *  
    178    * @return Boolean  True if the session id was successfully regenerated 
    179    * @throws sfDatabaseException if an error occured while regenrating the session id 
    180    */ 
    181   protected function updateSessionId($currentId, $newId) 
    182   { 
    183     // get table/column 
    184     $db_table    = $this->options['db_table']; 
    185     $db_id_col   = $this->options['db_id_col']; 
    186  
    187     // update the session id 
    188     $sql = "UPDATE $db_table SET $db_id_col=? WHERE $db_id_col=?"; 
    189  
    190     try 
    191     { 
    192       $stmt = $this->db->prepare($sql); 
    193       $stmt->bindParam(1, $newId, PDO::PARAM_STR); 
    194       $stmt->bindParam(2, $currentId, PDO::PARAM_STR); 
    195       $stmt->execute(); 
    196     } 
    197     catch (PDOException $e) 
    198     { 
    199       throw new sfDatabaseException(sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage())); 
    200     } 
    201  
    202     return true; 
    203   } 
    204171} 
  • branches/dwhittle/1.2/lib/storage/sfPostgreSQLSessionStorage.class.php

    r10431 r10594  
    159159    throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot write session data for id "%s".', $id)); 
    160160  } 
    161  
    162   /** 
    163    * Updates the session id. 
    164    * 
    165    * @param  string   $currentId The current session id 
    166    * @param  string   $newId     The new current id 
    167    *  
    168    * @return Boolean  True if the session id was successfully regenerated 
    169    * @throws sfDatabaseException if an error occured while regenrating the session id 
    170    */ 
    171   protected function updateSessionId($currentId, $newId) 
    172   { 
    173     // get table/column 
    174     $db_table    = $this->options['db_table']; 
    175     $db_id_col   = $this->options['db_id_col'