PageRenderTime 71ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 1ms

/cake/tests/cases/libs/model/datasources/dbo_source.test.php

https://bitbucket.org/webpolis/hurli
PHP | 4594 lines | 2740 code | 677 blank | 1177 comment | 32 complexity | 0c711952fccf9c9c891b014bed042ebd MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * DboSourceTest file
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The Open Group Test Suite License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package cake
  16. * @subpackage cake.tests.cases.libs.model.datasources
  17. * @since CakePHP(tm) v 1.2.0.4206
  18. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  19. */
  20. if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
  21. define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
  22. }
  23. App::import('Model', array('Model', 'DataSource', 'DboSource', 'DboMysql', 'App'));
  24. require_once dirname(dirname(__FILE__)) . DS . 'models.php';
  25. /**
  26. * TestModel class
  27. *
  28. * @package cake
  29. * @subpackage cake.tests.cases.libs.model.datasources
  30. */
  31. class TestModel extends CakeTestModel {
  32. /**
  33. * name property
  34. *
  35. * @var string 'TestModel'
  36. * @access public
  37. */
  38. var $name = 'TestModel';
  39. /**
  40. * useTable property
  41. *
  42. * @var bool false
  43. * @access public
  44. */
  45. var $useTable = false;
  46. /**
  47. * schema property
  48. *
  49. * @var array
  50. * @access protected
  51. */
  52. var $_schema = array(
  53. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  54. 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'),
  55. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  56. 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  57. 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  58. 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  59. 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'),
  60. 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  61. 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  62. 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  63. 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  64. 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  65. 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  66. 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  67. 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => '155'),
  68. 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
  69. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  70. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  71. );
  72. /**
  73. * find method
  74. *
  75. * @param mixed $conditions
  76. * @param mixed $fields
  77. * @param mixed $order
  78. * @param mixed $recursive
  79. * @access public
  80. * @return void
  81. */
  82. function find($conditions = null, $fields = null, $order = null, $recursive = null) {
  83. return array($conditions, $fields);
  84. }
  85. /**
  86. * findAll method
  87. *
  88. * @param mixed $conditions
  89. * @param mixed $fields
  90. * @param mixed $order
  91. * @param mixed $recursive
  92. * @access public
  93. * @return void
  94. */
  95. function findAll($conditions = null, $fields = null, $order = null, $recursive = null) {
  96. return $conditions;
  97. }
  98. }
  99. /**
  100. * TestModel2 class
  101. *
  102. * @package cake
  103. * @subpackage cake.tests.cases.libs.model.datasources
  104. */
  105. class TestModel2 extends CakeTestModel {
  106. /**
  107. * name property
  108. *
  109. * @var string 'TestModel2'
  110. * @access public
  111. */
  112. var $name = 'TestModel2';
  113. /**
  114. * useTable property
  115. *
  116. * @var bool false
  117. * @access public
  118. */
  119. var $useTable = false;
  120. }
  121. /**
  122. * TestModel4 class
  123. *
  124. * @package cake
  125. * @subpackage cake.tests.cases.libs.model.datasources
  126. */
  127. class TestModel3 extends CakeTestModel {
  128. /**
  129. * name property
  130. *
  131. * @var string 'TestModel3'
  132. * @access public
  133. */
  134. var $name = 'TestModel3';
  135. /**
  136. * useTable property
  137. *
  138. * @var bool false
  139. * @access public
  140. */
  141. var $useTable = false;
  142. }
  143. /**
  144. * TestModel4 class
  145. *
  146. * @package cake
  147. * @subpackage cake.tests.cases.libs.model.datasources
  148. */
  149. class TestModel4 extends CakeTestModel {
  150. /**
  151. * name property
  152. *
  153. * @var string 'TestModel4'
  154. * @access public
  155. */
  156. var $name = 'TestModel4';
  157. /**
  158. * table property
  159. *
  160. * @var string 'test_model4'
  161. * @access public
  162. */
  163. var $table = 'test_model4';
  164. /**
  165. * useTable property
  166. *
  167. * @var bool false
  168. * @access public
  169. */
  170. var $useTable = false;
  171. /**
  172. * belongsTo property
  173. *
  174. * @var array
  175. * @access public
  176. */
  177. var $belongsTo = array(
  178. 'TestModel4Parent' => array(
  179. 'className' => 'TestModel4',
  180. 'foreignKey' => 'parent_id'
  181. )
  182. );
  183. /**
  184. * hasOne property
  185. *
  186. * @var array
  187. * @access public
  188. */
  189. var $hasOne = array(
  190. 'TestModel5' => array(
  191. 'className' => 'TestModel5',
  192. 'foreignKey' => 'test_model4_id'
  193. )
  194. );
  195. /**
  196. * hasAndBelongsToMany property
  197. *
  198. * @var array
  199. * @access public
  200. */
  201. var $hasAndBelongsToMany = array('TestModel7' => array(
  202. 'className' => 'TestModel7',
  203. 'joinTable' => 'test_model4_test_model7',
  204. 'foreignKey' => 'test_model4_id',
  205. 'associationForeignKey' => 'test_model7_id',
  206. 'with' => 'TestModel4TestModel7'
  207. ));
  208. /**
  209. * schema method
  210. *
  211. * @access public
  212. * @return void
  213. */
  214. function schema() {
  215. if (!isset($this->_schema)) {
  216. $this->_schema = array(
  217. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  218. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  219. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  220. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  221. );
  222. }
  223. return $this->_schema;
  224. }
  225. }
  226. /**
  227. * TestModel4TestModel7 class
  228. *
  229. * @package cake
  230. * @subpackage cake.tests.cases.libs.model.datasources
  231. */
  232. class TestModel4TestModel7 extends CakeTestModel {
  233. /**
  234. * name property
  235. *
  236. * @var string 'TestModel4TestModel7'
  237. * @access public
  238. */
  239. var $name = 'TestModel4TestModel7';
  240. /**
  241. * table property
  242. *
  243. * @var string 'test_model4_test_model7'
  244. * @access public
  245. */
  246. var $table = 'test_model4_test_model7';
  247. /**
  248. * useTable property
  249. *
  250. * @var bool false
  251. * @access public
  252. */
  253. var $useTable = false;
  254. /**
  255. * schema method
  256. *
  257. * @access public
  258. * @return void
  259. */
  260. function schema() {
  261. if (!isset($this->_schema)) {
  262. $this->_schema = array(
  263. 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  264. 'test_model7_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8')
  265. );
  266. }
  267. return $this->_schema;
  268. }
  269. }
  270. /**
  271. * TestModel5 class
  272. *
  273. * @package cake
  274. * @subpackage cake.tests.cases.libs.model.datasources
  275. */
  276. class TestModel5 extends CakeTestModel {
  277. /**
  278. * name property
  279. *
  280. * @var string 'TestModel5'
  281. * @access public
  282. */
  283. var $name = 'TestModel5';
  284. /**
  285. * table property
  286. *
  287. * @var string 'test_model5'
  288. * @access public
  289. */
  290. var $table = 'test_model5';
  291. /**
  292. * useTable property
  293. *
  294. * @var bool false
  295. * @access public
  296. */
  297. var $useTable = false;
  298. /**
  299. * belongsTo property
  300. *
  301. * @var array
  302. * @access public
  303. */
  304. var $belongsTo = array('TestModel4' => array(
  305. 'className' => 'TestModel4',
  306. 'foreignKey' => 'test_model4_id'
  307. ));
  308. /**
  309. * hasMany property
  310. *
  311. * @var array
  312. * @access public
  313. */
  314. var $hasMany = array('TestModel6' => array(
  315. 'className' => 'TestModel6',
  316. 'foreignKey' => 'test_model5_id'
  317. ));
  318. /**
  319. * schema method
  320. *
  321. * @access public
  322. * @return void
  323. */
  324. function schema() {
  325. if (!isset($this->_schema)) {
  326. $this->_schema = array(
  327. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  328. 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  329. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  330. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  331. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  332. );
  333. }
  334. return $this->_schema;
  335. }
  336. }
  337. /**
  338. * TestModel6 class
  339. *
  340. * @package cake
  341. * @subpackage cake.tests.cases.libs.model.datasources
  342. */
  343. class TestModel6 extends CakeTestModel {
  344. /**
  345. * name property
  346. *
  347. * @var string 'TestModel6'
  348. * @access public
  349. */
  350. var $name = 'TestModel6';
  351. /**
  352. * table property
  353. *
  354. * @var string 'test_model6'
  355. * @access public
  356. */
  357. var $table = 'test_model6';
  358. /**
  359. * useTable property
  360. *
  361. * @var bool false
  362. * @access public
  363. */
  364. var $useTable = false;
  365. /**
  366. * belongsTo property
  367. *
  368. * @var array
  369. * @access public
  370. */
  371. var $belongsTo = array('TestModel5' => array(
  372. 'className' => 'TestModel5',
  373. 'foreignKey' => 'test_model5_id'
  374. ));
  375. /**
  376. * schema method
  377. *
  378. * @access public
  379. * @return void
  380. */
  381. function schema() {
  382. if (!isset($this->_schema)) {
  383. $this->_schema = array(
  384. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  385. 'test_model5_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  386. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  387. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  388. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  389. );
  390. }
  391. return $this->_schema;
  392. }
  393. }
  394. /**
  395. * TestModel7 class
  396. *
  397. * @package cake
  398. * @subpackage cake.tests.cases.libs.model.datasources
  399. */
  400. class TestModel7 extends CakeTestModel {
  401. /**
  402. * name property
  403. *
  404. * @var string 'TestModel7'
  405. * @access public
  406. */
  407. var $name = 'TestModel7';
  408. /**
  409. * table property
  410. *
  411. * @var string 'test_model7'
  412. * @access public
  413. */
  414. var $table = 'test_model7';
  415. /**
  416. * useTable property
  417. *
  418. * @var bool false
  419. * @access public
  420. */
  421. var $useTable = false;
  422. /**
  423. * schema method
  424. *
  425. * @access public
  426. * @return void
  427. */
  428. function schema() {
  429. if (!isset($this->_schema)) {
  430. $this->_schema = array(
  431. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  432. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  433. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  434. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  435. );
  436. }
  437. return $this->_schema;
  438. }
  439. }
  440. /**
  441. * TestModel8 class
  442. *
  443. * @package cake
  444. * @subpackage cake.tests.cases.libs.model.datasources
  445. */
  446. class TestModel8 extends CakeTestModel {
  447. /**
  448. * name property
  449. *
  450. * @var string 'TestModel8'
  451. * @access public
  452. */
  453. var $name = 'TestModel8';
  454. /**
  455. * table property
  456. *
  457. * @var string 'test_model8'
  458. * @access public
  459. */
  460. var $table = 'test_model8';
  461. /**
  462. * useTable property
  463. *
  464. * @var bool false
  465. * @access public
  466. */
  467. var $useTable = false;
  468. /**
  469. * hasOne property
  470. *
  471. * @var array
  472. * @access public
  473. */
  474. var $hasOne = array(
  475. 'TestModel9' => array(
  476. 'className' => 'TestModel9',
  477. 'foreignKey' => 'test_model8_id',
  478. 'conditions' => 'TestModel9.name != \'mariano\''
  479. )
  480. );
  481. /**
  482. * schema method
  483. *
  484. * @access public
  485. * @return void
  486. */
  487. function schema() {
  488. if (!isset($this->_schema)) {
  489. $this->_schema = array(
  490. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  491. 'test_model9_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  492. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  493. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  494. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  495. );
  496. }
  497. return $this->_schema;
  498. }
  499. }
  500. /**
  501. * TestModel9 class
  502. *
  503. * @package cake
  504. * @subpackage cake.tests.cases.libs.model.datasources
  505. */
  506. class TestModel9 extends CakeTestModel {
  507. /**
  508. * name property
  509. *
  510. * @var string 'TestModel9'
  511. * @access public
  512. */
  513. var $name = 'TestModel9';
  514. /**
  515. * table property
  516. *
  517. * @var string 'test_model9'
  518. * @access public
  519. */
  520. var $table = 'test_model9';
  521. /**
  522. * useTable property
  523. *
  524. * @var bool false
  525. * @access public
  526. */
  527. var $useTable = false;
  528. /**
  529. * belongsTo property
  530. *
  531. * @var array
  532. * @access public
  533. */
  534. var $belongsTo = array('TestModel8' => array(
  535. 'className' => 'TestModel8',
  536. 'foreignKey' => 'test_model8_id',
  537. 'conditions' => 'TestModel8.name != \'larry\''
  538. ));
  539. /**
  540. * schema method
  541. *
  542. * @access public
  543. * @return void
  544. */
  545. function schema() {
  546. if (!isset($this->_schema)) {
  547. $this->_schema = array(
  548. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  549. 'test_model8_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'),
  550. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  551. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  552. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  553. );
  554. }
  555. return $this->_schema;
  556. }
  557. }
  558. /**
  559. * Level class
  560. *
  561. * @package cake
  562. * @subpackage cake.tests.cases.libs.model.datasources
  563. */
  564. class Level extends CakeTestModel {
  565. /**
  566. * name property
  567. *
  568. * @var string 'Level'
  569. * @access public
  570. */
  571. var $name = 'Level';
  572. /**
  573. * table property
  574. *
  575. * @var string 'level'
  576. * @access public
  577. */
  578. var $table = 'level';
  579. /**
  580. * useTable property
  581. *
  582. * @var bool false
  583. * @access public
  584. */
  585. var $useTable = false;
  586. /**
  587. * hasMany property
  588. *
  589. * @var array
  590. * @access public
  591. */
  592. var $hasMany = array(
  593. 'Group'=> array(
  594. 'className' => 'Group'
  595. ),
  596. 'User2' => array(
  597. 'className' => 'User2'
  598. )
  599. );
  600. /**
  601. * schema method
  602. *
  603. * @access public
  604. * @return void
  605. */
  606. function schema() {
  607. if (!isset($this->_schema)) {
  608. $this->_schema = array(
  609. 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'),
  610. 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'),
  611. );
  612. }
  613. return $this->_schema;
  614. }
  615. }
  616. /**
  617. * Group class
  618. *
  619. * @package cake
  620. * @subpackage cake.tests.cases.libs.model.datasources
  621. */
  622. class Group extends CakeTestModel {
  623. /**
  624. * name property
  625. *
  626. * @var string 'Group'
  627. * @access public
  628. */
  629. var $name = 'Group';
  630. /**
  631. * table property
  632. *
  633. * @var string 'group'
  634. * @access public
  635. */
  636. var $table = 'group';
  637. /**
  638. * useTable property
  639. *
  640. * @var bool false
  641. * @access public
  642. */
  643. var $useTable = false;
  644. /**
  645. * belongsTo property
  646. *
  647. * @var array
  648. * @access public
  649. */
  650. var $belongsTo = array('Level');
  651. /**
  652. * hasMany property
  653. *
  654. * @var array
  655. * @access public
  656. */
  657. var $hasMany = array('Category2', 'User2');
  658. /**
  659. * schema method
  660. *
  661. * @access public
  662. * @return void
  663. */
  664. function schema() {
  665. if (!isset($this->_schema)) {
  666. $this->_schema = array(
  667. 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'),
  668. 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'),
  669. 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'),
  670. );
  671. }
  672. return $this->_schema;
  673. }
  674. }
  675. /**
  676. * User2 class
  677. *
  678. * @package cake
  679. * @subpackage cake.tests.cases.libs.model.datasources
  680. */
  681. class User2 extends CakeTestModel {
  682. /**
  683. * name property
  684. *
  685. * @var string 'User2'
  686. * @access public
  687. */
  688. var $name = 'User2';
  689. /**
  690. * table property
  691. *
  692. * @var string 'user'
  693. * @access public
  694. */
  695. var $table = 'user';
  696. /**
  697. * useTable property
  698. *
  699. * @var bool false
  700. * @access public
  701. */
  702. var $useTable = false;
  703. /**
  704. * belongsTo property
  705. *
  706. * @var array
  707. * @access public
  708. */
  709. var $belongsTo = array(
  710. 'Group' => array(
  711. 'className' => 'Group'
  712. ),
  713. 'Level' => array(
  714. 'className' => 'Level'
  715. )
  716. );
  717. /**
  718. * hasMany property
  719. *
  720. * @var array
  721. * @access public
  722. */
  723. var $hasMany = array(
  724. 'Article2' => array(
  725. 'className' => 'Article2'
  726. ),
  727. );
  728. /**
  729. * schema method
  730. *
  731. * @access public
  732. * @return void
  733. */
  734. function schema() {
  735. if (!isset($this->_schema)) {
  736. $this->_schema = array(
  737. 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'),
  738. 'group_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'),
  739. 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'),
  740. 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'),
  741. );
  742. }
  743. return $this->_schema;
  744. }
  745. }
  746. /**
  747. * Category2 class
  748. *
  749. * @package cake
  750. * @subpackage cake.tests.cases.libs.model.datasources
  751. */
  752. class Category2 extends CakeTestModel {
  753. /**
  754. * name property
  755. *
  756. * @var string 'Category2'
  757. * @access public
  758. */
  759. var $name = 'Category2';
  760. /**
  761. * table property
  762. *
  763. * @var string 'category'
  764. * @access public
  765. */
  766. var $table = 'category';
  767. /**
  768. * useTable property
  769. *
  770. * @var bool false
  771. * @access public
  772. */
  773. var $useTable = false;
  774. /**
  775. * belongsTo property
  776. *
  777. * @var array
  778. * @access public
  779. */
  780. var $belongsTo = array(
  781. 'Group' => array(
  782. 'className' => 'Group',
  783. 'foreignKey' => 'group_id'
  784. ),
  785. 'ParentCat' => array(
  786. 'className' => 'Category2',
  787. 'foreignKey' => 'parent_id'
  788. )
  789. );
  790. /**
  791. * hasMany property
  792. *
  793. * @var array
  794. * @access public
  795. */
  796. var $hasMany = array(
  797. 'ChildCat' => array(
  798. 'className' => 'Category2',
  799. 'foreignKey' => 'parent_id'
  800. ),
  801. 'Article2' => array(
  802. 'className' => 'Article2',
  803. 'order'=>'Article2.published_date DESC',
  804. 'foreignKey' => 'category_id',
  805. 'limit'=>'3')
  806. );
  807. /**
  808. * schema method
  809. *
  810. * @access public
  811. * @return void
  812. */
  813. function schema() {
  814. if (!isset($this->_schema)) {
  815. $this->_schema = array(
  816. 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'),
  817. 'group_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'),
  818. 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'),
  819. 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
  820. 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
  821. 'description' => array('type' => 'text', 'null' => false, 'default' => '', 'length' => null),
  822. );
  823. }
  824. return $this->_schema;
  825. }
  826. }
  827. /**
  828. * Article2 class
  829. *
  830. * @package cake
  831. * @subpackage cake.tests.cases.libs.model.datasources
  832. */
  833. class Article2 extends CakeTestModel {
  834. /**
  835. * name property
  836. *
  837. * @var string 'Article2'
  838. * @access public
  839. */
  840. var $name = 'Article2';
  841. /**
  842. * table property
  843. *
  844. * @var string 'article'
  845. * @access public
  846. */
  847. var $table = 'article';
  848. /**
  849. * useTable property
  850. *
  851. * @var bool false
  852. * @access public
  853. */
  854. var $useTable = false;
  855. /**
  856. * belongsTo property
  857. *
  858. * @var array
  859. * @access public
  860. */
  861. var $belongsTo = array(
  862. 'Category2' => array('className' => 'Category2'),
  863. 'User2' => array('className' => 'User2')
  864. );
  865. /**
  866. * schema method
  867. *
  868. * @access public
  869. * @return void
  870. */
  871. function schema() {
  872. if (!isset($this->_schema)) {
  873. $this->_schema = array(
  874. 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'),
  875. 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  876. 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  877. 'rate_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  878. 'rate_sum' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  879. 'viewed' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  880. 'version' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => '45'),
  881. 'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '200'),
  882. 'intro' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null),
  883. 'comments' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '4'),
  884. 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null),
  885. 'isdraft' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'),
  886. 'allow_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'),
  887. 'moderate_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'),
  888. 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'),
  889. 'multipage' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'),
  890. 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null),
  891. 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null),
  892. 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null)
  893. );
  894. }
  895. return $this->_schema;
  896. }
  897. }
  898. /**
  899. * CategoryFeatured2 class
  900. *
  901. * @package cake
  902. * @subpackage cake.tests.cases.libs.model.datasources
  903. */
  904. class CategoryFeatured2 extends CakeTestModel {
  905. /**
  906. * name property
  907. *
  908. * @var string 'CategoryFeatured2'
  909. * @access public
  910. */
  911. var $name = 'CategoryFeatured2';
  912. /**
  913. * table property
  914. *
  915. * @var string 'category_featured'
  916. * @access public
  917. */
  918. var $table = 'category_featured';
  919. /**
  920. * useTable property
  921. *
  922. * @var bool false
  923. * @access public
  924. */
  925. var $useTable = false;
  926. /**
  927. * schema method
  928. *
  929. * @access public
  930. * @return void
  931. */
  932. function schema() {
  933. if (!isset($this->_schema)) {
  934. $this->_schema = array(
  935. 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'),
  936. 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'),
  937. 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
  938. 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
  939. 'description' => array('text' => 'string', 'null' => false, 'default' => '', 'length' => null)
  940. );
  941. }
  942. return $this->_schema;
  943. }
  944. }
  945. /**
  946. * Featured2 class
  947. *
  948. * @package cake
  949. * @subpackage cake.tests.cases.libs.model.datasources
  950. */
  951. class Featured2 extends CakeTestModel {
  952. /**
  953. * name property
  954. *
  955. * @var string 'Featured2'
  956. * @access public
  957. */
  958. var $name = 'Featured2';
  959. /**
  960. * table property
  961. *
  962. * @var string 'featured2'
  963. * @access public
  964. */
  965. var $table = 'featured2';
  966. /**
  967. * useTable property
  968. *
  969. * @var bool false
  970. * @access public
  971. */
  972. var $useTable = false;
  973. /**
  974. * belongsTo property
  975. *
  976. * @var array
  977. * @access public
  978. */
  979. var $belongsTo = array(
  980. 'CategoryFeatured2' => array(
  981. 'className' => 'CategoryFeatured2'
  982. )
  983. );
  984. /**
  985. * schema method
  986. *
  987. * @access public
  988. * @return void
  989. */
  990. function schema() {
  991. if (!isset($this->_schema)) {
  992. $this->_schema = array(
  993. 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'),
  994. 'article_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  995. 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  996. 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20')
  997. );
  998. }
  999. return $this->_schema;
  1000. }
  1001. }
  1002. /**
  1003. * Comment2 class
  1004. *
  1005. * @package cake
  1006. * @subpackage cake.tests.cases.libs.model.datasources
  1007. */
  1008. class Comment2 extends CakeTestModel {
  1009. /**
  1010. * name property
  1011. *
  1012. * @var string 'Comment2'
  1013. * @access public
  1014. */
  1015. var $name = 'Comment2';
  1016. /**
  1017. * table property
  1018. *
  1019. * @var string 'comment'
  1020. * @access public
  1021. */
  1022. var $table = 'comment';
  1023. /**
  1024. * belongsTo property
  1025. *
  1026. * @var array
  1027. * @access public
  1028. */
  1029. var $belongsTo = array('ArticleFeatured2', 'User2');
  1030. /**
  1031. * useTable property
  1032. *
  1033. * @var bool false
  1034. * @access public
  1035. */
  1036. var $useTable = false;
  1037. /**
  1038. * schema method
  1039. *
  1040. * @access public
  1041. * @return void
  1042. */
  1043. function schema() {
  1044. if (!isset($this->_schema)) {
  1045. $this->_schema = array(
  1046. 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'),
  1047. 'article_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  1048. 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  1049. 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20')
  1050. );
  1051. }
  1052. return $this->_schema;
  1053. }
  1054. }
  1055. /**
  1056. * ArticleFeatured2 class
  1057. *
  1058. * @package cake
  1059. * @subpackage cake.tests.cases.libs.model.datasources
  1060. */
  1061. class ArticleFeatured2 extends CakeTestModel {
  1062. /**
  1063. * name property
  1064. *
  1065. * @var string 'ArticleFeatured2'
  1066. * @access public
  1067. */
  1068. var $name = 'ArticleFeatured2';
  1069. /**
  1070. * table property
  1071. *
  1072. * @var string 'article_featured'
  1073. * @access public
  1074. */
  1075. var $table = 'article_featured';
  1076. /**
  1077. * useTable property
  1078. *
  1079. * @var bool false
  1080. * @access public
  1081. */
  1082. var $useTable = false;
  1083. /**
  1084. * belongsTo property
  1085. *
  1086. * @var array
  1087. * @access public
  1088. */
  1089. var $belongsTo = array(
  1090. 'CategoryFeatured2' => array('className' => 'CategoryFeatured2'),
  1091. 'User2' => array('className' => 'User2')
  1092. );
  1093. /**
  1094. * hasOne property
  1095. *
  1096. * @var array
  1097. * @access public
  1098. */
  1099. var $hasOne = array(
  1100. 'Featured2' => array('className' => 'Featured2')
  1101. );
  1102. /**
  1103. * hasMany property
  1104. *
  1105. * @var array
  1106. * @access public
  1107. */
  1108. var $hasMany = array(
  1109. 'Comment2' => array('className'=>'Comment2', 'dependent' => true)
  1110. );
  1111. /**
  1112. * schema method
  1113. *
  1114. * @access public
  1115. * @return void
  1116. */
  1117. function schema() {
  1118. if (!isset($this->_schema)) {
  1119. $this->_schema = array(
  1120. 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'),
  1121. 'category_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  1122. 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'),
  1123. 'title' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'),
  1124. 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null),
  1125. 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'),
  1126. 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null),
  1127. 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null),
  1128. 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null)
  1129. );
  1130. }
  1131. return $this->_schema;
  1132. }
  1133. }
  1134. /**
  1135. * DboSourceTest class
  1136. *
  1137. * @package cake
  1138. * @subpackage cake.tests.cases.libs.model.datasources
  1139. */
  1140. class DboSourceTest extends CakeTestCase {
  1141. /**
  1142. * debug property
  1143. *
  1144. * @var mixed null
  1145. * @access public
  1146. */
  1147. var $debug = null;
  1148. /**
  1149. * autoFixtures property
  1150. *
  1151. * @var bool false
  1152. * @access public
  1153. */
  1154. var $autoFixtures = false;
  1155. /**
  1156. * fixtures property
  1157. *
  1158. * @var array
  1159. * @access public
  1160. */
  1161. var $fixtures = array(
  1162. 'core.apple', 'core.article', 'core.articles_tag', 'core.attachment', 'core.comment',
  1163. 'core.sample', 'core.tag', 'core.user', 'core.post', 'core.author', 'core.data_test'
  1164. );
  1165. /**
  1166. * startTest method
  1167. *
  1168. * @access public
  1169. * @return void
  1170. */
  1171. function startTest() {
  1172. $this->__config = $this->db->config;
  1173. if (!class_exists('DboTest')) {
  1174. $db = ConnectionManager::getDataSource('test_suite');
  1175. $class = get_class($db);
  1176. eval("class DboTest extends $class {
  1177. var \$simulated = array();
  1178. /**
  1179. * execute method
  1180. *
  1181. * @param \$sql
  1182. * @access protected
  1183. * @return void
  1184. */
  1185. function _execute(\$sql) {
  1186. \$this->simulated[] = \$sql;
  1187. return null;
  1188. }
  1189. /**
  1190. * getLastQuery method
  1191. *
  1192. * @access public
  1193. * @return void
  1194. */
  1195. function getLastQuery() {
  1196. return \$this->simulated[count(\$this->simulated) - 1];
  1197. }
  1198. }");
  1199. }
  1200. $this->testDb =& new DboTest($this->__config);
  1201. $this->testDb->cacheSources = false;
  1202. $this->testDb->startQuote = '`';
  1203. $this->testDb->endQuote = '`';
  1204. Configure::write('debug', 1);
  1205. $this->debug = Configure::read('debug');
  1206. $this->Model =& new TestModel();
  1207. }
  1208. /**
  1209. * endTest method
  1210. *
  1211. * @access public
  1212. * @return void
  1213. */
  1214. function endTest() {
  1215. unset($this->Model);
  1216. Configure::write('debug', $this->debug);
  1217. ClassRegistry::flush();
  1218. unset($this->debug);
  1219. }
  1220. /**
  1221. * testFieldDoubleEscaping method
  1222. *
  1223. * @access public
  1224. * @return void
  1225. */
  1226. function testFieldDoubleEscaping() {
  1227. $config = array_merge($this->__config, array('driver' => 'test'));
  1228. $test =& ConnectionManager::create('quoteTest', $config);
  1229. $test->simulated = array();
  1230. $this->Model =& new Article2(array('alias' => 'Article', 'ds' => 'quoteTest'));
  1231. $this->Model->setDataSource('quoteTest');
  1232. $this->assertEqual($this->Model->escapeField(), '`Article`.`id`');
  1233. $result = $test->fields($this->Model, null, $this->Model->escapeField());
  1234. $this->assertEqual($result, array('`Article`.`id`'));
  1235. $result = $test->read($this->Model, array(
  1236. 'fields' => $this->Model->escapeField(),
  1237. 'conditions' => null,
  1238. 'recursive' => -1
  1239. ));
  1240. $this->assertEqual(trim($test->simulated[0]), 'SELECT `Article`.`id` FROM `' . $this->testDb->fullTableName('article', false) . '` AS `Article` WHERE 1 = 1');
  1241. $test->startQuote = '[';
  1242. $test->endQuote = ']';
  1243. $this->assertEqual($this->Model->escapeField(), '[Article].[id]');
  1244. $result = $test->fields($this->Model, null, $this->Model->escapeField());
  1245. $this->assertEqual($result, array('[Article].[id]'));
  1246. $result = $test->read($this->Model, array(
  1247. 'fields' => $this->Model->escapeField(),
  1248. 'conditions' => null,
  1249. 'recursive' => -1
  1250. ));
  1251. $this->assertEqual(trim($test->simulated[1]), 'SELECT [Article].[id] FROM [' . $this->testDb->fullTableName('article', false) . '] AS [Article] WHERE 1 = 1');
  1252. ClassRegistry::removeObject('Article');
  1253. }
  1254. /**
  1255. * testGenerateAssociationQuerySelfJoin method
  1256. *
  1257. * @access public
  1258. * @return void
  1259. */
  1260. function testGenerateAssociationQuerySelfJoin() {
  1261. $this->startTime = microtime(true);
  1262. $this->Model =& new Article2();
  1263. $this->_buildRelatedModels($this->Model);
  1264. $this->_buildRelatedModels($this->Model->Category2);
  1265. $this->Model->Category2->ChildCat =& new Category2();
  1266. $this->Model->Category2->ParentCat =& new Category2();
  1267. $queryData = array();
  1268. foreach ($this->Model->Category2->__associations as $type) {
  1269. foreach ($this->Model->Category2->{$type} as $assoc => $assocData) {
  1270. $linkModel =& $this->Model->Category2->{$assoc};
  1271. $external = isset($assocData['external']);
  1272. if ($this->Model->Category2->alias == $linkModel->alias && $type != 'hasAndBelongsToMany' && $type != 'hasMany') {
  1273. $result = $this->testDb->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null);
  1274. $this->assertTrue($result);
  1275. } else {
  1276. if ($this->Model->Category2->useDbConfig == $linkModel->useDbConfig) {
  1277. $result = $this->testDb->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null);
  1278. $this->assertTrue($result);
  1279. }
  1280. }
  1281. }
  1282. }
  1283. $query = $this->testDb->generateAssociationQuery($this->Model->Category2, $null, null, null, null, $queryData, false, $null);
  1284. $this->assertPattern('/^SELECT\s+(.+)FROM(.+)`Category2`\.`group_id`\s+=\s+`Group`\.`id`\)\s+LEFT JOIN(.+)WHERE\s+1 = 1\s*$/', $query);
  1285. $this->Model =& new TestModel4();
  1286. $this->Model->schema();
  1287. $this->_buildRelatedModels($this->Model);
  1288. $binding = array('type' => 'belongsTo', 'model' => 'TestModel4Parent');
  1289. $queryData = array();
  1290. $resultSet = null;
  1291. $null = null;
  1292. $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
  1293. $_queryData = $queryData;
  1294. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1295. $this->assertTrue($result);
  1296. $expected = array(
  1297. 'fields' => array(
  1298. '`TestModel4`.`id`',
  1299. '`TestModel4`.`name`',
  1300. '`TestModel4`.`created`',
  1301. '`TestModel4`.`updated`',
  1302. '`TestModel4Parent`.`id`',
  1303. '`TestModel4Parent`.`name`',
  1304. '`TestModel4Parent`.`created`',
  1305. '`TestModel4Parent`.`updated`'
  1306. ),
  1307. 'joins' => array(
  1308. array(
  1309. 'table' => '`test_model4`',
  1310. 'alias' => 'TestModel4Parent',
  1311. 'type' => 'LEFT',
  1312. 'conditions' => '`TestModel4`.`parent_id` = `TestModel4Parent`.`id`'
  1313. )
  1314. ),
  1315. 'limit' => array(),
  1316. 'offset' => array(),
  1317. 'conditions' => array(),
  1318. 'order' => array(),
  1319. 'group' => null
  1320. );
  1321. $this->assertEqual($queryData, $expected);
  1322. $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
  1323. $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel4Parent`\.`id`, `TestModel4Parent`\.`name`, `TestModel4Parent`\.`created`, `TestModel4Parent`\.`updated`\s+/', $result);
  1324. $this->assertPattern('/FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model4` AS `TestModel4Parent`/', $result);
  1325. $this->assertPattern('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result);
  1326. $this->assertPattern('/\s+WHERE\s+1 = 1\s+$/', $result);
  1327. $params['assocData']['type'] = 'INNER';
  1328. $this->Model->belongsTo['TestModel4Parent']['type'] = 'INNER';
  1329. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $_queryData, $params['external'], $resultSet);
  1330. $this->assertTrue($result);
  1331. $this->assertEqual($_queryData['joins'][0]['type'], 'INNER');
  1332. }
  1333. /**
  1334. * testGenerateInnerJoinAssociationQuery method
  1335. *
  1336. * @access public
  1337. * @return void
  1338. */
  1339. function testGenerateInnerJoinAssociationQuery() {
  1340. $this->Model =& new TestModel9();
  1341. $test =& ConnectionManager::create('test2', $this->__config);
  1342. $this->Model->setDataSource('test2');
  1343. $this->Model->TestModel8 =& new TestModel8();
  1344. $this->Model->TestModel8->setDataSource('test2');
  1345. $this->testDb->read($this->Model, array('recursive' => 1));
  1346. $result = $this->testDb->getLastQuery();
  1347. $this->assertPattern('/`TestModel9` LEFT JOIN `' . $this->testDb->fullTableName('test_model8', false) . '`/', $result);
  1348. $this->Model->belongsTo['TestModel8']['type'] = 'INNER';
  1349. $this->testDb->read($this->Model, array('recursive' => 1));
  1350. $result = $this->testDb->getLastQuery();
  1351. $this->assertPattern('/`TestModel9` INNER JOIN `' . $this->testDb->fullTableName('test_model8', false) . '`/', $result);
  1352. }
  1353. /**
  1354. * testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding method
  1355. *
  1356. * @access public
  1357. * @return void
  1358. */
  1359. function testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding() {
  1360. $this->Model =& new TestModel8();
  1361. $this->Model->schema();
  1362. $this->_buildRelatedModels($this->Model);
  1363. $binding = array('type' => 'hasOne', 'model' => 'TestModel9');
  1364. $queryData = array();
  1365. $resultSet = null;
  1366. $null = null;
  1367. $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
  1368. $_queryData = $queryData;
  1369. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1370. $this->assertTrue($result);
  1371. $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
  1372. $this->assertPattern('/^SELECT\s+`TestModel8`\.`id`, `TestModel8`\.`test_model9_id`, `TestModel8`\.`name`, `TestModel8`\.`created`, `TestModel8`\.`updated`, `TestModel9`\.`id`, `TestModel9`\.`test_model8_id`, `TestModel9`\.`name`, `TestModel9`\.`created`, `TestModel9`\.`updated`\s+/', $result);
  1373. $this->assertPattern('/FROM\s+`test_model8` AS `TestModel8`\s+LEFT JOIN\s+`test_model9` AS `TestModel9`/', $result);
  1374. $this->assertPattern('/\s+ON\s+\(`TestModel9`\.`name` != \'mariano\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/', $result);
  1375. $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
  1376. }
  1377. /**
  1378. * testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding method
  1379. *
  1380. * @access public
  1381. * @return void
  1382. */
  1383. function testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding() {
  1384. $this->Model =& new TestModel9();
  1385. $this->Model->schema();
  1386. $this->_buildRelatedModels($this->Model);
  1387. $binding = array('type' => 'belongsTo', 'model' => 'TestModel8');
  1388. $queryData = array();
  1389. $resultSet = null;
  1390. $null = null;
  1391. $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
  1392. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1393. $this->assertTrue($result);
  1394. $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
  1395. $this->assertPattern('/^SELECT\s+`TestModel9`\.`id`, `TestModel9`\.`test_model8_id`, `TestModel9`\.`name`, `TestModel9`\.`created`, `TestModel9`\.`updated`, `TestModel8`\.`id`, `TestModel8`\.`test_model9_id`, `TestModel8`\.`name`, `TestModel8`\.`created`, `TestModel8`\.`updated`\s+/', $result);
  1396. $this->assertPattern('/FROM\s+`test_model9` AS `TestModel9`\s+LEFT JOIN\s+`test_model8` AS `TestModel8`/', $result);
  1397. $this->assertPattern('/\s+ON\s+\(`TestModel8`\.`name` != \'larry\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/', $result);
  1398. $this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
  1399. }
  1400. /**
  1401. * testGenerateAssociationQuerySelfJoinWithConditions method
  1402. *
  1403. * @access public
  1404. * @return void
  1405. */
  1406. function testGenerateAssociationQuerySelfJoinWithConditions() {
  1407. $this->Model =& new TestModel4();
  1408. $this->Model->schema();
  1409. $this->_buildRelatedModels($this->Model);
  1410. $binding = array('type' => 'belongsTo', 'model' => 'TestModel4Parent');
  1411. $queryData = array('conditions' => array('TestModel4Parent.name !=' => 'mariano'));
  1412. $resultSet = null;
  1413. $null = null;
  1414. $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
  1415. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1416. $this->assertTrue($result);
  1417. $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
  1418. $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel4Parent`\.`id`, `TestModel4Parent`\.`name`, `TestModel4Parent`\.`created`, `TestModel4Parent`\.`updated`\s+/', $result);
  1419. $this->assertPattern('/FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model4` AS `TestModel4Parent`/', $result);
  1420. $this->assertPattern('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result);
  1421. $this->assertPattern('/\s+WHERE\s+(?:\()?`TestModel4Parent`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result);
  1422. $this->Featured2 =& new Featured2();
  1423. $this->Featured2->schema();
  1424. $this->Featured2->bindModel(array(
  1425. 'belongsTo' => array(
  1426. 'ArticleFeatured2' => array(
  1427. 'conditions' => 'ArticleFeatured2.published = \'Y\'',
  1428. 'fields' => 'id, title, user_id, published'
  1429. )
  1430. )
  1431. ));
  1432. $this->_buildRelatedModels($this->Featured2);
  1433. $binding = array('type' => 'belongsTo', 'model' => 'ArticleFeatured2');
  1434. $queryData = array('conditions' => array());
  1435. $resultSet = null;
  1436. $null = null;
  1437. $params = &$this->_prepareAssociationQuery($this->Featured2, $queryData, $binding);
  1438. $result = $this->testDb->generateAssociationQuery($this->Featured2, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1439. $this->assertTrue($result);
  1440. $result = $this->testDb->generateAssociationQuery($this->Featured2, $null, null, null, null, $queryData, false, $null);
  1441. $this->assertPattern(
  1442. '/^SELECT\s+`Featured2`\.`id`, `Featured2`\.`article_id`, `Featured2`\.`category_id`, `Featured2`\.`name`,\s+'.
  1443. '`ArticleFeatured2`\.`id`, `ArticleFeatured2`\.`title`, `ArticleFeatured2`\.`user_id`, `ArticleFeatured2`\.`published`\s+' .
  1444. 'FROM\s+`featured2` AS `Featured2`\s+LEFT JOIN\s+`article_featured` AS `ArticleFeatured2`' .
  1445. '\s+ON\s+\(`ArticleFeatured2`.`published` = \'Y\'\s+AND\s+`Featured2`\.`article_featured2_id` = `ArticleFeatured2`\.`id`\)' .
  1446. '\s+WHERE\s+1\s+=\s+1\s*$/',
  1447. $result
  1448. );
  1449. }
  1450. /**
  1451. * testGenerateAssociationQueryHasOne method
  1452. *
  1453. * @access public
  1454. * @return void
  1455. */
  1456. function testGenerateAssociationQueryHasOne() {
  1457. $this->Model =& new TestModel4();
  1458. $this->Model->schema();
  1459. $this->_buildRelatedModels($this->Model);
  1460. $binding = array('type' => 'hasOne', 'model' => 'TestModel5');
  1461. $queryData = array();
  1462. $resultSet = null;
  1463. $null = null;
  1464. $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
  1465. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1466. $this->assertTrue($result);
  1467. $result = $this->testDb->buildJoinStatement($queryData['joins'][0]);
  1468. $expected = ' LEFT JOIN `test_model5` AS `TestModel5` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
  1469. $this->assertEqual(trim($result), trim($expected));
  1470. $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
  1471. $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
  1472. $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+/', $result);
  1473. $this->assertPattern('/`test_model5` AS `TestModel5`\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE/', $result);
  1474. $this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result);
  1475. }
  1476. /**
  1477. * testGenerateAssociationQueryHasOneWithConditions method
  1478. *
  1479. * @access public
  1480. * @return void
  1481. */
  1482. function testGenerateAssociationQueryHasOneWithConditions() {
  1483. $this->Model =& new TestModel4();
  1484. $this->Model->schema();
  1485. $this->_buildRelatedModels($this->Model);
  1486. $binding = array('type' => 'hasOne', 'model' => 'TestModel5');
  1487. $queryData = array('conditions' => array('TestModel5.name !=' => 'mariano'));
  1488. $resultSet = null;
  1489. $null = null;
  1490. $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
  1491. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1492. $this->assertTrue($result);
  1493. $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
  1494. $this->assertPattern('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
  1495. $this->assertPattern('/\s+FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model5` AS `TestModel5`/', $result);
  1496. $this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id`\s+=\s+`TestModel4`.`id`\)\s+WHERE/', $result);
  1497. $this->assertPattern('/\s+WHERE\s+(?:\()?\s*`TestModel5`.`name`\s+!=\s+\'mariano\'\s*(?:\))?\s*$/', $result);
  1498. }
  1499. /**
  1500. * testGenerateAssociationQueryBelongsTo method
  1501. *
  1502. * @access public
  1503. * @return void
  1504. */
  1505. function testGenerateAssociationQueryBelongsTo() {
  1506. $this->Model =& new TestModel5();
  1507. $this->Model->schema();
  1508. $this->_buildRelatedModels($this->Model);
  1509. $binding = array('type'=>'belongsTo', 'model'=>'TestModel4');
  1510. $queryData = array();
  1511. $resultSet = null;
  1512. $null = null;
  1513. $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
  1514. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1515. $this->assertTrue($result);
  1516. $result = $this->testDb->buildJoinStatement($queryData['joins'][0]);
  1517. $expected = ' LEFT JOIN `test_model4` AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
  1518. $this->assertEqual(trim($result), trim($expected));
  1519. $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
  1520. $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
  1521. $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+`test_model4` AS `TestModel4`/', $result);
  1522. $this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result);
  1523. $this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result);
  1524. }
  1525. /**
  1526. * testGenerateAssociationQueryBelongsToWithConditions method
  1527. *
  1528. * @access public
  1529. * @return void
  1530. */
  1531. function testGenerateAssociationQueryBelongsToWithConditions() {
  1532. $this->Model =& new TestModel5();
  1533. $this->Model->schema();
  1534. $this->_buildRelatedModels($this->Model);
  1535. $binding = array('type' => 'belongsTo', 'model' => 'TestModel4');
  1536. $queryData = array('conditions' => array('TestModel5.name !=' => 'mariano'));
  1537. $resultSet = null;
  1538. $null = null;
  1539. $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
  1540. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1541. $this->assertTrue($result);
  1542. $result = $this->testDb->buildJoinStatement($queryData['joins'][0]);
  1543. $expected = ' LEFT JOIN `test_model4` AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
  1544. $this->assertEqual(trim($result), trim($expected));
  1545. $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
  1546. $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
  1547. $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+`test_model4` AS `TestModel4`/', $result);
  1548. $this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result);
  1549. $this->assertPattern('/\s+WHERE\s+`TestModel5`.`name` != \'mariano\'\s*$/', $result);
  1550. }
  1551. /**
  1552. * testGenerateAssociationQueryHasMany method
  1553. *
  1554. * @access public
  1555. * @return void
  1556. */
  1557. function testGenerateAssociationQueryHasMany() {
  1558. $this->Model =& new TestModel5();
  1559. $this->Model->schema();
  1560. $this->_buildRelatedModels($this->Model);
  1561. $binding = array('type' => 'hasMany', 'model' => 'TestModel6');
  1562. $queryData = array();
  1563. $resultSet = null;
  1564. $null = null;
  1565. $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
  1566. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1567. $this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
  1568. $this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE/', $result);
  1569. $this->assertPattern('/\s+WHERE\s+`TestModel6`.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)/', $result);
  1570. $result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
  1571. $this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
  1572. $this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
  1573. $this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result);
  1574. }
  1575. /**
  1576. * testGenerateAssociationQueryHasManyWithLimit method
  1577. *
  1578. * @access public
  1579. * @return void
  1580. */
  1581. function testGenerateAssociationQueryHasManyWithLimit() {
  1582. $this->Model =& new TestModel5();
  1583. $this->Model->schema();
  1584. $this->_buildRelatedModels($this->Model);
  1585. $this->Model->hasMany['TestModel6']['limit'] = 2;
  1586. $binding = array('type' => 'hasMany', 'model' => 'TestModel6');
  1587. $queryData = array();
  1588. $resultSet = null;
  1589. $null = null;
  1590. $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
  1591. $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
  1592. $this->assertPattern(
  1593. '/^SELECT\s+' .
  1594. '`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+'.
  1595. 'FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+' .
  1596. '`TestModel6`.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)\s*'.
  1597. 'LIMIT \d*'.
  1598. '\s*$/', $result

Large files files are truncated, but you can click here to view the full file