Exemple #1
0
 /**
  * Test dispense.
  *
  * @return void
  */
 public function testBasicsDispense()
 {
     $redbean = R::getRedBean();
     // Can we dispense a bean?
     $page = $redbean->dispense("page");
     // Does it have a meta type?
     asrt((bool) $page->getMeta("type"), TRUE);
     // Does it have an ID?
     asrt(isset($page->id), TRUE);
     // Type should be 'page'
     asrt($page->getMeta("type"), "page");
     // ID should be 0 because bean does not exist in database yet.
     asrt($page->id, 0);
     // Try some faulty dispense actions.
     foreach (array("", ".", "-") as $value) {
         try {
             $redbean->dispense($value);
             fail();
         } catch (RedException $e) {
             pass();
         }
     }
     $bean = $redbean->dispense("testbean");
     $bean["property"] = 123;
     $bean["abc"] = "def";
     asrt($bean["property"], 123);
     asrt($bean["abc"], "def");
     asrt($bean->abc, "def");
     asrt(isset($bean["abd"]), FALSE);
     asrt(isset($bean["abc"]), TRUE);
 }
 /**
  * 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);
 }
 /**
  * Some basic tests.
  * 
  * @return void
  */
 public function testTags()
 {
     list($c, $d, $e, $f) = R::dispense('coffee', 4);
     R::tag($c, 'strong,black');
     R::tag($d, 'black');
     R::tag($e, 'strong,sweet');
     R::tag($f, 'black,strong');
     //$x = array_intersect(R::tagged('coffee','sweet'),R::tagged('coffee','strong'));
     asrt(count(R::taggedAll('coffee', 'strong,sweet')), 1);
     asrt(count(R::taggedAll('coffee', 'strong')), 3);
     asrt(count(R::taggedAll('coffee', '')), 0);
     asrt(count(R::taggedAll('coffee', 'sweet')), 1);
     asrt(count(R::taggedAll('coffee', 'sweet,strong')), 1);
     asrt(count(R::taggedAll('coffee', 'black,strong')), 2);
     asrt(count(R::taggedAll('coffee', array('black', 'strong'))), 2);
     asrt(count(R::taggedAll('coffee', 'salty')), 0);
     $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::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!");
     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, "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(R::hasTag($blog, "horror,commic,halloween", TRUE), FALSE);
     asrt(count(R::tag($blog)), 3);
     testpack("fetch tagged items");
 }
 /**
  * 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
 }
Exemple #5
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);
 }
Exemple #6
0
function test_unset()
{
    $a = [1, 2, 3];
    assert(count($a) === 3);
    unset($a[0]);
    assert(count($a) === 2);
    pass(__FUNCTION__);
}
Exemple #7
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');
 }
function loggedIn()
{
    global $app;
    if ($_COOKIE['login'] == pass($app['password']) or $app['password'] == '') {
        return true;
    } else {
        return false;
    }
}
Exemple #9
0
 /**
  * Github issue #458, selectDatabase causes PHP notice undefined index
  * if database key not found.
  *
  * @return void
  */
 public function testInvalidDB()
 {
     try {
         R::selectDatabase('idontexist');
         fail();
     } catch (RedException $exception) {
         pass();
     }
 }
Exemple #10
0
function enable_json_api($path)
{
    request($path, function () {
        header("Content-Type: application/json");
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Credentials: true");
        pass();
    });
}
Exemple #11
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();
 }
Exemple #12
0
function test_is($result, $expected, $explanation)
{
    if ($result === $expected) {
        pass($explanation);
    } else {
        fail($explanation);
        diag("Got '{$result}'");
        diag("Expected '{$expected}'");
    }
}
 /**
  * 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);
 }
Exemple #14
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();
 }
 /**
  * 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);
 }
Exemple #16
0
 /**
  * Test for issue90.
  * Checking 'own' relationship, makes it impossible to trash a bean.
  *
  * @return void
  */
 public function testIssue90()
 {
     $s = R::dispense('box');
     $s->name = 'a';
     $f = R::dispense('bottle');
     $s->ownBottle[] = $f;
     R::store($s);
     $s2 = R::dispense('box');
     $s2->name = 'a';
     R::store($s2);
     R::trash($s2);
     pass();
 }
