Beispiel #1
0
 /**
  * Test varchar 191 condition.
  *
  * @return void
  */
 public function testInnoDBIndexLimit()
 {
     R::nuke();
     $book = R::dispense('book');
     $book->text = 'abcd';
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(191)');
     $book = $book->fresh();
     $book->text = str_repeat('x', 190);
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(191)');
     $book = $book->fresh();
     $book->text = str_repeat('x', 191);
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(191)');
     $book = $book->fresh();
     $book->text = str_repeat('x', 192);
     R::store($book);
     $columns = R::inspect('book');
     asrt(isset($columns['text']), TRUE);
     asrt($columns['text'], 'varchar(255)');
 }
 /**
  * Tests the facade-only dispenseAll method.
  * 
  * @return void
  */
 public function testDispenseAll()
 {
     list($book, $page) = RedBean_Facade::dispenseAll('book,page');
     asrt($book instanceof RedBean_OODBBean, true);
     asrt($page instanceof RedBean_OODBBean, true);
     asrt($book->getMeta('type'), 'book');
     asrt($page->getMeta('type'), 'page');
     list($book, $page, $texts, $mark) = R::dispenseAll('book,page,text*2,mark');
     asrt($book instanceof RedBean_OODBBean, true);
     asrt($page instanceof RedBean_OODBBean, true);
     asrt(is_array($texts), true);
     asrt($mark instanceof RedBean_OODBBean, true);
     asrt($book->getMeta('type'), 'book');
     asrt($page->getMeta('type'), 'page');
     asrt($mark->getMeta('type'), 'mark');
     asrt($texts[0]->getMeta('type'), 'text');
     asrt($texts[1]->getMeta('type'), 'text');
     list($eggs, $milk, $butter) = R::dispenseAll('eggs*3,milk*1,butter*9');
     asrt(count($eggs), 3);
     asrt($milk instanceof RedBean_OODBBean, true);
     asrt(count($butter), 9);
     list($beer) = R::dispenseAll('beer*0');
     asrt(is_array($beer), true);
     asrt(count($beer), 0);
 }
 /**
  * Test Chill mode.
  * 
  * @return void
  */
 public function testChill()
 {
     $bean = R::dispense('bean');
     $bean->col1 = '1';
     $bean->col2 = '2';
     R::store($bean);
     asrt(count(R::$writer->getColumns('bean')), 3);
     $bean->col3 = '3';
     R::store($bean);
     asrt(count(R::$writer->getColumns('bean')), 4);
     R::freeze(array('umbrella'));
     $bean->col4 = '4';
     R::store($bean);
     asrt(count(R::$writer->getColumns('bean')), 5);
     R::freeze(array('bean'));
     $bean->col5 = '5';
     try {
         R::store($bean);
         fail();
     } catch (Exception $e) {
         pass();
     }
     asrt(count(R::$writer->getColumns('bean')), 5);
     R::freeze(array());
     $bean->col5 = '5';
     R::store($bean);
     asrt(count(R::$writer->getColumns('bean')), 6);
 }
 /**
  * Test integration with pre-existing schemas.
  * 
  * @return void
  */
 public function testPlaysNiceWithPreExitsingSchema()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $a = new RedBean_AssociationManager($toolbox);
     $page = $redbean->dispense("page");
     $page->name = "John's page";
     $idpage = $redbean->store($page);
     $page2 = $redbean->dispense("page");
     $page2->name = "John's second page";
     $idpage2 = $redbean->store($page2);
     $a->associate($page, $page2);
     $adapter->exec("ALTER TABLE " . $writer->esc('page') . "\n\t\tCHANGE " . $writer->esc('name') . " " . $writer->esc('name') . "\n\t\tVARCHAR( 254 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL ");
     $page = $redbean->dispense("page");
     $page->name = "Just Another Page In a Table";
     $cols = $writer->getColumns("page");
     asrt($cols["name"], "varchar(254)");
     //$pdo->SethMode(1);
     $redbean->store($page);
     pass();
     // No crash?
     $cols = $writer->getColumns("page");
     asrt($cols["name"], "varchar(254)");
     //must still be same
 }
 /**
  * Test extended associations.
  * 
  * @return void
  */
 public function testExtAssoc()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     R::nuke();
     $webpage = $redbean->dispense("webpage");
     $webpage->title = "page with ads";
     $ad = $redbean->dispense("ad");
     $ad->title = "buy this!";
     $top = $redbean->dispense("placement");
     $top->position = "top";
     $bottom = $redbean->dispense("placement");
     $bottom->position = "bottom";
     $ea = new RedBean_AssociationManager_ExtAssociationManager($toolbox);
     $ea->extAssociate($ad, $webpage, $top);
     $ads = $redbean->batch("ad", $ea->related($webpage, "ad"));
     $adsPos = $redbean->batch("ad_webpage", $ea->related($webpage, "ad", TRUE));
     asrt(count($ads), 1);
     asrt(count($adsPos), 1);
     $theAd = array_pop($ads);
     $theAdPos = array_pop($adsPos);
     asrt($theAd->title, $ad->title);
     asrt($theAdPos->position, $top->position);
     $ad2 = $redbean->dispense("ad");
     $ad2->title = "buy this too!";
     $ea->extAssociate($ad2, $webpage, $bottom);
     $ads = $redbean->batch("ad", $ea->related($webpage, "ad", TRUE));
     asrt(count($ads), 2);
 }
