소스 검색

[ZF-10778] Zend_Db_Table

- fixed configuration returned by Adapter (port/host).

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23577 44c647ce-9c0f-0410-b52a-842ac1e357ba
ramon 15 년 전
부모
커밋
dcbb320edd
2개의 변경된 파일63개의 추가작업 그리고 4개의 파일을 삭제
  1. 15 4
      library/Zend/Db/Table/Abstract.php
  2. 48 0
      tests/Zend/Db/Table/TestCommon.php

+ 15 - 4
library/Zend/Db/Table/Abstract.php

@@ -807,12 +807,23 @@ abstract class Zend_Db_Table_Abstract
             //get db configuration
             $dbConfig = $this->_db->getConfig();
 
+            $port = isset($dbConfig['options']['port'])
+                  ? ':'.$dbConfig['options']['port']
+                  : (isset($dbConfig['port'])
+                  ? ':'.$dbConfig['port']
+                  : null);
+
+            $host = isset($dbConfig['options']['host'])
+                  ? ':'.$dbConfig['options']['host']
+                  : (isset($dbConfig['host'])
+                  ? ':'.$dbConfig['host']
+                  : null);
+
             // Define the cache identifier where the metadata are saved
             $cacheId = md5( // port:host/dbname:schema.table (based on availabilty)
-                (isset($dbConfig['options']['port']) ? ':'.$dbConfig['options']['port'] : null)
-                . (isset($dbConfig['options']['host']) ? ':'.$dbConfig['options']['host'] : null)
-                . '/'.$dbConfig['dbname'].':'.$this->_schema.'.'.$this->_name
-                );
+                    $port . $host . '/'. $dbConfig['dbname'] . ':'
+                  . $this->_schema. '.' . $this->_name
+            );
         }
 
         // If $this has no metadata cache or metadata cache misses

+ 48 - 0
tests/Zend/Db/Table/TestCommon.php

@@ -1639,4 +1639,52 @@ abstract class Zend_Db_Table_TestCommon extends Zend_Db_Table_TestSetup
     {
         return array('stuff' => 'information');
     }
+
+    /**
+     * @group ZF-7042
+     * @group ZF-10778
+     */
+    public function testCacheIdGeneratedToMetadata()
+    {
+        /**
+         * @see Zend_Cache
+         */
+        require_once 'Zend/Cache.php';
+
+        /**
+         * @see Zend_Cache_Backend_BlackHole
+         */
+        require_once 'Zend/Cache/Backend/BlackHole.php';
+
+        Zend_Db_Table::setDefaultAdapter($this->_db);
+        $dbConfig     = $this->_db->getConfig();
+        $cacheId = md5(
+                (isset($dbConfig['port']) ? ':'.$dbConfig['port'] : null)
+                . (isset($dbConfig['host']) ? ':'.$dbConfig['host'] : null)
+                . '/'.$dbConfig['dbname'].':.cache_metadata'
+                );
+
+        $metadata = array('id' => array('PRIMARY' => true));
+        $cacheBackend = $this->getMock('Zend_Cache_Backend_BlackHole');
+        $cacheBackend->expects($this->any())
+                     ->method('load')
+                     ->with($this->equalTo($cacheId))
+                     ->will($this->returnValue($metadata));
+
+        $cache = Zend_Cache::factory('Core', $cacheBackend, array('automatic_serialization' => false));
+        Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
+
+        $this->_util->createTable('cache_metadata', array(
+            'id'   => 'IDENTITY',
+            'name' => 'VARCHAR(32)'
+        ));
+        $configTable = array(
+            'name'    => 'cache_metadata',
+            'primary' => 'id'
+        );
+        $table = new Zend_Db_Table($configTable);
+        $table->info(Zend_Db_Table::METADATA);
+        $this->_util->dropTable('cache_metadata');
+        Zend_Db_Table_Abstract::setDefaultMetadataCache(null);
+    }
 }