PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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