Beispiel #6
0
 /**
  * Test tainted.
  *
  * @return void
  */
 public function testTainted()
 {
     testpack('Original Tainted Tests');
     $redbean = R::getRedBean();
     $spoon = $redbean->dispense("spoon");
     asrt($spoon->getMeta("tainted"), TRUE);
     $spoon->dirty = "yes";
     asrt($spoon->getMeta("tainted"), TRUE);
     testpack('Tainted List test');
     $note = R::dispense('note');
     $note->text = 'abc';
     $note->ownNote[] = R::dispense('note')->setAttr('text', 'def');
     $id = R::store($note);
     $note = R::load('note', $id);
     asrt($note->isTainted(), FALSE);
     // Shouldn't affect tainted
     $note->text;
     asrt($note->isTainted(), FALSE);
     $note->ownNote;
     asrt($note->isTainted(), TRUE);
     testpack('Tainted Test Old Value');
     $text = $note->old('text');
     asrt($text, 'abc');
     asrt($note->hasChanged('text'), FALSE);
     $note->text = 'xxx';
     asrt($note->hasChanged('text'), TRUE);
     $text = $note->old('text');
     asrt($text, 'abc');
     testpack('Tainted Non-exist');
     asrt($note->hasChanged('text2'), FALSE);
     testpack('Misc Tainted Tests');
     $bean = R::dispense('bean');
     $bean->hasChanged('prop');
     $bean->old('prop');
 }
Beispiel #7
0
 /**
  * Various.
  * Various test for OCI. Some basic test cannot be performed because
  * practical issues (configuration testing VM image etc..).
  * 
  * @return void
  */
 public function testOCIVaria()
 {
     $village = R::dispense('village');
     $village->name = 'Lutry';
     $id = R::store($village);
     $village = R::load('village', $id);
     asrt($village->name, 'Lutry');
     list($mill, $tavern) = R::dispense('building', 2);
     $village->ownBuilding = array($mill, $tavern);
     //replaces entire list
     $id = R::store($village);
     asrt($id, 1);
     $village = R::load('village', $id);
     asrt(count($village->ownBuilding), 2);
     $village2 = R::dispense('village');
     $army = R::dispense('army');
     $village->sharedArmy[] = $army;
     $village2->sharedArmy[] = $army;
     R::store($village);
     $id = R::store($village2);
     $village = R::load('village', $id);
     $army = $village->sharedArmy;
     $myVillages = R::related($army, 'village');
     asrt(count($myVillages), 2);
     echo PHP_EOL;
 }
