*/
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id: sfLuceneStorageBlackholeTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(6, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
try {
    $bh = new sfLuceneStorageBlackhole('foo');
    $t->pass('__construct() accepts a string');
} catch (Exception $e) {
    $t->fail('__construct() accepts a string');
    $t->skip('the previous test must pass to continue');
    die;
}
$t->ok($bh instanceof sfLuceneStorage, 'sfLuceneStorageBlackhole implements sfLuceneStorage interface');
$t->is($bh->read(), null, '->read() is null initially');
try {
    $bh->write('foobar');
    $t->pass('->write() can write data');
    $t->is($bh->read(), 'foobar', '->read() reads the data written by ->write()');
} catch (Exception $e) {
    $t->fail('->write() can write data');
    $t->skip('->read() reads the data written by ->write()');
}
$bh->delete();
$t->is($bh->read(), null, '->delete() causes ->read() to return null');
    $t->skip('the previous test must pass to continue');
    die;
}
$t->is($c->getAllCategories(), array(), '->getAllCategories() returns an empty array in the beginning');
$t->diag('testing ->getCategory()');
$category = $c->getCategory('foo');
$t->ok($category instanceof sfLuceneCategory, '->getCategory() returns an instance of sfLuceneCategory');
$t->is($category->getName(), 'foo', '->getCategory() returns a category with the correct name');
$t->is($category->getCount(), 0, '->getCategory() returns a category with a default score of 0');
$t->ok($category->getHolder() === $c, '->getCategory()->getHolder() returns the same instance as the holder');
$t->ok($category === $c->getCategory('foo'), '->getCategory() returns the same category each time, for a given name');
$t->diag('testing ->save()');
$category->add(10);
$t->ok($c->isModified(), 'modifying a category flags the holder for modification');
$c->save();
$t->is($writer->read(), '$categories = array();$categories[\'foo\'] = 10;', '->save() writes the changes to the writer');
$c->getCategory('bar')->add(2)->getHolder()->save();
$t->is($writer->read(), '$categories = array();$categories[\'foo\'] = 10;$categories[\'bar\'] = 2;', '->save() writes multiple changes to the writer');
$t->ok($c->isModified() == false, '->save() resets the modification flag');
$writer->write('foobarbaz');
$c->save();
$t->is($writer->read(), 'foobarbaz', '->save() does nothing if it is not modified');
$t->diag('testing ->load()');
$writer->write('$categories = array();$categories[\'baz\'] = 4;');
$t->is($c->load()->getCategory('baz')->getCount(), 4, '->load() reloads the categories list from the writer');
$t->is(count($c->getAllCategories()), 1, '->load() removes any old categories');
$writer->write('$foo = array();');
try {
    $c->load();
    $t->fail('->load() throws an exception with malformed data');
} catch (Exception $e) {