public function hasTemplate($template) { return false; } } $t->diag('::isTaggable'); $t->ok(TaggableToolkit::isTaggable('ValidModel'), 'valid model name'); $t->ok(TaggableToolkit::isTaggable(new ValidModel('ValidModel')), 'valid model object'); $t->ok(!TaggableToolkit::isTaggable('InValidModel'), 'invalid model name'); $t->ok(!TaggableToolkit::isTaggable(new InValidModel('InValidModel')), 'invalid model object'); try { TaggableToolkit::isTaggable('MyClass'); $t->fail('no exception for no doctrine model name'); } catch (Exception $e) { $t->pass('no doctrine model name'); } class MyClass { } try { TaggableToolkit::isTaggable(new MyClass()); $t->fail('no exception for no doctrine model class'); } catch (Exception $e) { $t->pass('no doctrine model class'); } $t->diag('::normalize'); $t->todo('test normalize'); $t->diag('::triplify'); $tags = array('peter', 'wolf'); array_walk($tags, 'TaggableToolkit::triplify', 'namespace:key'); $t->is($tags, array('namespace:key=peter', 'namespace:key=wolf'), 'simple tags');
$t->ok(count($tagged_with_tag17) == 3, 'getObjectTaggedWith() returns objects tagged with several specific tags.'); $tagged_with_tag127 = Doctrine_Core::getTable('Tag')->getObjectTaggedWith('tag1, tag2, tag7', array('nb_common_tags' => 2)); $t->ok(count($tagged_with_tag127) == 6, 'the "nb_common_tags" option of getObjectTaggedWith() returns objects tagged with a certain number of tags within a set of specific tags.'); // these tests check the preloadTags() method Taggable::preloadTags($tagged_with_tag17); $nb_tags = 0; foreach ($tagged_with_tag17 as $tmp_object) { $nb_tags += count($tmp_object->getTags()); } $t->ok($nb_tags === 10, 'preloadTags() preloads the tags of the objects.'); // these tests check the isTaggable() method $t->diag('detecting if a model is taggable or not'); $t->ok(TaggableToolkit::isTaggable(TEST_CLASS) === true, 'it is possible to tell if a model is taggable from its name.'); $object = _create_object(); $t->ok(TaggableToolkit::isTaggable($object) === true, 'it is possible to tell if a model is taggable from one of its instances.'); $t->ok(TaggableToolkit::isTaggable(TEST_NON_TAGGABLE_CLASS) === false, TEST_NON_TAGGABLE_CLASS . ' is not taggable, and that is fine.'); // clean the database Doctrine_Query::create()->delete()->from('Tag')->execute(); Doctrine_Query::create()->delete()->from('Tagging')->execute(); Doctrine_Query::create()->delete()->from(TEST_CLASS)->execute(); Doctrine_Query::create()->delete()->from(TEST_CLASS_2)->execute(); // these tests check for the application of triple tags $t->diag('applying triple tagging'); $t->ok(TaggableToolkit::extractTriple('ns:key=value') === array('ns:key=value', 'ns', 'key', 'value'), 'triple extracted successfully.'); $t->ok(TaggableToolkit::extractTriple('ns:key') === array('ns:key', null, null, null), 'ns:key is not a triple.'); $t->ok(TaggableToolkit::extractTriple('ns') === array('ns', null, null, null), 'ns is not a triple.'); $object = _create_object(); $object->addTag('tutu'); $object->save(); $object = _create_object(); $object->addTag('ns:key=value');