SqlserverTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <?php
  2. /**
  3. * SqlserverTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package cake.libs
  16. * @since CakePHP(tm) v 1.2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('Model', 'Model');
  20. App::uses('AppModel', 'Model');
  21. App::uses('Sqlserver', 'Model/Datasource/Database');
  22. require_once dirname(dirname(dirname(__FILE__))) . DS . 'models.php';
  23. /**
  24. * SqlserverTestDb class
  25. *
  26. * @package cake.tests.cases.libs.model.datasources.dbo
  27. */
  28. class SqlserverTestDb extends Sqlserver {
  29. /**
  30. * simulated property
  31. *
  32. * @var array
  33. */
  34. public $simulated = array();
  35. /**
  36. * execute results stack
  37. *
  38. * @var array
  39. */
  40. public $executeResultsStack = array();
  41. /**
  42. * execute method
  43. *
  44. * @param mixed $sql
  45. * @return mixed
  46. */
  47. protected function _execute($sql) {
  48. $this->simulated[] = $sql;
  49. return empty($this->executeResultsStack) ? null : array_pop($this->executeResultsStack);
  50. }
  51. /**
  52. * fetchAll method
  53. *
  54. * @param mixed $sql
  55. * @return void
  56. */
  57. protected function _matchRecords($model, $conditions = null) {
  58. return $this->conditions(array('id' => array(1, 2)));
  59. }
  60. /**
  61. * getLastQuery method
  62. *
  63. * @return string
  64. */
  65. public function getLastQuery() {
  66. return $this->simulated[count($this->simulated) - 1];
  67. }
  68. /**
  69. * getPrimaryKey method
  70. *
  71. * @param mixed $model
  72. * @return string
  73. */
  74. public function getPrimaryKey($model) {
  75. return parent::_getPrimaryKey($model);
  76. }
  77. /**
  78. * clearFieldMappings method
  79. *
  80. * @return void
  81. */
  82. public function clearFieldMappings() {
  83. $this->_fieldMappings = array();
  84. }
  85. /**
  86. * describe method
  87. *
  88. * @param object $model
  89. * @return void
  90. */
  91. public function describe($model) {
  92. return empty($this->describe) ? parent::describe($model) : $this->describe;
  93. }
  94. }
  95. /**
  96. * SqlserverTestModel class
  97. *
  98. * @package cake.tests.cases.libs.model.datasources
  99. */
  100. class SqlserverTestModel extends Model {
  101. /**
  102. * name property
  103. *
  104. * @var string 'SqlserverTestModel'
  105. */
  106. public $name = 'SqlserverTestModel';
  107. /**
  108. * useTable property
  109. *
  110. * @var bool false
  111. */
  112. public $useTable = false;
  113. /**
  114. * _schema property
  115. *
  116. * @var array
  117. */
  118. protected $_schema = array(
  119. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
  120. 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'),
  121. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  122. 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  123. 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  124. 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  125. 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'),
  126. 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  127. 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  128. 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  129. 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  130. 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  131. 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  132. 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  133. 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''),
  134. 'last_login'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
  135. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  136. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  137. );
  138. /**
  139. * belongsTo property
  140. *
  141. * @var array
  142. */
  143. public $belongsTo = array(
  144. 'SqlserverClientTestModel' => array(
  145. 'foreignKey' => 'client_id'
  146. )
  147. );
  148. /**
  149. * find method
  150. *
  151. * @param mixed $conditions
  152. * @param mixed $fields
  153. * @param mixed $order
  154. * @param mixed $recursive
  155. * @return void
  156. */
  157. public function find($conditions = null, $fields = null, $order = null, $recursive = null) {
  158. return $conditions;
  159. }
  160. }
  161. /**
  162. * SqlserverClientTestModel class
  163. *
  164. * @package cake.tests.cases.libs.model.datasources
  165. */
  166. class SqlserverClientTestModel extends Model {
  167. /**
  168. * name property
  169. *
  170. * @var string 'SqlserverAssociatedTestModel'
  171. */
  172. public $name = 'SqlserverClientTestModel';
  173. /**
  174. * useTable property
  175. *
  176. * @var bool false
  177. */
  178. public $useTable = false;
  179. /**
  180. * _schema property
  181. *
  182. * @var array
  183. */
  184. protected $_schema = array(
  185. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
  186. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  187. 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  188. 'created' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
  189. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  190. );
  191. }
  192. /**
  193. * SqlserverTestResultIterator class
  194. *
  195. * @package cake.tests.cases.libs.model.datasources
  196. */
  197. class SqlserverTestResultIterator extends ArrayIterator {
  198. /**
  199. * closeCursor method
  200. *
  201. * @return void
  202. */
  203. public function closeCursor() {}
  204. }
  205. /**
  206. * SqlserverTest class
  207. *
  208. * @package cake.tests.cases.libs.model.datasources.dbo
  209. */
  210. class SqlserverTest extends CakeTestCase {
  211. /**
  212. * The Dbo instance to be tested
  213. *
  214. * @var DboSource
  215. */
  216. public $db = null;
  217. /**
  218. * autoFixtures property
  219. *
  220. * @var bool false
  221. */
  222. public $autoFixtures = false;
  223. /**
  224. * fixtures property
  225. *
  226. * @var array
  227. */
  228. public $fixtures = array('core.user', 'core.category', 'core.author', 'core.post');
  229. /**
  230. * Sets up a Dbo class instance for testing
  231. *
  232. */
  233. public function setUp() {
  234. $this->Dbo = ConnectionManager::getDataSource('test');
  235. if (!($this->Dbo instanceof Sqlserver)) {
  236. $this->markTestSkipped('Please configure the test datasource to use SQL Server.');
  237. }
  238. $this->db = new SqlserverTestDb($this->Dbo->config);
  239. $this->model = new SqlserverTestModel();
  240. }
  241. /**
  242. * tearDown method
  243. *
  244. * @return void
  245. */
  246. public function tearDown() {
  247. unset($this->Dbo);
  248. unset($this->model);
  249. }
  250. /**
  251. * testQuoting method
  252. *
  253. * @return void
  254. */
  255. public function testQuoting() {
  256. $expected = "1.200000";
  257. $result = $this->db->value(1.2, 'float');
  258. $this->assertIdentical($expected, $result);
  259. $expected = "'1,2'";
  260. $result = $this->db->value('1,2', 'float');
  261. $this->assertIdentical($expected, $result);
  262. $expected = 'NULL';
  263. $result = $this->db->value('', 'integer');
  264. $this->assertIdentical($expected, $result);
  265. $expected = 'NULL';
  266. $result = $this->db->value('', 'float');
  267. $this->assertIdentical($expected, $result);
  268. $expected = "''";
  269. $result = $this->db->value('', 'binary');
  270. $this->assertIdentical($expected, $result);
  271. }
  272. /**
  273. * testFields method
  274. *
  275. * @return void
  276. */
  277. public function testFields() {
  278. $fields = array(
  279. '[SqlserverTestModel].[id] AS [SqlserverTestModel__id]',
  280. '[SqlserverTestModel].[client_id] AS [SqlserverTestModel__client_id]',
  281. '[SqlserverTestModel].[name] AS [SqlserverTestModel__name]',
  282. '[SqlserverTestModel].[login] AS [SqlserverTestModel__login]',
  283. '[SqlserverTestModel].[passwd] AS [SqlserverTestModel__passwd]',
  284. '[SqlserverTestModel].[addr_1] AS [SqlserverTestModel__addr_1]',
  285. '[SqlserverTestModel].[addr_2] AS [SqlserverTestModel__addr_2]',
  286. '[SqlserverTestModel].[zip_code] AS [SqlserverTestModel__zip_code]',
  287. '[SqlserverTestModel].[city] AS [SqlserverTestModel__city]',
  288. '[SqlserverTestModel].[country] AS [SqlserverTestModel__country]',
  289. '[SqlserverTestModel].[phone] AS [SqlserverTestModel__phone]',
  290. '[SqlserverTestModel].[fax] AS [SqlserverTestModel__fax]',
  291. '[SqlserverTestModel].[url] AS [SqlserverTestModel__url]',
  292. '[SqlserverTestModel].[email] AS [SqlserverTestModel__email]',
  293. '[SqlserverTestModel].[comments] AS [SqlserverTestModel__comments]',
  294. 'CONVERT(VARCHAR(20), [SqlserverTestModel].[last_login], 20) AS [SqlserverTestModel__last_login]',
  295. '[SqlserverTestModel].[created] AS [SqlserverTestModel__created]',
  296. 'CONVERT(VARCHAR(20), [SqlserverTestModel].[updated], 20) AS [SqlserverTestModel__updated]'
  297. );
  298. $result = $this->db->fields($this->model);
  299. $expected = $fields;
  300. $this->assertEqual($expected, $result);
  301. $this->db->clearFieldMappings();
  302. $result = $this->db->fields($this->model, null, 'SqlserverTestModel.*');
  303. $expected = $fields;
  304. $this->assertEqual($expected, $result);
  305. $this->db->clearFieldMappings();
  306. $result = $this->db->fields($this->model, null, array('*', 'AnotherModel.id', 'AnotherModel.name'));
  307. $expected = array_merge($fields, array(
  308. '[AnotherModel].[id] AS [AnotherModel__id]',
  309. '[AnotherModel].[name] AS [AnotherModel__name]'));
  310. $this->assertEqual($expected, $result);
  311. $this->db->clearFieldMappings();
  312. $result = $this->db->fields($this->model, null, array('*', 'SqlserverClientTestModel.*'));
  313. $expected = array_merge($fields, array(
  314. '[SqlserverClientTestModel].[id] AS [SqlserverClientTestModel__id]',
  315. '[SqlserverClientTestModel].[name] AS [SqlserverClientTestModel__name]',
  316. '[SqlserverClientTestModel].[email] AS [SqlserverClientTestModel__email]',
  317. 'CONVERT(VARCHAR(20), [SqlserverClientTestModel].[created], 20) AS [SqlserverClientTestModel__created]',
  318. 'CONVERT(VARCHAR(20), [SqlserverClientTestModel].[updated], 20) AS [SqlserverClientTestModel__updated]'));
  319. $this->assertEqual($expected, $result);
  320. }
  321. /**
  322. * testDistinctFields method
  323. *
  324. * @return void
  325. */
  326. public function testDistinctFields() {
  327. $result = $this->db->fields($this->model, null, array('DISTINCT Car.country_code'));
  328. $expected = array('DISTINCT [Car].[country_code] AS [Car__country_code]');
  329. $this->assertEqual($expected, $result);
  330. $result = $this->db->fields($this->model, null, 'DISTINCT Car.country_code');
  331. $expected = array('DISTINCT [Car].[country_code] AS [Car__country_code]');
  332. $this->assertEqual($expected, $result);
  333. }
  334. /**
  335. * testDistinctWithLimit method
  336. *
  337. * @return void
  338. */
  339. public function testDistinctWithLimit() {
  340. $this->db->read($this->model, array(
  341. 'fields' => array('DISTINCT SqlserverTestModel.city', 'SqlserverTestModel.country'),
  342. 'limit' => 5
  343. ));
  344. $result = $this->db->getLastQuery();
  345. $this->assertPattern('/^SELECT DISTINCT TOP 5/', $result);
  346. }
  347. /**
  348. * testDescribe method
  349. *
  350. * @return void
  351. */
  352. public function testDescribe() {
  353. $SqlserverTableDescription = new SqlserverTestResultIterator(array(
  354. (object) array(
  355. 'Default' => '((0))',
  356. 'Field' => 'count',
  357. 'Key' => 0,
  358. 'Length' => '4',
  359. 'Null' => 'NO',
  360. 'Type' => 'integer'
  361. ),
  362. (object) array(
  363. 'Default' => '',
  364. 'Field' => 'body',
  365. 'Key' => 0,
  366. 'Length' => '-1',
  367. 'Null' => 'YES',
  368. 'Type' => 'nvarchar'
  369. ),
  370. (object) array(
  371. 'Default' => '',
  372. 'Field' => 'published',
  373. 'Key' => 0,
  374. 'Type' => 'datetime2',
  375. 'Length' => 8,
  376. 'Null' => 'YES',
  377. 'Size' => ''
  378. ),
  379. (object) array(
  380. 'Default' => '',
  381. 'Field' => 'id',
  382. 'Key' => 1,
  383. 'Type' => 'nchar',
  384. 'Length' => 72,
  385. 'Null' => 'NO',
  386. 'Size' => ''
  387. )
  388. ));
  389. $this->db->executeResultsStack = array($SqlserverTableDescription);
  390. $dummyModel = $this->model;
  391. $result = $this->db->describe($dummyModel);
  392. $expected = array(
  393. 'count' => array(
  394. 'type' => 'integer',
  395. 'null' => false,
  396. 'default' => '0',
  397. 'length' => 4
  398. ),
  399. 'body' => array(
  400. 'type' => 'text',
  401. 'null' => true,
  402. 'default' => null,
  403. 'length' => null
  404. ),
  405. 'published' => array(
  406. 'type' => 'datetime',
  407. 'null' => true,
  408. 'default' => '',
  409. 'length' => null
  410. ),
  411. 'id' => array(
  412. 'type' => 'string',
  413. 'null' => false,
  414. 'default' => '',
  415. 'length' => 36,
  416. 'key' => 'primary'
  417. )
  418. );
  419. $this->assertEqual($expected, $result);
  420. }
  421. /**
  422. * testBuildColumn
  423. *
  424. * @return void
  425. */
  426. public function testBuildColumn() {
  427. $column = array('name' => 'id', 'type' => 'integer', 'null' => false, 'default' => '', 'length' => '8', 'key' => 'primary');
  428. $result = $this->db->buildColumn($column);
  429. $expected = '[id] int IDENTITY (1, 1) NOT NULL';
  430. $this->assertEqual($expected, $result);
  431. $column = array('name' => 'client_id', 'type' => 'integer', 'null' => false, 'default' => '0', 'length' => '11');
  432. $result = $this->db->buildColumn($column);
  433. $expected = '[client_id] int DEFAULT 0 NOT NULL';
  434. $this->assertEqual($expected, $result);
  435. $column = array('name' => 'client_id', 'type' => 'integer', 'null' => true);
  436. $result = $this->db->buildColumn($column);
  437. $expected = '[client_id] int NULL';
  438. $this->assertEqual($expected, $result);
  439. // 'name' => 'type' format for columns
  440. $column = array('type' => 'integer', 'name' => 'client_id');
  441. $result = $this->db->buildColumn($column);
  442. $expected = '[client_id] int NULL';
  443. $this->assertEqual($expected, $result);
  444. $column = array('type' => 'string', 'name' => 'name');
  445. $result = $this->db->buildColumn($column);
  446. $expected = '[name] nvarchar(255) NULL';
  447. $this->assertEqual($expected, $result);
  448. $column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => '', 'length' => '255');
  449. $result = $this->db->buildColumn($column);
  450. $expected = '[name] nvarchar(255) DEFAULT \'\' NOT NULL';
  451. $this->assertEqual($expected, $result);
  452. $column = array('name' => 'name', 'type' => 'string', 'null' => false, 'length' => '255');
  453. $result = $this->db->buildColumn($column);
  454. $expected = '[name] nvarchar(255) NOT NULL';
  455. $this->assertEqual($expected, $result);
  456. $column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => null, 'length' => '255');
  457. $result = $this->db->buildColumn($column);
  458. $expected = '[name] nvarchar(255) NOT NULL';
  459. $this->assertEqual($expected, $result);
  460. $column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => null, 'length' => '255');
  461. $result = $this->db->buildColumn($column);
  462. $expected = '[name] nvarchar(255) NULL';
  463. $this->assertEqual($expected, $result);
  464. $column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => '', 'length' => '255');
  465. $result = $this->db->buildColumn($column);
  466. $expected = '[name] nvarchar(255) DEFAULT \'\'';
  467. $this->assertEqual($expected, $result);
  468. $column = array('name' => 'body', 'type' => 'text');
  469. $result = $this->db->buildColumn($column);
  470. $expected = '[body] nvarchar(MAX)';
  471. $this->assertEqual($expected, $result);
  472. }
  473. /**
  474. * testBuildIndex method
  475. *
  476. * @return void
  477. */
  478. public function testBuildIndex() {
  479. $indexes = array(
  480. 'PRIMARY' => array('column' => 'id', 'unique' => 1),
  481. 'client_id' => array('column' => 'client_id', 'unique' => 1)
  482. );
  483. $result = $this->db->buildIndex($indexes, 'items');
  484. $expected = array(
  485. 'PRIMARY KEY ([id])',
  486. 'ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id]);'
  487. );
  488. $this->assertEqual($expected, $result);
  489. $indexes = array('client_id' => array('column' => 'client_id'));
  490. $result = $this->db->buildIndex($indexes, 'items');
  491. $this->assertEqual($result, array());
  492. $indexes = array('client_id' => array('column' => array('client_id', 'period_id'), 'unique' => 1));
  493. $result = $this->db->buildIndex($indexes, 'items');
  494. $expected = array('ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id], [period_id]);');
  495. $this->assertEqual($expected, $result);
  496. }
  497. /**
  498. * testUpdateAllSyntax method
  499. *
  500. * @return void
  501. */
  502. public function testUpdateAllSyntax() {
  503. $fields = array('SqlserverTestModel.client_id' => '[SqlserverTestModel].[client_id] + 1');
  504. $conditions = array('SqlserverTestModel.updated <' => date('2009-01-01 00:00:00'));
  505. $this->db->update($this->model, $fields, null, $conditions);
  506. $result = $this->db->getLastQuery();
  507. $this->assertNoPattern('/SqlserverTestModel/', $result);
  508. $this->assertPattern('/^UPDATE \[sqlserver_test_models\]/', $result);
  509. $this->assertPattern('/SET \[client_id\] = \[client_id\] \+ 1/', $result);
  510. }
  511. /**
  512. * testGetPrimaryKey method
  513. *
  514. * @return void
  515. */
  516. public function testGetPrimaryKey() {
  517. $schema = $this->model->schema();
  518. $this->db->describe = $schema;
  519. $result = $this->db->getPrimaryKey($this->model);
  520. $this->assertEqual($result, 'id');
  521. unset($schema['id']['key']);
  522. $this->db->describe = $schema;
  523. $result = $this->db->getPrimaryKey($this->model);
  524. $this->assertNull($result);
  525. }
  526. /**
  527. * testInsertMulti
  528. *
  529. * @return void
  530. */
  531. public function testInsertMulti() {
  532. $this->db->describe = $this->model->schema();
  533. $fields = array('id', 'name', 'login');
  534. $values = array(
  535. array(1, 'Larry', 'PhpNut'),
  536. array(2, 'Renan', 'renan.saddam'));
  537. $this->db->simulated = array();
  538. $this->db->insertMulti($this->model, $fields, $values);
  539. $result = $this->db->simulated;
  540. $expected = array(
  541. 'SET IDENTITY_INSERT [sqlserver_test_models] ON',
  542. "INSERT INTO [sqlserver_test_models] ([id], [name], [login]) VALUES (1, N'Larry', N'PhpNut')",
  543. "INSERT INTO [sqlserver_test_models] ([id], [name], [login]) VALUES (2, N'Renan', N'renan.saddam')",
  544. 'SET IDENTITY_INSERT [sqlserver_test_models] OFF'
  545. );
  546. $this->assertEqual($expected, $result);
  547. $fields = array('name', 'login');
  548. $values = array(
  549. array('Larry', 'PhpNut'),
  550. array('Renan', 'renan.saddam'));
  551. $this->db->simulated = array();
  552. $this->db->insertMulti($this->model, $fields, $values);
  553. $result = $this->db->simulated;
  554. $expected = array(
  555. "INSERT INTO [sqlserver_test_models] ([name], [login]) VALUES (N'Larry', N'PhpNut')",
  556. "INSERT INTO [sqlserver_test_models] ([name], [login]) VALUES (N'Renan', N'renan.saddam')",
  557. );
  558. $this->assertEqual($expected, $result);
  559. }
  560. /**
  561. * SQL server < 11 doesn't have proper limit/offset support, test that our hack works.
  562. *
  563. * @return void
  564. */
  565. public function testLimitOffsetHack() {
  566. $this->loadFixtures('Author', 'Post', 'User');
  567. $query = array(
  568. 'limit' => 2,
  569. 'page' => 1,
  570. 'order' => 'User.user ASC',
  571. );
  572. $User = ClassRegistry::init('User');
  573. $results = $User->find('all', $query);
  574. $this->assertEquals(2, count($results));
  575. $this->assertEquals('garrett', $results[0]['User']['user']);
  576. $this->assertEquals('larry', $results[1]['User']['user']);
  577. $query = array(
  578. 'limit' => 2,
  579. 'page' => 2,
  580. 'order' => 'User.user ASC',
  581. );
  582. $User = ClassRegistry::init('User');
  583. $results = $User->find('all', $query);
  584. $this->assertEquals(2, count($results));
  585. $this->assertFalse(isset($results[0][0]));
  586. $this->assertEquals('mariano', $results[0]['User']['user']);
  587. $this->assertEquals('nate', $results[1]['User']['user']);
  588. }
  589. }