$result[] = $tag->getName();
}
$t->ok($result === array('ns:key=value', 'ns:key=tutu', 'ns:key=titi', 'ns:key=toto'), 'it is possible to search for triple tags by namespace.');
$tags_triple = TagPeer::getAll(null, array('triple' => true, 'key' => 'key'));
$result = array();
foreach ($tags_triple as $tag) {
    $result[] = $tag->getName();
}
$t->ok($result === array('ns:key=value', 'ns:key=tutu', 'ns:key=titi', 'ns:key=toto'), 'it is possible to search for triple tags by key.');
$tags_triple = TagPeer::getAll(null, array('triple' => true, 'value' => 'tutu'));
$result = array();
foreach ($tags_triple as $tag) {
    $result[] = $tag->getName();
}
$t->ok($result === array('ns:key=tutu'), 'it is possible to search for triple tags by value.');
$objects_triple = TagPeer::getTaggedWith(array(), array('namespace' => 'ns', 'model' => 'Post'));
$t->ok(count($objects_triple) == 1, 'it is possible to retrieve objects tagged with certain triple tags.');
// these tests check for the behavior of the triple tags when the plugin is set
// up so that namespace:key is a unique key
// clean the database
TagPeer::doDeleteAll();
TaggingPeer::doDeleteAll();
call_user_func(array(_create_object()->getPeer(), 'doDeleteAll'));
sfConfig::set('app_deppPropelActAsTaggableBehaviorPlugin_triple_distinct', true);
$t->diag('querying triple tagging');
$object = _create_object();
$object->addTag('tutu');
$object->save();
$object = _create_object();
$object->addTag('ns:key=value');
$object->addTag('ns:key=tutu');
    $result[] = $tag->getName();
}
$t->ok($result === array('ns:key=value', 'ns:key=tutu', 'ns:key=titi', 'ns:key=toto'), 'it is possible to search for triple tags by namespace.');
$tags_triple = TagPeer::getAll(null, array('triple' => true, 'key' => 'key'));
$result = array();
foreach ($tags_triple as $tag) {
    $result[] = $tag->getName();
}
$t->ok($result === array('ns:key=value', 'ns:key=tutu', 'ns:key=titi', 'ns:key=toto'), 'it is possible to search for triple tags by key.');
$tags_triple = TagPeer::getAll(null, array('triple' => true, 'value' => 'tutu'));
$result = array();
foreach ($tags_triple as $tag) {
    $result[] = $tag->getName();
}
$t->ok($result === array('ns:key=tutu'), 'it is possible to search for triple tags by value.');
$objects_triple = TagPeer::getTaggedWith(array(), array('namespace' => 'ns', 'model' => TEST_CLASS));
$t->ok(count($objects_triple) == 1, 'it is possible to retrieve objects tagged with certain triple tags.');
// clean the database
TagPeer::doDeleteAll();
TaggingPeer::doDeleteAll();
call_user_func(array(_create_object()->getPeer(), 'doDeleteAll'));
// these tests check for the behavior of the triple tags when the plugin is set
// up so that namespace:key is a unique key
sfConfig::set('app_sfPropelActAsTaggableBehaviorPlugin_triple_distinct', true);
$t->diag('querying triple tagging');
$object = _create_object();
$object->addTag('tutu');
$object->save();
$object = _create_object();
$object->addTag('ns:key=value');
$object->addTag('ns:key=tutu');
$t->ok(array_keys($tags) == array('tag3', 'tag8'), 'getRelatedTags() can retrieve tags related to an array of tags.');
// getRelatedTags() test
$tags = TagPeer::getRelatedTags('tag2,tag7');
$t->ok(array_keys($tags) == array('tag3', 'tag8'), 'getRelatedTags() also accepts a coma-separated string.');
// getTaggedWith() tests
$object_2_1 = _create_object_2();
$object_2_1->addTag('tag1,tag3,tag7');
$object_2_1->save();
$object_2_2 = _create_object_2();
$object_2_2->addTag('tag2,tag7');
$object_2_2->save();
$tagged_with_tag4 = TagPeer::getTaggedWith('tag4');
$t->ok(count($tagged_with_tag4) == 2, 'getTaggedWith() returns objects tagged with one specific tag.');
$tagged_with_tag7 = TagPeer::getTaggedWith('tag7');
$t->ok(count($tagged_with_tag7) == 5, 'getTaggedWith() can return several object types.');
$tagged_with_tag17 = TagPeer::getTaggedWith(array('tag1', 'tag7'));
$t->ok(count($tagged_with_tag17) == 3, 'getTaggedWith() returns objects tagged with several specific tags.');
// these tests check the isTaggable() method
$t->diag('detecting if a model is taggable or not');
$t->ok(sfPropelActAsTaggableToolkit::isTaggable(TEST_CLASS) === true, 'it is possible to tell if a model is taggable from its name.');
$object = _create_object();
$t->ok(sfPropelActAsTaggableToolkit::isTaggable($object) === true, 'it is possible to tell if a model is taggable from one of its instances.');
$t->ok(sfPropelActAsTaggableToolkit::isTaggable('Tristan\'s cat') === false, 'Tristan\'s cat is not taggable, and that is fine.');
TagPeer::doDeleteAll();
TaggingPeer::doDeleteAll();
call_user_func(array(_create_object()->getPeer(), 'doDeleteAll'));
// these tests check for the application of triple tags
$t->diag('applying triple tagging');
$t->ok(sfPropelActAsTaggableToolkit::extractTriple('ns:key=value') === array('ns:key=value', 'ns', 'key', 'value'), 'triple extracted successfully.');
$t->ok(sfPropelActAsTaggableToolkit::extractTriple('ns:key') === array('ns:key', null, null, null), 'ns:key is not a triple.');
$t->ok(sfPropelActAsTaggableToolkit::extractTriple('ns') === array('ns', null, null, null), 'ns is not a triple.');
Beispiel #4
0
 public function getTaggedWith($options = array())
 {
     return TagPeer::getTaggedWith($this->getName());
 }