Beispiel #8
0
 /**
  * Test dump().
  *
  * @return void
  */
 public function testDump()
 {
     $beans = R::dispense('bean', 2);
     $beans[0]->name = 'hello';
     $beans[1]->name = 'world';
     $array = R::dump($beans);
     asrt(is_array($array), TRUE);
     foreach ($array as $item) {
         asrt(is_string($item), TRUE);
     }
     $beans[1]->name = 'world, and a very long string that should be shortened';
     $array = R::dump($beans);
     asrt(is_array($array), TRUE);
     asrt(strpos($array[1], '...'), 35);
     //just to get 100% test cov, we dont need to test this
     dmp($beans);
     pass();
     //test wrong input
     asrt(is_array(R::dump(NULL)), TRUE);
     asrt(count(R::dump(NULL)), 0);
     asrt(is_array(R::dump('')), TRUE);
     asrt(count(R::dump('')), 0);
     asrt(is_array(R::dump(1)), TRUE);
     asrt(count(R::dump(1)), 0);
     asrt(is_array(R::dump(TRUE)), TRUE);
     asrt(count(R::dump(FALSE)), 0);
 }
 /**
  * Test foreign keys with SQLite.
  * 
  * @return void
  */
 public function testForeignKeysWithSQLite()
 {
     $book = R::dispense('book');
     $page = R::dispense('page');
     $cover = R::dispense('cover');
     list($g1, $g2) = R::dispense('genre', 2);
     $g1->name = '1';
     $g2->name = '2';
     $book->ownPage = array($page);
     $book->cover = $cover;
     $book->sharedGenre = array($g1, $g2);
     R::store($book);
     $fkbook = R::getAll('pragma foreign_key_list(book)');
     $fkgenre = R::getAll('pragma foreign_key_list(book_genre)');
     $fkpage = R::getAll('pragma foreign_key_list(page)');
     asrt($fkpage[0]['from'], 'book_id');
     asrt($fkpage[0]['to'], 'id');
     asrt($fkpage[0]['table'], 'book');
     asrt(count($fkgenre), 2);
     if ($fkgenre[0]['from'] == 'book') {
         asrt($fkgenre[0]['to'], 'id');
         asrt($fkgenre[0]['table'], 'book');
     }
     if ($fkgenre[0]['from'] == 'genre') {
         asrt($fkgenre[0]['to'], 'id');
         asrt($fkgenre[0]['table'], 'genre');
     }
     asrt($fkbook[0]['from'], 'cover_id');
     asrt($fkbook[0]['to'], 'id');
     asrt($fkbook[0]['table'], 'cover');
 }
Beispiel #10
0
 /**
  * Test SQLite table rebuilding.
  *
  * @return void
  */
 public function testRebuilder()
 {
     $toolbox = R::getToolBox();
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->xownPage[] = $page;
     $id = R::store($book);
     $book = R::load('book', $id);
     asrt(count($book->xownPage), 1);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
     R::trash($book);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->xownPage[] = $page;
     $id = R::store($book);
     $book = R::load('book', $id);
     asrt(count($book->xownPage), 1);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
     $book->added = 2;
     R::store($book);
     $book->added = 'added';
     R::store($book);
     R::trash($book);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
 }
Beispiel #11
0
 /**
  * Does the toolbox contain the necessary tools ?
  * 
  * @return void
  */
 public function testDoesToolboxContainTheTools()
 {
     $toolbox = R::getToolBox();
     asrt($toolbox->getDatabaseAdapter() instanceof Adapter, TRUE);
     asrt($toolbox->getRedBean() instanceof OODB, TRUE);
     asrt($toolbox->getWriter() instanceof QueryWriter, TRUE);
 }
