/**
  * 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);
 }
 public function getTags($bean)
 {
     return R::tag($bean);
 }
Exemple #3
0
 public static function hasTag($bean, $tags, $all = false)
 {
     $foundtags = R::tag($bean);
     if (is_string($foundtags)) {
         $foundtags = explode(",", $tags);
     }
     $same = array_intersect($tags, $foundtags);
     if ($all) {
         return implode(",", $same) === implode(",", $tags);
     }
     return (bool) (count($same) > 0);
 }
Exemple #4
0
R::exec("drop table book");
R::wipe("book");
R::wipe("tag");
R::wipe("book_tag");
$b = R::dispense("book");
$b->title = 'horror';
R::store($b);
$c = R::dispense("book");
$c->title = 'creepy';
R::store($c);
$d = R::dispense("book");
$d->title = "chicklit";
R::store($d);
R::tag($b, "horror,classic");
R::tag($d, "women,classic");
R::tag($c, "horror");
$x = R::tagged("book", "classic");
asrt(count($x), 2);
$x = R::tagged("book", "classic,horror");
asrt(count($x), 3);
testpack("test optimization related() ");
class TestFormatter implements RedBean_IBeanFormatter
{
    public function formatBeanTable($table)
    {
        return "xx_{$table}";
    }
    public function formatBeanID($table)
    {
        return "id";
    }
 /**
  * Fetching tagged items.
  * 
  * @return void
  */
 public function fetchTaggedItems()
 {
     $b = R::dispense("book");
     $b->title = 'horror';
     R::store($b);
     $c = R::dispense("book");
     $c->title = 'creepy';
     R::store($c);
     $d = R::dispense("book");
     $d->title = "chicklit";
     R::store($d);
     R::tag($b, "horror,classic");
     R::tag($d, "women,classic");
     R::tag($c, "horror");
     $x = R::tagged("book", "classic");
     asrt(count($x), 2);
     $x = R::tagged("book", "classic,horror");
     asrt(count($x), 3);
     $x = R::tagged("book", array("classic", "horror"));
     asrt(count($x), 3);
 }