Changeset 10594
- Timestamp:
- 08/01/08 18:50:33 (5 months ago)
- Files:
-
- branches/dwhittle/1.1/lib/routing/sfPatternRouting.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/storage/sfDatabaseSessionStorage.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/storage/sfMySQLSessionStorage.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/storage/sfPDOSessionStorage.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/storage/sfPostgreSQLSessionStorage.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/task/project/sfProjectClearControllersTask.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/yaml/sfYamlDumper.class.php (modified) (1 diff)
- branches/dwhittle/1.1/test/unit/routing/sfPatternRoutingTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/storage/sfMySQLStorageTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/storage/sfMySQLiStorageTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/storage/sfPDOSessionStorageTest.php (modified) (1 diff)
- branches/dwhittle/1.1/test/unit/yaml/fixtures/sfTests.yml (modified) (1 diff)
- branches/dwhittle/1.1/test/unit/yaml/sfYamlDumperTest.php (modified) (1 diff)
- branches/dwhittle/1.1/test/unit/yaml/sfYamlParserTest.php (modified) (1 diff)
- branches/dwhittle/1.2/lib/routing/sfPatternRouting.class.php (modified) (1 diff)
- branches/dwhittle/1.2/lib/storage/sfDatabaseSessionStorage.class.php (modified) (1 diff)
- branches/dwhittle/1.2/lib/storage/sfMySQLSessionStorage.class.php (modified) (1 diff)
- branches/dwhittle/1.2/lib/storage/sfPDOSessionStorage.class.php (modified) (1 diff)
- branches/dwhittle/1.2/lib/storage/sfPostgreSQLSessionStorage.class.php (modified) (1 diff)
- branches/dwhittle/1.2/lib/task/project/sfProjectClearControllersTask.class.php (modified) (1 diff)
- branches/dwhittle/1.2/lib/widget/sfWidget.class.php (modified) (1 diff)
- branches/dwhittle/1.2/lib/yaml/sfYamlDumper.class.php (modified) (1 diff)
- branches/dwhittle/1.2/test/unit/routing/sfPatternRoutingTest.php (modified) (2 diffs)
- branches/dwhittle/1.2/test/unit/storage/sfMySQLStorageTest.php (modified) (2 diffs)
- branches/dwhittle/1.2/test/unit/storage/sfMySQLiStorageTest.php (modified) (2 diffs)
- branches/dwhittle/1.2/test/unit/storage/sfPDOSessionStorageTest.php (modified) (1 diff)
- branches/dwhittle/1.2/test/unit/yaml/fixtures/sfTests.yml (modified) (1 diff)
- branches/dwhittle/1.2/test/unit/yaml/sfYamlDumperTest.php (modified) (1 diff)
- branches/dwhittle/1.2/test/unit/yaml/sfYamlParserTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dwhittle/1.1/lib/routing/sfPatternRouting.class.php
r10218 r10594 560 560 // replace variables 561 561 $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) 563 566 { 564 567 $realUrl = str_replace($value, urlencode($tparams[$variable]), $realUrl); branches/dwhittle/1.1/lib/storage/sfDatabaseSessionStorage.class.php
r10431 r10594 177 177 178 178 $newId = session_id(); 179 $this->sessionRead($newId); 179 180 180 $this->updateSessionId($currentId, $newId);181 return $this->sessionWrite($newId, $this->sessionRead($currentId)); 181 182 } 182 183 /**184 * Updates the session id.185 *186 * @param string $currentId The current session id187 * @param string $newId The new current id188 *189 * @return Boolean True if the session id was successfully regenerated190 * @throws sfDatabaseException if an error occured while regenrating the session id191 */192 abstract protected function updateSessionId($currentId, $newId);193 183 194 184 /** branches/dwhittle/1.1/lib/storage/sfMySQLSessionStorage.class.php
r10431 r10594 162 162 163 163 /** 164 * Updates the session id.165 *166 * @param string $currentId The current session id167 * @param string $newId The new current id168 *169 * @return Boolean True if the session id was successfully regenerated170 * @throws sfDatabaseException if an error occured while regenrating the session id171 */172 protected function updateSessionId($currentId, $newId)173 {174 // get table/column175 $db_table = $this->options['db_table'];176 $db_id_col = $this->options['db_id_col'];177 178 // cleanup the session ids, just in case179 $newId = $this->db_escape($newId);180 $currentId = $this->db_escape($currentId);181 182 // update the session id183 $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 data191 throw new sfDatabaseException(sprintf('%s cannot update session id from "%s" to "%s" (%s).', get_class($this), $currentId, $newId, mysql_error()));192 }193 194 /**195 164 * Executes an SQL Query 196 165 * branches/dwhittle/1.1/lib/storage/sfPDOSessionStorage.class.php
r10562 r10594 170 170 return true; 171 171 } 172 173 /**174 * Updates the session id.175 *176 * @param string $currentId The current session id177 * @param string $newId The new current id178 *179 * @return Boolean True if the session id was successfully regenerated180 * @throws sfDatabaseException if an error occured while regenrating the session id181 */182 protected function updateSessionId($currentId, $newId)183 {184 // get table/column185 $db_table = $this->options['db_table'];186 $db_id_col = $this->options['db_id_col'];187 188 // update the session id189 $sql = "UPDATE $db_table SET $db_id_col=? WHERE $db_id_col=?";190 191 try192 {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 }205 172 } branches/dwhittle/1.1/lib/storage/sfPostgreSQLSessionStorage.class.php
r10431 r10594 159 159 throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot write session data for id "%s".', $id)); 160 160 } 161 162 /**163 * Updates the session id.164 *165 * @param string $currentId The current session id166 * @param string $newId The new current id167 *168 * @return Boolean True if the session id was successfully regenerated169 * @throws sfDatabaseException if an error occured while regenrating the session id170 */171 protected function updateSessionId($currentId, $newId)172 {173 // get table/column174 $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 case178 $currentId = addslashes($currentId);179 $newId = addslashes($newId);180 181 // update the session id182 $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 data190 throw new sfDatabaseException(sprintf('% cannot update session id from "%s" to "%s".', get_class($this), $currentId, $newId));191 }192 161 } branches/dwhittle/1.1/lib/task/project/sfProjectClearControllersTask.class.php
r8154 r10594 67 67 $content = file_get_contents($controller); 68 68 69 if (preg_match('/ new (.*?)Configuration\(\'(.*?)\'/', $content, $match))69 if (preg_match('/ProjectConfiguration::getApplicationConfiguration\(\'(.*?)\', \'(.*?)\'/', $content, $match)) 70 70 { 71 71 // 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 41 41 else 42 42 { 43 $isAHash = count(array_diff_key($input, array_fill(0, count($input), true)));43 $isAHash = array_keys($input) !== range(0, count($input) - 1); 44 44 45 45 foreach ($input as $key => $value) branches/dwhittle/1.1/test/unit/routing/sfPatternRoutingTest.php
r8851 r10594 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 14 $t = new lime_test(142, new lime_output_color()); 13 $t = new lime_test(143, new lime_output_color()); 15 14 16 15 class sfPatternRoutingTest extends sfPatternRouting … … 584 583 $params = array('module' => 'default', 'action' => 'action', 'param1' => 'param1'); 585 584 $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 3 3 /* 4 4 * This file is part of the symfony package. 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 5 6 * (c) 2008 Dejan Spasic <spasic.dejan@yahoo.de> 6 7 * … … 11 12 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 13 14 ob_start(); 15 $plan = 16; 16 $t = new lime_test($plan, new lime_output_color()); 17 13 18 if (!extension_loaded('mysql')) 14 19 { 15 return false; 20 $t->skip('Mysql extension must be loaded', $plan); 21 exit(0); 16 22 } 17 23 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 ); 24 30 25 ob_start(); 26 $t = new lime_test(5, new lime_output_color()); 31 if (!isset($mysql_config)) 32 { 33 $t->skip('Mysql credentials needed to run these tests', $plan); 34 exit(0); 35 } 27 36 28 if(isset($sfTestMysqlSessionStorage_DatabaseName, $sfTestMysqlSessionStorage_MysqlParameters)) 37 try 29 38 { 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 } 43 catch (sfDatabaseException $e) 44 { 45 $t->diag($e->getMessage()); 46 $t->skip('Unable to connect to MySQL database, skipping', $plan); 47 exit(0); 48 } 34 49 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 51 mysql_query('DROP DATABASE IF EXISTS sf_mysql_storage_unit_test', $connection); 52 mysql_query('CREATE DATABASE sf_mysql_storage_unit_test', $connection) or $t->fail('Cannot create database sf_mysql_storage_unit_test'); 53 mysql_select_db('sf_mysql_storage_unit_test', $connection); 54 mysql_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'); 38 60 39 mysql_select_db($sfTestMysqlSessionStorage_DatabaseName, $connection);40 mysql_close($connection);61 ini_set('session.use_cookies', 0); 62 $session_id = "1"; 41 63 42 unset($connection); 64 $storage = new sfMySQLSessionStorage(array( 65 'db_table' => 'session', 66 'session_id' => $session_id, 67 'database' => $database) 68 ); 43 69 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'); 46 72 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); 53 77 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'); 56 81 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'); 60 87 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'); 63 93 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(); 69 95 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); 98 list($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'); 72 101 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'); 102 mysql_free_result($result); 103 unset($thisSessData, $result); 78 104 79 mysql_free_result($result); 80 unset($thisSessData, $result); 105 // sessionRead() 106 try 107 { 108 $retrieved_data = $storage->sessionRead($session_id); 109 $t->pass('sessionRead() does not throw an exception'); 110 } 111 catch (Exception $e) 112 { 113 $t->fail('sessionRead() does not throw an exception'); 114 } 115 $t->is($retrieved_data, $newSessionData, 'sessionRead() reads session data'); 81 116 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'; 119 try 120 { 121 $write = $storage->sessionWrite($session_id, $otherSessionData); 122 $t->pass('sessionWrite() does not throw an exception'); 123 } 124 catch (Exception $e) 125 { 126 $t->fail('sessionWrite() does not throw an exception'); 127 } 85 128 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'); 88 131 89 mysql_free_result($result); 90 unset($count, $result); 132 // sessionDestroy() 133 try 134 { 135 $storage->sessionDestroy($session_id); 136 $t->pass('sessionDestroy() does not throw an exception'); 137 } 138 catch (Exception $e) 139 { 140 $t->fail('sessionDestroy() does not throw an exception'); 141 } 91 142 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); 93 144 94 // shutdown the storage 95 $storage->shutdown();145 list($count) = mysql_fetch_row($result); 146 $t->is($count, 0, 'session is removed from the database'); 96 147 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 } 148 mysql_free_result($result); 149 unset($count, $result); branches/dwhittle/1.1/test/unit/storage/sfMySQLiStorageTest.php
r9169 r10594 3 3 /* 4 4 * This file is part of the symfony package. 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 5 6 * (c) 2008 Dejan Spasic <spasic.dejan@yahoo.de> 6 7 * … … 11 12 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 13 14 ob_start(); 15 $plan = 12; 16 $t = new lime_test($plan, new lime_output_color()); 17 13 18 if (!extension_loaded('mysqli')) 14 19 { 15 return false; 20 $t->skip('Mysqli extension must be loaded', $plan); 21 exit(0); 16 22 } 17 23 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 ); 24 30 25 ob_start(); 26 $t = new lime_test(5, new lime_output_color()); 31 if (!isset($mysqli_config)) 32 { 33 $t->skip('Mysql credentials needed to run these tests', $plan); 34 exit(0); 35 } 27 36 28 if(isset($sfTestMysqlSessionStorage_DatabaseName, $sfTestMysqlSessionStorage_MysqlParameters)) 37 try 29 38 { 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 } 43 catch (sfDatabaseException $e) 44 { 45 $t->diag($e->getMessage()); 46 $t->skip('Unable to connect to MySQL database, skipping', $plan); 47 exit(0); 48 } 34 49 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 51 mysqli_query($connection, 'DROP DATABASE IF EXISTS sf_mysqli_storage_unit_test'); 52 mysqli_query($connection, 'CREATE DATABASE sf_mysqli_storage_unit_test') or $t->fail('Cannot create database sf_mysqli_storage_unit_test'); 53 mysqli_select_db($connection, 'sf_mysqli_storage_unit_test'); 54 mysqli_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'); 38 60 39 mysqli_select_db($connection,$sfTestMysqlSessionStorage_DatabaseName);40 mysqli_close($connection);61 ini_set('session.use_cookies', 0); 62 $session_id = "1"; 41 63 42 unset($connection); 64 $storage = new sfMySQLiSessionStorage(array( 65 'db_table' => 'session', 66 'session_id' => $session_id, 67 'database' => $database) 68 ); 43 69 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'); 46 72 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(); 54 77 55 ini_set('session.use_cookies', 0); 56 $sessionId = "1"; 78 // do some session operations 79 $_SESSION['foo'] = 'bar'; 80 $_SESSION['bar'] = 'foo'; 81 unset($_SESSION['foo']); 82 $session_data = session_encode(); 57 83 58 $storage = new sfMySQLiSessionStorage(array('db_table' => 'session', 59 'session_id' => $sessionId, 60 'database' => $database)); 84 // end of session 85 session_write_close(); 61 86 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)); 89 list($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'); 64 92 65 // do some session operations 66 $_SESSION['foo'] = 'bar'; 67 $_SESSION['bar'] = 'foo'; 68 unset($_SESSION['foo']); 69 $sessionData = session_encode(); 93 mysqli_free_result($result); 94 unset($thisSessData, $result); 70 95 71 // end of session 72 session_write_close(); 96 // sessionRead() 97 try 98 { 99 $retrieved_data = $storage->sessionRead($session_id); 100 $t->pass('sessionRead() does not throw an exception'); 101 } 102 catch (Exception $e) 103 { 104 $t->fail('sessionRead() does not throw an exception'); 105 } 106 $t->is($retrieved_data, $session_data, 'sessionRead() reads session data'); 73 107 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(); 111 try 112 { 113 $write = $storage->sessionWrite($session_id, $session_data); 114 $t->pass('sessionWrite() does not throw an exception'); 115 } 116 catch (Exception $e) 117 { 118 $t->fail('sessionWrite() does not throw an exception'); 119 } 79 120 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'); 82 123 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() 125 try 126 { 127 $storage->sessionDestroy($session_id); 128 $t->pass('sessionDestroy() does not throw an exception'); 129 } 130 catch (Exception $e) 131 { 132 $t->fail('sessionDestroy() does not throw an exception'); 133 } 86 134 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)); 89 136 90 mysqli_free_result($result);91 unset($count, $result);137 list($count) = mysqli_fetch_row($result); 138 $t->is($count, 0, 'session is removed from the database'); 92 139 93 mysqli_query($database->getResource(), 'DROP DATABASE ' . $sfTestMysqlSessionStorage_DatabaseName); 140 mysqli_free_result($result); 141 unset($count, $result); 94 142 95 // shutdown the storage 96 $storage->shutdown(); 143 mysqli_query($connection, 'DROP DATABASE sf_mysqli_storage_unit_test'); 97 144 98 // shutdown the database99 $database->shutdown();145 // shutdown the storage 146 $storage->shutdown(); 100 147 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 151 unset($mysqli_config); branches/dwhittle/1.1/test/unit/storage/sfPDOSessionStorageTest.php
r9683 r10594 12 12 13 13 ob_start(); 14 $t = new lime_test( 5, new lime_output_color());14 $t = new lime_test(15, new lime_output_color()); 15 15 16 16 if (!extension_loaded('SQLite')) 17 17 { 18 18 $t->skip('SQLite needed to run these tests', 5); 19 exit(0); 19 20 } 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 27 ini_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() 58 try 21 59 { 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 } 63 catch (Exception $e) 64 { 65 $t->fail('sessionRead() does not throw an exception'); 66 } 67 $t->is($retrieved_data, $newSessionData, 'sessionRead() reads session data'); 26 68 27 ini_set('session.use_cookies', 0); 28 $session_id = "1"; 69 // sessionWrite() 70 $otherSessionData = 'foo:foo:foo'; 71 try 72 { 73 $write = $storage->sessionWrite($session_id, $otherSessionData); 74 $t->pass('sessionWrite() does not throw an exception'); 75 } 76 catch (Exception $e) 77 { 78 $t->fail('sessionWrite() does not throw an exception'); 79 } 29 80 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'); 33 83 34 // do some session operations 35 $_SESSION['foo'] = 'bar'; 36 $_SESSION['bar'] = 'foo'; 37 unset($_SESSION['foo']); 38 $session_data = session_encode(); 84 // sessionGC() 85 try 86 { 87 $storage->sessionGC(0); 88 $t->pass('sessionGC() does not throw an exception'); 89 } 90 catch (Exception $e) 91 { 92 $t->fail('sessionGC() does not throw an exception'); 93 } 39 94 40 // end of session 41 session_write_close(); 95 // destroy the session 96 try 97 { 98 $storage->sessionDestroy($session_id); 99 $t->pass('sessionDestroy() does not throw an exception'); 100 } 101 catch (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'); 42 108 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 92 92 php: | 93 93 array('foo', array('bar' => array('bar' => 'foo'))) 94 --- 95 test: A sequence with an unordered array 96 brief: > 97 A sequence with an unordered array 98 yaml: | 99 1: foo 100 0: bar 101 php: | 102 array(1 => 'foo', 0 => 'bar') branches/dwhittle/1.1/test/unit/yaml/sfYamlDumperTest.php
r8932 r10594 13 13 require_once(dirname(__FILE__).'/../../../lib/yaml/sfYamlDumper.class.php'); 14 14 15 $t = new lime_test(14 0, new lime_output_color());15 $t = new lime_test(141, new lime_output_color()); 16 16 17 17 $parser = new sfYamlParser(); branches/dwhittle/1.1/test/unit/yaml/sfYamlParserTest.php
r8932 r10594 12 12 require_once(dirname(__FILE__).'/../../../lib/yaml/sfYamlParser.class.php'); 13 13 14 $t = new lime_test(14 0, new lime_output_color());14 $t = new lime_test(141, new lime_output_color()); 15 15 16 16 $parser = new sfYamlParser(); branches/dwhittle/1.2/lib/routing/sfPatternRouting.class.php
r10218 r10594 559 559 // replace variables 560 560 $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) 562 565 { 563 566 $realUrl = str_replace($value, urlencode($tparams[$variable]), $realUrl); branches/dwhittle/1.2/lib/storage/sfDatabaseSessionStorage.class.php
r10431 r10594 177 177 178 178 $newId = session_id(); 179 $this->sessionRead($newId); 179 180 180 $this->updateSessionId($currentId, $newId);181 return $this->sessionWrite($newId, $this->sessionRead($currentId)); 181 182 } 182 183 /**184 * Updates the session id.185 *186 * @param string $currentId The current session id187 * @param string $newId The new current id188 *189 * @return Boolean True if the session id was successfully regenerated190 * @throws sfDatabaseException if an error occured while regenrating the session id191 */192 abstract protected function updateSessionId($currentId, $newId);193 183 194 184 /** branches/dwhittle/1.2/lib/storage/sfMySQLSessionStorage.class.php
r10431 r10594 162 162 163 163 /** 164 * Updates the session id.165 *166 * @param string $currentId The current session id167 * @param string $newId The new current id168 *169 * @return Boolean True if the session id was successfully regenerated170 * @throws sfDatabaseException if an error occured while regenrating the session id171 */172 protected function updateSessionId($currentId, $newId)173 {174 // get table/column175 $db_table = $this->options['db_table'];176 $db_id_col = $this->options['db_id_col'];177 178 // cleanup the session ids, just in case179 $newId = $this->db_escape($newId);180 $currentId = $this->db_escape($currentId);181 182 // update the session id183 $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 data191 throw new sfDatabaseException(sprintf('%s cannot update session id from "%s" to "%s" (%s).', get_class($this), $currentId, $newId, mysql_error()));192 }193 194 /**195 164 * Executes an SQL Query 196 165 * branches/dwhittle/1.2/lib/storage/sfPDOSessionStorage.class.php
r10562 r10594 169 169 return true; 170 170 } 171 172 /**173 * Updates the session id.174 *175 * @param string $currentId The current session id176 * @param string $newId The new current id177 *178 * @return Boolean True if the session id was successfully regenerated179 * @throws sfDatabaseException if an error occured while regenrating the session id180 */181 protected function updateSessionId($currentId, $newId)182 {183 // get table/column184 $db_table = $this->options['db_table'];185 $db_id_col = $this->options['db_id_col'];186 187 // update the session id188 $sql = "UPDATE $db_table SET $db_id_col=? WHERE $db_id_col=?";189 190 try191 {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 }204 171 } branches/dwhittle/1.2/lib/storage/sfPostgreSQLSessionStorage.class.php
r10431 r10594 159 159 throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot write session data for id "%s".', $id)); 160 160 } 161 162 /**163 * Updates the session id.164 *165 * @param string $currentId The current session id166 * @param string $newId The new current id167 *168 * @return Boolean True if the session id was successfully regenerated169 * @throws sfDatabaseException if an error occured while regenrating the session id170 */171 protected function updateSessionId($currentId, $newId)172 {173 // get table/column174 $db_table = $this->options['db_table'];175 $db_id_col = $this->options['db_id_col'