Beispiel #12
0
 /**
  * Test types.
  * Test how RedBeanPHP OODB and OODBBean handle type and type casts.
  * 
  * Rules:
  * 
  * 1. before storing a bean all types are preserved except booleans (they are converted to STRINGS '0' or '1')
  * 2. after store-reload all bean property values are STRINGS or NULL 
  *    (or ARRAYS but that's only from a user perspective because these are lazy loaded)
  * 3. the ID returned by store() is an INTEGER (if possible; on 32 bit systems overflowing values will be cast to STRINGS!)
  * 
  * After loading:
  * ALL VALUES EXCEPT NULL -> STRING
  * NULL -> NULL
  * 
  * @note Why not simply return bean->id in store()? Because not every driver returns the same type:
  * databases without insert_id support require a separate query or a suffix returning STRINGS, not INTEGERS.
  * 
  * @note Why not preserve types? I.e. I store integer, why do I get back a string?
  * Answer: types are handled different across database platforms, would cause overhead to inspect every value for type,
  * also PHP is a dynamically typed language so types should not matter that much. Another reason: due to the nature
  * of RB columns in the database might change (INT -> STRING) this would cause return types to change as well which would
  * cause 'cascading errors', i.e. a column gets widened and suddenly your code would break.
  * 
  * @note Unfortunately the 32/64-bit issue cannot be tested fully. Return-strategy store() is probably the safest
  * solution.
  * 
  * @return void
  */
 public function testTypes()
 {
     testpack('Beans can only contain STRING and NULL after reload');
     R::nuke();
     $bean = R::dispense('bean');
     $bean->number = 123;
     $bean->float = 12.3;
     $bean->bool = false;
     $bean->bool2 = true;
     $bean->text = 'abc';
     $bean->null = null;
     $bean->datetime = new \DateTime('NOW', new \DateTimeZone('Europe/Amsterdam'));
     $id = R::store($bean);
     asrt(is_int($id), TRUE);
     asrt(is_float($bean->float), TRUE);
     asrt(is_integer($bean->number), TRUE);
     asrt(is_string($bean->bool), TRUE);
     asrt(is_string($bean->bool2), TRUE);
     asrt(is_string($bean->datetime), TRUE);
     asrt(is_string($bean->text), TRUE);
     asrt(is_null($bean->null), TRUE);
     $bean = R::load('bean', $id);
     asrt(is_string($bean->id), TRUE);
     asrt(is_string($bean->float), TRUE);
     asrt(is_string($bean->number), TRUE);
     asrt(is_string($bean->bool), TRUE);
     asrt(is_string($bean->bool2), TRUE);
     asrt(is_string($bean->datetime), TRUE);
     asrt(is_string($bean->text), TRUE);
     asrt(is_null($bean->null), TRUE);
     asrt($bean->bool, '0');
     asrt($bean->bool2, '1');
 }
Beispiel #13
0
 /**
  * Test fix for issue #512 - thanks for reporting Bernhard H.
  * OODBBean::__toString() implementation only works with C_ERR_IGNORE
  *
  * @return void
  */
 public function testToStringIssue512()
 {
     R::setErrorHandlingFUSE(\RedBeanPHP\OODBBean::C_ERR_FATAL);
     $boxedBean = R::dispense('boxedbean');
     $str = (string) $boxedBean;
     asrt($str, '{"id":0}');
     //no fatal error
     R::setErrorHandlingFUSE(FALSE);
 }
Beispiel #14
0
 /**
  * Test meta column type.
  * 
  * @return void
  */
 public function TypeColumn()
 {
     $book = R::dispense('book');
     $page = R::dispense('page');
     $page->book = $book;
     R::store($page);
     pass();
     asrt($page->getMeta('cast.book_id'), 'id');
 }
Beispiel #15
0
 /**
  * Test usage of named parameters in SQL snippets.
  * Issue #299 on Github.
  *
  * @return void
  */
 public function testNamedParamsInSnippets()
 {
     testpack('Test whether we can use named parameters in SQL snippets.');
     R::nuke();
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->title = 'book';
     $book->sharedPage[] = $page;
     R::store($book);
     //should not give error like: Uncaught [HY093] - SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
     $books = $page->withCondition(' title = :title ', array(':title' => 'book'))->sharedBook;
     asrt(count($books), 1);
     //should not give error...
     $books = $page->withCondition(' title = :title ', array(':title' => 'book'))->sharedBook;
     asrt(count($books), 1);
     R::nuke();
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->title = 'book';
     $book->comment = 'comment';
     $page->title = 'page';
     $book->ownPage[] = $page;
     R::store($book);
     //should also not give error..
     $count = $book->countOwn('page');
     asrt($count, 1);
     $book = $book->fresh();
     //should also not give error..
     $count = $book->withCondition(' title = ? ', array('page'))->countOwn('page');
     asrt($count, 1);
     $book = $book->fresh();
     //should also not give error..
     $count = $book->withCondition(' title = :title ', array(':title' => 'page'))->countOwn('page');
     asrt($count, 1);
     $book = $book->fresh();
     $pages = $book->withCondition(' title = :title ', array(':title' => 'page'))->ownPage;
     asrt(count($pages), 1);
     //test with duplicate slots...
     $page = reset($pages);
     $page2 = R::dispense('page');
     $page2->ownPage[] = $page;
     R::store($page2);
     $page2 = $page2->fresh();
     $pages = $page2->withCondition(' title = :title ', array(':title' => 'page'))->ownPage;
     asrt(count($pages), 1);
     //test with find()
     $books = R::getRedBean()->find('book', array('title' => array('book')), ' AND title = :title ', array(':title' => 'book'));
     asrt(count($books), 1);
     $books = R::getRedBean()->find('book', array('title' => array('book', 'book2'), 'comment' => array('comment', 'comment2')), ' AND title = :title ', array(':title' => 'book'));
     asrt(count($books), 1);
     //just check numeric works as well...
     $books = R::getRedBean()->find('book', array('title' => array('book', 'book2'), 'comment' => array('comment', 'comment2')), ' AND title = ? ', array('book'));
     asrt(count($books), 1);
     //just extra check to verify glue works
     $books = R::getRedBean()->find('book', array('title' => array('book', 'book2'), 'comment' => array('comment', 'comment2')), ' ORDER BY id ');
     asrt(count($books), 1);
 }
