TestCommon.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  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-2008 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-2008 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('Zend_Db_Table_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('Zend_Db_Table_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->findParentZend_Db_Table_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->findParentZend_Db_Table_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('Zend_Db_Table_TableProducts', 'Zend_Db_Table_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('Zend_Db_Table_TableProducts', 'Zend_Db_Table_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->findZend_Db_Table_TableProductsViaZend_Db_Table_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->findZend_Db_Table_TableProductsViaZend_Db_Table_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', 'Zend_Db_Table_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(), 'Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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->findZend_Db_Table_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->findZend_Db_Table_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('Zend_Db_Table_TableBugsCustom')
  350. ->find(1)
  351. ->current();
  352. $bug_id = $this->_db->foldCase('bug_id');
  353. $this->assertEquals(
  354. 3,
  355. count($bugProducts = $bug->findDependentRowset('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_TableProductsCustom')
  425. ->find(1)
  426. ->current();
  427. $this->assertEquals(
  428. 1,
  429. count($product1->findDependentRowset('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_TableBugsCustom')
  459. ->find(1)
  460. ->current();
  461. $this->assertEquals(
  462. 3,
  463. count($bug1->findDependentRowset('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_TableAccountsCustom')
  483. ->find('mmouse')
  484. ->current();
  485. $this->assertEquals(
  486. 1,
  487. count($account1->findDependentRowset('Zend_Db_Table_TableBugsCustom')),
  488. 'Expecting to find one dependent row'
  489. );
  490. $account1->delete();
  491. $tableBugsCustom = $this->_getTable('Zend_Db_Table_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('Zend_Db_Table_TableProductsCustom')
  511. ->find(1)
  512. ->current();
  513. $this->assertEquals(
  514. 1,
  515. count($product1->findDependentRowset('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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('Zend_Db_Table_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. $myRowClass = 'Zend_Db_Table_Row_TestMyRow';
  568. Zend_Loader::loadClass($myRowClass);
  569. $bug1Reporter = $this->_table['bugs']
  570. ->find(1)
  571. ->current()
  572. ->findParentRow($this->_table['accounts']->setRowClass($myRowClass));
  573. $this->assertType($myRowClass, $bug1Reporter,
  574. "Expecting object of type $myRowClass, got ".get_class($bug1Reporter));
  575. }
  576. /**
  577. * Ensures that findParentRow() returns an instance of a custom row class when passed a string class
  578. * name, where the class has $_rowClass overridden.
  579. *
  580. * @return void
  581. */
  582. public function testTableRelationshipFindParentRowCustomClass()
  583. {
  584. $myRowClass = 'Zend_Db_Table_Row_TestMyRow';
  585. Zend_Loader::loadClass($myRowClass);
  586. Zend_Loader::loadClass('Zend_Db_Table_TableAccountsCustom');
  587. $bug1Reporter = $this->_getTable('Zend_Db_Table_TableBugsCustom')
  588. ->find(1)
  589. ->current()
  590. ->findParentRow(new Zend_Db_Table_TableAccountsCustom(array('db' => $this->_db)));
  591. $this->assertType($myRowClass, $bug1Reporter,
  592. "Expecting object of type $myRowClass, got ".get_class($bug1Reporter));
  593. }
  594. /**
  595. * Ensures that findDependentRowset() returns instances of custom row and rowset classes when
  596. * passed an instance of the table class.
  597. *
  598. * @return void
  599. */
  600. public function testTableRelationshipFindDependentRowsetCustomInstance()
  601. {
  602. $myRowsetClass = 'Zend_Db_Table_Rowset_TestMyRowset';
  603. $myRowClass = 'Zend_Db_Table_Row_TestMyRow';
  604. Zend_Loader::loadClass($myRowsetClass);
  605. $account_name = $this->_db->quoteIdentifier('account_name', true);
  606. $bugs = $this->_table['accounts']
  607. ->fetchRow($this->_db->quoteInto("$account_name = ?", 'mmouse'))
  608. ->findDependentRowset(
  609. $this->_table['bugs']
  610. ->setRowsetClass($myRowsetClass)
  611. ->setRowClass($myRowClass),
  612. 'Engineer'
  613. );
  614. $this->assertType($myRowsetClass, $bugs,
  615. "Expecting object of type $myRowsetClass, got ".get_class($bugs));
  616. $this->assertEquals(3, count($bugs));
  617. foreach ($bugs as $bug) {
  618. $this->assertType($myRowClass, $bug,
  619. "Expecting object of type $myRowClass, got ".get_class($bug));
  620. }
  621. }
  622. /**
  623. * Ensures that findDependentRowset() returns instances of custom row and rowset classes when
  624. * passed the named class.
  625. *
  626. * @return void
  627. */
  628. public function testTableRelationshipFindDependentRowsetCustomClass()
  629. {
  630. $myRowsetClass = 'Zend_Db_Table_Rowset_TestMyRowset';
  631. $myRowClass = 'Zend_Db_Table_Row_TestMyRow';
  632. Zend_Loader::loadClass($myRowsetClass);
  633. $account_name = $this->_db->quoteIdentifier('account_name', true);
  634. $bugs = $this->_getTable('Zend_Db_Table_TableAccountsCustom')
  635. ->fetchRow($this->_db->quoteInto("$account_name = ?", 'mmouse'))
  636. ->findDependentRowset('Zend_Db_Table_TableBugsCustom', 'Engineer');
  637. $this->assertType($myRowsetClass, $bugs,
  638. "Expecting object of type $myRowsetClass, got ".get_class($bugs));
  639. $this->assertEquals(3, count($bugs));
  640. foreach ($bugs as $bug) {
  641. $this->assertType($myRowClass, $bug,
  642. "Expecting object of type $myRowClass, got ".get_class($bug));
  643. }
  644. }
  645. /**
  646. * Ensures that findManyToManyRowset() returns instances of custom row and rowset class when
  647. * passed an instance of the table class.
  648. *
  649. * @return void
  650. */
  651. public function testTableRelationshipFindManyToManyRowsetCustomInstance()
  652. {
  653. $myRowsetClass = 'Zend_Db_Table_Rowset_TestMyRowset';
  654. $myRowClass = 'Zend_Db_Table_Row_TestMyRow';
  655. Zend_Loader::loadClass($myRowsetClass);
  656. $bug1Products = $this->_table['bugs']
  657. ->find(1)
  658. ->current()
  659. ->findManyToManyRowset(
  660. $this->_table['products']
  661. ->setRowsetClass($myRowsetClass)
  662. ->setRowClass($myRowClass),
  663. 'Zend_Db_Table_TableBugsProducts'
  664. );
  665. $this->assertType($myRowsetClass, $bug1Products,
  666. "Expecting object of type $myRowsetClass, got ".get_class($bug1Products));
  667. $this->assertEquals(3, count($bug1Products));
  668. foreach ($bug1Products as $bug1Product) {
  669. $this->assertType($myRowClass, $bug1Product,
  670. "Expecting object of type $myRowClass, got ".get_class($bug1Product));
  671. }
  672. }
  673. /**
  674. * Ensures that findManyToManyRowset() returns instances of custom row and rowset classes when
  675. * passed the named class.
  676. *
  677. * @return void
  678. */
  679. public function testTableRelationshipFindManyToManyRowsetCustomClass()
  680. {
  681. $myRowsetClass = 'Zend_Db_Table_Rowset_TestMyRowset';
  682. $myRowClass = 'Zend_Db_Table_Row_TestMyRow';
  683. Zend_Loader::loadClass($myRowsetClass);
  684. $bug1Products = $this->_getTable('Zend_Db_Table_TableBugsCustom')
  685. ->find(1)
  686. ->current()
  687. ->findManyToManyRowset(
  688. 'Zend_Db_Table_TableProductsCustom',
  689. 'Zend_Db_Table_TableBugsProductsCustom'
  690. );
  691. $this->assertType($myRowsetClass, $bug1Products,
  692. "Expecting object of type $myRowsetClass, got ".get_class($bug1Products));
  693. $this->assertEquals(3, count($bug1Products));
  694. foreach ($bug1Products as $bug1Product) {
  695. $this->assertType($myRowClass, $bug1Product,
  696. "Expecting object of type $myRowClass, got ".get_class($bug1Product));
  697. }
  698. }
  699. /**
  700. * Ensures that rows returned by findParentRow() are updatable.
  701. *
  702. * @return void
  703. */
  704. public function testTableRelationshipFindParentRowIsUpdateable()
  705. {
  706. $bug_id = $this->_db->quoteIdentifier('bug_id', true);
  707. $account_name = $this->_db->foldCase('account_name');
  708. $table = $this->_table['bugs'];
  709. $childRows = $table->fetchAll("$bug_id = 1");
  710. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  711. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  712. $childRow1 = $childRows->current();
  713. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  714. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  715. $parentRow = $childRow1->findParentRow('Zend_Db_Table_TableAccounts');
  716. $this->assertType('Zend_Db_Table_Row_Abstract', $parentRow,
  717. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($parentRow));
  718. $this->assertEquals('goofy', $parentRow->$account_name);
  719. $parentRow->$account_name = 'clarabell';
  720. try {
  721. $parentRow->save();
  722. } catch (Zend_Exception $e) {
  723. $this->fail('Failed with unexpected '.get_class($e).': '.$e->getMessage());
  724. }
  725. $accounts = $this->_db->quoteIdentifier('zfaccounts', true);
  726. $account_name = $this->_db->quoteIdentifier('account_name', true);
  727. $accounts_list = $this->_db->fetchCol("SELECT $account_name from $accounts ORDER BY $account_name");
  728. // if the save() did an UPDATE instead of an INSERT, then goofy should
  729. // be missing, and clarabell should be present
  730. $this->assertEquals(array('clarabell', 'dduck', 'mmouse'), $accounts_list);
  731. }
  732. /**
  733. * Ensures that rows returned by findDependentRowset() are updatable.
  734. *
  735. * @return void
  736. */
  737. public function testTableRelationshipFindDependentRowsetIsUpdateable()
  738. {
  739. $table = $this->_table['accounts'];
  740. $bug_id_column = $this->_db->foldCase('bug_id');
  741. $bug_description = $this->_db->foldCase('bug_description');
  742. $parentRows = $table->find('mmouse');
  743. $this->assertType('Zend_Db_Table_Rowset_Abstract', $parentRows,
  744. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($parentRows));
  745. $parentRow1 = $parentRows->current();
  746. $childRows = $parentRow1->findDependentRowset('Zend_Db_Table_TableBugs');
  747. $this->assertType('Zend_Db_Table_Rowset_Abstract', $childRows,
  748. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($childRows));
  749. $this->assertEquals(1, $childRows->count());
  750. $childRow1 = $childRows->current();
  751. $this->assertType('Zend_Db_Table_Row_Abstract', $childRow1,
  752. 'Expecting object of type Zend_Db_Table_Row_Abstract, got '.get_class($childRow1));
  753. $childRow1->$bug_description = 'Updated description';
  754. $bug_id = $childRow1->$bug_id_column;
  755. try {
  756. $childRow1->save();
  757. } catch (Zend_Exception $e) {
  758. $this->fail('Failed with unexpected '.get_class($e).': '.$e->getMessage());
  759. }
  760. // find the row we just updated and make sure it has the new value.
  761. $bugs_table = $this->_table['bugs'];
  762. $bugs_rows = $bugs_table->find($bug_id);
  763. $this->assertEquals(1, $bugs_rows->count());
  764. $bug1 = $bugs_rows->current();
  765. $this->assertEquals($bug_id, $bug1->$bug_id_column);
  766. $this->assertEquals('Updated description', $bug1->$bug_description);
  767. }
  768. /**
  769. * Ensures that rows returned by findManyToManyRowset() are updatable.
  770. *
  771. * @return void
  772. */
  773. public function testTableRelationshipFindManyToManyRowsetIsUpdateable()
  774. {
  775. $table = $this->_table['bugs'];
  776. $product_id_column = $this->_db->foldCase('product_id');
  777. $product_name = $this->_db->foldCase('product_name');
  778. $originRows = $table->find(1);
  779. $originRow1 = $originRows->current();
  780. $destRows = $originRow1->findManyToManyRowset('Zend_Db_Table_TableProducts', 'Zend_Db_Table_TableBugsProducts');
  781. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  782. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  783. $this->assertEquals(3, $destRows->count());
  784. $row1 = $destRows->current();
  785. $product_id = $row1->$product_id_column;
  786. $row1->$product_name = 'AmigaOS';
  787. try {
  788. $row1->save();
  789. } catch (Zend_Exception $e) {
  790. $this->fail('Failed with unexpected '.get_class($e).': '.$e->getMessage());
  791. }
  792. // find the row we just updated and make sure it has the new value.
  793. $products_table = $this->_table['products'];
  794. $product_rows = $products_table->find($product_id);
  795. $this->assertEquals(1, $product_rows->count());
  796. $product_row = $product_rows->current();
  797. $this->assertEquals($product_id, $product_row->$product_id_column);
  798. $this->assertEquals('AmigaOS', $product_row->$product_name);
  799. }
  800. public function testTableRelationshipOmitRefColumns()
  801. {
  802. $refMap = array(
  803. 'Reporter' => array(
  804. 'columns' => array('reported_by'),
  805. 'refTableClass' => 'Zend_Db_Table_TableAccounts'
  806. )
  807. );
  808. $table = $this->_getTable('Zend_Db_Table_TableSpecial',
  809. array(
  810. 'name' => 'zfbugs',
  811. 'referenceMap' => $refMap
  812. )
  813. );
  814. $bug1 = $table->find(1)->current();
  815. $reporter = $bug1->findParentRow('Zend_Db_Table_TableAccounts');
  816. $this->assertEquals(array('account_name' => 'goofy'), $reporter->toArray());
  817. }
  818. /**
  819. * Create database table based on BUGS_PRODUCTS bug with alternative
  820. * spellings of column names. Then create a Table class for this
  821. * physical table and return it.
  822. */
  823. protected function _getBugsProductsWithDissimilarColumns()
  824. {
  825. $altCols = array(
  826. 'boog_id' => 'INTEGER NOT NULL',
  827. 'produck_id' => 'INTEGER NOT NULL',
  828. 'PRIMARY KEY' => 'boog_id,produck_id'
  829. );
  830. $this->_util->createTable('AltBugsProducts', $altCols);
  831. $altBugsProducts = $this->_db->quoteIdentifier($this->_db->foldCase('zfalt_bugs_products'), true);
  832. $bugsProducts = $this->_db->quoteIdentifier($this->_db->foldCase('zfbugs_products'), true);
  833. $this->_db->query("INSERT INTO $altBugsProducts SELECT * FROM $bugsProducts");
  834. $refMap = array(
  835. 'Boog' => array(
  836. 'columns' => array('boog_id'),
  837. 'refTableClass' => 'Zend_Db_Table_TableBugs',
  838. 'refColumns' => array('bug_id')
  839. ),
  840. 'Produck' => array(
  841. 'columns' => array('produck_id'),
  842. 'refTableClass' => 'Zend_Db_Table_TableProducts',
  843. 'refColumns' => array('product_id')
  844. )
  845. );
  846. $options = array('name' => 'zfalt_bugs_products', 'referenceMap' => $refMap);
  847. $table = $this->_getTable('Zend_Db_Table_TableSpecial', $options);
  848. return $table;
  849. }
  850. /**
  851. * Test that findParentRow() works even if the column names are
  852. * not the same.
  853. */
  854. public function testTableRelationshipFindParentRowWithDissimilarColumns()
  855. {
  856. $bug_id = $this->_db->foldCase('bug_id');
  857. $product_id = $this->_db->foldCase('product_id');
  858. $intersectionTable = $this->_getBugsProductsWithDissimilarColumns();
  859. $intRow = $intersectionTable->find(2, 3)->current();
  860. $bugRow = $intRow->findParentRow('Zend_Db_Table_TableBugs');
  861. $this->assertEquals(2, $bugRow->$bug_id);
  862. $productRow = $intRow->findParentRow('Zend_Db_Table_TableProducts');
  863. $this->assertEquals(3, $productRow->$product_id);
  864. }
  865. /**
  866. * Test that findDependentRowset() works even if the column names are
  867. * not the same.
  868. */
  869. public function testTableRelationshipFindDependentRowsetWithDissimilarColumns()
  870. {
  871. $intersectionTable = $this->_getBugsProductsWithDissimilarColumns();
  872. $bugsTable = $this->_getTable('Zend_Db_Table_TableBugs');
  873. $bugRow = $bugsTable->find(2)->current();
  874. $intRows = $bugRow->findDependentRowset($intersectionTable);
  875. $this->assertEquals(array(2, 3), array_values($intRows->current()->toArray()));
  876. }
  877. /**
  878. * Test that findManyToManyRowset() works even if the column names are
  879. * not the same.
  880. */
  881. public function testTableRelationshipFindManyToManyRowsetWithDissimilarColumns()
  882. {
  883. $product_id = $this->_db->foldCase('product_id');
  884. $intersectionTable = $this->_getBugsProductsWithDissimilarColumns();
  885. $bugsTable = $this->_getTable('Zend_Db_Table_TableBugs');
  886. $bugRow = $bugsTable->find(2)->current();
  887. $productRows = $bugRow->findManyToManyRowset('Zend_Db_Table_TableProducts', $intersectionTable);
  888. $this->assertEquals(3, $productRows->current()->$product_id);
  889. }
  890. /**
  891. * Test that findManyToManyRowset() works even if the column types are
  892. * not the same.
  893. */
  894. public function testTableRelationshipFindManyToManyRowsetWithDissimilarTypes()
  895. {
  896. $table = $this->_table['products'];
  897. $originRows = $table->find(1);
  898. $originRow1 = $originRows->current();
  899. $destRows = $originRow1->findManyToManyRowset('Zend_Db_Table_TableBugs', 'Zend_Db_Table_TableBugsProducts');
  900. $this->assertType('Zend_Db_Table_Rowset_Abstract', $destRows,
  901. 'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($destRows));
  902. $this->assertEquals(1, $destRows->count());
  903. }
  904. }