/** * @package sfLucenePlugin * @subpackage Test * @author Carl Vondrick * @version SVN: $Id: sfLuceneTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $ */ require dirname(__FILE__) . '/../bootstrap/unit.php'; $t = new limeade_test(91, limeade_output::get()); $limeade = new limeade_sf($t); $app = $limeade->bootstrap(); $luceneade = new limeade_lucene($limeade); $luceneade->configure()->clear_sandbox(); $t->diag('testing ::getInstance()'); $t->ok(!is_dir(sfConfig::get('sf_data_dir') . '/index/testLucene/en'), 'Lucene directory does not initially exist'); try { $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');
* @author Carl Vondrick * @version SVN: $Id$ */ require dirname(__FILE__) . '/../../bootstrap/unit.php'; sfConfig::set('sf_orm', 'doctrine'); $t = new limeade_test(23, limeade_output::get()); $lucene = sfLucene::getInstance('index', 'en', $app_configuration); class MockResult extends sfLuceneDocument { } $mockresult = new MockResult($lucene->getLucene()); $mockresult->score = 0.425; $mockresult->id = 1; $t->diag('testing constructor'); try { $ex = $t->no_exception('__construct() accepts a valid result and valid sfLucene instance'); new sfLuceneResult($mockresult, $lucene); $ex->no(); } catch (Exception $e) { $ex->caught($e); } $mockresult->sfl_type = 'action'; $t->isa_ok(sfLuceneResult::getInstance($mockresult, $lucene), 'sfLuceneActionResult', '::getInstance() returns an instance of sfLuceneActionResult for "type" = action'); $mockresult->sfl_type = 'model'; $t->isa_ok(sfLuceneResult::getInstance($mockresult, $lucene), 'sfLuceneDoctrineResult', '::getInstance() returns an instance of sfLuceneModelResult for "type" = model'); $mockresult->sfl_type = 'regular'; $result = sfLuceneResult::getInstance($mockresult, $lucene); $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');
* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * @package sfLucenePlugin * @subpackage Test * @author Carl Vondrick * @version SVN: $Id$ */ require dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new limeade_test(2, limeade_output::get()); class Foo { public $executed = false; public function execute() { $this->executed = true; } } $context = sf_lucene_get_fake_context($app_configuration); $filter = new sfLuceneCacheFilter($context); $chain = new Foo(); try { $ex = $t->no_exception('->execute() runs without an exception'); $filter->execute($chain); $ex->no(); } catch (Exception $e) { $ex->caught($e); } $t->ok($chain->executed, '->execute() runs ->execute() on the chain');
die; } $t->instanceof_ok($bh, 'sfLuceneStorage', 'sfLuceneStorageFilesystem 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()'); } $t->ok(file_exists($file), '->write() creates the file'); $t->is(file_get_contents($file), 'foobar', '->write() writes the data to the file'); try { $ex = $t->no_exception('__construct() functions if the directory tree already exists'); $bh2 = new sfLuceneStorageFileSystem($luceneade->sandbox_dir . '/storage/long/folder/flower'); $ex->no(); } catch (Exception $e) { $ex->caught($e); } try { $ex = $t->no_exception('->write() functions if the directory tree already exists'); $bh2->write('foobar'); $ex->no(); } catch (Exception $e) { $ex->caught($e); } $bh->delete(); $t->is($bh->read(), null, '->delete() causes ->read() to return null'); $t->ok(!file_exists($file), '->delete() deletes the file');
* @subpackage Test * @author Carl Vondrick * @version SVN: $Id$ */ require dirname(__FILE__) . '/../bootstrap/unit.php'; $t = new limeade_test(50, limeade_output::get()); $lucene = sfLucene::getInstance('index', 'en', $app_configuration); $t->cmp_ok($lucene->getPublicName(), '===', 'index (en)', '::getPublicName()'); $t->cmp_ok($lucene->getParameter('name'), '===', 'index', '::getParameter() - name'); $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 {