Jelajahi Sumber

[ZF-9294] Zend_Session

- Fixed Zend_Session_SaveHandler_DbTable allows AUTO_QUOTE_IDENTIFIERS disabled.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23542 44c647ce-9c0f-0410-b52a-842ac1e357ba
ramon 15 tahun lalu
induk
melakukan
a60cbbf1d1

+ 3 - 3
library/Zend/Session/SaveHandler/DbTable.php

@@ -386,8 +386,8 @@ class Zend_Session_SaveHandler_DbTable
      */
     public function gc($maxlifetime)
     {
-        $this->delete($this->getAdapter()->quoteIdentifier($this->_modifiedColumn) . ' + '
-                    . $this->getAdapter()->quoteIdentifier($this->_lifetimeColumn) . ' < '
+        $this->delete($this->getAdapter()->quoteIdentifier($this->_modifiedColumn, true) . ' + '
+                    . $this->getAdapter()->quoteIdentifier($this->_lifetimeColumn, true) . ' < '
                     . $this->getAdapter()->quote(time()));
 
         return true;
@@ -548,7 +548,7 @@ class Zend_Session_SaveHandler_DbTable
                     $primaryArray[$primary] = $value;
                     break;
                 case self::PRIMARY_TYPE_WHERECLAUSE:
-                    $primaryArray[] = $this->getAdapter()->quoteIdentifier($primary) . ' = '
+                    $primaryArray[] = $this->getAdapter()->quoteIdentifier($primary, true) . ' = '
                                     . $this->getAdapter()->quote($value);
                     break;
                 case self::PRIMARY_TYPE_NUM:

+ 89 - 2
tests/Zend/Session/SaveHandler/DbTableTest.php

@@ -515,18 +515,105 @@ class Zend_Session_SaveHandler_DbTableTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * @group 9294
+     */
+    public function testDestroyWithAutoQuoteIdentifiersEnabledAndDisabled()
+    {
+        $id       = uniqid();
+        $config   = $this->_saveHandlerTableConfig;
+        $configDb = array(
+            'options' => array(
+                'autoQuoteIdentifiers' => false,
+            ),
+            'profiler' => true
+        );
+        $this->_setupDb($config['primary'], $configDb);
+        $config['db'] = $this->_db;
+
+        $saveHandler = new Zend_Session_SaveHandler_DbTable($config);
+        $saveHandler->destroy($id);
+        $lastQuery = $this->_db
+                          ->getProfiler()
+                          ->getLastQueryProfile()
+                          ->getQuery();
+        $partQueryExpected = "WHERE (id = '$id') AND (save_path = '') AND (name = '')";
+        $this->assertContains($partQueryExpected, $lastQuery);
+
+        $configDb = array(
+            'options' => array(
+                'autoQuoteIdentifiers' => true,
+            ),
+            'profiler' => true
+        );
+        $this->_setupDb($config['primary'], $configDb);
+        $config['db'] = $this->_db;
+
+        $saveHandler = new Zend_Session_SaveHandler_DbTable($config);
+        $saveHandler->destroy($id);
+        $lastQuery = $this->_db
+                          ->getProfiler()
+                          ->getLastQueryProfile()
+                          ->getQuery();
+        $partQueryExpected = "WHERE (\"id\" = '$id') AND (\"save_path\" = '') AND (\"name\" = '')";
+        $this->assertContains($partQueryExpected, $lastQuery);
+    }
+
+    /**
+     * @group 9294
+     */
+    public function testGcWithAutoQuoteIdentifiersEnabledAndDisabled()
+    {
+        $config = $this->_saveHandlerTableConfig;
+        $configDb = array(
+            'options' => array(
+                'autoQuoteIdentifiers' => false,
+            ),
+            'profiler' => true
+        );
+        $this->_setupDb($config['primary'], $configDb);
+        $config['db'] = $this->_db;
+
+        $saveHandler = new Zend_Session_SaveHandler_DbTable($config);
+        $saveHandler->gc(false);
+        $lastQuery = $this->_db
+                          ->getProfiler()
+                          ->getLastQueryProfile()
+                          ->getQuery();
+        $partQueryExpected = "WHERE (modified + lifetime < ";
+        $this->assertContains($partQueryExpected, $lastQuery);
+
+        $configDb = array(
+            'options' => array(
+                'autoQuoteIdentifiers' => true,
+            ),
+            'profiler' => true
+        );
+        $this->_setupDb($config['primary'], $configDb);
+        $config['db'] = $this->_db;
+
+        $saveHandler = new Zend_Session_SaveHandler_DbTable($config);
+        $saveHandler->gc(false);
+        $lastQuery = $this->_db
+                          ->getProfiler()
+                          ->getLastQueryProfile()
+                          ->getQuery();
+        $partQueryExpected = "WHERE (\"modified\" + \"lifetime\" < ";
+        $this->assertContains($partQueryExpected, $lastQuery);
+    }
+
+    /**
      * Sets up the database connection and creates the table for session data
      *
      * @param  array $primary
      * @return void
      */
-    protected function _setupDb(array $primary)
+    protected function _setupDb(array $primary, array $config = array())
     {
         if (!extension_loaded('pdo_sqlite')) {
             $this->markTestSkipped('The pdo_sqlite extension must be available and enabled for this test');
         }
 
-        $this->_db = Zend_Db::factory('Pdo_Sqlite', array('dbname' => ':memory:'));
+        $this->_db = Zend_Db::factory('Pdo_Sqlite', array('dbname' => ':memory:') + $config);
         Zend_Db_Table_Abstract::setDefaultAdapter($this->_db);
         $query = array();
         $query[] = 'CREATE TABLE `Sessions` ( ';