diff --git a/library/Zend/Db/Table/AbstractTable.php b/library/Zend/Db/Table/AbstractTable.php index c9695cfe04f..92de2704490 100644 --- a/library/Zend/Db/Table/AbstractTable.php +++ b/library/Zend/Db/Table/AbstractTable.php @@ -457,6 +457,7 @@ public function setReferences(array $referenceMap) public function getReference($tableClassname, $ruleKey = null) { $thisClass = get_class($this); + $tableClassname = '\\' . ltrim($tableClassname, '\\'); if ($thisClass === 'Zend\Db\Table\Table') { $thisClass = $this->_definitionConfigName; } diff --git a/tests/Zend/Db/Table/Table/AbstractTest.php b/tests/Zend/Db/Table/Table/AbstractTest.php index 704f791d733..970d602bd29 100644 --- a/tests/Zend/Db/Table/Table/AbstractTest.php +++ b/tests/Zend/Db/Table/Table/AbstractTest.php @@ -1621,6 +1621,49 @@ public function testTableAndIdentityWithVeryLongName() $this->assertEquals(1, count($rowset)); $this->_util->dropTable('thisisaveryverylongtablename'); } + + + /** + * @group ZF2-66 + */ + public function testgetReferenceWihoutSlashAtTheBeginning() + { + $refReporter = array( + 'columns' => array('reported_by'), + 'refTableClass' => '\ZendTest\Db\Table\TestAsset\TableAccounts', + 'refColumns' => array('account_id') + ); + $refEngineer = array( + 'columns' => array('assigned_to'), + 'refTableClass' => '\ZendTest\Db\Table\TestAsset\TableAccounts', + 'refColumns' => array('account_id') + ); + $refMap = array( + 'Reporter' => $refReporter, + 'Engineer' => $refEngineer + ); + $table = $this->_getTable('\ZendTest\Db\Table\TestAsset\TableBugs',array('referenceMap' => $refMap)); + + $this->assertEquals($refReporter, $table->getReference('ZendTest\Db\Table\TestAsset\TableAccounts')); + $this->assertEquals($refReporter, $table->getReference('ZendTest\Db\Table\TestAsset\TableAccounts', 'Reporter')); + $this->assertEquals($refEngineer, $table->getReference('ZendTest\Db\Table\TestAsset\TableAccounts', 'Engineer')); + + $this->assertEquals( + $table->getReference('\ZendTest\Db\Table\TestAsset\TableAccounts'), + $table->getReference('ZendTest\Db\Table\TestAsset\TableAccounts') + ); + + $this->assertEquals( + $table->getReference('\ZendTest\Db\Table\TestAsset\TableAccounts', 'Reporter'), + $table->getReference('ZendTest\Db\Table\TestAsset\TableAccounts', 'Reporter') + ); + + $this->assertEquals( + $table->getReference('\ZendTest\Db\Table\TestAsset\TableAccounts', 'Engineer'), + $table->getReference('ZendTest\Db\Table\TestAsset\TableAccounts', 'Engineer') + ); + } + protected function _getRowForTableAndIdentityWithVeryLongName() {