TestCommon.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Db
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Db_Table_TestSetup
  24. */
  25. require_once 'Zend/Db/Table/TestSetup.php';
  26. /**
  27. * @see Zend_Loader
  28. */
  29. require_once 'Zend/Loader.php';
  30. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  31. /**
  32. * @category Zend
  33. * @package Zend_Db
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. abstract class Zend_Db_Table_Relationships_TestCommon extends Zend_Db_Table_TestSetup
  39. {
  40. public function testTableRelationshipFindParentRow()
  41. {
  42. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  43. $account_name = $this->_db->foldCase('account_name');
  44. $table = $this->_table['bugs'];
  45. $childRows = $table->fetchAll("$bug_id = 1");
  46. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  47. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  48. $childRow1 = $childRows->current();
  49. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  50. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  51. $parentRow = $childRow1->findParentRow('My_ZendDbTable_TableAccounts');
  52. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  53. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  54. $this->assertEquals('goofy', $parentRow->$account_name);
  55. }
  56. public function testTableRelationshipFindParentRowSelect()
  57. {
  58. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  59. $account_name = $this->_db->foldCase('account_name');
  60. $account_name_column = $this->_db->quoteIdentifier('account_name', true);
  61. $table = $this->_table['bugs'];
  62. $select = $table->select()->where($account_name_column . ' = ?', 'goofy');
  63. $childRows = $table->fetchAll("$bug_id = 1");
  64. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  65. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  66. $childRow1 = $childRows->current();
  67. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  68. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  69. $parentRow = $childRow1->findParentRow('My_ZendDbTable_TableAccounts', null, $select);
  70. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  71. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  72. $this->assertEquals('goofy', $parentRow->$account_name);
  73. }
  74. public function testTableRelationshipMagicFindParentRow()
  75. {
  76. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  77. $account_name = $this->_db->foldCase('account_name');
  78. $table = $this->_table['bugs'];
  79. $childRows = $table->fetchAll("$bug_id = 1");
  80. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  81. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  82. $childRow1 = $childRows->current();
  83. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  84. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  85. $parentRow = $childRow1->findParentMy_ZendDbTable_TableAccounts();
  86. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  87. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  88. $this->assertEquals('goofy', $parentRow->$account_name);
  89. }
  90. public function testTableRelationshipMagicFindParentRowSelect()
  91. {
  92. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  93. $account_name = $this->_db->foldCase('account_name');
  94. $account_name_column = $this->_db->quoteIdentifier('account_name', true);
  95. $table = $this->_table['bugs'];
  96. $select = $table->select()->where($account_name_column . ' = ?', 'goofy');
  97. $childRows = $table->fetchAll("$bug_id = 1");
  98. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  99. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  100. $childRow1 = $childRows->current();
  101. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  102. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  103. $parentRow = $childRow1->findParentMy_ZendDbTable_TableAccounts($select);
  104. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  105. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  106. $this->assertEquals('goofy', $parentRow->$account_name);
  107. }
  108. public function testTableRelationshipMagicException()
  109. {
  110. $table = $this->_table['bugs'];
  111. $parentRows = $table->find(1);
  112. $parentRow1 = $parentRows->current();
  113. // Completely bogus method
  114. try {
  115. $result = $parentRow1->nonExistantMethod();
  116. $this->fail('Expected to catch Zend_Db_Table_Row_Exception');
  117. } catch (Zend_Exception $e) {
  118. $this->assertType('Zend_Db_Table_Row_Exception', $e,
  119. 'Expecting object of type Zend_Db_Table_Row_Exception got '.get_class($e));
  120. $this->assertEquals("Unrecognized method 'nonExistantMethod()'", $e->getMessage());
  121. }
  122. }
  123. public function testTableRelationshipFindParentRowException()
  124. {
  125. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  126. $table = $this->_table['bugs'];
  127. $childRows = $table->fetchAll("$bug_id = 1");
  128. $childRow1 = $childRows->current();
  129. try {
  130. $parentRow = $childRow1->findParentRow('nonexistant_class');
  131. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  132. } catch (Zend_Exception $e) {
  133. $this->assertType('Zend_Db_Table_Row_Exception', $e,
  134. 'Expecting object of type Zend_Db_Table_Row_Exception got '.get_class($e));
  135. $this->assertEquals('File "nonexistant' . DIRECTORY_SEPARATOR . 'class.php" does not exist or class "nonexistant_class" was not found in the file', $e->getMessage());
  136. }
  137. try {
  138. $parentRow = $childRow1->findParentRow(new stdClass());
  139. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for wrong table class');
  140. } catch (Zend_Exception $e) {
  141. $this->assertType('Zend_Db_Table_Exception', $e,
  142. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  143. $this->assertEquals('Parent table must be a Zend_Db_Table_Abstract, but it is stdClass', $e->getMessage());
  144. }
  145. }
  146. public function testTableRelationshipFindManyToManyRowset()
  147. {
  148. $table = $this->_table['bugs'];
  149. $originRows = $table->find(1);
  150. $originRow1 = $originRows->current();
  151. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableProducts', 'My_ZendDbTable_TableBugsProducts');
  152. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  153. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  154. $this->assertEquals(3, $destRows->count());
  155. }
  156. public function testTableRelationshipFindManyToManyRowsetSelect()
  157. {
  158. $product_name = $this->_db->foldCase('product_name');
  159. $bug_id = $this->_db->foldCase('bug_id');
  160. $bug_id_column = $this->_db->quoteIdentifier('bug_id', true);
  161. $table = $this->_table['bugs'];
  162. $select = $table->select()->where($bug_id_column . ' = ?', 1)
  163. ->limit(2)
  164. ->order($product_name . ' ASC');
  165. $originRows = $table->find(1);
  166. $originRow1 = $originRows->current();
  167. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableProducts', 'My_ZendDbTable_TableBugsProducts',
  168. null, null, $select);
  169. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  170. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  171. $this->assertEquals(2, $destRows->count());
  172. $childRow = $destRows->current();
  173. $this->assertEquals('Linux', $childRow->$product_name);
  174. }
  175. public function testTableRelationshipMagicFindManyToManyRowset()
  176. {
  177. $table = $this->_table['bugs'];
  178. $originRows = $table->find(1);
  179. $originRow1 = $originRows->current();
  180. $destRows = $originRow1->findMy_ZendDbTable_TableProductsViaMy_ZendDbTable_TableBugsProducts();
  181. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  182. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  183. $this->assertEquals(3, $destRows->count());
  184. }
  185. public function testTableRelationshipMagicFindManyToManyRowsetSelect()
  186. {
  187. $product_name = $this->_db->foldCase('product_name');
  188. $bug_id = $this->_db->foldCase('bug_id');
  189. $bug_id_column = $this->_db->quoteIdentifier('bug_id', true);
  190. $table = $this->_table['bugs'];
  191. $select = $table->select()->where($bug_id_column . ' = ?', 1)
  192. ->limit(2)
  193. ->order($product_name . ' ASC');
  194. $originRows = $table->find(1);
  195. $originRow1 = $originRows->current();
  196. $destRows = $originRow1->findMy_ZendDbTable_TableProductsViaMy_ZendDbTable_TableBugsProducts($select);
  197. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  198. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  199. $this->assertEquals(2, $destRows->count());
  200. $childRow = $destRows->current();
  201. $this->assertEquals('Linux', $childRow->$product_name);
  202. }
  203. public function testTableRelationshipFindManyToManyRowsetException()
  204. {
  205. $table = $this->_table['bugs'];
  206. $originRows = $table->find(1);
  207. $originRow1 = $originRows->current();
  208. // Use nonexistant class for destination table
  209. try {
  210. $destRows = $originRow1->findManyToManyRowset('nonexistant_class', 'My_ZendDbTable_TableBugsProducts');
  211. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  212. } catch (Zend_Exception $e) {
  213. $this->assertType('Zend_Db_Table_Exception', $e,
  214. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  215. $this->assertEquals('File "nonexistant' . DIRECTORY_SEPARATOR . 'class.php" does not exist or class "nonexistant_class" was not found in the file', $e->getMessage());
  216. }
  217. // Use stdClass instead of table class for destination table
  218. try {
  219. $destRows = $originRow1->findManyToManyRowset(new stdClass(), 'My_ZendDbTable_TableBugsProducts');
  220. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  221. } catch (Zend_Exception $e) {
  222. $this->assertType('Zend_Db_Table_Exception', $e,
  223. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  224. $this->assertEquals('Match table must be a Zend_Db_Table_Abstract, but it is stdClass', $e->getMessage());
  225. }
  226. // Use nonexistant class for intersection table
  227. try {
  228. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableProducts', 'nonexistant_class');
  229. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  230. } catch (Zend_Exception $e) {
  231. $this->assertType('Zend_Db_Table_Exception', $e,
  232. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  233. $this->assertEquals('File "nonexistant' . DIRECTORY_SEPARATOR . 'class.php" does not exist or class "nonexistant_class" was not found in the file', $e->getMessage());
  234. }
  235. // Use stdClass instead of table class for intersection table
  236. try {
  237. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableProducts', new stdClass());
  238. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  239. } catch (Zend_Exception $e) {
  240. $this->assertType('Zend_Db_Table_Exception', $e,
  241. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  242. $this->assertEquals('Intersection table must be a Zend_Db_Table_Abstract, but it is stdClass', $e->getMessage());
  243. }
  244. }
  245. public function testTableRelationshipFindDependentRowset()
  246. {
  247. $table = $this->_table['bugs'];
  248. $bug_id = $this->_db->foldCase('bug_id');
  249. $product_id = $this->_db->foldCase('product_id');
  250. $parentRows = $table->find(1);
  251. $this->assertType('Zend_Db_Table_Rowset_Abstract', $parentRows,
  252. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($parentRows));
  253. $parentRow1 = $parentRows->current();
  254. $childRows = $parentRow1->findDependentRowset('My_ZendDbTable_TableBugsProducts');
  255. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  256. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  257. $this->assertEquals(3, $childRows->count());
  258. $childRow1 = $childRows->current();
  259. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  260. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  261. $this->assertEquals(1, $childRow1->$bug_id);
  262. $this->assertEquals(1, $childRow1->$product_id);
  263. }
  264. public function testTableRelationshipFindDependentRowsetSelect()
  265. {
  266. $table = $this->_table['bugs'];
  267. $bug_id = $this->_db->foldCase('bug_id');
  268. $product_id = $this->_db->foldCase('product_id');
  269. $select = $table->select()->limit(2)
  270. ->order($product_id . ' DESC');
  271. $parentRows = $table->find(1);
  272. $this->assertType('Zend_Db_Table_Rowset_Abstract', $parentRows,
  273. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($parentRows));
  274. $parentRow1 = $parentRows->current();
  275. $childRows = $parentRow1->findDependentRowset('My_ZendDbTable_TableBugsProducts', null, $select);
  276. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  277. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  278. $childRow1 = $childRows->current();
  279. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  280. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  281. $this->assertEquals(1, $childRow1->$bug_id);
  282. $this->assertEquals(3, $childRow1->$product_id);
  283. }
  284. public function testTableRelationshipMagicFindDependentRowset()
  285. {
  286. $table = $this->_table['bugs'];
  287. $bug_id = $this->_db->foldCase('bug_id');
  288. $product_id = $this->_db->foldCase('product_id');
  289. $parentRows = $table->find(1);
  290. $parentRow1 = $parentRows->current();
  291. $childRows = $parentRow1->findMy_ZendDbTable_TableBugsProducts();
  292. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  293. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  294. $this->assertEquals(3, $childRows->count());
  295. $childRow1 = $childRows->current();
  296. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  297. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  298. $this->assertEquals(1, $childRow1->$bug_id);
  299. $this->assertEquals(1, $childRow1->$product_id);
  300. }
  301. public function testTableRelationshipMagicFindDependentRowsetSelect()
  302. {
  303. $table = $this->_table['bugs'];
  304. $bug_id = $this->_db->foldCase('bug_id');
  305. $product_id = $this->_db->foldCase('product_id');
  306. $select = $table->select()->limit(2)
  307. ->order($product_id . ' DESC');
  308. $parentRows = $table->find(1);
  309. $parentRow1 = $parentRows->current();
  310. $childRows = $parentRow1->findMy_ZendDbTable_TableBugsProducts($select);
  311. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  312. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  313. $this->assertEquals(2, $childRows->count());
  314. $childRow1 = $childRows->current();
  315. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  316. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  317. $this->assertEquals(1, $childRow1->$bug_id);
  318. $this->assertEquals(3, $childRow1->$product_id);
  319. }
  320. public function testTableRelationshipFindDependentRowsetException()
  321. {
  322. $table = $this->_table['bugs'];
  323. $parentRows = $table->find(1);
  324. $parentRow1 = $parentRows->current();
  325. try {
  326. $childRows = $parentRow1->findDependentRowset('nonexistant_class');
  327. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for nonexistent table class');
  328. } catch (Zend_Exception $e) {
  329. $this->assertType('Zend_Db_Table_Exception', $e,
  330. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  331. $this->assertEquals('File "nonexistant' . DIRECTORY_SEPARATOR . 'class.php" does not exist or class "nonexistant_class" was not found in the file', $e->getMessage());
  332. }
  333. try {
  334. $childRows = $parentRow1->findDependentRowset(new stdClass());
  335. $this->fail('Expected to catch Zend_Db_Table_Row_Exception for wrong table class');
  336. } catch (Zend_Exception $e) {
  337. $this->assertType('Zend_Db_Table_Row_Exception', $e,
  338. 'Expecting object of type Zend_Db_Table_Row_Exception got '.get_class($e));
  339. $this->assertEquals('Dependent table must be a Zend_Db_Table_Abstract, but it is stdClass', $e->getMessage());
  340. }
  341. }
  342. /**
  343. * Ensures that basic cascading update functionality succeeds using strings for single columns
  344. *
  345. * @return void
  346. */
  347. public function testTableRelationshipCascadingUpdateUsageBasicString()
  348. {
  349. $bug = $this->_getTable('My_ZendDbTable_TableBugsCustom')
  350. ->find(1)
  351. ->current();
  352. $bug_id = $this->_db->foldCase('bug_id');
  353. $this->assertEquals(
  354. 3,
  355. count($bugProducts = $bug->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  356. 'Expecting to find three dependent rows'
  357. );
  358. $bug->$bug_id = 333;
  359. $bug->save();
  360. $this->assertEquals(
  361. 3,
  362. count($bugProducts = $bug->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  363. 'Expecting to find three dependent rows'
  364. );
  365. foreach ($bugProducts as $bugProduct) {
  366. $this->assertEquals(333, $bugProduct->$bug_id);
  367. }
  368. $bug->$bug_id = 1;
  369. $bug->save();
  370. $this->assertEquals(
  371. 3,
  372. count($bugProducts = $bug->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  373. 'Expecting to find three dependent rows'
  374. );
  375. foreach ($bugProducts as $bugProduct) {
  376. $this->assertEquals(1, $bugProduct->$bug_id);
  377. }
  378. }
  379. /**
  380. * Ensures that basic cascading update functionality succeeds using arrays for single columns
  381. *
  382. * @return void
  383. */
  384. public function testTableRelationshipCascadingUpdateUsageBasicArray()
  385. {
  386. $account1 = $this->_getTable('My_ZendDbTable_TableAccountsCustom')
  387. ->find('mmouse')
  388. ->current();
  389. $account_name = $this->_db->foldCase('account_name');
  390. $reported_by = $this->_db->foldCase('reported_by');
  391. $this->assertEquals(
  392. 1,
  393. count($account1->findDependentRowset('My_ZendDbTable_TableBugsCustom')),
  394. 'Expecting to find one dependent row'
  395. );
  396. $account1->$account_name = 'daisy';
  397. $account1->save();
  398. $this->assertEquals(
  399. 1,
  400. count($account1Bugs = $account1->findDependentRowset('My_ZendDbTable_TableBugsCustom')),
  401. 'Expecting to find one dependent row'
  402. );
  403. foreach ($account1Bugs as $account1Bug) {
  404. $this->assertEquals('daisy', $account1Bug->$reported_by);
  405. }
  406. $account1->$account_name = 'mmouse';
  407. $account1->save();
  408. $this->assertEquals(
  409. 1,
  410. count($account1Bugs = $account1->findDependentRowset('My_ZendDbTable_TableBugsCustom')),
  411. 'Expecting to find one dependent row'
  412. );
  413. foreach ($account1Bugs as $account1Bug) {
  414. $this->assertEquals('mmouse', $account1Bug->$reported_by);
  415. }
  416. }
  417. /**
  418. * Ensures that cascading update functionality is not run when onUpdate != self::CASCADE
  419. *
  420. * @return void
  421. */
  422. public function testTableRelationshipCascadingUpdateUsageInvalidNoop()
  423. {
  424. $product1 = $this->_getTable('My_ZendDbTable_TableProductsCustom')
  425. ->find(1)
  426. ->current();
  427. $this->assertEquals(
  428. 1,
  429. count($product1->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  430. 'Expecting to find one dependent row'
  431. );
  432. $product_id = $this->_db->foldCase('product_id');
  433. $product1->$product_id = 333;
  434. $product1->save();
  435. $this->assertEquals(
  436. 0,
  437. count($product1BugsProducts = $product1->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  438. 'Expecting to find one dependent row'
  439. );
  440. $product1->$product_id = 1;
  441. $product1->save();
  442. $this->assertEquals(
  443. 1,
  444. count($product1BugsProducts = $product1->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  445. 'Expecting to find one dependent row'
  446. );
  447. foreach ($product1BugsProducts as $product1BugsProduct) {
  448. $this->assertEquals(1, $product1BugsProduct->$product_id);
  449. }
  450. }
  451. /**
  452. * Ensures that basic cascading delete functionality succeeds using strings for single columns
  453. *
  454. * @return void
  455. */
  456. public function testTableRelationshipCascadingDeleteUsageBasicString()
  457. {
  458. $bug1 = $this->_getTable('My_ZendDbTable_TableBugsCustom')
  459. ->find(1)
  460. ->current();
  461. $this->assertEquals(
  462. 3,
  463. count($bug1->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  464. 'Expecting to find three dependent rows'
  465. );
  466. $bug1->delete();
  467. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  468. $this->assertEquals(
  469. 0,
  470. count($this->_getTable('My_ZendDbTable_TableBugsProductsCustom')->fetchAll("$bug_id = 1")),
  471. 'Expecting cascading delete to have reduced dependent rows to zero'
  472. );
  473. }
  474. /**
  475. * Ensures that basic cascading delete functionality succeeds using arrays for single columns
  476. *
  477. * @return void
  478. */
  479. public function testTableRelationshipCascadingDeleteUsageBasicArray()
  480. {
  481. $reported_by = $this->_db->quoteIdentifier('reported_by', true);
  482. $account1 = $this->_getTable('My_ZendDbTable_TableAccountsCustom')
  483. ->find('mmouse')
  484. ->current();
  485. $this->assertEquals(
  486. 1,
  487. count($account1->findDependentRowset('My_ZendDbTable_TableBugsCustom')),
  488. 'Expecting to find one dependent row'
  489. );
  490. $account1->delete();
  491. $tableBugsCustom = $this->_getTable('My_ZendDbTable_TableBugsCustom');
  492. $this->assertEquals(
  493. 0,
  494. count(
  495. $tableBugsCustom->fetchAll(
  496. $tableBugsCustom->getAdapter()
  497. ->quoteInto("$reported_by = ?", 'mmouse')
  498. )
  499. ),
  500. 'Expecting cascading delete to have reduced dependent rows to zero'
  501. );
  502. }
  503. /**
  504. * Ensures that cascading delete functionality is not run when onDelete != self::CASCADE
  505. *
  506. * @return void
  507. */
  508. public function testTableRelationshipCascadingDeleteUsageInvalidNoop()
  509. {
  510. $product1 = $this->_getTable('My_ZendDbTable_TableProductsCustom')
  511. ->find(1)
  512. ->current();
  513. $this->assertEquals(
  514. 1,
  515. count($product1->findDependentRowset('My_ZendDbTable_TableBugsProductsCustom')),
  516. 'Expecting to find one dependent row'
  517. );
  518. $product1->delete();
  519. $product_id = $this->_db->quoteIdentifier('product_id', true);
  520. $this->assertEquals(
  521. 1,
  522. count($this->_getTable('My_ZendDbTable_TableBugsProductsCustom')->fetchAll("$product_id = 1")),
  523. 'Expecting to find one dependent row'
  524. );
  525. }
  526. public function testTableRelationshipGetReference()
  527. {
  528. $table = $this->_table['bugs'];
  529. $map = $table->getReference('My_ZendDbTable_TableAccounts', 'Reporter');
  530. $this->assertThat($map, $this->arrayHasKey('columns'));
  531. $this->assertThat($map, $this->arrayHasKey('refTableClass'));
  532. $this->assertThat($map, $this->arrayHasKey('refColumns'));
  533. }
  534. public function testTableRelationshipGetReferenceException()
  535. {
  536. $table = $this->_table['bugs'];
  537. try {
  538. $table->getReference('My_ZendDbTable_TableAccounts', 'Nonexistent');
  539. $this->fail('Expected to catch Zend_Db_Table_Exception for nonexistent reference rule');
  540. } catch (Zend_Exception $e) {
  541. $this->assertType('Zend_Db_Table_Exception', $e,
  542. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  543. }
  544. try {
  545. $table->getReference('Nonexistent', 'Reporter');
  546. $this->fail('Expected to catch Zend_Db_Table_Exception for nonexistent rule tableClass');
  547. } catch (Zend_Exception $e) {
  548. $this->assertType('Zend_Db_Table_Exception', $e,
  549. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  550. }
  551. try {
  552. $table->getReference('Nonexistent');
  553. $this->fail('Expected to catch Zend_Db_Table_Exception for nonexistent rule tableClass');
  554. } catch (Zend_Exception $e) {
  555. $this->assertType('Zend_Db_Table_Exception', $e,
  556. 'Expecting object of type Zend_Db_Table_Exception got '.get_class($e));
  557. }
  558. }
  559. /**
  560. * Ensures that findParentRow() returns an instance of a custom row class when passed an instance
  561. * of the table class having $_rowClass overridden.
  562. *
  563. * @return void
  564. */
  565. public function testTableRelationshipFindParentRowCustomInstance()
  566. {
  567. $this->_useMyIncludePath();
  568. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  569. Zend_Loader::loadClass($myRowClass);
  570. $bug1Reporter = $this->_table['bugs']
  571. ->find(1)
  572. ->current()
  573. ->findParentRow($this->_table['accounts']->setRowClass($myRowClass));
  574. $this->assertType($myRowClass, $bug1Reporter,
  575. "Expecting object of type $myRowClass, got ".get_class($bug1Reporter));
  576. }
  577. /**
  578. * Ensures that findParentRow() returns an instance of a custom row class when passed a string class
  579. * name, where the class has $_rowClass overridden.
  580. *
  581. * @return void
  582. */
  583. public function testTableRelationshipFindParentRowCustomClass()
  584. {
  585. $this->_useMyIncludePath();
  586. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  587. Zend_Loader::loadClass($myRowClass);
  588. Zend_Loader::loadClass('My_ZendDbTable_TableAccountsCustom');
  589. $bug1Reporter = $this->_getTable('My_ZendDbTable_TableBugsCustom')
  590. ->find(1)
  591. ->current()
  592. ->findParentRow(new My_ZendDbTable_TableAccountsCustom(array('db' => $this->_db)));
  593. $this->assertType($myRowClass, $bug1Reporter,
  594. "Expecting object of type $myRowClass, got ".get_class($bug1Reporter));
  595. }
  596. /**
  597. * Ensures that findDependentRowset() returns instances of custom row and rowset classes when
  598. * passed an instance of the table class.
  599. *
  600. * @return void
  601. */
  602. public function testTableRelationshipFindDependentRowsetCustomInstance()
  603. {
  604. $this->_useMyIncludePath();
  605. $myRowsetClass = 'My_ZendDbTable_Rowset_TestMyRowset';
  606. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  607. Zend_Loader::loadClass($myRowsetClass);
  608. $account_name = $this->_db->quoteIdentifier('account_name', true);
  609. $bugs = $this->_table['accounts']
  610. ->fetchRow($this->_db->quoteInto("$account_name = ?", 'mmouse'))
  611. ->findDependentRowset(
  612. $this->_table['bugs']
  613. ->setRowsetClass($myRowsetClass)
  614. ->setRowClass($myRowClass),
  615. 'Engineer'
  616. );
  617. $this->assertType($myRowsetClass, $bugs,
  618. "Expecting object of type $myRowsetClass, got ".get_class($bugs));
  619. $this->assertEquals(3, count($bugs));
  620. foreach ($bugs as $bug) {
  621. $this->assertType($myRowClass, $bug,
  622. "Expecting object of type $myRowClass, got ".get_class($bug));
  623. }
  624. }
  625. /**
  626. * Ensures that findDependentRowset() returns instances of custom row and rowset classes when
  627. * passed the named class.
  628. *
  629. * @return void
  630. */
  631. public function testTableRelationshipFindDependentRowsetCustomClass()
  632. {
  633. $this->_useMyIncludePath();
  634. $myRowsetClass = 'My_ZendDbTable_Rowset_TestMyRowset';
  635. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  636. Zend_Loader::loadClass($myRowsetClass);
  637. $account_name = $this->_db->quoteIdentifier('account_name', true);
  638. $bugs = $this->_getTable('My_ZendDbTable_TableAccountsCustom')
  639. ->fetchRow($this->_db->quoteInto("$account_name = ?", 'mmouse'))
  640. ->findDependentRowset('My_ZendDbTable_TableBugsCustom', 'Engineer');
  641. $this->assertType($myRowsetClass, $bugs,
  642. "Expecting object of type $myRowsetClass, got ".get_class($bugs));
  643. $this->assertEquals(3, count($bugs));
  644. foreach ($bugs as $bug) {
  645. $this->assertType($myRowClass, $bug,
  646. "Expecting object of type $myRowClass, got ".get_class($bug));
  647. }
  648. }
  649. /**
  650. * Ensures that findManyToManyRowset() returns instances of custom row and rowset class when
  651. * passed an instance of the table class.
  652. *
  653. * @return void
  654. */
  655. public function testTableRelationshipFindManyToManyRowsetCustomInstance()
  656. {
  657. $this->_useMyIncludePath();
  658. $myRowsetClass = 'My_ZendDbTable_Rowset_TestMyRowset';
  659. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  660. Zend_Loader::loadClass($myRowsetClass);
  661. $bug1Products = $this->_table['bugs']
  662. ->find(1)
  663. ->current()
  664. ->findManyToManyRowset(
  665. $this->_table['products']
  666. ->setRowsetClass($myRowsetClass)
  667. ->setRowClass($myRowClass),
  668. 'My_ZendDbTable_TableBugsProducts'
  669. );
  670. $this->assertType($myRowsetClass, $bug1Products,
  671. "Expecting object of type $myRowsetClass, got ".get_class($bug1Products));
  672. $this->assertEquals(3, count($bug1Products));
  673. foreach ($bug1Products as $bug1Product) {
  674. $this->assertType($myRowClass, $bug1Product,
  675. "Expecting object of type $myRowClass, got ".get_class($bug1Product));
  676. }
  677. }
  678. /**
  679. * Ensures that findManyToManyRowset() returns instances of custom row and rowset classes when
  680. * passed the named class.
  681. *
  682. * @return void
  683. */
  684. public function testTableRelationshipFindManyToManyRowsetCustomClass()
  685. {
  686. $this->_useMyIncludePath();
  687. $myRowsetClass = 'My_ZendDbTable_Rowset_TestMyRowset';
  688. $myRowClass = 'My_ZendDbTable_Row_TestMyRow';
  689. Zend_Loader::loadClass($myRowsetClass);
  690. $bug1Products = $this->_getTable('My_ZendDbTable_TableBugsCustom')
  691. ->find(1)
  692. ->current()
  693. ->findManyToManyRowset(
  694. 'My_ZendDbTable_TableProductsCustom',
  695. 'My_ZendDbTable_TableBugsProductsCustom'
  696. );
  697. $this->assertType($myRowsetClass, $bug1Products,
  698. "Expecting object of type $myRowsetClass, got ".get_class($bug1Products));
  699. $this->assertEquals(3, count($bug1Products));
  700. foreach ($bug1Products as $bug1Product) {
  701. $this->assertType($myRowClass, $bug1Product,
  702. "Expecting object of type $myRowClass, got ".get_class($bug1Product));
  703. }
  704. }
  705. /**
  706. * Ensures that rows returned by findParentRow() are updatable.
  707. *
  708. * @return void
  709. */
  710. public function testTableRelationshipFindParentRowIsUpdateable()
  711. {
  712. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  713. $account_name = $this->_db->foldCase('account_name');
  714. $table = $this->_table['bugs'];
  715. $childRows = $table->fetchAll("$bug_id = 1");
  716. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  717. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  718. $childRow1 = $childRows->current();
  719. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  720. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  721. $parentRow = $childRow1->findParentRow('My_ZendDbTable_TableAccounts');
  722. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  723. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  724. $this->assertEquals('goofy', $parentRow->$account_name);
  725. $parentRow->$account_name = 'clarabell';
  726. try {
  727. $parentRow->save();
  728. } catch (Zend_Exception $e) {
  729. $this->fail('Failed with unexpected '.get_class($e).': '.$e->getMessage());
  730. }
  731. $accounts = $this->_db->quoteIdentifier('zfaccounts', true);
  732. $account_name = $this->_db->quoteIdentifier('account_name', true);
  733. $accounts_list = $this->_db->fetchCol("SELECT $account_name from $accounts ORDER BY $account_name");
  734. // if the save() did an UPDATE instead of an INSERT, then goofy should
  735. // be missing, and clarabell should be present
  736. $this->assertEquals(array('clarabell', 'dduck', 'mmouse'), $accounts_list);
  737. }
  738. /**
  739. * Ensures that rows returned by findDependentRowset() are updatable.
  740. *
  741. * @return void
  742. */
  743. public function testTableRelationshipFindDependentRowsetIsUpdateable()
  744. {
  745. $table = $this->_table['accounts'];
  746. $bug_id_column = $this->_db->foldCase('bug_id');
  747. $bug_description = $this->_db->foldCase('bug_description');
  748. $parentRows = $table->find('mmouse');
  749. $this->assertType('Zend_Db_Table_Rowset_Abstract', $parentRows,
  750. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($parentRows));
  751. $parentRow1 = $parentRows->current();
  752. $childRows = $parentRow1->findDependentRowset('My_ZendDbTable_TableBugs');
  753. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  754. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  755. $this->assertEquals(1, $childRows->count());
  756. $childRow1 = $childRows->current();
  757. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  758. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  759. $childRow1->$bug_description = 'Updated description';
  760. $bug_id = $childRow1->$bug_id_column;
  761. try {
  762. $childRow1->save();
  763. } catch (Zend_Exception $e) {
  764. $this->fail('Failed with unexpected '.get_class($e).': '.$e->getMessage());
  765. }
  766. // find the row we just updated and make sure it has the new value.
  767. $bugs_table = $this->_table['bugs'];
  768. $bugs_rows = $bugs_table->find($bug_id);
  769. $this->assertEquals(1, $bugs_rows->count());
  770. $bug1 = $bugs_rows->current();
  771. $this->assertEquals($bug_id, $bug1->$bug_id_column);
  772. $this->assertEquals('Updated description', $bug1->$bug_description);
  773. }
  774. /**
  775. * Ensures that rows returned by findManyToManyRowset() are updatable.
  776. *
  777. * @return void
  778. */
  779. public function testTableRelationshipFindManyToManyRowsetIsUpdateable()
  780. {
  781. $table = $this->_table['bugs'];
  782. $product_id_column = $this->_db->foldCase('product_id');
  783. $product_name = $this->_db->foldCase('product_name');
  784. $originRows = $table->find(1);
  785. $originRow1 = $originRows->current();
  786. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableProducts', 'My_ZendDbTable_TableBugsProducts');
  787. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  788. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  789. $this->assertEquals(3, $destRows->count());
  790. $row1 = $destRows->current();
  791. $product_id = $row1->$product_id_column;
  792. $row1->$product_name = 'AmigaOS';
  793. try {
  794. $row1->save();
  795. } catch (Zend_Exception $e) {
  796. $this->fail('Failed with unexpected '.get_class($e).': '.$e->getMessage());
  797. }
  798. // find the row we just updated and make sure it has the new value.
  799. $products_table = $this->_table['products'];
  800. $product_rows = $products_table->find($product_id);
  801. $this->assertEquals(1, $product_rows->count());
  802. $product_row = $product_rows->current();
  803. $this->assertEquals($product_id, $product_row->$product_id_column);
  804. $this->assertEquals('AmigaOS', $product_row->$product_name);
  805. }
  806. public function testTableRelationshipOmitRefColumns()
  807. {
  808. $refMap = array(
  809. 'Reporter' => array(
  810. 'columns' => array('reported_by'),
  811. 'refTableClass' => 'My_ZendDbTable_TableAccounts'
  812. )
  813. );
  814. $table = $this->_getTable('My_ZendDbTable_TableSpecial',
  815. array(
  816. 'name' => 'zfbugs',
  817. 'referenceMap' => $refMap
  818. )
  819. );
  820. $bug1 = $table->find(1)->current();
  821. $reporter = $bug1->findParentRow('My_ZendDbTable_TableAccounts');
  822. $this->assertEquals(array('account_name' => 'goofy'), $reporter->toArray());
  823. }
  824. /**
  825. * Test that findParentRow() works even if the column names are
  826. * not the same.
  827. */
  828. public function testTableRelationshipFindParentRowWithDissimilarColumns()
  829. {
  830. $bug_id = $this->_db->foldCase('bug_id');
  831. $product_id = $this->_db->foldCase('product_id');
  832. $intersectionTable = $this->_getBugsProductsWithDissimilarColumns();
  833. $intRow = $intersectionTable->find(2, 3)->current();
  834. $bugRow = $intRow->findParentRow('My_ZendDbTable_TableBugs');
  835. $this->assertEquals(2, $bugRow->$bug_id);
  836. $productRow = $intRow->findParentRow('My_ZendDbTable_TableProducts');
  837. $this->assertEquals(3, $productRow->$product_id);
  838. }
  839. /**
  840. * Test that findDependentRowset() works even if the column names are
  841. * not the same.
  842. */
  843. public function testTableRelationshipFindDependentRowsetWithDissimilarColumns()
  844. {
  845. $intersectionTable = $this->_getBugsProductsWithDissimilarColumns();
  846. $bugsTable = $this->_getTable('My_ZendDbTable_TableBugs');
  847. $bugRow = $bugsTable->find(2)->current();
  848. $intRows = $bugRow->findDependentRowset($intersectionTable);
  849. $this->assertEquals(array(2, 3), array_values($intRows->current()->toArray()));
  850. }
  851. /**
  852. * Test that findManyToManyRowset() works even if the column names are
  853. * not the same.
  854. */
  855. public function testTableRelationshipFindManyToManyRowsetWithDissimilarColumns()
  856. {
  857. $product_id = $this->_db->foldCase('product_id');
  858. $intersectionTable = $this->_getBugsProductsWithDissimilarColumns();
  859. $bugsTable = $this->_getTable('My_ZendDbTable_TableBugs');
  860. $bugRow = $bugsTable->find(2)->current();
  861. $productRows = $bugRow->findManyToManyRowset('My_ZendDbTable_TableProducts', $intersectionTable);
  862. $this->assertEquals(3, $productRows->current()->$product_id);
  863. }
  864. /**
  865. * Test that findManyToManyRowset() works even if the column types are
  866. * not the same.
  867. */
  868. public function testTableRelationshipFindManyToManyRowsetWithDissimilarTypes()
  869. {
  870. $table = $this->_table['products'];
  871. $originRows = $table->find(1);
  872. $originRow1 = $originRows->current();
  873. $destRows = $originRow1->findManyToManyRowset('My_ZendDbTable_TableBugs', 'My_ZendDbTable_TableBugsProducts');
  874. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  875. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  876. $this->assertEquals(1, $destRows->count());
  877. }
  878. /**
  879. * @group ZF-3486
  880. */
  881. public function testTableRelationshipCanFindParentViaConcreteInstantiation()
  882. {
  883. Zend_Db_Table::setDefaultAdapter($this->_db);
  884. $definition = array(
  885. 'Bugs' => array(
  886. 'name' => 'zfbugs',
  887. 'referenceMap' => array(
  888. 'Engineer' => array(
  889. 'columns' => 'assigned_to',
  890. 'refTableClass' => 'Accounts',
  891. 'refColumns' => 'account_name'
  892. )
  893. )
  894. ),
  895. 'Accounts' => array(
  896. 'name' => 'zfaccounts'
  897. )
  898. );
  899. $bugsTable = new Zend_Db_Table('Bugs', $definition);
  900. $rowset = $bugsTable->find(1);
  901. $row = $rowset->current();
  902. $parent = $row->findParentRow('Accounts', 'Engineer');
  903. $this->assertEquals('mmouse', $parent->account_name);
  904. Zend_Db_Table::setDefaultAdapter();
  905. }
  906. /**
  907. * Utility Methods Below
  908. *
  909. */
  910. /**
  911. * Create database table based on BUGS_PRODUCTS bug with alternative
  912. * spellings of column names. Then create a Table class for this
  913. * physical table and return it.
  914. */
  915. protected function _getBugsProductsWithDissimilarColumns()
  916. {
  917. $altCols = array(
  918. 'boog_id' => 'INTEGER NOT NULL',
  919. 'produck_id' => 'INTEGER NOT NULL',
  920. 'PRIMARY KEY' => 'boog_id,produck_id'
  921. );
  922. $this->_util->createTable('AltBugsProducts', $altCols);
  923. $altBugsProducts = $this->_db->quoteIdentifier($this->_db->foldCase('zfalt_bugs_products'), true);
  924. $bugsProducts = $this->_db->quoteIdentifier($this->_db->foldCase('zfbugs_products'), true);
  925. $this->_db->query("INSERT INTO $altBugsProducts SELECT * FROM $bugsProducts");
  926. $refMap = array(
  927. 'Boog' => array(
  928. 'columns' => array('boog_id'),
  929. 'refTableClass' => 'My_ZendDbTable_TableBugs',
  930. 'refColumns' => array('bug_id')
  931. ),
  932. 'Produck' => array(
  933. 'columns' => array('produck_id'),
  934. 'refTableClass' => 'My_ZendDbTable_TableProducts',
  935. 'refColumns' => array('product_id')
  936. )
  937. );
  938. $options = array('name' => 'zfalt_bugs_products', 'referenceMap' => $refMap);
  939. $table = $this->_getTable('My_ZendDbTable_TableSpecial', $options);
  940. return $table;
  941. }
  942. }