Exemple #17
0
 /**
  * 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);
 }
Exemple #18
0
 /**
  * Test recursive imports (formely known as R::graph).
  *
  * @return void
  */
 public function testRecursiveImport()
 {
     $book = R::dispense(array('_type' => 'book', 'title' => 'The magic book', 'ownPageList' => array(array('_type' => 'page', 'content' => 'magic potions'), array('_type' => 'page', 'content' => 'magic spells'))));
     $id = R::store($book);
     $book = R::load('book', $id);
     asrt($book->title, 'The magic book');
     $pages = $book->with(' ORDER BY content ASC ')->ownPageList;
     asrt(count($pages), 2);
     $page1 = array_shift($pages);
     asrt($page1->content, 'magic potions');
     $page2 = array_shift($pages);
     asrt($page2->content, 'magic spells');
     R::nuke();
     $book = R::dispense(array('_type' => 'book', 'title' => 'The magic book', 'author' => array('_type' => 'author', 'name' => 'Dr. Evil'), 'coAuthor' => array('_type' => 'author', 'name' => 'Dr. Creepy'), 'ownPageList' => array(array('_type' => 'page', 'content' => 'magic potions', 'ownRecipe' => array('a' => array('_type' => 'recipe', 'name' => 'Invisibility Salad'), 'b' => array('_type' => 'recipe', 'name' => 'Soup of Madness'), 'c' => array('_type' => 'recipe', 'name' => 'Love cake'))), array('_type' => 'page', 'content' => 'magic spells')), 'sharedCategory' => array(array('_type' => 'category', 'label' => 'wizardry'))));
     $id = R::store($book);
     $book = R::load('book', $id);
     asrt($book->title, 'The magic book');
     $pages = $book->with(' ORDER BY content ASC ')->ownPageList;
     asrt(count($pages), 2);
     $page1 = array_shift($pages);
     asrt($page1->content, 'magic potions');
     $page2 = array_shift($pages);
     asrt($page2->content, 'magic spells');
     $recipes = $page1->with(' ORDER BY name ASC ')->ownRecipeList;
     asrt(count($recipes), 3);
     $recipe1 = array_shift($recipes);
     asrt($recipe1->name, 'Invisibility Salad');
     $recipe2 = array_shift($recipes);
     asrt($recipe2->name, 'Love cake');
     $recipe3 = array_shift($recipes);
     asrt($recipe3->name, 'Soup of Madness');
     $categories = $book->sharedCategoryList;
     asrt(count($categories), 1);
     $category = reset($categories);
     asrt($category->label, 'wizardry');
     asrt($book->author->name, 'Dr. Evil');
     asrt($book->fetchAs('author')->coAuthor->name, 'Dr. Creepy');
     try {
         R::dispense(array());
         fail();
     } catch (RedException $ex) {
         pass();
     }
     try {
         R::dispense(array('property' => 'value'));
         fail();
     } catch (RedException $ex) {
         pass();
     }
 }
Exemple #19
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();
 }
Exemple #20
0
 /**
  * Tests whether invalid list checks are
  * operational in frozen mode.
  *
  * @return void
  */
 public function testInvalidList()
 {
     R::nuke();
     $book = R::dispense('book');
     $book->xownPageList[] = R::dispense('page');
     $book->sharedTagList[] = R::dispense('tag');
     R::store($book);
     R::freeze(TRUE);
     $book = R::dispense('book');
     $book->xownPageList[] = 'nonsense';
     try {
         R::store($book);
         fail();
     } catch (\Exception $e) {
         pass();
     }
     R::freeze(FALSE);
 }
