} 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); } try { sfLucene::getInstance('testLucene', 'en', true); $t->fail('::getInstance() fails to rebuild index if index is already open');
/** * @package sfLucenePlugin * @subpackage Test * @author Carl Vondrick * @version SVN: $Id: sfLuceneToolkitTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $ */ 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
$t->isa_ok($result, 'sfLuceneResult', '::getInstance() returns an instance of sfLuceneResult for "type" = regular'); $t->diag('testing ->getSearch(), ->getResult()'); $t->is($result->getSearch(), $lucene, '->getSearch() returns the same instance of sfLucene as initialized with'); $t->is($result->getResult(), $mockresult, '->getResult() returns the same instace of the result as initialized with'); $t->diag('testing simple ->get*()'); $t->is($result->getScore(), 43, '->getScore() gets the percentage from decimal and rounds'); $t->is($result->getInternalPartial(), 'sfLucene/regularResult', '->getInternalPartial() returns the correct partial name'); $t->diag('testing dynamic ->getXXX()'); $mockresult->sequence = '123'; $t->is($result->getSequence(), '123', '->getXXX() returns property XXX on document'); $t->ok($result->hasSequence(), '->hasXXX() returns true if document has property XXX'); $mockresult->super_duper_man = 'Fabien Potencier'; $t->is($result->getSuperDuperMan(), 'Fabien Potencier', '->getXXX() returns property XXX for camel case'); $t->ok($result->hasSuperDuperMan(), '->hasXXX() returns if document has property XXX for camel case'); try { $ex = $t->exception('->getXXX() fails if the property does not exist'); $result->getSomethingReallyBad(); $ex->no(); } catch (Exception $e) { $ex->caught($e); } $t->ok(!$result->hasSomethingReallyBad(), '->hasXXX() returns false if the document does not have property XXX'); $mockresult->sfl_field = '987'; $t->is($result->getInternalField(), '987', '->getInternalXXX() returns internal properties'); $t->ok($result->hasInternalField(), '->hasInternalXXX() returns true if internal property exists'); $t->diag('testing ->getInternalDescription()'); try { $ex = $t->no_exception('->getInternalDescription() executes even if there is no description'); $result->getInternalDescription(); $ex->no(); } catch (Exception $e) {
$t->cmp_ok($lucene->getParameter('culture'), '===', 'en', '::getParameter() - culture'); $t->cmp_ok($lucene->getParameter('encoding'), '===', 'UTF-8', '::getParameter() - encoding'); $t->cmp_ok($lucene->getParameter('host'), '===', 'localhost', '::getParameter() - host'); $t->cmp_ok($lucene->getParameter('port'), '===', '8983', '::getParameter() - port'); $t->cmp_ok($lucene->getParameter('base_url'), '===', '/solr', '::getParameter() - base_url'); try { $e = $t->no_exception('::getInstance() allows valid cultures'); $lucene = sfLucene::getInstance('index', 'en', $app_configuration); $e->no(); } catch (Exception $ex) { $e->caught($ex); } $lucene->unlatch(); 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 {