$e = $t->no_exception('::getInstance() allows valid cultures');
    $lucene = sfLucene::getInstance('testLucene', 'en');
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
$t->ok(is_dir(sfConfig::get('sf_data_dir') . '/index/testLucene/en'), '::getInstance() creates the index');
$stat = stat(sfConfig::get('sf_data_dir') . '/index/testLucene/en/segments.gen');
$lucene->unlatch();
unset($lucene);
try {
    $lucene = sfLucene::getInstance('testLucene', 'en');
    clearstatcache();
    $t->is_deeply(stat(sfConfig::get('sf_data_dir') . '/index/testLucene/en/segments.gen'), $stat, '::getInstance() again opens the index');
} catch (Exception $e) {
    $t->skip('::getInstance() agains opens the index');
}
try {
    $e = $t->exception('::getInstance() rejects invalid cultures');
    sfLucene::getInstance('testLucene', 'piglatin');
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
try {
    $e = $t->exception('::getInstance() rejects invalid names');
    sfLucene::getInstance('badname', 'en');
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
    $t->fail('__construct() takes a sfLuce instance');
}
$t->isa_ok(sfLuceneCriteria::newInstance(sfLucene::getInstance('testLucene')), 'sfLuceneCriteria', '::newInstance() returns an sfLuceneCriteria object');
$t->diag('testing ->getQuery()');
$t->isa_ok($criteria->getQuery(), 'Zend_Search_Lucene_Search_Query_Boolean', '->getQuery() returns an instance of ZSL_Search_Query_Boolean');
$t->diag('testing ->add()');
try {
    $criteria->add('test', true);
    $t->pass('->add() accepts a string');
    $queries = inst()->add('foo')->add('bar')->getQuery()->getSubqueries();
    $t->ok($queries[0] == Zend_Search_Lucene_Search_QueryParser::parse('foo'), '->add() correctly parses and adds text queries');
    $t->ok($queries[1] == Zend_Search_Lucene_Search_QueryParser::parse('bar'), '->add() correctly parses and adds text queries and keeps them in order');
} catch (Exception $e) {
    $e->printStackTrace();
    $t->fail('->add() accepts a string');
    $t->skip('->add() correctly parses and adds text queries');
    $t->skip('->add() correctly parses and adds text queries and keeps them in order');
}
try {
    $criteria->add(new Zend_Search_Lucene_Search_Query_Boolean(), false);
    $t->pass('->add() accepts a Zend query');
    $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
    $query->addTerm(new Zend_Search_Lucene_Index_Term('word1'), true);
    $query->addTerm(new Zend_Search_Lucene_Index_Term('word2'), null);
    $query->addTerm(new Zend_Search_Lucene_Index_Term('word3'), false);
    $queries = inst()->add($query)->getQuery()->getSubqueries();
    $t->ok($queries[0] == $query, '->add() correctly adds a Zend query');
} catch (Exception $e) {
    $t->fail('->add() accepts a Zend query');
    $t->skip('->add() correctly adds a Zend query');
}
Exemplo n.º 3
0
$t->cmp_ok($s, '===', '("test")', '::addSane() with standard string');
$criteria->addSane('&" ? \\unsafe');
$s = $criteria->getQuery();
$t->cmp_ok($s, '===', '("test") AND ("&" OR "?" OR "\\\\unsafe")', '::addSane() with standard string');
try {
    $criteria->add('carl!');
    $t->fail('->add() rejects an illegal query');
} catch (Exception $e) {
    $t->pass('->add() rejects an illegal query');
}
try {
    $criteria->addSane('carl!');
    $t->pass('->addSane() accepts an illegal query');
} catch (Exception $e) {
    $t->fail('->addSane() accepts an illegal query');
    $t->skip('->addSane() correctly adds an illegal query');
}
$t->diag('testing addWildcard()');
$s = inst()->addWildcard('foo*')->getQuery();
$t->cmp_ok($s, '===', '"foo*"', '->addWildcard() registers the correct query with mutlitple character wildcards');
$s = inst()->addWildcard('f?o')->getQuery();
$t->cmp_ok($s, '===', '"f?o"', '->addWildcard() registers the correct query with single character wildcards');
$s = inst()->addWildcard('foo* baz?')->getQuery();
$t->cmp_ok($s, '===', '"foo* baz?"', '->addWildcard() registers the correct query with mixing character wildcards');
$t->diag('testing addPhrase()');
$s = inst()->addPhrase("foo bar")->getQuery();
$t->cmp_ok($s, '==', '"foo bar"', '->addPhrase() registers the correct simple phrase query');
$t->diag('testing addRange()');
$s = inst()->addRange('a', 'b')->getQuery();
$t->cmp_ok($s, '===', '[a TO b]', '->addRange() registers a simple, two-way range');
$s = inst()->addRange('a')->getQuery();
 */
/**
 * @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->is($results->getLinks(5), range(2, 6), '->getLinks() returns the correct link range');
$results->setPage(1);
$t->is($results->getLinks(5), range(1, 5), '->getLinks() returns correct link range when at start of index');
$results->setPage(101);
$t->is($results->getLinks(5), range(97, 101), '->getLinks() returns link range when at end of index');
$t->diag('testing mixins');
function callListener($event)
{
    if ($event['method'] == 'goodMethod') {
        $args = $event['arguments'];
        $event->setReturnValue($args[0] + 1);
        return true;
    }
    return false;
}
$lucene->getEventDispatcher()->connect('pager.method_not_found', 'callListener');
try {
    $results->someBadMethod();
    $t->fail('__call() rejects bad methods');
} catch (Exception $e) {
    $t->pass('__call() rejects bad methods');
}
try {
    $return = $results->goodMethod(2);
    $t->pass('__call() accepts good methods');
    $t->is($return, 3, '__call() passes arguments');
} catch (Exception $e) {
    $t->fail('__call() accepts good methods and passes arguments');
    $e->printStackTrace();
    $t->skip('__call() passes arguments');
}
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id$
 */
require dirname(__FILE__) . '/../../../bootstrap/unit.php';
$t = new limeade_test(3, limeade_output::get());
class Foo
{
    public $executed = false;
    public function execute()
    {
        $this->executed = true;
    }
}
$context = sfContext::createInstance($app_configuration);
$context->getResponse()->setContent('foobar 2357');
$filter = new sfLuceneRenderingFilter($context);
$chain = new Foo();
try {
    ob_start();
    $filter->execute($chain);
    $content = ob_get_clean();
    $t->pass('->execute() runs without an exception');
    $t->like($content, '/^foobar 2357.*/', '->execute() sends response content');
} catch (Exception $e) {
    ob_end_clean();
    $t->fail('->execute() runs without an exception');
    $t->skip('->execute() sends response content');
}
$t->ok($chain->executed, '->execute() runs ->execute() on the chain');
} catch (Exception $e) {
    $t->fail('__construct() must accept an instance of sfLucene');
    $e->printStackTrace();
}
try {
    new sfLuceneCategories($lucene, 'dd');
    $t->fail('__construct() must reject invalid writers');
} catch (Exception $e) {
    $t->pass('__construct() must reject invalid writers');
}
try {
    $c = new sfLuceneCategories($lucene, $writer);
    $t->pass('__construct() must accept valid writers');
} catch (Exception $e) {
    $t->fail('__construct() must accept valid writers');
    $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');
Exemplo n.º 8
0
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(11, limeade_output::get());
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
$luke = new sfLuceneLuke($lucene);
$t->cmp_ok($luke->getRequestHandlerUrl(), '===', 'http://localhost:8983/solr/index_en/admin/luke', '::getRequestUrl() ok');
if ($lucene->getSearchService()->ping()) {
    $t->diag('Solr available');
    $luke->loadInformation();
    $t->cmp_ok($luke->getNumDocs(), '===', 3, '::getNumDocs() ok');
    $t->cmp_ok($luke->getMaxDoc(), '>', 0, '::getMaxDoc() ok');
    $t->cmp_ok($luke->getNumTerms(), '===', 38, '::getNumTerms() ok');
    $t->cmp_ok(date("U", $luke->getVersion()), '!==', false, '::getVersion() ok');
    $t->cmp_ok($luke->getOptimized(), '===', true, '::getOptimized() ok');
    $t->cmp_ok($luke->getCurrent(), '===', true, '::getCurrent() ok');
    $t->ok(is_bool($luke->getHasDeletions()), '::getHasDeletions() ok');
    $t->ok(is_string($luke->getDirectory()), '::getDirectory() ok');
    $t->ok(strtotime($luke->getLastModified()), '::getLastModified() ok');
    $t->cmp_ok($luke->getStats('prout', 'null'), '===', null, '::getStats() ok');
} else {
    $t->skip('::getNumDocs()');
    $t->skip('::getMaxDoc()');
    $t->skip('::getNumTerms()');
    $t->skip('::getVersion()');
    $t->skip('::getOptimized()');
    $t->skip('::getCurrent()');
    $t->skip('::getHasDeletions()');
    $t->skip('::getDirectory()');
    $t->skip('::getLastModified()');
    $t->skip('::getStats()');
}
Exemplo n.º 9
0
unset($lucene);
try {
    $e = $t->exception('::getInstance() rejects invalid cultures');
    sfLucene::getInstance('index', 'piglatin', $app_configuration);
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
try {
    $e = $t->exception('::getInstance() rejects invalid names');
    sfLucene::getInstance('badname', 'en', $app_configuration);
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
$t->skip('->numDocs() TODO !! indicates index is empty');
$t->diag('testing ::getAllInstances()');
try {
    $e = $t->no_exception('::getAllInstance() executes without exception');
    $instances = sfLucene::getAllInstances($app_configuration);
    $e->no();
} catch (Exception $ex) {
    $instances = array();
    $e->caught($ex);
}
$t->is_deeply($instances, array(sfLucene::getInstance('index', 'en', $app_configuration), sfLucene::getInstance('index', 'fr', $app_configuration), sfLucene::getInstance('fooLucene', 'en', $app_configuration)), '::getAllInstances() returns all instances');
$t->is_deeply(sfLucene::getAllNames($app_configuration), array('index', 'fooLucene'), '::getAllNames() returns all configured names');
$t->diag('testing ->loadConfig()');
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
$h = $lucene->getParameterHolder();
$t->isa_ok($h, 'sfParameterHolder', '->getParameterHolder() returns a parameter holder');
}
$indexer->delete();
$h->set('callback', 'getZendDocument');
try {
    $indexer->insert();
    $lucene->commit();
    $t->is($lucene->numDocs(), 1, '->insert() executes if document callback returns a Zend_Search_Lucene_Document');
    $doc = getDoc($lucene, $indexer->getModelGuid());
    try {
        $t->is($doc->callback, 'foo', '->insert() uses document from document callback');
    } catch (Exception $e) {
        $t->fail('->insert() uses document from document callback');
    }
} catch (Exception $e) {
    $t->fail('->insert() executes if document callback returns a Zend_Search_Lucene_Document');
    $t->skip('->insert() uses document from document callback');
}
$indexer->delete();
$h->set('callback', null);
$t->diag('testing ->insert(), categories');
$indexer->insert();
$lucene->commit();
$doc = getDoc($lucene, $indexer->getModelGuid());
$t->is($doc->sfl_category, 'Forum', '->insert() configures categories correctly');
$t->is($doc->sfl_categories_cache, serialize(explode(' ', $doc->sfl_category)), '->insert() configures categories cache correctly');
$t->is($lucene->getCategoriesHarness()->getCategory('Forum')->getCount(), 1, '->insert() updated category database count');
$app->i18n()->setup('en');
$indexer->delete();
$indexer->insert();
$lucene->commit();
$doc = getDoc($lucene, $indexer->getModelGuid());