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');
$object->addTag('ns:key=titi');
$object->addTag('ns:second_key=toto');
$object->save();
$tags_triple = TagPeer::getAll(null, array('triple' => true, 'namespace' => 'ns'));
$t->ok(count($tags_triple) == 2, 'it is possible to set up the plugin so that namespace:key is a unique key.');
$object2 = _create_object();
$object2->addTag('ns:key=value');
$object2->addTag('ns:second_key=toto');
$object2->save();
$tags_triple = TagPeer::getAll(null, array('triple' => true, 'namespace' => 'ns'));
$t->ok(count($tags_triple) == 3, 'it is possible to apply triple tags to various objects when the plugin is set up so that namespace:key is a unique key.');
// test object creation
function _create_object()
{
    $classname = TEST_CLASS;
    if (!class_exists($classname)) {
        throw new Exception(sprintf('Unknow class "%s"', $classname));
    }
    return new $classname();
}
// second type of test object creation
$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.');
$object = _create_object();
$object->addTag('tutu');
$object->save();
$object = _create_object();
$object->addTag('ns:key=value');
$object->addTag('ns:key=tutu');
$object->addTag('ns:key=titi');
$object->addTag('ns:key=toto');
$object->save();
$object_tags = $object->getTags();
$t->ok($object->hasTag('ns:key=value'), 'object has triple tag');
$tag = TagPeer::retrieveOrCreateByTagname('ns:key=value');
$t->ok($tag->getIsTriple(), 'a triple tag created from a string is identified as a triple.');
$tag = TagPeer::retrieveOrCreateByTagname('tutu');
$t->ok(!$tag->getIsTriple(), 'a non tripled tag created from a string is not identified as a triple.');
// these tests check for TagPeer triple tags specific methods (tag clouds generation)
$t->diag('querying triple tagging');
$tags_triple = TagPeer::getAll(null, array('triple' => true));
$result = array();
    $t->diag($obj->getId() . ": " . $obj->{$getter}());
}
$t->diag('Remove the second object (test cascading)');
$obj2->delete();
unset($user);
$user = call_user_func_array($monitorer_callable, $user_id);
$t->ok($user->countMonitoredObjects(TEST_MONITORABLE) == 1, 'the user is now monitoring one object again');
$t->diag('Remove the other user\'s monitor');
$obj1->removeMonitoringUser($other_user_id);
$t->ok($obj1->countMonitoringUsers() == 1, 'one user left now monitoring.');
unset($user);
$user = call_user_func_array($monitorer_callable, $user_id);
$t->ok($user->countMonitoredObjects(TEST_MONITORABLE) == 1, 'the user is always monitoring one object');
// test news generators
$t->diag('Create a generator object');
$obj3 = _create_object('Generatore di test', TEST_GENERATOR);
$obj3->setMonitorableId($obj1->getPrimaryKey());
$obj3->setTestDate('2008-11-02');
$obj3->save();
$generated_news = $obj3->getGeneratedNews();
$t->ok(count($generated_news) == 1, "One news was generated");
$single_news = $generated_news[0];
$t->diag("Data: " . $single_news->getDate());
$t->diag("Priority: " . $single_news->getPriority());
$t->diag('Remove the first  object (resetting)');
$obj1->delete();
$t->diag('Remove the generator  object (news should be removed, too)');
$obj3->delete();
$t->diag('Tests terminated');
// test objects creation
function _create_object($string = 'Default title', $classname = TEST_MONITORABLE)
$object2->publishComment($comments[0]['Id']);
$t->ok(call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == 2 && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbComments() && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbPublicComments(), 'publishing works fine (and cache is ok)');
$t->diag('removal');
$object2->removeComment($comments[0]['Id']);
$t->ok(call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == 1 && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbComments() && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbPublicComments(), 'removing works fine (and cache is ok)');
$object2->clearComments();
$t->ok(call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == 0 && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbComments() && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbPublicComments(), 'clearing all comments fine (and cache is ok)');
// these tests check for comments inserted by authenticated users
$t->diag('comments by authenticated users');
// autenticazione (user_id = 8, è un utenza con mail e website)
// bisogna settare
//  enabled: true
//  name_method, email_method, website_method
$user = OppUserPeer::retrieveByPK(8);
sfContext::getInstance()->getUser()->signIn($user);
$object1 = _create_object();
$object1->setName('oggetto per commento autenticato');
$object1->save();
$object1->addComment('My first comment.');
$comments = $object1->getComments();
$t->ok($comments[0]['AuthorId'] != null && $comments[0]['AuthorName'] != null && $comments[0]['AuthorWebsite'] != null, 'comments by authenticated users have an author_id field');
// logout
sfContext::getInstance()->getUser()->signOut();
// test object creation
function _create_object()
{
    $classname = TEST_CLASS;
    if (!class_exists($classname)) {
        throw new Exception(sprintf('Unknow class "%s"', $classname));
    }
    $obj = new $classname();
$t->ok($object->getCounter() == 1, 'after one increment, the counters value is 1.');
$rand = rand(1, 100);
$i = 0;
while ($i < $rand) {
    $object->incrementCounter();
    $i++;
}
$t->ok($object->getCounter() == 1 + $rand, 'each call to getCounter() increments the counter.');
$object2 = _create_object();
$object2->save();
$object2->incrementCounter();
$object2->incrementCounter();
$t->ok($object->getCounter() == 1 + $rand && $object2->getCounter() == 2, 'separate objects have separate counters.');
$object->delete();
$t->ok(sfCounterPeer::doCount(new Criteria()) == 1, 'When an object is deleted, its counter is also deleted.');
$object3 = _create_object();
$object3->save();
$object3->incrementCounter();
$object3->incrementCounter();
$object3->incrementCounter();
$object3->incrementCounter();
$object3->incrementCounter();
$object3->incrementCounter();
$object3->incrementCounter();
$object3->incrementCounter();
$object3->incrementCounter();
$object3->incrementCounter();
$object3->incrementCounter();
$most_counted = sfCounterPeer::getMostCounted();
$t->ok($most_counted[0]->getCounter() > $most_counted[1]->getCounter(), 'sfCounterPeer::getMostCounted() returns objects from the most counted to the less one.');
$object3->incrementCounter();