Exemple #21
0
 /**
  * Test if RedBeanPHP can properly handle keywords.
  * 
  * @return void
  */
 public function testKeywords()
 {
     $keywords = array('anokeyword', 'znokeyword', 'group', 'drop', 'inner', 'join', 'select', 'table', 'int', 'cascade', 'float', 'call', 'in', 'status', 'order', 'limit', 'having', 'else', 'if', 'while', 'distinct', 'like');
     foreach ($keywords as $k) {
         R::nuke();
         $bean = R::dispense($k);
         $bean->{$k} = $k;
         $id = R::store($bean);
         $bean = R::load($k, $id);
         $bean2 = R::dispense('other');
         $bean2->name = $k;
         $bean->bean = $bean2;
         $bean->ownBean[] = $bean2;
         $bean->sharedBean[] = $bean2;
         $id = R::store($bean);
         R::trash($bean);
         pass();
     }
 }
 /**
  * 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::$redbean->count("page"), 0);
     asrt(R::$redbean->count("kazoo"), 0);
     // non existing table
     R::freeze(TRUE);
     asrt(R::$redbean->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 (RedBean_Exception_SQL $e) {
             pass();
         }
     }
 }
 /**
  * Test parameter binding.
  * 
  * @return void
  */
 public function testParamBindingWithPostgres()
 {
     testpack("param binding pgsql");
     $page = R::dispense("page");
     $page->name = "abc";
     $page->number = 2;
     R::store($page);
     R::exec("insert into page (name) values(:name) ", array(":name" => "my name"));
     R::exec("insert into page (number) values(:one) ", array(":one" => 1));
     R::exec("insert into page (number) values(:one) ", array(":one" => "1"));
     R::exec("insert into page (number) values(:one) ", array(":one" => "1234"));
     R::exec("insert into page (number) values(:one) ", array(":one" => "-21"));
     pass();
     testpack('Test whether we can properly bind and receive NULL values');
     $adapter = R::$adapter;
     asrt($adapter->getCell('SELECT TEXT( :nil ) ', array(':nil' => 'NULL')), 'NULL');
     asrt($adapter->getCell('SELECT TEXT( :nil ) ', array(':nil' => NULL)), NULL);
     asrt($adapter->getCell('SELECT TEXT( ? ) ', array('NULL')), 'NULL');
     asrt($adapter->getCell('SELECT TEXT( ? ) ', array(NULL)), NULL);
 }
 /**
  * Test if RedBeanPHP can properly handle keywords.
  * 
  * @return void
  */
 public function testKeywords()
 {
     $keywords = array('anokeyword', 'znokeyword', 'group', 'DROP', 'inner', 'JOIN', 'select', 'table', 'int', 'cascade', 'float', 'CALL', 'in', 'status', 'order', 'limit', 'having', 'else', 'if', 'while', 'distinct', 'like');
     R::setStrictTyping(FALSE);
     RedBean_OODBBean::setFlagBeautifulColumnNames(FALSE);
     foreach ($keywords as $k) {
         R::nuke();
         $bean = R::dispense($k);
         $bean->{$k} = $k;
         $id = R::store($bean);
         $bean = R::load($k, $id);
         $bean2 = R::dispense('other');
         $bean2->name = $k;
         $bean->bean = $bean2;
         $bean->ownBean[] = $bean2;
         $bean->sharedBean[] = $bean2;
         $id = R::store($bean);
         R::trash($bean);
         pass();
     }
     RedBean_OODBBean::setFlagBeautifulColumnNames(TRUE);
     R::setStrictTyping(TRUE);
 }
Exemple #25
0
 /**
  * Test boxing beans.
  *
  * @return void
  */
 public function testBoxing()
 {
     R::nuke();
     $bean = R::dispense('boxedbean')->box();
     R::trash($bean);
     pass();
     $bean = R::dispense('boxedbean');
     $bean->sharedBoxbean = R::dispense('boxedbean')->box();
     R::store($bean);
     pass();
     $bean = R::dispense('boxedbean');
     $bean->ownBoxedbean = R::dispense('boxedbean')->box();
     R::store($bean);
     pass();
     $bean = R::dispense('boxedbean');
     $bean->other = R::dispense('boxedbean')->box();
     R::store($bean);
     pass();
     $bean = R::dispense('boxedbean');
     $bean->title = 'MyBean';
     $box = $bean->box();
     asrt($box instanceof \Model_Boxedbean, TRUE);
     R::store($box);
 }
Exemple #26
0
<?php