Beispiel #16
0
 /**
  * You cant access meta data using the array accessors.
  *
  * @return void
  */
 public function testNoArrayMetaAccess()
 {
     $bean = R::dispense('bean');
     $bean->setMeta('greet', 'hello');
     asrt(isset($bean['greet']), FALSE);
     asrt(isset($bean['__info']['greet']), FALSE);
     asrt(isset($bean['__info']), FALSE);
     asrt(isset($bean['meta']), FALSE);
     asrt(count($bean), 1);
 }
Beispiel #17
0
 /**
  * Test UTF8 handling.
  *
  * @return void
  */
 public function testUTF8()
 {
     $str = '𠜎ὃ𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜';
     $bean = R::dispense('bean');
     $bean->bla = $str;
     R::store($bean);
     $bean = R::load('bean', $bean->id);
     asrt($bean->bla, $str);
     pass();
 }
 /**
  * Various tests for OCI.
  * 
  * @return void
  */
 public function testVaria()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $page = $redbean->dispense("page");
     try {
         $adapter->exec("an invalid query");
         fail();
     } catch (RedBean_Exception_SQL $e) {
         pass();
     }
     asrt((int) $adapter->getCell("SELECT 123 FROM DUAL"), 123);
     $page->aname = "my page";
     $id = (int) $redbean->store($page);
     asrt((int) $page->id, 1);
     asrt((int) $pdo->GetCell("SELECT count(*) FROM page"), 1);
     asrt($pdo->GetCell("SELECT aname FROM page WHERE ROWNUM<=1"), "my page");
     asrt((int) $id, 1);
     $page = $redbean->load("page", 1);
     asrt($page->aname, "my page");
     asrt((bool) $page->getMeta("type"), TRUE);
     asrt(isset($page->id), TRUE);
     asrt($page->getMeta("type"), "page");
     asrt((int) $page->id, $id);
     R::nuke();
     $rooms = R::dispense('room', 2);
     $rooms[0]->kind = 'suite';
     $rooms[1]->kind = 'classic';
     $rooms[0]->number = 6;
     $rooms[1]->number = 7;
     R::store($rooms[0]);
     R::store($rooms[1]);
     $rooms = R::getAssoc('SELECT ' . R::$writer->esc('number') . ', kind FROM room ORDER BY kind ASC');
     foreach ($rooms as $key => $room) {
         asrt($key === 6 || $key === 7, TRUE);
         asrt($room == 'classic' || $room == 'suite', TRUE);
     }
     $rooms = R::$adapter->getAssoc('SELECT kind FROM room');
     foreach ($rooms as $key => $room) {
         asrt($room == 'classic' || $room == 'suite', TRUE);
         asrt($room, $key);
     }
     $rooms = R::getAssoc('SELECT ' . R::$writer->esc('number') . ', kind FROM rooms2 ORDER BY kind ASC');
     asrt(count($rooms), 0);
     asrt(is_array($rooms), TRUE);
     $date = R::dispense('mydate');
     $date->date = '2012-12-12 20:50';
     $date->time = '12:15';
     $id = R::store($date);
     $ok = R::load('mydate', 1);
 }
