require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(14, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$luceneade = new limeade_lucene($limeade);
$luceneade->configure()->clear_sandbox();
$t->diag('testing ::loadZend()');
sfConfig::set('app_lucene_zend_location', '/tmp');
try {
    $e = $t->exception('::loadZend() fails with non-existant Zend path');
    sfLuceneToolkit::loadZend();
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
$limeade->config()->remove('app_lucene_zend_location');
$t->not_like_included('#/Zend/Search/Lucene/#', 'Zend Search Lucene is not loaded after failed run');
$t->not_in_include_path('Zend/Search/Lucene.php', 'Zend Search Lucene is not in the include path after failed run');
sfLuceneToolkit::loadZend();
$t->like_included('#/Zend/Search/Lucene/#', '::loadZend() loads Zend Search Lucene');
$t->in_include_path('Zend/Search/Lucene.php', '::loadZend() configures include path');
$t->diag('testing ::getDirtyIndexRemains()');
$luceneade->clear_sandbox();
$root = sfConfig::get('sf_data_dir') . '/index/';
// build valid indexes structure
sfLucene::getInstance('testLucene', 'en')->getLucene();
sfLucene::getInstance('testLucene', 'fr')->getLucene();
// build invalid indexes structures
file_put_contents($root . 'testLucene/en/random_file', 'r@nd()');
mkdir($root . 'testLucene/foo', 0777, true);
file_put_contents($root . 'testLucene/foo/bar', 'foo');