/** * Begin testing. * This method runs the actual test pack. * * @return void */ public function testBatch() { R::freeze(FALSE); $toolbox = R::getToolBox(); $adapter = $toolbox->getDatabaseAdapter(); $writer = $toolbox->getWriter(); $redbean = $toolbox->getRedBean(); $pdo = $adapter->getDatabase(); $page = $redbean->dispense("page"); $page->name = "page no. 1"; $page->rating = 1; $id1 = $redbean->store($page); $page = $redbean->dispense("page"); $page->name = "page no. 2"; $id2 = $redbean->store($page); $batch = $redbean->batch("page", array($id1, $id2)); asrt(count($batch), 2); asrt($batch[$id1]->getMeta("type"), "page"); asrt($batch[$id2]->getMeta("type"), "page"); asrt((int) $batch[$id1]->id, $id1); asrt((int) $batch[$id2]->id, $id2); $book = $redbean->dispense("book"); $book->name = "book 1"; $redbean->store($book); $book = $redbean->dispense("book"); $book->name = "book 2"; $redbean->store($book); $book = $redbean->dispense("book"); $book->name = "book 3"; $redbean->store($book); $books = $redbean->batch("book", $adapter->getCol("SELECT id FROM book")); asrt(count($books), 3); $a = $redbean->batch('book', 9919); asrt(is_array($a), TRUE); asrt(count($a), 0); $a = $redbean->batch('triangle', 1); asrt(is_array($a), TRUE); asrt(count($a), 0); R::freeze(TRUE); $a = $redbean->batch('book', 9919); asrt(is_array($a), TRUE); asrt(count($a), 0); try { $a = $redbean->batch('triangle', 1); fail(); } catch (SQL $e) { pass(); } R::freeze(FALSE); asrt(R::wipe('spaghettimonster'), FALSE); }
/** * Test count and wipe. * * @return void */ public function testCountAndWipe() { testpack("Test count and wipe"); $page = R::dispense("page"); $page->name = "ABC"; R::store($page); $n1 = R::count("page"); $page = R::dispense("page"); $page->name = "DEF"; R::store($page); $n2 = R::count("page"); asrt($n1 + 1, $n2); R::wipe("page"); asrt(R::count("page"), 0); asrt(R::getRedBean()->count("page"), 0); asrt(R::getRedBean()->count("kazoo"), 0); // non existing table R::freeze(TRUE); asrt(R::getRedBean()->count("kazoo"), 0); // non existing table R::freeze(FALSE); $page = R::dispense('page'); $page->name = 'foo'; R::store($page); $page = R::dispense('page'); $page->name = 'bar'; R::store($page); asrt(R::count('page', ' name = ? ', array('foo')), 1); // Now count something that does not exist, this should return 0. (just be polite) asrt(R::count('teapot', ' name = ? ', array('flying')), 0); asrt(R::count('teapot'), 0); $currentDriver = $this->currentlyActiveDriverID; // Some drivers don't support that many error codes. if ($currentDriver === 'mysql' || $currentDriver === 'postgres') { try { R::count('teaport', ' for tea '); fail(); } catch (SQL $e) { pass(); } } }
/** * Test Transactions. * * @return void */ public function testTransactions() { testpack('transactions'); R::begin(); $bean = R::dispense('bean'); R::store($bean); R::commit(); asrt(R::count('bean'), 1); R::wipe('bean'); R::freeze(1); R::begin(); $bean = R::dispense('bean'); R::store($bean); R::rollback(); asrt(R::count('bean'), 0); R::freeze(FALSE); testpack('genSlots'); asrt(R::genSlots(array('a', 'b')), '?,?'); asrt(R::genSlots(array('a')), '?'); asrt(R::genSlots(array()), ''); }
public static function clearsystemlog($userid) { if (self::if_table_exists('systemlog')) { $rs = R::wipe('systemlog'); return $rs; } else { self::createSystemlog(); return 0; } }