/** * 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 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 addTags($bean, $tags) { return R::addTags($bean, $tags); }
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::$flagUseLegacyTaggingAPI = true; R::addTags($blog, "horror"); R::$flagUseLegacyTaggingAPI = false; 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); testpack("New relations"); $pdo->Execute("DROP TABLE IF EXISTS person_person"); $pdo->Execute("DROP TABLE IF EXISTS person"); R::$writer->tableFormatter = new RedBean_DefaultBeanFormatter(); $track = R::dispense('track'); $album = R::dispense('cd'); $track->name = 'a'; $track->orderNum = 1; $track2 = R::dispense('track'); $track2->orderNum = 2; $track2->name = 'b'; R::associate($album, $track); R::associate($album, $track2);