Beispiel #19
0
 /**
  * Test for issue #386.
  * Can we use large numbers in LIMIT ?
  * 
  * @return void
  */
 public function testLargeNum()
 {
     $number = R::dispense('number');
     $number->name = 'big number';
     R::store($number);
     //This should not cause an error... (some people use LIMIT 0, HUGE to simulate OFFSET on MYSQL).
     $beans = R::findAll('number', ' LIMIT ? ', array(PHP_INT_MAX));
     asrt(is_array($beans), TRUE);
     asrt(count($beans), 1);
     pass();
 }
Beispiel #20
0
 /**
  * Test the __toString method of the SQLHelper. 
  */
 public function testToString()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $sqlHelper = new RedBean_SQLHelper($adapter);
     $sqlHelper->begin()->select('*')->from('table')->where('name = ?')->put('name');
     $str = (string) $sqlHelper;
     asrt(strpos($str, 'query') !== false, true);
     asrt(strpos($str, 'select * from table where name = ?') !== false, true);
     asrt(strpos($str, '=> Array') !== false, true);
     asrt(strpos($str, 'params') !== false, true);
 }
 /**
  * Test basic labels.
  * 
  * @return void
  */
 public function testLabels()
 {
     testpack('Test Labels');
     $meals = R::dispenseLabels('meal', array('meat', 'fish', 'vegetarian'));
     asrt(is_array($meals), TRUE);
     asrt(count($meals), 3);
     foreach ($meals as $m) {
         asrt($m instanceof RedBean_OODBBean, TRUE);
     }
     $listOfMeals = implode(',', R::gatherLabels($meals));
     asrt($listOfMeals, 'fish,meat,vegetarian');
 }
Beispiel #22
0
 /**
  * Test FUSE and model formatting.
  * 
  * @todo move tagging tests to tag tester.
  * 
  * @return void
  */
 public function testFUSE()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $blog = R::dispense('blog');
     $blog->title = 'testing';
     $blog->blog = 'tesing';
     R::store($blog);
     $blogpost = R::load("blog", 1);
     $post = R::dispense("post");
     $post->message = "hello";
     R::associate($blog, $post);
     $a = R::getAll("select * from blog ");
     RedBean_ModelHelper::setModelFormatter(new mymodelformatter());
     $w = R::dispense("weirdo");
     asrt($w->blah(), "yes!");
     R::tag($post, "lousy,smart");
     asrt(implode(',', R::tag($post)), "lousy,smart");
     R::tag($post, "clever,smart");
     $tagz = implode(',', R::tag($post));
     asrt($tagz == "smart,clever" || $tagz == "clever,smart", TRUE);
     R::tag($blog, array("smart", "interesting"));
     asrt(implode(',', R::tag($blog)), "smart,interesting");
     try {
         R::tag($blog, array("smart", "interesting", "lousy!"));
         pass();
     } catch (RedBean_Exception $e) {
         fail();
     }
     asrt(implode(',', R::tag($blog)), "smart,interesting,lousy!");
     asrt(implode(",", R::tag($blog)), "smart,interesting,lousy!");
     R::untag($blog, array("smart", "interesting"));
     asrt(implode(",", R::tag($blog)), "lousy!");
     asrt(R::hasTag($blog, array("lousy!")), TRUE);
     asrt(R::hasTag($blog, array("lousy!", "smart")), TRUE);
     asrt(R::hasTag($blog, array("lousy!", "smart"), TRUE), FALSE);
     R::tag($blog, FALSE);
     asrt(count(R::tag($blog)), 0);
     R::tag($blog, array("funny", "comic"));
     asrt(count(R::tag($blog)), 2);
     R::addTags($blog, array("halloween"));
     asrt(count(R::tag($blog)), 3);
     asrt(R::hasTag($blog, array("funny", "commic", "halloween"), TRUE), FALSE);
     R::unTag($blog, array("funny"));
     R::addTags($blog, "horror");
     asrt(count(R::tag($blog)), 3);
     asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
     // No double tags
     R::addTags($blog, "horror");
     asrt(R::hasTag($blog, array("horror", "commic", "halloween"), TRUE), FALSE);
     asrt(count(R::tag($blog)), 3);
 }
