/frameworks/solar/1.1.1/source/solar/tests/Test/Solar/Sql/Model/Collection.php

https://github.com/ggunlugu/ornekler · PHP · 612 lines · 295 code · 79 blank · 238 comment · 0 complexity · b107577011c979b8417cc3b623af529a MD5 · raw file

  1. <?php
  2. /**
  3. *
  4. * Concrete class test.
  5. *
  6. */
  7. class Test_Solar_Sql_Model_Collection extends Solar_Test {
  8. /**
  9. *
  10. * Configuration values.
  11. *
  12. * @var array
  13. *
  14. */
  15. protected $_Test_Solar_Sql_Model_Collection = array(
  16. );
  17. protected $_sql_config = array(
  18. 'adapter' => 'Solar_Sql_Adapter_Sqlite',
  19. );
  20. protected $_sql = null;
  21. protected $_catalog_config = array(
  22. 'classes' => array(
  23. 'Mock_Solar_Model',
  24. ),
  25. );
  26. protected $_catalog = null;
  27. protected $_fixture = null;
  28. // -----------------------------------------------------------------
  29. //
  30. // Support methods.
  31. //
  32. // -----------------------------------------------------------------
  33. /**
  34. *
  35. * Setup; runs before each test method.
  36. *
  37. */
  38. public function preTest()
  39. {
  40. parent::preTest();
  41. // set up an SQL connection
  42. $this->_sql = Solar::factory(
  43. 'Solar_Sql',
  44. $this->_sql_config
  45. );
  46. $this->_sql->setProfiling(true);
  47. // set up a model catalog
  48. $this->_catalog = Solar::factory(
  49. 'Solar_Sql_Model_Catalog',
  50. $this->_catalog_config
  51. );
  52. // register the connection and catalog
  53. Solar_Registry::set('sql', $this->_sql);
  54. Solar_Registry::set('model_catalog', $this->_catalog);
  55. // fixture to populate tables
  56. $this->_fixture = Solar::factory('Fixture_Solar_Sql_Model');
  57. }
  58. // -----------------------------------------------------------------
  59. //
  60. // Test methods.
  61. //
  62. // -----------------------------------------------------------------
  63. /**
  64. *
  65. * Test -- Constructor.
  66. *
  67. */
  68. public function test__construct()
  69. {
  70. $obj = Solar::factory('Solar_Sql_Model_Collection');
  71. $this->assertInstance($obj, 'Solar_Sql_Model_Collection');
  72. }
  73. /**
  74. *
  75. * Test -- Returns a record from the collection based on its key value.
  76. *
  77. */
  78. public function test__get()
  79. {
  80. $this->_fixture->setup();
  81. $model = $this->_catalog->getModel('users');
  82. $params = array(
  83. 'cols' => array('handle', 'id', 'created', 'updated'),
  84. 'order' => 'handle',
  85. );
  86. $coll = $model->fetchAssoc($params);
  87. $record = $coll->handle_1;
  88. $this->assertEquals($record->handle, 'handle_1');
  89. $record->free();
  90. }
  91. /**
  92. *
  93. * Test -- Does a certain key exist in the data?
  94. *
  95. */
  96. public function test__isset()
  97. {
  98. $this->_fixture->setup();
  99. $model = $this->_catalog->getModel('users');
  100. $params = array(
  101. 'cols' => array('handle', 'id', 'created', 'updated'),
  102. 'order' => 'handle',
  103. );
  104. $coll = $model->fetchAssoc($params);
  105. $this->assertTrue(isset($coll->handle_1));
  106. $this->assertFalse(isset($coll->no_such_handle));
  107. $coll->free();
  108. }
  109. /**
  110. *
  111. * Test -- Sets a key value.
  112. *
  113. */
  114. public function test__set()
  115. {
  116. $this->_fixture->setup();
  117. $model = $this->_catalog->getModel('users');
  118. $params = array(
  119. 'cols' => array('handle', 'id', 'created', 'updated'),
  120. 'order' => 'handle',
  121. );
  122. $coll = $model->fetchAssoc($params);
  123. // get a record, make sure it's the right one
  124. $record = $coll->handle_1;
  125. $this->assertEquals($record->handle, 'handle_1');
  126. // clone it and replace within the collection
  127. $clone = clone $record;
  128. $clone->handle = 'zim-zim';
  129. $coll->handle_1 = $clone;
  130. // make sure it was really replaced
  131. $this->assertSame($coll->handle_1, $clone);
  132. $this->assertNotSame($coll->handle_1, $record);
  133. $clone->free();
  134. $record->free();
  135. $coll->free();
  136. }
  137. /**
  138. *
  139. * Test -- Sets a key in the data to null.
  140. *
  141. */
  142. public function test__unset()
  143. {
  144. $this->_fixture->setup();
  145. $model = $this->_catalog->getModel('users');
  146. $params = array(
  147. 'cols' => array('handle', 'id', 'created', 'updated'),
  148. 'order' => 'handle',
  149. );
  150. $coll = $model->fetchAssoc($params);
  151. // get a record, make sure it's the right one
  152. $record = $coll->handle_1;
  153. $this->assertEquals($record->handle, 'handle_1');
  154. // unset it from the collection
  155. unset($coll->handle_1);
  156. // make sure it's not set any more
  157. $this->assertFalse(isset($coll->handle_1));
  158. $coll->free();
  159. $record->free();
  160. }
  161. /**
  162. *
  163. * Test -- Countable: how many keys are there?
  164. *
  165. */
  166. public function testCount()
  167. {
  168. $this->_fixture->setup();
  169. $model = $this->_catalog->getModel('users');
  170. $sql = $model->sql;
  171. $stmt = "SELECT COUNT(*) FROM {$model->table_name}";
  172. $expect = $sql->fetchValue($stmt);
  173. $this->assertTrue($expect > 0);
  174. $params = array(
  175. 'cols' => array('handle', 'id', 'created', 'updated'),
  176. 'order' => 'handle',
  177. );
  178. $coll = $model->fetchAll($params);
  179. $this->assertEquals($coll->count(), $expect);
  180. $this->assertEquals(count($coll), $expect);
  181. $coll->free();
  182. }
  183. /**
  184. *
  185. * Test -- Iterator: get the current value for the array pointer.
  186. *
  187. */
  188. public function testCurrent()
  189. {
  190. $this->todo('stub');
  191. }
  192. /**
  193. *
  194. * Test -- Deletes each record in the collection one-by-one.
  195. *
  196. */
  197. public function testDelete()
  198. {
  199. $this->todo('stub');
  200. }
  201. /**
  202. *
  203. * Test -- Returns the model from which the data originates.
  204. *
  205. */
  206. public function testGetModel()
  207. {
  208. $this->todo('stub');
  209. }
  210. /**
  211. *
  212. * Test -- Gets the injected pager information for the collection.
  213. *
  214. */
  215. public function testGetPagerInfo()
  216. {
  217. $this->todo('stub');
  218. }
  219. /**
  220. *
  221. * Test -- Iterator: get the current key for the array pointer.
  222. *
  223. */
  224. public function testKey()
  225. {
  226. $this->todo('stub');
  227. }
  228. /**
  229. *
  230. * Test -- Loads the struct with data from an array or another struct.
  231. *
  232. */
  233. public function testLoad()
  234. {
  235. $this->todo('stub');
  236. }
  237. /**
  238. *
  239. * Test -- Loads *related* data for the collection.
  240. *
  241. */
  242. public function testLoadRelated()
  243. {
  244. $this->todo('stub');
  245. }
  246. /**
  247. *
  248. * Test -- Iterator: move to the next position.
  249. *
  250. */
  251. public function testNext()
  252. {
  253. $this->todo('stub');
  254. }
  255. /**
  256. *
  257. * Test -- ArrayAccess: does the requested key exist?
  258. *
  259. */
  260. public function testOffsetExists()
  261. {
  262. $this->_fixture->setup();
  263. $model = $this->_catalog->getModel('users');
  264. $params = array(
  265. 'cols' => array('handle', 'id', 'created', 'updated'),
  266. 'order' => 'handle',
  267. );
  268. $coll = $model->fetchAll($params);
  269. $this->assertTrue(isset($coll[0]));
  270. $this->assertFalse(isset($coll[99])); // fixture has no more than 30
  271. $coll->free();
  272. }
  273. /**
  274. *
  275. * Test -- ArrayAccess: get a key value.
  276. *
  277. */
  278. public function testOffsetGet()
  279. {
  280. $this->_fixture->setup();
  281. $model = $this->_catalog->getModel('users');
  282. $params = array(
  283. 'cols' => array('handle', 'id', 'created', 'updated'),
  284. 'order' => 'handle',
  285. );
  286. $coll = $model->fetchAll($params);
  287. $record = $coll[0];
  288. $this->assertEquals($record->handle, 'handle_1');
  289. $record->free();
  290. $coll->free();
  291. }
  292. /**
  293. *
  294. * Test -- ArrayAccess: set a key value; appends to the array when using [] notation.
  295. *
  296. */
  297. public function testOffsetSet()
  298. {
  299. $this->_fixture->setup();
  300. $model = $this->_catalog->getModel('users');
  301. $params = array(
  302. 'cols' => array('handle', 'id', 'created', 'updated'),
  303. 'order' => 'handle',
  304. );
  305. $coll = $model->fetchAll($params);
  306. // get a record, make sure it's the right one
  307. $record = $coll[0];
  308. $this->assertEquals($record->handle, 'handle_1');
  309. // clone it and replace within the collection
  310. $clone = clone $record;
  311. $clone->handle = 'dib-dib';
  312. $coll[0] = $clone;
  313. // make sure it was really replaced
  314. $this->assertSame($coll[0], $clone);
  315. $this->assertNotSame($coll[0], $record);
  316. $clone->free();
  317. $record->free();
  318. $coll->free();
  319. }
  320. /**
  321. *
  322. * Test -- ArrayAccess: unset a key.
  323. *
  324. */
  325. public function testOffsetUnset()
  326. {
  327. $this->_fixture->setup();
  328. $model = $this->_catalog->getModel('users');
  329. $params = array(
  330. 'cols' => array('handle', 'id', 'created', 'updated'),
  331. 'order' => 'handle',
  332. );
  333. $coll = $model->fetchAll($params);
  334. // get a record, make sure it's the right one
  335. $record = $coll[0];
  336. $this->assertEquals($record->handle, 'handle_1');
  337. // unset it from the collection
  338. unset($coll[0]);
  339. // make sure it's not set any more
  340. $this->assertFalse(isset($coll[0]));
  341. $record->free();
  342. $coll->free();
  343. }
  344. /**
  345. *
  346. * Test -- Iterator: move to the first position.
  347. *
  348. */
  349. public function testRewind()
  350. {
  351. $this->todo('stub');
  352. }
  353. /**
  354. *
  355. * Test -- Saves all the records from this collection to the database one-by-one, inserting or updating as needed.
  356. *
  357. */
  358. public function testSave()
  359. {
  360. $this->todo('stub');
  361. }
  362. /**
  363. *
  364. * Test -- Injects the model from which the data originates.
  365. *
  366. */
  367. public function testSetModel()
  368. {
  369. $this->todo('stub');
  370. }
  371. /**
  372. *
  373. * Test -- Injects pager information for the collection.
  374. *
  375. */
  376. public function testSetPagerInfo()
  377. {
  378. $this->todo('stub');
  379. }
  380. /**
  381. *
  382. * Test -- Returns the data for each record in this collection as an array.
  383. *
  384. */
  385. public function testToArray()
  386. {
  387. $this->todo('stub');
  388. }
  389. /**
  390. *
  391. * Test -- Iterator: is the current position valid?
  392. *
  393. */
  394. public function testValid()
  395. {
  396. $this->todo('stub');
  397. }
  398. /**
  399. *
  400. * Test -- Returns a string representation of the object.
  401. *
  402. */
  403. public function test__toString()
  404. {
  405. $this->todo('stub');
  406. }
  407. /**
  408. *
  409. * Test -- Fetches a new record and appends it to the collection.
  410. *
  411. */
  412. public function testAppendNew()
  413. {
  414. $this->todo('stub');
  415. }
  416. /**
  417. *
  418. * Test -- Deletes each record in the collection one-by-one.
  419. *
  420. */
  421. public function testDeleteAll()
  422. {
  423. $this->todo('stub');
  424. }
  425. /**
  426. *
  427. * Test -- Deletes a record from the database and removes it from the collection.
  428. *
  429. */
  430. public function testDeleteOne()
  431. {
  432. $this->todo('stub');
  433. }
  434. /**
  435. *
  436. * Test -- Frees memory used by this struct.
  437. *
  438. */
  439. public function testFree()
  440. {
  441. $this->todo('stub');
  442. }
  443. /**
  444. *
  445. * Test -- Returns an array of all values for a single column in the collection.
  446. *
  447. */
  448. public function testGetColVals()
  449. {
  450. $this->todo('stub');
  451. }
  452. /**
  453. *
  454. * Test -- Returns an array of invalidation messages from each invalid record, keyed on the record offset within the collection.
  455. *
  456. */
  457. public function testGetInvalid()
  458. {
  459. $this->todo('stub');
  460. }
  461. /**
  462. *
  463. * Test -- Returns an array of the invalid record objects within the collection, keyed on the record offset within the collection.
  464. *
  465. */
  466. public function testGetInvalidRecords()
  467. {
  468. $this->todo('stub');
  469. }
  470. /**
  471. *
  472. * Test -- Returns an array of the unique primary keys contained in this collection.
  473. *
  474. */
  475. public function testGetPrimaryVals()
  476. {
  477. $this->todo('stub');
  478. }
  479. /**
  480. *
  481. * Test -- Given a record object, looks up its offset value in the collection.
  482. *
  483. */
  484. public function testGetRecordOffset()
  485. {
  486. $this->todo('stub');
  487. }
  488. /**
  489. *
  490. * Test -- Is the struct dirty?
  491. *
  492. */
  493. public function testIsDirty()
  494. {
  495. $this->todo('stub');
  496. }
  497. /**
  498. *
  499. * Test -- Are there any invalid records in the collection?
  500. *
  501. */
  502. public function testIsInvalid()
  503. {
  504. $this->todo('stub');
  505. }
  506. /**
  507. *
  508. * Test -- Removes all records from the collection but **does not** delete them from the database.
  509. *
  510. */
  511. public function testRemoveAll()
  512. {
  513. $this->todo('stub');
  514. }
  515. /**
  516. *
  517. * Test -- Removes one record from the collection but **does not** delete it from the database.
  518. *
  519. */
  520. public function testRemoveOne()
  521. {
  522. $this->todo('stub');
  523. }
  524. /**
  525. *
  526. * Test -- Returns a string representation of the struct.
  527. *
  528. */
  529. public function testToString()
  530. {
  531. $this->todo('stub');
  532. }
  533. }