require_once LIBPATH . "redfun.php";
require_once LIBPATH . "auth.php";
if (isset($_SESSION['userid'])) {
    if ($_REQUEST['action'] == "name") {
        name($_REQUEST['name'], $_SESSION['userid']);
    } elseif ($_REQUEST['action'] == "busy") {
        busy($_REQUEST['busy'], $_SESSION['userid']);
    } elseif ($_REQUEST['action'] == "contacts") {
        contacts($_REQUEST['phone'], $_REQUEST['email'], $_REQUEST['region'], $_SESSION['userid']);
    } elseif ($_REQUEST['action'] == "description") {
        description($_REQUEST['description'], $_SESSION['userid']);
    } elseif ($_REQUEST['action'] == "password") {
        pass($_REQUEST['pass'], $_REQUEST['oldpass'], $_SESSION['userid']);
    } elseif ($_REQUEST['action'] == "namemail") {
        namemail($_REQUEST['name'], $_REQUEST['email'], $_SESSION['userid']);
    }
} else {
    ?>
<script>alert("Вы не имеете доступа к этой странице, авторизуйтесь!");</script><?php 
    echo "<script>document.location.replace('/main');</script>";
}
Exemple #27
0
 /**
  * Test various.
  * Test various somewhat uncommon trash/unassociate scenarios.
  * (i.e. unassociate unrelated beans, trash non-persistant beans etc).
  * Should be handled gracefully - no output checking.
  *
  * @return void
  */
 public function testVaria2()
 {
     $toolbox = R::getToolBox();
     $redbean = $toolbox->getRedBean();
     $a = new AssociationManager($toolbox);
     $book = $redbean->dispense("book");
     $author1 = $redbean->dispense("author");
     $author2 = $redbean->dispense("author");
     $book->title = "My First Post";
     $author1->name = "Derek";
     $author2->name = "Whoever";
     $a->unassociate($book, $author1);
     $a->unassociate($book, $author2);
     pass();
     $redbean->trash($redbean->dispense("bla"));
     pass();
     $bean = $redbean->dispense("bla");
     $bean->name = 1;
     $bean->id = 2;
     $redbean->trash($bean);
     pass();
 }
Exemple #28
0
 /**
  * Traverse can only work with own-lists, otherwise infinite loops.
  *
  * @return void
  */
 public function testSharedTraversal()
 {
     $friend = R::dispense('friend');
     try {
         $friend->traverse('sharedFriend', function ($friend) {
         });
         fail();
     } catch (RedException $e) {
         pass();
     }
 }
function ident($server, $debug = 0, $output = null)
{
    $method = "interopEchoTests.whichToolkit";
    $result = xu_rpc_http_concise(array('method' => $method, 'host' => $server['host'], 'uri' => $server['uri'], 'port' => $server['port'], 'debug' => $debug, 'output' => $output));
    if ($result && $result['toolkitDocsUrl'] && !$result['faultCode']) {
        pass($method);
        echo "<br>";
        foreach ($result as $key => $value) {
            if (substr($value, 0, 7) === "http://") {
                $value = "<a href='{$value}'>{$value}</a>";
            }
            echo "<b>{$key}:</b> {$value}<br>";
        }
    } else {
        fail($method, false, $result);
    }
}
Exemple #30
0
 /**
  * Test NULL.
  * 
  * @return void
  */
 public function testNull()
 {
     asrt(setget("NULL"), "NULL");
     asrt(setget("NULL"), "NULL");
     asrt(setget("0123", 1), "0123");
     asrt(setget("0000123", 1), "0000123");
     asrt(setget(NULL), NULL);
     asrt(setget(0) == 0, TRUE);
     asrt(setget(1) == 1, TRUE);
     asrt(setget(TRUE) == TRUE, TRUE);
     asrt(setget(FALSE) == FALSE, TRUE);
     // minor test sqltest
     $a = R::getWriter()->sqlStateIn('000', array());
     // Unknown state must return FALSE.
     asrt($a, FALSE);
     try {
         R::getWriter()->esc('`aaa`');
         fail();
     } catch (\Exception $e) {
         pass();
     }
     asrt($e instanceof RedException, TRUE);
 }