PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/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
  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);
  1170. }
  1171. // remove all objects from memory
  1172. $this->assertTrue($m->evictAll('eptAuthor'));
  1173. $this->assertTrue($m->evictAll('eptBook'));
  1174. // check if author is removed from each book
  1175. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  1176. // get book by oid
  1177. $this->assertTrue($b = $m->get('eptBook', $bk_oids[$i]));
  1178. // check pages
  1179. $this->assertTrue($b->pages == $bk_pages[$i]);
  1180. // author must have been removed
  1181. $this->assertFalse($b->author);
  1182. }
  1183. // check if each book is removed from the author
  1184. $this->assertTrue($a = $m->get('eptAuthor', $a_oid));
  1185. if ($a->books instanceof epArray) {
  1186. if (version_compare(phpversion(), "5.1.0", "<")) {
  1187. $this->assertTrue($a->books->count() == self::MAX_ITEMS);
  1188. } else {
  1189. $this->assertTrue(count($a->books) == self::MAX_ITEMS);
  1190. }
  1191. } else {
  1192. $this->assertTrue(count($a->books) == self::MAX_ITEMS);
  1193. }
  1194. foreach ($a->books as $k => $b) {
  1195. // redundant check
  1196. $this->assertTrue($a->books->inArray($b));
  1197. // remove the book
  1198. $a->books[$k] = null;
  1199. // commit the changes
  1200. $this->assertTrue($m->commit($a));
  1201. // make sure the book has been removed
  1202. $this->assertFalse($a->books->inArray($b));
  1203. }
  1204. // remove all objects from memory
  1205. $this->assertTrue($m->evictAll('eptAuthor'));
  1206. $this->assertTrue($m->evictAll('eptBook'));
  1207. $this->assertTrue($a = $m->get('eptAuthor', $a_oid));
  1208. if ($a->books instanceof epArray) {
  1209. if (version_compare(phpversion(), "5.1.0", "<")) {
  1210. $this->assertTrue($a->books->count() == 0);
  1211. } else {
  1212. $this->assertTrue(count($a->books) == 0);
  1213. }
  1214. } else {
  1215. $this->assertTrue(count($a->books) == 0);
  1216. }
  1217. // -----------------------------------------------------
  1218. // check for bug #142
  1219. // reconnect the authors and books
  1220. // remove all objects from memory
  1221. $this->assertTrue($m->evictAll('eptAuthor'));
  1222. $this->assertTrue($m->evictAll('eptBook'));
  1223. $this->assertTrue($m->evictAll('eptBookstore'));
  1224. $this->assertTrue($a =& $m->get('eptAuthor', $a_oid));
  1225. $this->assertTrue($s =& $m->get('eptBookstore', $s_oid));
  1226. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  1227. // get book by oid
  1228. $this->assertTrue($b = $m->get('eptBook', $bk_oids[$i]));
  1229. // check pages
  1230. $this->assertTrue($b->pages == $bk_pages[$i]);
  1231. // check bookstore
  1232. $this->assertTrue($b->bookstore === $s);
  1233. $this->assertTrue($b->author = $a);
  1234. // add book into author
  1235. if (!($books = $a->books)) {
  1236. $books = array();
  1237. }
  1238. $books[] = $b;
  1239. // assign books to author's books
  1240. $this->assertTrue($a->books = $books);
  1241. $this->assertTrue(count($a->books) == count($books));
  1242. $this->assertTrue($b->epIsDirty());
  1243. // commit book
  1244. $this->assertTrue($m->commit($b));
  1245. // make sure oid are valid
  1246. $this->assertTrue(($oid = $b->epGetObjectId()));
  1247. }
  1248. // now delete each book and check to see if both
  1249. // the publisher's and author's book counts go down
  1250. for($i = 0; $i < self::MAX_ITEMS; $i ++) {
  1251. // get book by oid
  1252. $this->assertTrue($b =& $m->get('eptBook', $bk_oids[$i]));
  1253. // check pages
  1254. $this->assertTrue($b->pages == $bk_pages[$i]);
  1255. $m->delete($b);
  1256. // we want to check that it is out of memory and database
  1257. // but this is impossible because the reference in store::books
  1258. // is different than the one that is being deleted
  1259. // for some reason, though, it doesn't have this problem with
  1260. // authors::books
  1261. $this->assertTrue($m->evictAll('eptAuthor'));
  1262. $this->assertTrue($m->evictAll('eptBook'));
  1263. $this->assertTrue($m->evictAll('eptBookstore'));
  1264. $this->assertTrue($a =& $m->get('eptAuthor', $a_oid));
  1265. $this->assertTrue($s =& $m->get('eptBookstore', $s_oid));
  1266. if ($a->books instanceof epArray) {
  1267. if (version_compare(phpversion(), "5.1.0", "<")) {
  1268. $this->assertTrue($a->books->count() == self::MAX_ITEMS - $i - 1);
  1269. } else {
  1270. $this->assertTrue(count($a->books) == self::MAX_ITEMS - $i - 1);
  1271. }
  1272. } else {
  1273. $this->assertTrue(count($a->books) == self::MAX_ITEMS - $i - 1);
  1274. }
  1275. if ($s->books instanceof epArray) {
  1276. if (version_compare(phpversion(), "5.1.0", "<")) {
  1277. $this->assertTrue($s->books->count() == self::MAX_ITEMS - $i - 1);
  1278. } else {
  1279. $this->assertTrue(count($s->books) == self::MAX_ITEMS - $i - 1);
  1280. }
  1281. } else {
  1282. $this->assertTrue(count($s->books) == self::MAX_ITEMS - $i - 1);
  1283. }
  1284. }
  1285. // -----------------------------------------------------
  1286. // clean up
  1287. $m->deleteAll('eptAuthor');
  1288. $m->deleteAll('eptBook');
  1289. }
  1290. /**
  1291. * test bug 234, all relationships deleted after
  1292. * creating and deleting in memory objects without commit it
  1293. */
  1294. function _testRelationsDeletes() {
  1295. $this->assertTrue($m = & $this->m);
  1296. // use manager to create one object
  1297. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  1298. // delete all books
  1299. $m->deleteAll('eptBook');
  1300. $m->setConfigOption('log_queries', true);
  1301. //
  1302. // new object | delete | check queries
  1303. //
  1304. // test object creation
  1305. $title = md5('eptBook');
  1306. $this->assertTrue($o = $m->create('eptBook', $title));
  1307. $this->assertTrue($o->title === $title);
  1308. $this->assertFalse($o->epIsDirty());
  1309. $this->assertFalse($o->epGetObjectId());
  1310. // del object
  1311. $o->delete();
  1312. $queries = $this->m->getQueries();
  1313. // no queries executed when objects are still in memory
  1314. $this->assertFalse( count($queries = array_shift( $queries )) );
  1315. // delete all books
  1316. $m->deleteAll('eptBook');
  1317. }
  1318. /**
  1319. * test {@link epManager}: deletion of composed_of fields
  1320. * {@link epManager::delete()}
  1321. */
  1322. function _testComposedOfDelete() {
  1323. // get the manager
  1324. $this->assertTrue($m = & $this->m);
  1325. // use manager to create one object
  1326. include_once(EP_TESTS.'/classes/bookstore/src/eptAuthor.php');
  1327. // empty db: author and contact
  1328. $m->deleteAll('eptAuthor');
  1329. $m->deleteAll('eptContact');
  1330. // -----------------------------------------------------
  1331. // create an author
  1332. $name = "author-test";
  1333. $this->assertTrue($a = $m->create('eptAuthor', $name));
  1334. // check title
  1335. $this->assertFalse($a->epIsDirty());
  1336. $this->assertTrue($a->name === $name);
  1337. // set id
  1338. $id = rand(1, 1000);
  1339. $this->assertTrue($a->id = $id);
  1340. $this->assertTrue($a->id === $id);
  1341. // set ages
  1342. $age = rand(1, 120);
  1343. $this->assertTrue($a->age = $age);
  1344. $this->assertTrue($a->age === $age);
  1345. // commit
  1346. $this->assertTrue($a->epIsDirty());
  1347. $this->assertTrue($m->commit($a));
  1348. $this->assertTrue(($oid = $a->epGetObjectId()));
  1349. // get author oid to be used later
  1350. $this->assertTrue($a_oid = $a->epGetObjectId());
  1351. // -----------------------------------------------------
  1352. // create a contact
  1353. $this->assertTrue($c = $m->create('eptContact', $name));
  1354. // set phone
  1355. $phone = '123-456-789';
  1356. $this->assertTrue($c->phone = $phone);
  1357. $this->assertTrue($c->phone === $phone);
  1358. // set zipcode
  1359. $zipcode = '54321';
  1360. $this->assertTrue($c->zipcode = $zipcode);
  1361. $this->assertTrue($c->zipcode === $zipcode);
  1362. // commit
  1363. $this->assertTrue($c->epIsDirty());
  1364. $this->assertTrue($m->commit($c));
  1365. $this->assertFalse($c->epIsDirty());
  1366. // get contact oid to be used later
  1367. $this->assertTrue($c_oid = $c->epGetObjectId());
  1368. // -----------------------------------------------------
  1369. // assign contact to author and commit
  1370. $this->assertTrue($a->contact = $c);
  1371. $this->assertTrue($a->epIsDirty());
  1372. $this->assertTrue($m->commit($a));
  1373. $this->assertFalse($a->epIsDirty());
  1374. // -----------------------------------------------------
  1375. // remove author and contact from memory
  1376. $this->assertTrue($m->evictAll('eptAuthor'));
  1377. $this->assertTrue($m->evictAll('eptContact'));
  1378. // make sure author is gone
  1379. $this->assertFalse($a);
  1380. $this->assertFalse($c);
  1381. // read author back
  1382. $this->assertTrue($a = & $m->get('eptAuthor', $a_oid));
  1383. // check its primitive fields
  1384. $this->assertTrue($a->name === $name);
  1385. $this->assertTrue($a->id === $id);
  1386. $this->assertTrue($a->age === $age);
  1387. // check fields in the contact
  1388. $this->assertTrue($a->contact->phone === $phone);
  1389. $this->assertTrue($a->contact->zipcode === $zipcode);
  1390. // -----------------------------------------------------
  1391. // test delete author
  1392. //$c = & $a->getContact();
  1393. $this->assertTrue($m->delete($a));
  1394. $this->assertFalse($a);
  1395. //$this->assertFalse($c);
  1396. // make sure we can't find author and contact any more
  1397. $this->assertFalse($a = $m->get('eptAuthor', $a_oid));
  1398. $this->assertFalse($a = $m->get('eptContact', $c_oid));
  1399. // -----------------------------------------------------
  1400. // clean up
  1401. $m->deleteAll('eptAuthor');
  1402. $m->deleteAll('eptContact');
  1403. }
  1404. /**
  1405. * Test epObject::epStartTransaction() and epEndTransaction()
  1406. */
  1407. function _testTransactionObject() {
  1408. $this->assertTrue($m = & $this->m);
  1409. // use manager to create one object
  1410. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  1411. // delete all books
  1412. $m->deleteAll('eptBook');
  1413. //
  1414. // 1. create object (no rollback)
  1415. //
  1416. // test object creation
  1417. $title = md5('eptBook');
  1418. $this->assertTrue($o = $m->create('eptBook', $title));
  1419. $this->assertFalse($o->epIsDirty());
  1420. $this->assertTrue($o->title === $title);
  1421. $this->assertFalse($o->epIsDirty());
  1422. // signal object the start of transaction
  1423. $this->assertTrue($o->epStartTransaction());
  1424. // signal object the start of transaction (without rollback)
  1425. $this->assertTrue($o->epEndTransaction());
  1426. // everything remains the same
  1427. $this->assertTrue($o->title === $title);
  1428. $this->assertFalse($o->epIsDirty());
  1429. $this->assertFalse($o->epGetObjectId());
  1430. //
  1431. // 2. change object (with rollback)
  1432. //
  1433. // signal object the start of transaction
  1434. $this->assertTrue($o->epStartTransaction());
  1435. $this->assertTrue($o->epInTransaction());
  1436. $title_0 = $title;
  1437. $title = md5($title_0);
  1438. $o->title = $title;
  1439. // signal object the start of transaction (true: with rollback)
  1440. $this->assertTrue($o->epEndTransaction(true));
  1441. $this->assertFalse($o->epInTransaction());
  1442. $this->assertTrue($o->title === $title_0);
  1443. $this->assertFalse($o->epIsDirty());
  1444. $this->assertFalse($o->epGetObjectId());
  1445. //
  1446. // 3. change object (without rollback)
  1447. //
  1448. // signal object the start of transaction
  1449. $this->assertTrue($o->epStartTransaction());
  1450. $this->assertTrue($o->epInTransaction());
  1451. $title_0 = $title;
  1452. $title = md5($title_0);
  1453. $o->title = $title;
  1454. // signal object the start of transaction (false (default): with rollback)
  1455. $this->assertTrue($o->epEndTransaction());
  1456. $this->assertFalse($o->epInTransaction());
  1457. $this->assertTrue($o->title == $title); // new value
  1458. $this->assertTrue($o->epIsDirty()); // now dirty
  1459. $this->assertFalse($o->epGetObjectId()); // still no oid
  1460. //
  1461. // 4. commit object (with rollback)
  1462. //
  1463. // signal object the start of transaction
  1464. $this->assertTrue($o->epStartTransaction());
  1465. $this->assertTrue($o->epInTransaction());
  1466. // commit (save) object so we get valid oid
  1467. $this->assertTrue($o->commit());
  1468. $this->assertTrue($o->epGetObjectId()); // valid oid
  1469. // signal object the start of transaction (false (default): with rollback)
  1470. $this->assertTrue($o->epEndTransaction(true));
  1471. $this->assertFalse($o->epInTransaction());
  1472. // after rollback still no object id
  1473. $this->assertFalse($o->epGetObjectId()); // no oid
  1474. // delete all books
  1475. $m->deleteAll('eptBook');
  1476. }
  1477. /**
  1478. * Test transaction: start and commit
  1479. */
  1480. function _testTransactionStartCommit() {
  1481. $this->assertTrue($m = & $this->m);
  1482. // use manager to create one object
  1483. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  1484. // delete all books
  1485. $m->deleteAll('eptBook');
  1486. // start transaction
  1487. $this->assertTrue($m->start_t());
  1488. // test object creation
  1489. $title = md5('eptBook');
  1490. $this->assertTrue($o = $m->create('eptBook', $title));
  1491. $this->assertFalse($o->epIsDirty());
  1492. $this->assertTrue($o->title === $title);
  1493. $this->assertFalse($o->epIsDirty());
  1494. $this->assertFalse(($oid = $o->epGetObjectId()));
  1495. // commit transaction
  1496. $this->assertTrue($m->commit_t());
  1497. // check object id
  1498. $this->assertTrue(($oid = $o->epGetObjectId()));
  1499. // delete all books
  1500. $m->deleteAll('eptBook');
  1501. }
  1502. /**
  1503. * Transaction: start and rollback
  1504. */
  1505. function _testTransactionStartRollback() {
  1506. $this->assertTrue($m = & $this->m);
  1507. // use manager to create one object
  1508. include_once(EP_TESTS.'/classes/bookstore/src/eptBook.php');
  1509. // delete all books
  1510. $m->deleteAll('eptBook');
  1511. //
  1512. // start | new object | change object | rollback
  1513. //
  1514. // start transaction
  1515. $this->assertTrue($m->start_t());
  1516. // test object creation
  1517. $title = md5('eptBook');
  1518. $this->assertTrue($o = $m->create('eptBook', $title));
  1519. $this->assertTrue($o->title === $title);
  1520. $this->assertFalse($o->epIsDirty());
  1521. $this->assertFalse($o->epGetObjectId());
  1522. // rollback transaction
  1523. $this->assertTrue($m->rollback_t());
  1524. // check object
  1525. $this->assertFalse($o->epGetObjectId());
  1526. $this->assertTrue($o->title == $title);
  1527. //
  1528. // 2. change object | rollback
  1529. //
  1530. // start transaction
  1531. $this->assertTrue($m->start_t());
  1532. $title_0 = $title;
  1533. $title = md5($title_0);
  1534. $o->title = $title;
  1535. // rollback transaction
  1536. $this->assertTrue($m->rollback_t());
  1537. // check object
  1538. $this->assertTrue($o->title == $title_0);
  1539. $this->assertFalse($o->epGetObjectId());
  1540. // delete all books
  1541. $m->deleteAll('eptBook');
  1542. }
  1543. /**
  1544. * Transaction: end and rollback
  1545. * tests bug #217 after rollback some objects remain in db
  1546. */
  1547. function _testTransactionEndRollback() {
  1548. $this->assertTrue($m = & $this->m);
  1549. // use manager to create one object
  1550. include_once(EP_TESTS.'/classes/bookstore/src/eptAuthor.php');
  1551. // delete all authors and its contacts
  1552. $m->deleteAll('eptAuthor');
  1553. //
  1554. // start | new object | change object | commit (1)
  1555. //
  1556. try{
  1557. // start transaction
  1558. $this->assertTrue($m->start_t());
  1559. // test object creation
  1560. $this->assertTrue($c = $m->create('eptContact'));
  1561. $this->assertFalse($c->epIsDirty());
  1562. $this->assertFalse($c->epGetObjectId());
  1563. // test object creation
  1564. $name = 'eptAuthor';
  1565. $this->assertTrue($o = $m->create('eptAuthor', $name));
  1566. $this->assertTrue($o->name === $name);
  1567. $this->assertFalse($o->epIsDirty());
  1568. $this->assertFalse($o->epGetObjectId());
  1569. $o->contact = $c;
  1570. // commit transaction first time
  1571. $this->assertTrue($m->commit_t());
  1572. //
  1573. // start | new object | change object | commit (2)
  1574. //
  1575. // start transaction
  1576. $this->assertTrue($m->start_t());
  1577. // test object creation
  1578. $this->assertTrue($c1 = $m->create('eptContact'));
  1579. $this->assertFalse($c1->epIsDirty());
  1580. $this->assertFalse($c1->epGetObjectId());
  1581. // test object creation
  1582. $name = 'eptAuthor'; //fails to insert duplicated author
  1583. $this->assertTrue($o1 = $m->create('eptAuthor', $name));
  1584. $this->assertTrue($o1->name === $name);
  1585. $this->assertFalse($o1->epIsDirty());
  1586. $this->assertFalse($o1->epGetObjectId());
  1587. $o1->contact = $c1;
  1588. // commit transaction with auto rollback
  1589. // this will fail and one spare contact is in db due to bug #217
  1590. $m->commit_t();
  1591. }catch (Exception $e){
  1592. $cs = $m->get('eptContact');
  1593. //no more than one contact must exist
  1594. $this->assertTrue(count($cs) == 0);
  1595. }
  1596. // delete all authors
  1597. $m->deleteAll('eptAuthor');
  1598. }
  1599. /**
  1600. * Run all tests
  1601. * @param string $dbal (adodb, peardb)
  1602. * @param string $dbtype (mysql, sqlite)
  1603. */
  1604. function _allTests($dbal, $dbtype) {
  1605. echo "tests for $dbal/$dbtype started.. " . epNewLine();
  1606. echo " setup..";
  1607. $this->_setUp($dbal, $dbtype);
  1608. echo "done " . epNewLine();
  1609. echo " single object..";
  1610. $this->_testSingleObject();
  1611. echo "done " . epNewLine();
  1612. echo " multiple objects..";
  1613. $this->_testMultiObjects();
  1614. echo "done " . epNewLine();
  1615. echo " array sort by..";
  1616. $this->_testArraySortBy();
  1617. echo "done " . epNewLine();
  1618. echo " array to object..";
  1619. $this->_testCreateFromArray();
  1620. echo "done " . epNewLine();
  1621. echo " data typess..";
  1622. $this->_testDataTypes();
  1623. echo "done " . epNewLine();
  1624. echo " find objects..";
  1625. $this->_testObjectFind();
  1626. echo "done " . epNewLine();
  1627. echo " find objects by child..";
  1628. $this->_testObjectFindByChild();
  1629. echo "done " . epNewLine();
  1630. echo " object query primitive..";
  1631. $this->_testObjectQueryPrimitive();
  1632. echo "done " . epNewLine();
  1633. echo " object query relationship..";
  1634. $this->_testObjectQueryRelationship();
  1635. echo "done " . epNewLine();
  1636. echo " object relationship..";
  1637. $this->_testObjectRelation();
  1638. echo "done " . epNewLine();
  1639. echo " object relationship deletion..";
  1640. $this->_testRelationsDeletes();
  1641. echo "done " . epNewLine();
  1642. echo " composed delete..";
  1643. $this->_testComposedOfDelete();
  1644. echo "done " . epNewLine();
  1645. echo " object transaction..";
  1646. $this->_testTransactionObject();
  1647. echo "done " . epNewLine();
  1648. echo " transaction: commit..";
  1649. $this->_testTransactionStartCommit();
  1650. echo "done " . epNewLine();
  1651. echo " transaction: rollback..";
  1652. $this->_testTransactionStartRollback();
  1653. echo "done " . epNewLine();
  1654. echo " transaction: rollback surplus..";
  1655. $this->_testTransactionEndRollback();
  1656. echo "done " . epNewLine();
  1657. echo " complete!" . epNewLine();
  1658. }
  1659. /**
  1660. * Test adodb & mysql
  1661. */
  1662. function testAdodbMysql() {
  1663. // skip testing adodb + mysql if not allowed
  1664. if (!$this->canTestAdodb() || !$this->canTestMysql()) {
  1665. return;
  1666. }
  1667. $this->_allTests('adodb', 'mysql');
  1668. }
  1669. /**
  1670. * Test peardb & mysql
  1671. */
  1672. function testPearMysql() {
  1673. // skip testing peardb + mysql if not allowed
  1674. if (!$this->canTestPeardb() || !$this->canTestMysql()) {
  1675. return;
  1676. }
  1677. $this->_allTests('peardb', 'mysql');
  1678. }
  1679. /**
  1680. * Test pdo & mysql
  1681. */
  1682. function testPdoMysql() {
  1683. // skip testing pdo + mysql if not allowed
  1684. if (!$this->canTestPdo('mysql') || !$this->canTestMysql()) {
  1685. return;
  1686. }
  1687. $this->_allTests('pdo', 'mysql');
  1688. }
  1689. /**
  1690. * Test adodb & pgsql
  1691. */
  1692. function testAdodbPgsql() {
  1693. // skip testing adodb + pgsql if not allowed
  1694. if (!$this->canTestAdodb() || !$this->canTestPgsql()) {
  1695. return;
  1696. }
  1697. $this->_allTests('adodb', 'pgsql');
  1698. }
  1699. /**
  1700. * Test peardb & pgsql
  1701. */
  1702. function testPearPgsql() {
  1703. // skip testing peardb + mysql if not allowed
  1704. if (!$this->canTestPeardb() || !$this->canTestPgsql()) {
  1705. return;
  1706. }
  1707. $this->_allTests('peardb', 'pgsql');
  1708. }
  1709. /**
  1710. * Test pdo & pgsql
  1711. */
  1712. function testPdoPgsql() {
  1713. // skip testing pgsql if not allowed
  1714. if (!$this->canTestPdo('pgsql') || !$this->canTestPgsql()) {
  1715. return;
  1716. }
  1717. $this->_allTests('pdo', 'pgsql');
  1718. }
  1719. /**
  1720. * Test adodb & sqlite
  1721. */
  1722. function testAdodbSqlite() {
  1723. // skip testing sqlite if not allowed
  1724. if (!$this->canTestAdodb() || !$this->canTestSqlite()) {
  1725. return;
  1726. }
  1727. $this->_allTests('adodb', 'sqlite');
  1728. }
  1729. /**
  1730. * Test peardb & mysql
  1731. */
  1732. function testPearSqlite() {
  1733. // skip testing sqlite if not allowed
  1734. if (!$this->canTestPeardb() || !$this->canTestSqlite()) {
  1735. return;
  1736. }
  1737. $this->_allTests('peardb', 'sqlite');
  1738. }
  1739. /**
  1740. * Test pdo & sqlite
  1741. */
  1742. function testPdoSqlite() {
  1743. // skip testing sqlite if not allowed
  1744. if (!$this->canTestPdo('sqlite') || !$this->canTestSqlite()) {
  1745. return;
  1746. }
  1747. $this->_allTests('pdo', 'sqlite');
  1748. }
  1749. }
  1750. if (!defined('EP_GROUP_TEST')) {
  1751. $tm = microtime(true);
  1752. $t = new epTestManager;
  1753. if ( epIsWebRun() ) {
  1754. $t->run(new HtmlReporter());
  1755. } else {
  1756. $t->run(new TextReporter());
  1757. }
  1758. $elapsed = microtime(true) - $tm;
  1759. echo epNewLine() . 'Time elapsed: ' . $elapsed . ' seconds';
  1760. }
  1761. ?>