PageRenderTime 64ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/runtime/epTestManager.php

https://bitbucket.org/davidmpaz/ezpdo
PHP | 2289 lines | 1176 code | 528 blank | 585 comment | 184 complexity | 65cf91ad94dca473484d0f482ce30f8c MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0

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

  1. <?php
  2. /**
  3. * $Id: epTestManager.php 1019 2006-11-29 06:26:43Z nauhygon $
  4. *
  5. * Copyright(c) 2005 by Oak Nauhygon. All rights reserved.
  6. *
  7. * @author Oak Nauhygon <ezpdo4php@gmail.com>
  8. * @version $Revision: 1019 $ $Date: 2006-11-29 01:26:43 -0500 (Wed, 29 Nov 2006) $
  9. * @package ezpdo.tests
  10. * @subpackage ezpdo.tests.runtime
  11. */
  12. /**
  13. * need epTestCase
  14. */
  15. include_once(dirname(__FILE__).'/epTestRuntime.php');
  16. /**
  17. * The unit test class for {@link epManager}
  18. *
  19. * @author Oak Nauhygon <ezpdo4php@gmail.com>
  20. * @version $Revision: 1019 $ $Date: 2006-11-29 01:26:43 -0500 (Wed, 29 Nov 2006) $
  21. * @package ezpdo.tests
  22. * @subpackage ezpdo.tests.runtime
  23. */
  24. class epTestManager extends epTestRuntime {
  25. /**
  26. * The cached manager
  27. * @var epManager
  28. */
  29. protected $m = false;
  30. /**
  31. * Maximum number of items to insert to a table
  32. */
  33. const MAX_ITEMS = 10;
  34. /**
  35. * Maximum number of items to insert to a table
  36. */
  37. const HALF_ITEMS = 10;
  38. /**
  39. * remove output dir in teardown
  40. */
  41. function tearDown() {
  42. epRmDir(dirname(__FILE__) . '/output');
  43. }
  44. /**
  45. * test {@link epManager} with single object
  46. * create, set/get vars, refresh, commit, delete
  47. */
  48. function _testSingleObject() {
  49. $this->assertTrue($m = & $this->m);
  50. // use manager to create one object
  51. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  52. // delete all books
  53. $m->deleteAll('eptBook');
  54. // test object creation
  55. $title = md5('eptBook');
  56. $this->assertTrue($o = $m->create('eptBook', $title));
  57. $this->assertFalse($o->epIsDirty());
  58. $this->assertTrue($o->title === $title);
  59. $this->assertFalse($dirty = $o->epIsDirty());
  60. // call method doNothing should not change dirty flag
  61. $o->doNothing();
  62. $this->assertTrue($o->epIsDirty() == $dirty);
  63. // test commit
  64. $this->assertTrue($m->commit($o));
  65. // check object id
  66. $this->assertTrue(($oid = $o->epGetObjectId()));
  67. // test setter/getter
  68. $pages = rand(1, 1000);
  69. $this->assertFalse(($pages0 = $o->pages) === $pages);
  70. $o->setPages($pages);
  71. $this->assertTrue($o->pages === $pages);
  72. $this->assertTrue($dirty = $o->epIsDirty());
  73. // call method doNothing should not change dirty flag
  74. $o->doNothing();
  75. $this->assertTrue($o->epIsDirty() == $dirty);
  76. // call refresh so $pages will be replace with old value $page0
  77. $this->assertTrue($m->refresh($o));
  78. $this->assertFalse($dirty = $o->epIsDirty());
  79. $this->assertTrue($o->pages === $pages0);
  80. // call method doNothing should not change dirty flag
  81. $o->doNothing();
  82. $this->assertTrue($o->epIsDirty() == $dirty);
  83. // set pages again and commit
  84. $this->assertFalse(($pages0 = $o->pages) === $pages);
  85. $o->setPages($pages);
  86. $this->assertTrue($o->pages === $pages);
  87. $this->assertTrue($o->epIsDirty());
  88. $this->assertTrue($m->commit($o));
  89. // insert id should not change
  90. $this->assertTrue($oid == $o->epGetObjectId());
  91. // now refresh again
  92. $this->assertTrue($o->pages !== $pages0);
  93. $this->assertTrue($o->pages === $pages);
  94. // try get (should get the cached)
  95. $this->assertTrue($o2 = & $m->get('eptBook', $oid));
  96. $this->assertTrue($o2 === $o);
  97. // test delete
  98. $this->assertTrue($m->delete($o));
  99. // cannot get obj for the oid
  100. $this->assertFalse($m->get('eptBook', $oid));
  101. // delete all books
  102. $m->deleteAll('eptBook');
  103. }
  104. /**
  105. * test {@link epManager}:
  106. * {@link epManager::getAll()}
  107. * {@link epManager::flush()}
  108. */
  109. function _testMultiObjects() {
  110. // configure epManager
  111. $this->assertTrue($m = & $this->m);
  112. // use manager to create one object
  113. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  114. // empty db
  115. $m->deleteAll('eptBook');
  116. // create self::MAX_ITEMS eptBook's
  117. $oids = array();
  118. $all_pages = array();
  119. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  120. $title = "title" . md5($i);
  121. $this->assertTrue($o = & $m->create('eptBook', $title));
  122. // check title
  123. $this->assertFalse($dirty = $o->epIsDirty());
  124. // call method doNothing should not change dirty flag
  125. $o->doNothing();
  126. $this->assertTrue($o->epIsDirty() == $dirty );
  127. $this->assertTrue($o->title === $title);
  128. // set pages
  129. $pages = rand(1, 1000);
  130. $this->assertTrue($o->pages = $pages);
  131. $this->assertTrue($o->pages === $pages);
  132. // chech dirty flag
  133. $this->assertTrue($o->epIsDirty());
  134. // commit
  135. $this->assertTrue($m->commit($o));
  136. // make sure oid are valid
  137. $this->assertTrue(($oid = $o->epGetObjectId()));
  138. // keep track of oids and pages
  139. $oids[] = $oid;
  140. $all_pages[] = $pages;
  141. }
  142. // change page number for the first self::HALF_ITEMS books
  143. for($i = 0; $i < self::HALF_ITEMS; $i ++) {
  144. // get book by oid
  145. $this->assertTrue($o = & $m->get('eptBook', $oids[$i]));
  146. // check dirty flag (false)
  147. $this->assertFalse($dirty = $o->epIsDirty());
  148. // call method doNothing should not change dirty flag
  149. $o->doNothing();
  150. $this->assertTrue($o->epIsDirty() == $dirty);
  151. // chanage pages
  152. $this->assertTrue(($pages = $o->pages) === $all_pages[$i]);
  153. $this->assertTrue($o->pages = $pages + 1);
  154. // check dirty flag (true)
  155. $this->assertTrue($o->epIsDirty());
  156. }
  157. // now use epManager::getAll(): should get nothing since everything has been cached
  158. $this->assertTrue($os = $m->getAll('eptBook'));
  159. $this->assertTrue(count($os) == self::MAX_ITEMS);
  160. $this->assertTrue($m->count('eptBook') == self::MAX_ITEMS);
  161. // check: the first self::HALF_ITEMS should be retrieved from cache, page number +1 (dirty))
  162. for($i = 0; $i < self::HALF_ITEMS; $i ++) {
  163. // get book by oid
  164. $this->assertTrue($o = & $m->get('eptBook', $oids[$i]));
  165. // check dirty flag (true)
  166. $this->assertTrue($o->epIsDirty());
  167. // chanage pages
  168. $this->assertTrue($o->pages === $all_pages[$i] + 1);
  169. }
  170. // check: the second self::HALF_ITEMS should be retrieved from db, same page number (no dirty)
  171. for($i = self::HALF_ITEMS; $i < self::MAX_ITEMS; $i ++) {
  172. // get book by oid
  173. $this->assertTrue($o = & $m->get('eptBook', $oids[$i]));
  174. // check dirty flag (false)
  175. $this->assertFalse($dirty = $o->epIsDirty());
  176. // call method doNothing should not change dirty flag
  177. $o->doNothing();
  178. $this->assertTrue($o->epIsDirty() == $dirty);
  179. // chanage pages
  180. $this->assertTrue($o->pages === $all_pages[$i]);
  181. }
  182. // test flush
  183. $this->assertTrue($m->flush());
  184. // before refresh, change values in cached objects
  185. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  186. // get book by oid
  187. $this->assertTrue($o = & $m->get('eptBook', $oids[$i]));
  188. // check dirty flag (false)
  189. $this->assertFalse($dirty = $o->epIsDirty());
  190. // call method doNothing should not change dirty flag
  191. $o->doNothing();
  192. $this->assertTrue($o->epIsDirty() == $dirty);
  193. // chanage pages
  194. $pages = $o->pages + rand(1, 1000);
  195. $this->assertTrue($o->pages = $pages);
  196. $all_pages[$i] = $pages;
  197. // check dirty flag (true)
  198. $this->assertTrue($o->epIsDirty());
  199. }
  200. // now refresh so get value from db that should all differ from memory
  201. // before refresh, change values in cached objects
  202. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  203. // get book by oid
  204. $this->assertTrue($o = & $m->get('eptBook', $oids[$i]));
  205. // check dirty flag (false)
  206. $this->assertTrue($o->epIsDirty());
  207. // refresh
  208. $this->assertTrue($m->refresh($o));
  209. // check that pages are different from those stored in memory
  210. $this->assertTrue($o->pages !== $all_pages[$i]);
  211. // check dirty flag (true)
  212. $this->assertFalse($dirty = $o->epIsDirty());
  213. // call method doNothing should not change dirty flag
  214. $o->doNothing();
  215. $this->assertTrue($o->epIsDirty() == $dirty);
  216. }
  217. // delete all objects
  218. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  219. // get book by oid
  220. $this->assertTrue($o = & $m->get('eptBook', $oids[$i]));
  221. // delete
  222. $this->assertTrue($m->delete($o));
  223. }
  224. // make sure we have deleted all
  225. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  226. // get book by oid
  227. $this->assertFalse($o = & $m->get('eptBook', $oids[$i]));
  228. }
  229. }
  230. /**
  231. * test createFromArray and updateFromArray
  232. */
  233. function _testCreateFromArray() {
  234. $this->assertTrue($m = & $this->m);
  235. // use manager to create one object
  236. include_once(EP_TESTS.'/classes/bookstore/src/eptAuthor.php');
  237. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  238. // delete all books
  239. $m->deleteAll('eptAuthor');
  240. $m->deleteAll('eptBook');
  241. // array to be used for object creation
  242. $author = array(
  243. 'name' => "author-".md5('author'),
  244. 'id' => rand(1, 1000),
  245. 'age' => rand(1, 120),
  246. 'books' => array(
  247. 'title' => 'title-'.md5('book'),
  248. 'pages' => rand(1, 1000),
  249. )
  250. );
  251. // create object from array
  252. $a = $m->createFromArray('eptAuthor', $author);
  253. // check if all vars are correct
  254. $this->assertTrue($a->name == $author['name']);
  255. $this->assertTrue($a->id == $author['id']);
  256. $this->assertTrue($a->age == $author['age']);
  257. $this->assertNotNull($a->books);
  258. $this->assertNotNull($a->books[0]->title == $author['books']['title']);
  259. $this->assertNotNull($a->books[0]->pages == $author['books']['pages']);
  260. // array to be used for object update
  261. $author_diff = array(
  262. 'name' => "author-".md5('author'),
  263. 'age' => rand(1, 120),
  264. 'books' => $a->books
  265. );
  266. // update object from array
  267. $a_ = $m->updateFromArray($a, $author_diff);
  268. // check if all vars are correct
  269. $this->assertTrue($a_ === $a);
  270. $this->assertTrue($a->name == $author_diff['name']);
  271. $this->assertTrue($a->id == $author['id']);
  272. $this->assertTrue($a->age == $author_diff['age']);
  273. $this->assertNotNull($a->books);
  274. $this->assertNotNull($a->books[0]->title == $author['books']['title']);
  275. $this->assertNotNull($a->books[0]->pages == $author_diff['books']['pages']);
  276. // array to be used for object creation
  277. $author2 = array(
  278. 'name' => "author-".md5('author2'),
  279. 'id' => rand(1, 1000),
  280. 'age' => rand(1, 120),
  281. 'contact' => array(
  282. 'phone' => '1234567',
  283. 'zipcode' => '8901',
  284. ),
  285. 'books' => array(
  286. array(
  287. 'title' => 'title-'.md5('book1'),
  288. 'pages' => rand(1, 1000),
  289. ),
  290. array(
  291. 'title' => 'title-'.md5('book2'),
  292. 'pages' => rand(1, 1000),
  293. ),
  294. ),
  295. );
  296. // create object from array
  297. $a2 = $m->createFromArray('eptAuthor', $author2);
  298. // check if all vars are correct
  299. $this->assertTrue($a2->name == $author2['name']);
  300. $this->assertTrue($a2->id == $author2['id']);
  301. $this->assertTrue($a2->age == $author2['age']);
  302. $this->assertNotNull($a2->contact);
  303. $this->assertNotNull($a2->contact->phone = $author2['contact']['phone']);
  304. $this->assertNotNull($a2->contact->zipcode = $author2['contact']['zipcode']);
  305. $this->assertNotNull($a2->books);
  306. $this->assertNotNull($a2->books[0]->title == $author2['books'][0]['title']);
  307. $this->assertNotNull($a2->books[0]->pages == $author2['books'][0]['pages']);
  308. $this->assertNotNull($a2->books[1]->title == $author2['books'][1]['title']);
  309. $this->assertNotNull($a2->books[1]->pages == $author2['books'][1]['pages']);
  310. // flush all
  311. $m->flush();
  312. // delete all books
  313. $m->deleteAll('eptAuthor');
  314. $m->deleteAll('eptBook');
  315. }
  316. /**
  317. * test {@link epArray}: orderby
  318. * {@link epArray::orderBy()}
  319. */
  320. function _testArraySortBy() {
  321. // configure epManager
  322. $this->assertTrue($m = & $this->m);
  323. include_once(EP_TESTS.'/classes/bookstore/src/eptAuthor.php');
  324. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  325. // empty db
  326. $m->deleteAll('eptAuthor');
  327. $m->deleteAll('eptBook');
  328. // create an author
  329. $this->assertTrue($author = $m->create('eptAuthor'));
  330. // add books into author
  331. $book_oids = array();
  332. $book_titles = array();
  333. $book_pages = array();
  334. $book_title_page_oids = array();
  335. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  336. // create a book
  337. $this->assertTrue($book = $m->create('eptBook'));
  338. // set book title
  339. $title = "title" . md5('whatever');
  340. $book->title = $title;
  341. $this->assertTrue($title === $book->title);
  342. $book_titles[] = $title;
  343. // set book pages
  344. $pages = rand(1, 1000);
  345. $book->pages = $pages;
  346. $this->assertTrue($pages === $book->pages);
  347. $book_pages[] = $pages;
  348. // commit it
  349. $this->assertTrue($book->commit());
  350. $this->assertTrue($book->oid > 0);
  351. $book_oids[] = $book->oid;
  352. // add book into author
  353. $author->books[] = $book;
  354. $this->assertTrue($author->books->count() == $i + 1);
  355. $book_title_page_oids[] = array(
  356. 'title' => $title,
  357. 'pages' => $pages,
  358. 'oid' => $book->oid
  359. );
  360. }
  361. // sort by title asc
  362. $this->assertTrue($author->books->sortBy('title', SORT_ASC));
  363. sort($book_titles);
  364. $i = 0;
  365. foreach($author->books as $book) {
  366. $this->assertTrue($book_titles[$i] === $book->title);
  367. $i ++;
  368. }
  369. // sort by title desc
  370. $this->assertTrue($author->books->sortBy('title', SORT_DESC));
  371. rsort($book_titles);
  372. $i = 0;
  373. foreach($author->books as $book) {
  374. $this->assertTrue($book_titles[$i] === $book->title);
  375. $i ++;
  376. }
  377. // sort by pages asc
  378. $this->assertTrue($author->books->sortBy('pages', SORT_ASC));
  379. sort($book_pages);
  380. $i = 0;
  381. foreach($author->books as $book) {
  382. $this->assertTrue($book_pages[$i] === $book->pages);
  383. $i ++;
  384. }
  385. // sort by pages desc
  386. $this->assertTrue($author->books->sortBy('pages', SORT_DESC));
  387. rsort($book_pages);
  388. $i = 0;
  389. foreach($author->books as $book) {
  390. $this->assertTrue($book_pages[$i] === $book->pages);
  391. $i ++;
  392. }
  393. // sort by oid asc
  394. $this->assertTrue($author->books->sortBy('oid', SORT_ASC));
  395. sort($book_oids);
  396. $i = 0;
  397. foreach($author->books as $book) {
  398. $this->assertTrue($book_oids[$i] === $book->oid);
  399. $i ++;
  400. }
  401. // sort by pages desc
  402. $this->assertTrue($author->books->sortBy('oid', SORT_DESC));
  403. rsort($book_oids);
  404. $i = 0;
  405. foreach($author->books as $book) {
  406. $this->assertTrue($book_oids[$i] === $book->oid);
  407. $i ++;
  408. }
  409. // multisort
  410. $this->assertTrue($author->books->sortBy('title', SORT_DESC, 'pages', SORT_ASC, 'oid', SORT_DESC));
  411. foreach ($book_title_page_oids as $key => $row) {
  412. $_titles[$key] = $row['title'];
  413. $_pages[$key] = $row['pages'];
  414. $_oids[$key] = $row['oid'];
  415. }
  416. array_multisort($_titles, SORT_DESC, $_pages, SORT_ASC, $_oids, SORT_DESC, $book_title_page_oids);
  417. $i = 0;
  418. foreach($author->books as $book) {
  419. $this->assertTrue($book_title_page_oids[$i]['title'] === $book->title);
  420. $this->assertTrue($book_title_page_oids[$i]['pages'] === $book->pages);
  421. $this->assertTrue($book_title_page_oids[$i]['oid'] === $book->oid);
  422. $i ++;
  423. }
  424. }
  425. /**
  426. * test datatypes
  427. */
  428. function _testDataTypes() {
  429. // configure epManager
  430. $this->assertTrue($m = & $this->m);
  431. // use manager to create one object
  432. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  433. // empty db book
  434. $m->deleteAll('eptBook');
  435. $title = "title" . md5('whatever');
  436. $this->assertTrue($b = $m->create('eptBook', $title));
  437. // a new object cannot be dirty
  438. $this->assertFalse($b->epIsDirty());
  439. //
  440. // do all the setting here
  441. //
  442. // set title (char)
  443. $this->assertTrue($b->title === $title);
  444. $this->assertTrue(is_string($b->title));
  445. // set pages (integer)
  446. $pages = rand(1, 1000);
  447. $this->assertTrue($b->pages = $pages);
  448. $this->assertTrue($b->pages === $pages);
  449. $this->assertTrue(is_integer($b->pages));
  450. // set recommended (boolean)
  451. $recommended = true;
  452. $this->assertTrue($b->recommended = $recommended);
  453. $this->assertTrue($b->recommended === $recommended);
  454. $this->assertTrue(is_bool($b->recommended));
  455. // set excerpt (clob(8192))
  456. $excerpt = str_repeat("excerpt", (integer)(8192/7));
  457. $this->assertTrue($b->excerpt = $excerpt);
  458. $this->assertTrue($b->excerpt === $excerpt);
  459. $this->assertTrue(is_string($b->excerpt));
  460. // set coverimg (blob(8192))
  461. $part = file_get_contents(dirname(__FILE__) . '/input/mysql_logo.gif');
  462. $coverimg = str_repeat($part, (integer)(8192/strlen($part)));
  463. $this->assertTrue($b->coverimg = $coverimg);
  464. $this->assertTrue($b->coverimg === $coverimg);
  465. $this->assertTrue(is_string($b->coverimg));
  466. // set pubdate (date)
  467. $pubdate = time();
  468. $this->assertTrue($b->pubdate = $pubdate);
  469. $this->assertTrue($b->pubdate === $pubdate);
  470. $this->assertTrue(is_integer($b->pubdate));
  471. // chech dirty flag
  472. $this->assertTrue($b->epIsDirty());
  473. // commit book
  474. $this->assertTrue($m->commit($b));
  475. $this->assertTrue($oid = $b->epGetObjectId());
  476. // now evict the book from memory
  477. $this->assertTrue($m->evictAll('eptBook'));
  478. $this->assertFalse($b);
  479. // read it from db
  480. $this->assertTrue($b = & $m->get('eptBook', $oid));
  481. //
  482. // do all the re-checking here
  483. //
  484. // check title (char)
  485. $this->assertTrue($b->title == $title);
  486. $this->assertTrue(is_string($b->title));
  487. // check pages (integer)
  488. $this->assertTrue($b->pages == $pages);
  489. $this->assertTrue(is_integer($b->pages));
  490. // check recommended (boolean)
  491. $this->assertTrue($b->recommended == $recommended);
  492. $this->assertTrue(is_bool($b->recommended));
  493. // check excerpt (clob(8192))
  494. $this->assertTrue($b->excerpt == $excerpt);
  495. $this->assertTrue(is_string($b->excerpt));
  496. // check coverimg (blob(8192))
  497. $this->assertTrue($b->coverimg == $coverimg);
  498. $this->assertTrue(is_string($b->coverimg));
  499. // set pubdate (date)
  500. $this->assertTrue($b->pubdate == $pubdate);
  501. $this->assertTrue(is_integer($b->pubdate));
  502. // cleanup
  503. $m->deleteAll('eptBook');
  504. }
  505. /**
  506. * test {@link epManager}: find
  507. * {@link epManager::find()}
  508. */
  509. function _testObjectFind() {
  510. // configure epManager
  511. $this->assertTrue($m = & $this->m);
  512. // use manager to create one object
  513. include_once(EP_TESTS.'/classes/bookstore/src/eptAuthor.php');
  514. // empty db
  515. $m->deleteAll('eptAuthor');
  516. $m->deleteAll('eptBook');
  517. // create self::MAX_ITEMS eptBook's
  518. $oids = array(); // object ids
  519. $names = array(); // author names
  520. $ages = array(); // author ages
  521. $ids = array(); // author id
  522. $objs = array(); // all objects
  523. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  524. $name = "author-" . md5($i);
  525. $this->assertTrue($o = & $m->create('eptAuthor', $name));
  526. // check title
  527. $this->assertFalse($o->epIsDirty());
  528. $this->assertTrue($o->name === $name);
  529. // set id
  530. $id = rand(1, 1000);
  531. //$this->assertTrue($o->setId($id));
  532. $this->assertTrue($o->id = $id);
  533. $this->assertTrue($o->id === $id);
  534. // set ages
  535. $age = rand(1, 120);
  536. $this->assertTrue($o->age = $age);
  537. $this->assertTrue($o->age === $age);
  538. // chech dirty flag
  539. $this->assertTrue($o->epIsDirty());
  540. // commit
  541. $this->assertTrue($m->commit($o));
  542. // make sure oid are valid
  543. $this->assertTrue(($oid = $o->epGetObjectId()));
  544. // keep track of oids and pages
  545. $names[] = $name;
  546. $ages[] = $age;
  547. $oids[] = $oid;
  548. $ids[] = $id;
  549. $objs[] = & $o;
  550. }
  551. // test find - all objects are in cache
  552. $eo = & $m->create('eptAuthor'); // example object
  553. // set null to all vars
  554. $eo->uuid = '';
  555. $eo->name = '';
  556. $eo->id = null;
  557. $eo->age = null;
  558. // find objects in cache only
  559. $this->assertTrue($os = $m->find($eo, EP_GET_FROM_CACHE));
  560. $this->assertTrue(count($os) == self::MAX_ITEMS);
  561. // evict and find in cache
  562. $this->assertTrue($m->evictAll('eptAuthor'));
  563. $this->assertFalse($os = $m->find($eo, EP_GET_FROM_CACHE));
  564. // after eviction, the objects themselves are deleted (set to null)
  565. $this->assertFalse($o); // test the last one first
  566. // now check everyone (should all be deleted (ie null))
  567. foreach($objs as &$o) {
  568. $this->assertFalse($o);
  569. }
  570. // find objects from db
  571. $this->assertTrue($os = $m->find($eo, EP_GET_FROM_DB));
  572. $this->assertTrue(count($os) == self::MAX_ITEMS);
  573. // delete all objects
  574. $m->deleteAll('eptAuthor');
  575. // make sure we have deleted all
  576. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  577. // get book by oid
  578. $this->assertFalse($o = & $m->get('eptAuthor', $oids[$i]));
  579. }
  580. }
  581. /**
  582. * test {@link epManager}: find
  583. * {@link epManager::find()}
  584. */
  585. function _testObjectFindByChild() {
  586. // configure epManager
  587. $this->assertTrue($m = & $this->m);
  588. // use manager to create one object
  589. include_once(EP_TESTS.'/classes/bookstore/src/eptAuthor.php');
  590. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  591. include_once(EP_TESTS.'/classes/bookstore/src/eptContact.php');
  592. include_once(EP_TESTS.'/classes/bookstore/src/eptBookstore.php');
  593. // empty db
  594. $m->deleteAll('eptAuthor');
  595. $m->deleteAll('eptBook');
  596. $m->deleteAll('eptContact');
  597. $m->deleteAll('eptBookstore');
  598. // create self::MAX_ITEMS eptBook's
  599. $oids = array(); // object ids
  600. $names = array(); // author names
  601. $ages = array(); // author ages
  602. $ids = array(); // author ids
  603. $phones = array(); // author.contact phones
  604. $zipcodes = array(); // author.contact zipcodes
  605. $titles = array(); // book titles
  606. $pages = array(); // book pages
  607. $objs = array(); // all objects
  608. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  609. $name = "author-" . md5($i);
  610. $this->assertTrue($o = & $m->create('eptAuthor', $name));
  611. // check title
  612. $this->assertFalse($dirty = $o->epIsDirty());
  613. // call method doNothing should not change dirty flag
  614. $o->doNothing();
  615. $this->assertTrue($o->epIsDirty() == $dirty);
  616. // set name
  617. $this->assertTrue($o->name === $name);
  618. // set id
  619. $id = rand(1, 1000);
  620. //$this->assertTrue($o->setId($id));
  621. $this->assertTrue($o->id = $id);
  622. $this->assertTrue($o->id === $id);
  623. // set ages
  624. $age = rand(1, 120);
  625. $this->assertTrue($o->age = $age);
  626. $this->assertTrue($o->age === $age);
  627. // check dirty flag
  628. $this->assertTrue($o->epIsDirty());
  629. // add the contact
  630. $this->assertTrue($o->contact = $m->create('eptContact'));
  631. $this->assertFalse($o->contact->epIsDirty());
  632. // set phone number
  633. $phone = rand(100, 999)."-456-".rand(1000, 9999);
  634. $this->assertTrue($o->contact->phone = $phone);
  635. $this->assertTrue($o->contact->phone === $phone);
  636. // set the zipcode
  637. $zipcode = rand(10000, 99999);
  638. $this->assertTrue($o->contact->zipcode = $zipcode);
  639. $this->assertTrue($o->contact->zipcode === $zipcode);
  640. // check dirty flag
  641. $this->assertTrue($o->contact->epIsDirty());
  642. // 2 books for each author
  643. for ($j = 0; $j < 2; $j++) {
  644. // add the book
  645. $title = 'title-'.$i.'-'.$j;
  646. $this->assertTrue($o->books[$j] = $m->create('eptBook', $title));
  647. $this->assertFalse($o->books[$j]->epIsDirty());
  648. $this->assertTrue($o->books[$j]->title === $title);
  649. // set author
  650. $this->assertTrue($o->books[$j]->author = $o);
  651. $this->assertTrue($o->books[$j]->author === $o);
  652. // set amount of pages
  653. $page = rand(1, 1000);
  654. $this->assertTrue($o->books[$j]->pages = $page);
  655. $this->assertTrue($o->books[$j]->pages === $page);
  656. $titles[$i][] = $title;
  657. $pages[$i][] = $page;
  658. }
  659. // commit
  660. $this->assertTrue($m->commit($o));
  661. // make sure oid are valid
  662. $this->assertTrue(($oid = $o->epGetObjectId()));
  663. // keep track of oids and pages
  664. $names[] = $name;
  665. $ages[] = $age;
  666. $oids[] = $oid;
  667. $ids[] = $id;
  668. $phones[] = $phone;
  669. $zipcodes[] = $zipcode;
  670. $objs[] = & $o;
  671. }
  672. // test find - all objects are in cache
  673. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  674. // find by book title of author
  675. $eo = & $m->create('eptAuthor'); // example object
  676. // set null to all vars
  677. $eo->uuid = '';
  678. $eo->name = '';
  679. $eo->id = null;
  680. $eo->age = null;
  681. $eo->books[0] = $m->create('eptBook');
  682. $eo->books[0]->title = $titles[$i][0];
  683. $eo->books[0]->uuid = null;
  684. $eo->books[0]->pages = null;
  685. $eo->books[0]->recommended = null;
  686. $eo->books[0]->pubdate = null;
  687. $eo->books[0]->coverimg = null;
  688. $eo->books[0]->excerpt = null;
  689. // match its author up again
  690. $eo->books[0]->author = $eo;
  691. // find each author
  692. $this->assertTrue($os = $m->find($eo, EP_GET_FROM_CACHE));
  693. // example object should be uncommittable
  694. $this->assertFalse($eo->books[0]->epIsCommittable());
  695. $this->assertTrue(count($os) == 1);
  696. $this->assertTrue($os[0]->name === $names[$i]);
  697. // find book by author's contact
  698. for($j = 0; $j < 2; $j++) {
  699. $eb = & $m->create('eptBook');
  700. $eb->uuid = null;
  701. $eb->pages = null;
  702. $eb->recommended = null;
  703. $eb->pubdate = null;
  704. $eb->coverimg = null;
  705. $eb->excerpt = null;
  706. $eb->author = $m->create('eptAuthor');
  707. $eb->author->uuid = '';
  708. $eb->author->name = '';
  709. $eb->author->id = null;
  710. $eb->author->age = null;
  711. $eb->author->contact = $m->create('eptContact');
  712. $eb->author->contact->phone = $phones[$i];
  713. $eb->author->contact->zipcode = null;
  714. $eb->author->contact->uuid = null;
  715. // find the book
  716. $this->assertTrue($os = $m->find($eb, EP_GET_FROM_CACHE));
  717. $this->assertFalse($eb->author->epIsCommittable());
  718. $this->assertFalse($eb->author->contact->epIsCommittable());
  719. $this->assertTrue(count($os) == 2);
  720. $this->assertTrue($os[$j]->title === $titles[$i][$j]);
  721. $this->assertTrue($os[$j]->author->name === $names[$i]);
  722. }
  723. }
  724. // evict and find in cache
  725. $this->assertTrue($m->evictAll('eptAuthor'));
  726. $this->assertTrue($m->evictAll('eptBook'));
  727. $this->assertTrue($m->evictAll('eptContact'));
  728. $this->assertFalse($os = $m->find($eo, EP_GET_FROM_CACHE));
  729. // test find - all objects are in cache
  730. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  731. // find by book title of author
  732. $eo = & $m->create('eptAuthor'); // example object
  733. // set null to all vars
  734. $eo->uuid = '';
  735. $eo->name = '';
  736. $eo->id = null;
  737. $eo->age = null;
  738. $eo->books[0] = $m->create('eptBook');
  739. $eo->books[0]->title = $titles[$i][0];
  740. $eo->books[0]->uuid = null;
  741. $eo->books[0]->pages = null;
  742. $eo->books[0]->recommended = null;
  743. $eo->books[0]->pubdate = null;
  744. $eo->books[0]->coverimg = null;
  745. $eo->books[0]->excerpt = null;
  746. // match its author up again
  747. $eo->books[0]->author = $eo;
  748. // find each author
  749. $this->assertTrue($os = $m->find($eo, EP_GET_FROM_DB));
  750. // example object should be uncommittable
  751. $this->assertFalse($eo->books[0]->epIsCommittable());
  752. $this->assertTrue(count($os) == 1);
  753. $this->assertTrue($os[0]->name === $names[$i]);
  754. // find book by author's contact
  755. for($j = 0; $j < 2; $j++) {
  756. $eb = & $m->create('eptBook');
  757. $eb->uuid = null;
  758. $eb->pages = null;
  759. $eb->recommended = null;
  760. $eb->pubdate = null;
  761. $eb->coverimg = null;
  762. $eb->excerpt = null;
  763. $eb->author = $m->create('eptAuthor');
  764. $eb->author->uuid = '';
  765. $eb->author->name = '';
  766. $eb->author->id = null;
  767. $eb->author->age = null;
  768. $eb->author->contact = $m->create('eptContact');
  769. $eb->author->contact->phone = $phones[$i];
  770. $eb->author->contact->zipcode = null;
  771. $eb->author->contact->uuid = null;
  772. // find the book
  773. $this->assertTrue($os = $m->find($eb, EP_GET_FROM_DB));
  774. $this->assertFalse($eb->author->epIsCommittable());
  775. $this->assertFalse($eb->author->contact->epIsCommittable());
  776. $this->assertTrue(count($os) == 2);
  777. // there is no way to know for certain what order the data comes
  778. // back out. But both of them must come out
  779. if ($os[$j]->title === $titles[$i][$j]) {
  780. $this->assertTrue($os[$j]->title === $titles[$i][$j]);
  781. } else {
  782. $this->assertTrue($os[$j]->title === $titles[$i][$j?0:1]);
  783. }
  784. $this->assertTrue($os[$j]->author->name === $names[$i]);
  785. }
  786. }
  787. // delete all objects
  788. $m->deleteAll('eptAuthor');
  789. $m->deleteAll('eptBook');
  790. $m->deleteAll('eptContact');
  791. $m->deleteAll('eptBookstore');
  792. // make sure we have deleted all
  793. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  794. // get book by oid
  795. $this->assertFalse($o = & $m->get('eptAuthor', $oids[$i]));
  796. }
  797. }
  798. /**
  799. * test {@link epQuery}: query/find
  800. * More complete tests are moved to tests/query/epTestQueryRuntime.php
  801. * !!!Add new test cases there!!!
  802. * {@link epManager::find()}
  803. */
  804. function _testObjectQueryPrimitive() {
  805. $this->assertTrue($m = & $this->m);
  806. // use manager to create one object
  807. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  808. // empty db
  809. $m->deleteAll('eptBook');
  810. // create eptBook's (self::MAX_ITEMS in total)
  811. $bk_oids = array();
  812. $bk_pages = array();
  813. $bk_titles = array();
  814. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  815. $title = "title" . md5($i);
  816. $this->assertTrue($b = & $m->create('eptBook', $title));
  817. // check title
  818. $this->assertFalse($b->epIsDirty());
  819. $this->assertTrue($b->title === $title);
  820. // set pages
  821. $pages = rand(1, 1000);
  822. $this->assertTrue($b->pages = $pages);
  823. $this->assertTrue($b->pages === $pages);
  824. // chech dirty flag
  825. $this->assertTrue($b->epIsDirty());
  826. // commit book
  827. $this->assertTrue($m->commit($b));
  828. // make sure oid are valid
  829. $this->assertTrue(($oid = $b->epGetObjectId()));
  830. // keep track of oids and pages
  831. $bk_oids[] = $oid;
  832. $bk_pages[] = $pages;
  833. $bk_titles[] = $title;
  834. }
  835. // remove all objects from memory
  836. $this->assertTrue($m->evictAll('eptBook'));
  837. // -----------------
  838. // test epQuery here
  839. // -----------------
  840. // test simple expression
  841. $this->assertTrue($os = $m->query("from eptBook as book where book.pages > ?", 0));
  842. $this->assertTrue(count($os) == self::MAX_ITEMS);
  843. $this->assertTrue($m->count('eptBook') == self::MAX_ITEMS);
  844. // test like
  845. $this->assertTrue($os = $m->query("from eptBook as book where book.title LIKE 'title%'"));
  846. $this->assertTrue(count($os) == self::MAX_ITEMS);
  847. $this->assertTrue($m->count('eptBook') == self::MAX_ITEMS);
  848. // count array values
  849. $value_counts = array_count_values($bk_pages);
  850. // search book by book title
  851. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  852. // find book by title
  853. $this->assertTrue($os = $m->query("from eptBook as book where book.title = ?", $bk_titles[$i]));
  854. $this->assertTrue(count($os) == 1);
  855. $this->assertTrue($os[0]->pages == $bk_pages[$i]);
  856. // find book by pages
  857. $this->assertTrue($os = $m->query("from eptBook as book where book.pages = ?", $bk_pages[$i]));
  858. $this->assertTrue(count($os) == $value_counts[$bk_pages[$i]]);
  859. }
  860. // clean up
  861. $m->deleteAll('eptBook');
  862. $m->deleteAll('eptAuthor');
  863. }
  864. /**
  865. * test {@link epQuery}: query/find (with relationship fields)
  866. * More complete tests are moved to tests/query/epTestQueryRuntime.php
  867. * !!!Add new test cases there!!!
  868. * {@link epManager::find()}
  869. */
  870. function _testObjectQueryRelationship() {
  871. $this->assertTrue($m = & $this->m);
  872. // use manager to create one object
  873. include_once(EP_TESTS.'/classes/bookstore/src/eptAuthor.php');
  874. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  875. // empty db
  876. $m->deleteAll('eptAuthor');
  877. $m->deleteAll('eptBook');
  878. // -----------------------------------------------------
  879. // create one author
  880. $name = "author-test";
  881. $this->assertTrue($a = $m->create('eptAuthor', $name));
  882. // check title
  883. $this->assertFalse($a->epIsDirty());
  884. $this->assertTrue($a->name === $name);
  885. // set id
  886. $id = rand(1, 1000);
  887. $this->assertTrue($a->id = $id);
  888. $this->assertTrue($a->id === $id);
  889. // set ages
  890. $age = rand(1, 120);
  891. $this->assertTrue($a->age = $age);
  892. $this->assertTrue($a->age === $age);
  893. // chech dirty flag
  894. $this->assertTrue($a->epIsDirty());
  895. // commit
  896. $this->assertTrue($m->commit($a));
  897. // make sure oid are valid
  898. $this->assertTrue(($oid = $a->epGetObjectId()));
  899. // -----------------------------------------------------
  900. // create eptBook's (self::MAX_ITEMS in total)
  901. $bk_oids = array();
  902. $bk_pages = array();
  903. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  904. $title = "title" . md5($i);
  905. $this->assertTrue($b = $m->create('eptBook', $title));
  906. // check title
  907. $this->assertFalse($b->epIsDirty());
  908. $this->assertTrue($b->title === $title);
  909. // set pages
  910. $pages = rand(1, 1000);
  911. $this->assertTrue($b->pages = $pages);
  912. $this->assertTrue($b->pages === $pages);
  913. // chech dirty flag
  914. $this->assertTrue($b->epIsDirty());
  915. // set author to book
  916. $this->assertTrue($b->author = $a);
  917. // add book into author
  918. if (!($books = $a->books)) {
  919. $books = array();
  920. }
  921. $books[] = $b;
  922. // assign books to author's books
  923. $this->assertTrue($a->books = $books);
  924. $this->assertTrue(count($a->books) == count($books));
  925. $this->assertTrue($b->epIsDirty());
  926. // commit book
  927. $this->assertTrue($m->commit($b));
  928. // make sure oid are valid
  929. $this->assertTrue(($oid = $b->epGetObjectId()));
  930. // keep track of oids and pages
  931. $bk_oids[] = $oid;
  932. $bk_pages[] = $pages;
  933. }
  934. // make sure the author has the right number of books
  935. if (version_compare(phpversion(), "5.1.0", "<")) {
  936. $this->assertTrue($a->books->count() == self::MAX_ITEMS);
  937. } else {
  938. $this->assertTrue(count($a->books) == self::MAX_ITEMS);
  939. }
  940. // -----------------------------------------------------
  941. // remove all objects from memory
  942. $this->assertTrue($m->evictAll('eptAuthor'));
  943. $this->assertTrue($m->evictAll('eptBook'));
  944. // make sure author is gone
  945. $this->assertFalse($a);
  946. // test 1
  947. $this->assertTrue($os = $m->query("from eptAuthor as a where a.books.contains(book) and book.pages > ?", 0));
  948. $this->assertTrue(count($os) == $m->count('eptAuthor'));
  949. // test 2
  950. $this->assertTrue($os = $m->query("from eptAuthor as a where a.books.contains(book) and book.title LIKE 'title%'"));
  951. $this->assertTrue(count($os) == $m->count('eptAuthor'));
  952. // test 3
  953. $this->assertTrue($os = $m->query("from eptAuthor as a where a.books.contains(b) and b.author.name like 'author-test%'"));
  954. $this->assertTrue(count($os) == $m->count('eptAuthor'));
  955. // test 4
  956. $this->assertTrue($os = $m->query("from eptAuthor as a where a.books.contains(b) and b.author.books.contains(b2) and b2.title like 'title%'"));
  957. $this->assertTrue(count($os) == $m->count('eptAuthor'));
  958. // clean up
  959. $m->deleteAll('eptBook');
  960. $m->deleteAll('eptAuthor');
  961. }
  962. /**
  963. * test {@link epManager}
  964. * {@link epManager::find()}
  965. */
  966. function _testObjectRelation() {
  967. // get the manager
  968. $this->assertTrue($m = & $this->m);
  969. // use manager to create one object
  970. include_once(EP_TESTS.'/classes/bookstore/src/eptAuthor.php');
  971. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  972. include_once(EP_TESTS.'/classes/bookstore/src/eptBookstore.php');
  973. // empty db
  974. $m->deleteAll('eptAuthor');
  975. $m->deleteAll('eptBook');
  976. // -----------------------------------------------------
  977. // create one author
  978. $name = "author-test";
  979. $this->assertTrue($a = $m->create('eptAuthor', $name));
  980. // check title
  981. $this->assertFalse($a->epIsDirty());
  982. $this->assertTrue($a->name === $name);
  983. // set id
  984. $id = rand(1, 1000);
  985. $this->assertTrue($a->id = $id);
  986. $this->assertTrue($a->id === $id);
  987. // set ages
  988. $age = rand(1, 120);
  989. $this->assertTrue($a->age = $age);
  990. $this->assertTrue($a->age === $age);
  991. // chech dirty flag
  992. $this->assertTrue($a->epIsDirty());
  993. // commit
  994. $this->assertTrue($m->commit($a));
  995. // make sure oid are valid
  996. $this->assertTrue(($a_oid = $a->epGetObjectId()));
  997. // -----------------------------------------------------
  998. $storename = 'store';
  999. $this->assertTrue($s = $m->create('eptBookstore', $storename));
  1000. // check title
  1001. $this->assertFalse($s->epIsDirty());
  1002. $this->assertTrue($s->name === $storename);
  1003. // commit
  1004. $this->assertTrue($m->commit($s));
  1005. // make sure oid are valid
  1006. $this->assertTrue(($s_oid = $s->epGetObjectId()));
  1007. // -----------------------------------------------------
  1008. // create eptBook's (self::MAX_ITEMS in total)
  1009. $bk_oids = array();
  1010. $bk_pages = array();
  1011. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  1012. $title = "title" . md5($i);
  1013. $this->assertTrue($b = $m->create('eptBook', $title));
  1014. // check title
  1015. $this->assertFalse($b->epIsDirty());
  1016. $this->assertTrue($b->title === $title);
  1017. // set pages
  1018. $pages = rand(1, 1000);
  1019. $this->assertTrue($b->pages = $pages);
  1020. $this->assertTrue($b->pages === $pages);
  1021. // check dirty flag
  1022. $this->assertTrue($b->epIsDirty());
  1023. // check modified vars (both)
  1024. $this->assertTrue($modified_vars = $b->epGetModifiedVars());
  1025. $this->assertTrue(count($modified_vars) == 1);
  1026. $this->assertTrue($modified_vars['pages'] == $pages);
  1027. // check modified vars (primitive)
  1028. $this->assertTrue($modified_vars = $b->epGetModifiedVars(epObject::VAR_PRIMITIVE));
  1029. $this->assertTrue(count($modified_vars) == 1);
  1030. $this->assertTrue($modified_vars['pages'] == $pages);
  1031. // check modified vars (relationship)
  1032. $this->assertFalse($modified_vars = $b->epGetModifiedVars(epObject::VAR_RELATIONSHIP));
  1033. // set author to book
  1034. $this->assertTrue($b->author = $a);
  1035. $this->assertTrue($b->bookstore = $s);
  1036. // check modified vars
  1037. $this->assertTrue($modified_vars = $b->epGetModifiedVars());
  1038. $this->assertTrue(count($modified_vars) == 3);
  1039. $this->assertTrue($modified_vars['pages'] == $pages);
  1040. $this->assertTrue($modified_vars['author'] == true);
  1041. // check modified vars (primitive)
  1042. $this->assertTrue($modified_vars = $b->epGetModifiedVars(epObject::VAR_PRIMITIVE));
  1043. $this->assertTrue(count($modified_vars) == 1);
  1044. $this->assertTrue($modified_vars['pages'] == $pages);
  1045. // check modified vars (relationship)
  1046. $this->assertTrue($modified_vars = $b->epGetModifiedVars(epObject::VAR_RELATIONSHIP));
  1047. $this->assertTrue(count($modified_vars) == 2);
  1048. $this->assertTrue($modified_vars['author'] == true);
  1049. $this->assertTrue($modified_vars['bookstore'] == true);
  1050. // add book into author
  1051. if (!($books = $a->books)) {
  1052. $books = array();
  1053. }
  1054. $books[] = $b;
  1055. // assign books to author's books
  1056. $this->assertTrue($a->books = $books);
  1057. $this->assertTrue(count($a->books) == count($books));
  1058. // add book into bookstore
  1059. if (!($books = $s->books)) {
  1060. $books = array();
  1061. }
  1062. $books[] = $b;
  1063. // assign books to author's books
  1064. $this->assertTrue($s->books = $books);
  1065. $this->assertTrue(count($s->books) == count($books));
  1066. $this->assertTrue($b->epIsDirty());
  1067. // commit book
  1068. $this->assertTrue($m->commit($b));
  1069. // make sure oid are valid
  1070. $this->assertTrue(($oid = $b->epGetObjectId()));
  1071. // keep track of oids and pages
  1072. $bk_oids[] = $oid;
  1073. $bk_pages[] = $pages;
  1074. }
  1075. // make sure the author has the right number of books
  1076. if (version_compare(phpversion(), "5.1.0", "<")) {
  1077. $this->assertTrue($a->books->count() == self::MAX_ITEMS);
  1078. } else {
  1079. $this->assertTrue(count($a->books) == self::MAX_ITEMS);
  1080. }
  1081. // -----------------------------------------------------
  1082. // remove all objects from memory
  1083. $this->assertTrue($m->evictAll('eptAuthor'));
  1084. $this->assertTrue($m->evictAll('eptBook'));
  1085. // make sure author is gone
  1086. $this->assertFalse($a);
  1087. // retrieve author, change a value and recommit
  1088. // other values should not have changed
  1089. $this->assertTrue($a =& $m->get('eptAuthor', $a_oid));
  1090. // check old id, change id
  1091. $this->assertFalse($a->epIsDirty());
  1092. $this->assertTrue($a->id === $id);
  1093. $id = rand(1, 1000);
  1094. $this->assertTrue($a->id = $id);
  1095. $this->assertTrue($a->id === $id);
  1096. // chech dirty flag
  1097. $this->assertTrue($a->epIsDirty());
  1098. // commit
  1099. $this->assertTrue($m->commit($a));
  1100. // make sure oid are valid
  1101. $this->assertTrue(($a_oid = $a->epGetObjectId()));
  1102. // remove all objects from memory
  1103. $this->assertTrue($m->evictAll('eptAuthor'));
  1104. $this->assertTrue($m->evictAll('eptBook'));
  1105. // make sure author is gone
  1106. $this->assertFalse($a);
  1107. // all values should be good
  1108. $this->assertTrue($a =& $m->get('eptAuthor', $a_oid));
  1109. // check title
  1110. $this->assertFalse($a->epIsDirty());
  1111. $this->assertTrue($a->name === $name);
  1112. // set id
  1113. $this->assertTrue($a->id === $id);
  1114. // set ages
  1115. $this->assertTrue($a->age === $age);
  1116. // make sure the author has the right number of books
  1117. if (version_compare(phpversion(), "5.1.0", "<")) {
  1118. $this->assertTrue($a->books->count() == self::MAX_ITEMS);
  1119. } else {
  1120. $this->assertTrue(count($a->books) == self::MAX_ITEMS);
  1121. }
  1122. // -----------------------------------------------------
  1123. // remove all objects from memory
  1124. $this->assertTrue($m->evictAll('eptAuthor'));
  1125. $this->assertTrue($m->evictAll('eptBook'));
  1126. // make sure author is gone
  1127. $this->assertFalse($a);
  1128. // retrieve books one by one and check its author
  1129. $a0 = false;
  1130. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  1131. // get book by oid
  1132. $this->assertTrue($b = $m->get('eptBook', $bk_oids[$i]));
  1133. // check pages
  1134. $this->assertTrue($b->pages == $bk_pages[$i]);
  1135. // check author
  1136. $this->assertNotNull($a = $b->author);
  1137. // same author (ref)
  1138. if ($a0 && $a) {
  1139. $this->assertTrue($a0 === $a);
  1140. }
  1141. // does it have the right author
  1142. $this->assertTrue($a->name === $name);
  1143. // does it have the right age
  1144. $this->assertTrue($a->age == $age);
  1145. // does it have the right id
  1146. $this->assertTrue($a->id == $id);
  1147. // check books the author has is self::MAX_ITEMS
  1148. if ($a->books instanceof epArray) {
  1149. if (version_compare(phpversion(), "5.1.0", "<")) {
  1150. $this->assertTrue($a->books->count() == self::MAX_ITEMS);
  1151. } else {
  1152. $this->assertTrue(count($a->books) == self::MAX_ITEMS);
  1153. }
  1154. } else {
  1155. $this->assertTrue(count($a->books) == self::MAX_ITEMS);
  1156. }
  1157. $a0 = & $a;
  1158. }
  1159. // remove author from book
  1160. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  1161. // get book by oid
  1162. $this->assertTrue($b = $m->get('eptBook', $bk_oids[$i]));
  1163. // check pages
  1164. $this->assertTrue($b->pages == $bk_pages[$i]);
  1165. // remove author
  1166. $b->author = null;
  1167. // commit
  1168. $m->commit($b);
  1169. $this->assertFalse($b->author

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