Beispiel #23
0
 /**
  * Test self referential N-M relations (page_page).
  * 
  * @return void
  */
 public function testSelfReferential()
 {
     $page = R::dispense('page')->setAttr('title', 'a');
     $page->sharedPage[] = R::dispense('page')->setAttr('title', 'b');
     R::store($page);
     $page = $page->fresh();
     $page = reset($page->sharedPage);
     asrt($page->title, 'b');
     $tables = array_flip(R::inspect());
     asrt(isset($tables['page_page']), true);
     $columns = R::inspect('page_page');
     asrt(isset($columns['page2_id']), true);
 }
 /**
  * Begin testing.
  * This method runs the actual test pack.
  * 
  * @return void
  */
 public function run()
 {
     R::nuke();
     file_put_contents('/tmp/test_log.txt', '');
     R::log('/tmp/test_log.txt');
     $bean = R::dispense('bean');
     $bean->name = TRUE;
     R::store($bean);
     $bean->name = 'test';
     R::store($bean);
     $log = file_get_contents('/tmp/test_log.txt');
     asrt(strlen($log) > 0, TRUE);
     echo $log;
 }
Beispiel #25
0
 /**
  * Test for issue #386.
  * Can we use large numbers in LIMIT ?
  * 
  * @return void
  */
 public function testLargeNum()
 {
     if (defined('HHVM_VERSION')) {
         return;
     }
     //oops hhvm has incorrect binding for large nums.
     $number = R::dispense('number');
     $number->name = 'big number';
     R::store($number);
     //This should not cause an error... (some people use LIMIT 0, HUGE to simulate OFFSET on MYSQL).
     $beans = R::findAll('number', ' LIMIT ? ', array(PHP_INT_MAX));
     asrt(is_array($beans), TRUE);
     asrt(count($beans), 1);
     pass();
 }
Beispiel #26
0
 /**
  * Nuclear test suite.
  * 
  * @return void
  */
 public function testNuke()
 {
     $bean = R::dispense('bean');
     R::store($bean);
     asrt(count(R::$writer->getTables()), 1);
     R::nuke();
     asrt(count(R::$writer->getTables()), 0);
     $bean = R::dispense('bean');
     R::store($bean);
     asrt(count(R::$writer->getTables()), 1);
     R::freeze();
     R::nuke();
     // No effect
     asrt(count(R::$writer->getTables()), 1);
     R::freeze(FALSE);
 }
Beispiel #27
0
 /**
  * Test closing database connection.
  * 
  * @return void
  */
 public function testClose()
 {
     asrt(R::$adapter->getDatabase()->isConnected(), TRUE);
     R::close();
     asrt(R::$adapter->getDatabase()->isConnected(), FALSE);
     // Can we create a database using empty setup?
     R::setup();
     $id = R::store(R::dispense('bean'));
     asrt($id > 0, TRUE);
     // Test freeze via kickstart in setup
     $toolbox = RedBean_Setup::kickstart('sqlite:/tmp/bla.txt', NULL, NULL, TRUE);
     asrt($toolbox->getRedBean()->isFrozen(), TRUE);
     // Test Oracle setup
     $toolbox = RedBean_Setup::kickstart('oracle:test-value', 'test', 'test', FALSE);
     asrt($toolbox instanceof RedBean_ToolBox, TRUE);
 }
 /**
  * Test scanning and coding of values.
  * 
  * @return void
  */
 public function testScanningAndCoding()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $writer->createTable("testtable");
     $writer->addColumn("testtable", "special", RedBean_QueryWriter_CUBRID::C_DATATYPE_SPECIAL_DATE);
     $cols = $writer->getColumns("testtable");
     asrt($writer->code($cols['special'], TRUE), RedBean_QueryWriter_CUBRID::C_DATATYPE_SPECIAL_DATE);
     asrt($writer->code($cols['special'], FALSE), RedBean_QueryWriter_CUBRID::C_DATATYPE_SPECIFIED);
     $writer->addColumn("testtable", "special2", RedBean_QueryWriter_CUBRID::C_DATATYPE_SPECIAL_DATETIME);
     $cols = $writer->getColumns("testtable");
     asrt($writer->code($cols['special2'], TRUE), RedBean_QueryWriter_CUBRID::C_DATATYPE_SPECIAL_DATETIME);
     asrt($writer->code($cols['special'], FALSE), RedBean_QueryWriter_CUBRID::C_DATATYPE_SPECIFIED);
 }
Beispiel #29
0
 /**
  * In the past it was not possible to export beans
  * like 'feed' (Model_Feed).
  *
  * @return void
  */
 public function testExportIssue()
 {
     R::nuke();
     $feed = R::dispense('feed');
     $feed->post = array('first', 'second');
     R::store($feed);
     $rows = R::getAll('SELECT * FROM feed');
     asrt($rows[0]['post'], '["first","second"]');
     $feed = $feed->fresh();
     asrt(is_array($feed->post), TRUE);
     asrt($feed->post[0], 'first');
     asrt($feed->post[1], 'second');
     R::store($feed);
     $rows = R::getAll('SELECT * FROM feed');
     asrt($rows[0]['post'], '["first","second"]');
     $feed = R::load('feed', $feed->id);
     $feed->post[] = 'third';
     R::store($feed);
     $rows = R::getAll('SELECT * FROM feed');
     asrt($rows[0]['post'], '["first","second","third"]');
     $feed = $feed->fresh();
     asrt(is_array($feed->post), TRUE);
     asrt($feed->post[0], 'first');
     asrt($feed->post[1], 'second');
     asrt($feed->post[2], 'third');
     //now the catch: can we use export?
     //PHP Fatal error:  Call to a member function export() on a non-object
     $feeds = R::exportAll(R::find('feed'));
     asrt(is_array($feeds), TRUE);
     $feed = reset($feeds);
     asrt($feed['post'][0], 'first');
     asrt($feed['post'][1], 'second');
     asrt($feed['post'][2], 'third');
     //can we also dup()?
     $feedOne = R::findOne('feed');
     R::store(R::dup($feedOne));
     asrt(R::count('feed'), 2);
     //can we delete?
     R::trash($feedOne);
     asrt(R::count('feed'), 1);
     $feedTwo = R::findOne('feed');
     $feed = $feedTwo->export();
     asrt($feed['post'][0], 'first');
     asrt($feed['post'][1], 'second');
     asrt($feed['post'][2], 'third');
 }
 /**
  * Test import from and tainted.
  * 
  * @return void
  */
 public function testImportFromAndTainted()
 {
     testpack('Test importFrom() and Tainted');
     $bean = R::dispense('bean');
     R::store($bean);
     $bean->name = 'abc';
     asrt($bean->getMeta('tainted'), TRUE);
     R::store($bean);
     asrt($bean->getMeta('tainted'), FALSE);
     $copy = R::dispense('bean');
     R::store($copy);
     $copy = R::load('bean', $copy->id);
     asrt($copy->getMeta('tainted'), FALSE);
     $copy->import(array('name' => 'xyz'));
     asrt($copy->getMeta('tainted'), TRUE);
     $copy->setMeta('tainted', FALSE);
     asrt($copy->getMeta('tainted'), FALSE);
     $copy->importFrom($bean);
     asrt($copy->getMeta('tainted'), TRUE);
     testpack('Test basic import() feature.');
     $bean = new RedBean_OODBBean();
     $bean->import(array("a" => 1, "b" => 2));
     asrt($bean->a, 1);
     asrt($bean->b, 2);
     $bean->import(array("a" => 3, "b" => 4), "a,b");
     asrt($bean->a, 3);
     asrt($bean->b, 4);
     $bean->import(array("a" => 5, "b" => 6), " a , b ");
     asrt($bean->a, 5);
     asrt($bean->b, 6);
     $bean->import(array("a" => 1, "b" => 2));
     testpack('Test inject() feature.');
     $coffee = R::dispense('coffee');
     $coffee->id = 2;
     $coffee->liquid = 'black';
     $cup = R::dispense('cup');
     $cup->color = 'green';
     // Pour coffee in cup
     $cup->inject($coffee);
     // Do we still have our own property?
     asrt($cup->color, 'green');
     // Did we pour the liquid in the cup?
     asrt($cup->liquid, 'black');
     // Id should not be transferred
     asrt($cup->id, 0);
 }