}
class Bar extends BaseObject
{
}
function getDoc($lucene, $guid)
{
    $term = new Zend_Search_Lucene_Index_Term($guid, 'sfl_guid');
    $query = new Zend_Search_Lucene_Search_Query_Term($term);
    $hits = $lucene->find($query);
    return $hits[0];
}
$lucene = sfLucene::getInstance('testLucene', 'en');
$model = new FakeForum();
$model->setPrimaryKey(42);
$h = $lucene->getParameterHolder()->get('models')->get('FakeForum');
$t->diag('testing constructor');
try {
    new sfLucenePropelIndexer('foo', $model);
    $t->fail('__construct() rejects invalid search instances');
} catch (Exception $e) {
    $t->pass('__construct() rejects invalid search instances');
}
try {
    new sfLucenePropelIndexer($lucene, new Bar());
    $t->fail('__construct() rejects unregistered models');
} catch (Exception $e) {
    $t->pass('__construct() rejects unregistered models');
}
try {
    new sfLucenePropelIndexer($lucene, new Foo());
    $t->fail('__construct() rejects non-Propel models');
    }
}
class MockDocument
{
    public function getFieldValue($field)
    {
        if ($field == 'sfl_type') {
            return 'regular';
        }
        throw new Exception('d');
    }
}
$data = array(new MockResult('foo'), new MockResult('bar'), new MockResult('baz'));
$search = sfLucene::getInstance('testLucene');
$results = new sfLuceneResults($data, $search);
$t->diag('testing ->getSearch(), ->toArray()');
$t->is($results->getSearch(), $search, '->getSearch() returns the same search instance');
$t->is($results->toArray(), $data, '->toArray() returns the same search data');
$t->diag('testing Iterator interface');
$got = array();
$once = false;
foreach ($results as $key => $value) {
    if (!$once) {
        $t->ok($value instanceof sfLuceneResult, 'iterator interface returns instances of sfLuceneResult');
        $once = true;
    }
    $got[$key] = $value->getResult();
}
$t->is($got, $data, 'sfLuceneResults implements the Iterator interface');
$t->diag('testing Countable interface');
$t->is(count($results), count($data), 'sfLuceneResults implements the Countable interface');
 * @author Carl Vondrick
 * @version SVN: $Id: sfLucenePropelInitializerTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(4, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$luceneade = new limeade_lucene($limeade);
$luceneade->configure()->clear_sandbox()->load_models();
class FooBehavior extends sfPropelBehavior
{
    public static function getBehaviors()
    {
        return self::$behaviors;
    }
}
class FooMixer extends sfMixer
{
    public static function getMixins()
    {
        return self::$mixins;
    }
}
$t->diag('testing ::getInstance()');
$init = sfLucenePropelInitializer::getInstance();
$t->isa_ok($init, 'sfLucenePropelInitializer', '::getInstance() returns an instance of sfLucenePropelInitializer');
$t->is(sfLucenePropelInitializer::getInstance(), $init, '::getInstance() returns the same instance each time (singleton)');
$t->is_deeply(FooBehavior::getBehaviors(), array('search' => array('methods' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'saveIndex'), 1 => array(0 => 'sfLucenePropelBehavior', 1 => 'deleteIndex'), 2 => array(0 => 'sfLucenePropelBehavior', 1 => 'insertIndex')), 'hooks' => array(':save:pre' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'preSave')), ':save:post' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'postSave')), ':delete:pre' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'preDelete')), ':delete:post' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'postDelete'))))), '__construct() registers the correct methods and hooks');
$t->diag('testing ->setup()');
$init->setup('FakeModel');
$t->is_deeply(FooMixer::getMixins(), array('BaseFakeForum:save:pre' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'preSave')), 'BaseFakeForum:save:post' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'postSave')), 'BaseFakeForum:delete:pre' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'preDelete')), 'BaseFakeForum:delete:post' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'postDelete')), 'BaseFakeForum:saveIndex' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'saveIndex')), 'BaseFakeForum:deleteIndex' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'deleteIndex')), 'BaseFakeForum:insertIndex' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'insertIndex')), 'BaseFakeModel:save:pre' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'preSave')), 'BaseFakeModel:save:post' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'postSave')), 'BaseFakeModel:delete:pre' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'preDelete')), 'BaseFakeModel:delete:post' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'postDelete')), 'BaseFakeModel:saveIndex' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'saveIndex')), 'BaseFakeModel:deleteIndex' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'deleteIndex')), 'BaseFakeModel:insertIndex' => array(0 => array(0 => 'sfLucenePropelBehavior', 1 => 'insertIndex'))), '->setup() configures sfMixer correctly');
 * 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: 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 = new limeade_test(18, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$highlighter = new sfLuceneHighlighterMarkerDry();
try {
    $kw = new sfLuceneHighlighterKeywordNamed($highlighter, 'foobar');
    $t->pass('__construct() accepts a valid highlighter and valid name');
} catch (Exception $e) {
    $t->fail('__construct() accepts a valid highlighter and valid name');
}
$t->is($kw->getHighlighter(), $highlighter, '->getHighlighter() returns the correct highlighter');
$t->is($kw->getName(), 'foobar', '->getName() returns the correct name');
$t->is($kw->getLength(), 6, '->getLength() returns the correct length');
$got = $kw->tokenize('Foobar is my favorite foobar, but it needs the bar to be foobar');
$expected = array(new sfLuceneHighlighterToken($kw, 'foobar', 22, 28), new sfLuceneHighlighterToken($kw, 'foobar', 57, 63));
$t->diag('testing ->tokenize()');
$t->is($got, $expected, '->tokenize() returns correct positions for case-sensitivity');
$t->is($kw->tokenize('nothing interesting here.  move along!'), array(), '->tokenize() returns nothing if it does not appear in the string');
$t->ok($kw->tokenize('mr foobar, where are the foobars?') == array(new sfLuceneHighlighterToken($kw, 'foobar', 3, 9)), '->tokenize() only tokenizes exact matches');
$t->ok($kw->tokenize('foobar where art thou?') == array(new sfLuceneHighlighterToken($kw, 'foobar', 0, 6)), '->tokenize() can tokenize tokens in the very beginning');
$t->is($kw->tokenize('to be or not to be, that is the foobar'), array(new sfLuceneHighlighterToken($kw, 'foobar', 32, 38)), '->tokenize() can tokenize tokens in the very end');
$t->is($kw->tokenize('foobar'), array(new sfLuceneHighlighterToken($kw, 'foobar', 0, 6)), '->tokenize() can tokenize tokens in the very end and very beginning');
$t->is($kw->tokenize("\nfoobar\n"), array(new sfLuceneHighlighterToken($kw, 'foobar', 1, 7)), '->tokenize() can tokenize tokens with line returns around it');
$t->diag('testing ::generate()');
$lighters = array(new sfLuceneHighlighterMarkerUppercase(), new sfLuceneHighlighterMarkerSprint('[h]%s[/h]'));
$harness = new sfLuceneHighlighterMarkerHarness($lighters);
$keywords = sfLuceneHighlighterKeywordNamed::generate($harness, array('a', 'b', 'c'));
$t->is(count($keywords), 3, '::generate() returns the same number of initial keywords');
$t->ok($keywords[0]->getName() == 'a' && $keywords[1]->getName() == 'b' && $keywords[2]->getName() == 'c', '::generate() returns the keywords in the same order with the correct names');
$t->ok($keywords[0]->getHighlighter() === $lighters[0] && $keywords[1]->getHighlighter() == $lighters[1] && $keywords[2]->getHighlighter() == $lighters[0], '::generate() modulates on the same order as the harness');
$t->diag('testing ::explode()');
예제 #6
0
<?php

require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(2, limeade_output::get());
$t->diag('document format a document');
$document = new Apache_Solr_Document();
$document->setBoost(10);
$document->setField('sfl_guid', 'GUID_1234');
$document->setField('name', 'Thomas Rabaix', 1);
$document->setMultiValue('skills', 'php');
$document->setMultiValue('skills', 'symfony');
$document->addField('skills', 'objective-c');
$expected = array('name' => 'skills', 'value' => array(0 => 'php', 1 => 'symfony', 2 => 'objective-c'), 'boost' => false);
$t->cmp_ok($document->getField('skills'), '==', $expected, '::getField test multivalue setter');
$expected = array('name' => 'name', 'value' => 'Thomas Rabaix', 'boost' => 1);
$t->cmp_ok($document->getField('name'), '==', $expected, '::getField test setter');
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id: sfLuceneCategoryTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(15, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$luceneade = new limeade_lucene($limeade);
$luceneade->configure()->clear_sandbox();
$lucene = sfLucene::getInstance('testLucene', 'en');
$writer = new sfLuceneStorageBlackhole('foo');
$holder = new sfLuceneCategories($lucene, $writer);
$t->diag('testing __construct');
try {
    new sfLuceneCategory('foo', 'bar');
    $t->fail('__construct() must reject invalid holders');
} catch (Exception $e) {
    $t->pass('__construct() must reject invalid holders');
}
try {
    $c = new sfLuceneCategory($holder, 'bar', 5);
    $t->pass('__construct() must accept valid holders');
} catch (Exception $e) {
    $t->fail('__construct() must accept valid holders');
}
$t->diag('testing initialization parameters');
$t->is($c->getCount(), 5, '->getCount() returns default count');
$t->is($c->getName(), 'bar', '->getName() returns the correct name');
 * file that was distributed with this source code.
 */
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id: sfLucenePagerTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(30, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$luceneade = new limeade_lucene($limeade);
$luceneade->configure()->clear_sandbox();
$lucene = sfLucene::getInstance('testLucene', 'en');
$t->diag('testing constructor');
try {
    new sfLucenePager('a', $lucene);
    $t->fail('__construct() rejects a non-array');
} catch (Exception $e) {
    $t->pass('__construct() rejects a non-array');
}
try {
    new sfLucenePager(new sfLuceneResults(array(), $lucene));
    $t->pass('__construct() accepts sfLuceneResults');
} catch (Exception $e) {
    $t->fail('__construct() accepts sfLuceneResults');
}
try {
    new sfLucenePager(array(), null);
    $t->fail('__construct() must have a search instance');
예제 #9
0
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Thomas Rabaix
 * @version SVN: $Id$
 */
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()');
 * 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: 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()');
예제 #11
0
$service = new sfLuceneService('127.0.0.1', '8983');
if (!$service->ping()) {
    //  $t->fail('Solr is not running');  die();
}
$t->is($service->getHost(), '127.0.0.1', '->getHost() ok');
$t->is($service->getPort(), '8983', '->getPort() ok');
$t->is($service->getPath(), '/solr/', '->getPath() ok');
$service->setPath('/solr/index_fr/');
$t->is($service->getPath(), '/solr/index_fr/', '->setPath() ok');
try {
    $response = $service->deleteByQuery('non_existent_field:asd');
    $t->fail('::deleteByQuery refers to a non existent field');
} catch (Exception $e) {
    $t->pass('::deleteByQuery raise an error on non existent field');
}
$t->diag("search for rande, limit:2, offset:0");
$response = $service->search('rande', 0, 2);
$t->ok($response instanceof sfLuceneDocument, '::search returns Apache_Solr_Response object');
$t->cmp_ok($response->getHttpStatusMessage(), '===', 'OK', '::getHttpStatusMessage return OK');
$t->cmp_ok($response->getHttpStatus(), '===', '200', '::getHttpStatus return code 200');
$t->cmp_ok($response->response->numFound, '===', 3, '->response->numFound return 3 entries');
$t->cmp_ok(count($response->response->docs), '===', 2, '->response->numFound return 2 entries');
$t->ok($response->response->docs[0] instanceof sfLuceneDocument, '->response->docs[0] return an instance sfLuceneDocument');
$t->cmp_ok($response->response->docs[0]->sfl_guid, '===', 'GUID_1', '->response->docs[0]->sfl_guid ok');
$t->cmp_ok($response->response->docs[1]->sfl_guid, '===', 'GUID_2', '->response->docs[1]->sfl_guid ok');
//
$t->diag("search for rande, limit:1, offset:2");
$response = $service->search('rande', 2, 1);
$t->ok($response instanceof sfLuceneDocument, '::search returns Apache_Solr_Response object');
$t->cmp_ok($response->getHttpStatusMessage(), '===', 'OK', '::getHttpStatusMessage return OK');
$t->cmp_ok($response->getHttpStatus(), '===', '200', '::getHttpStatus return code 200');
예제 #12
0
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');
$t->is($h->get('name'), 'index', 'property "name" is the name of the index');
{
    public $name;
    public function __construct($a)
    {
        $this->name = $a;
    }
}
// create fake response
$standard_response = '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":3,"start":%s,"docs":[%s]}, %s}';
$expected_objects = array();
$results = array();
foreach (range(1, 3) as $num) {
    $results[] = sprintf('{"description":"symfony fan boy","id":%d,"name":"rande","sfl_guid":"GUID_%d","skills":["symfony","php","objective-c"]}', $num, $num);
}
// faceting stuff
$facets = '"facet_counts":{"facet_queries":{"name:[a TO z]":3},"facet_fields":{"sfl_model":{"User":1, "Group": 2}},"facet_dates":{}}';
$standard_response = sprintf($standard_response, 3, implode(", ", $results), $facets);
$response = new sfLuceneResponse($standard_response);
$search = sfLucene::getInstance('index', 'en', $app_configuration);
$results = new sfLuceneFacetsResults($response, $search);
$t->diag('testing facet queries');
$expected_queries = array("name:[a TO z]" => 3);
$t->is_deeply($results->getFacetQueries(), $expected_queries, '->getFacetQueries() returns the expected array');
$t->is_deeply($results->getFacetQuery("name:[a TO z]"), 3, '->getFacetQuery() returns the expected value');
$t->is_deeply($results->getFacetQuery("non_existant_facet"), null, '->getFacetQuery() return correct value on non existant facet');
$t->diag('testing facet fields');
$expected_fields = array('sfl_model' => array("User" => 1, "Group" => 2));
$t->is_deeply($results->getFacetFields(), $expected_fields, '->getFacetFields() returns the expected array');
$t->cmp_ok($results->getFacetsField('non_existant_field'), '===', null, '->getFacetsField() return null on non existant field');
$t->is_deeply($results->getFacetField('sfl_model'), array("User" => 1, "Group" => 2), '->getFacetField() return correct facet\'s value');
$t->is_deeply($results->getFacetField('non_existant_facet'), null, '->getFacetField() return correct value on non existant facet');
 * 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(19, limeade_output::get());
$chain = new sfFilterChain();
$context = sf_lucene_get_fake_context($app_configuration);
$context->getRouting()->setCurrentRouteName('current_route');
sfConfig::set('sf_i18n', false);
$highlight = new sfLuceneHighlightFilter($context, array('highlight_qs' => 'h', 'notice_tag' => '~notice~', 'highlight_strings' => array('<highlighted>%s</highlighted>', '<highlighted2>%s</highlighted2>'), 'notice_referer_string' => '<from>%from%</from><keywords>%keywords%</keywords><remove>%remove%</remove>', 'notice_string' => '<keywords>%keywords%</keywords><remove>%remove%</remove>', 'remove_string' => '~remove~', 'css' => 'search.css'));
$t->diag('testing validation');
function notify($given = null)
{
    // $d = debug_backtrace();
    // var_dump($d[0]); die();
    static $event;
    if ($given) {
        $event = $given;
    }
    return $event;
}
$request = $context->getRequest();
$response = $context->getResponse();
$request->setParameter('h', 'test');
$context->getEventDispatcher()->connect('application.log', 'notify');
$response->setContent('<html><body>&foobar; </foo></body></html>');
{
}
class Bar
{
}
class sfLuceneActionIndexer
{
}
$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()->load_models();
$search = sfLucene::getInstance('testLucene');
$h = $search->getParameterHolder();
$t->diag('testing construct()');
try {
    $factory = new sfLuceneIndexerFactory($search);
    $t->pass('construct() accepts an instance of sfLucene');
} catch (Exception $e) {
    $t->fail('construct() accepts an instance of sfLucene');
}
$t->diag('testing ->getHandlers()');
$handlers = $factory->getHandlers();
$t->is(array_keys($handlers), array('model', 'action'), '->getHandlers() returns instances of the model and action handler by default');
$t->ok($handlers['model'] == new sfLucenePropelIndexerHandler($search), '->getHandlers() returns a valid model handler');
$t->ok($handlers['action'] == new sfLuceneActionIndexerHandler($search), '->getHandlers() returns a valid action handler');
$h->get('factories')->set('indexers', array('action' => array('Foo', 'FooIndexer')));
$handlers = $factory->getHandlers();
$t->ok($handlers['action'] == new Foo($search), '->getHandlers() can overload built-in handlers');
$h->get('factories')->set('indexers', array('action' => null));
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id: sfLuceneCriteriaTest.php 24784 2009-12-02 09:58:03Z rande $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(5, limeade_output::get());
class Foo
{
}
function inst($app_configuration)
{
    return sfLuceneCriteria::newInstance();
}
$t->diag('testing constructors');
try {
    $criteria = new sfLuceneFacetsCriteria();
    $t->pass('__construct() takes a sfLucene instance');
} catch (Exception $e) {
    $t->fail('__construct() takes a sfLuce instance');
}
$t->isa_ok(sfLuceneFacetsCriteria::newInstance(), 'sfLuceneFacetsCriteria', '::newInstance() returns an sfLuceneFacetsCriteria object');
$t->diag('testing ->getQuery()');
$t->ok(is_string($criteria->getQuery()), '->getQuery() returns an instance a string');
$criteria->addFacetField('language');
$criteria->addFacetField('task');
$criteria->addFacetQuery('price:[0 TO 100]');
$criteria->addFacetQuery('price:[100 TO 200]');
$expected = array('fl' => array(0 => '*,score'), 'sort' => array(0 => 'score desc'), 'facet' => array(0 => 'true'), 'facet.field' => array(0 => 'language', 1 => 'task'), 'facet.query' => array(0 => 'price:[0 TO 100]', 1 => 'price:[100 TO 200]'));
$t->is_deeply($criteria->getParams(), $expected, '->getParams() return the parameters array');
 */
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id: sfLuceneCategoriesTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(20, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$luceneade = new limeade_lucene($limeade);
$luceneade->configure()->clear_sandbox();
$lucene = sfLucene::getInstance('testLucene', 'en');
$writer = new sfLuceneStorageBlackhole('foo');
$t->diag('testing constructor and initialization');
try {
    new sfLuceneCategories('foo');
    $t->fail('__construct() must reject invalid search instances');
} catch (Exception $e) {
    $t->pass('__construct() must reject invalid search instances');
}
try {
    new sfLuceneCategories($lucene);
    $t->pass('__construct() must accept an instance of sfLucene');
} catch (Exception $e) {
    $t->fail('__construct() must accept an instance of sfLucene');
    $e->printStackTrace();
}
try {
    new sfLuceneCategories($lucene, 'dd');
예제 #18
0
<?php

/*
 * This file is part of the sfLucenePlugin package
 * (c) 2007 - 2008 Carl Vondrick <*****@*****.**>
 *
 * 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';
require dirname(__FILE__) . '/../../../lib/helper/sfLuceneHelper.php';
$t = new limeade_test(7, limeade_output::get());
$t->diag('testing highlighting');
$t->is(highlight_result_text('Hello.  This is a pretty <em class="thing">awesome</em> thing to be talking about.', 'thing talking'), 'Hello.  This is a pretty awesome <strong class="highlight">thing</strong> to be <strong class="highlight">talking</strong> about.', 'highlight_result_text() highlights text and strips out HTML');
$t->is(highlight_result_text('Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. This is a pretty <em class="thing">awesome</em> thing to be talking about.  Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. Foo bar. ', 'thing talking', 50), '...is is a pretty awesome <strong class="highlight">thing</strong> to be <strong class="highlight">talking</strong> about....', 'highlight_result_text() highlights and truncates text');
$t->is(highlight_keywords('Hello.  This is a pretty <em class="thing">awesome</em> thing to be talking about.', 'thing talking'), 'Hello.  This is a pretty <em class="thing">awesome</em> <strong class="highlight">thing</strong> to be <strong class="highlight">talking</strong> about.', 'highlight_kewyords() highlights text');
$t->diag('testing query string manipulation');
$t->is(add_highlight_qs('test/model', 'foo bar'), 'test/model?sf_highlight=foo bar', 'add_highlight_qs() adds a query string correctly');
$t->is(add_highlight_qs('test/model?a=b', 'foo bar'), 'test/model?a=b&sf_highlight=foo bar', 'add_highlight_qs() handles existing query strings');
$t->is(add_highlight_qs('test/model#anchor', 'foo bar'), 'test/model?sf_highlight=foo bar#anchor', 'add_highlight_qs() handles anchors');
$t->is(add_highlight_qs('test/model?a=b#anchor', 'foo bar'), 'test/model?a=b&sf_highlight=foo bar#anchor', 'add_highlight_qs() handles anchors and existing query strings');
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(3, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$luceneade = new limeade_lucene($limeade);
$luceneade->configure()->clear_sandbox()->load_models();
class FooIndexer extends sfLucenePropelIndexerHandler
{
    public $rebuilds = array();
    public function rebuildModel($name)
    {
        $this->rebuilds[] = $name;
    }
}
$search = sfLucene::getInstance('testLucene', 'en');
$t->diag('testing ->rebuild()');
$handler = new FooIndexer($search);
$handler->rebuild();
$t->is($handler->rebuilds, array('FakeForum'), '->rebuild() calls ->rebuildModel() for all models');
$t->diag('testing ->rebuildModel()');
$handler = new sfLucenePropelIndexerHandler($search);
$search->getParameter('models')->get('FakeForum')->set('rebuild_limit', 5);
$models = array();
for ($x = 0; $x < 6; $x++) {
    $var = new FakeForum();
    $var->setCulture('en');
    $var->setTitle('foo');
    $var->setDescription('bar');
    $var->setCoolness(3);
    $var->save();
    $var->deleteIndex();
 * @version SVN: $Id: sfLuceneCriteriaTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(53, limeade_output::get());
$limeade = new limeade_sf($t);
$limeade->bootstrap();
$luceneade = new limeade_lucene($limeade);
$luceneade->configure();
class Foo
{
}
function inst()
{
    return sfLuceneCriteria::newInstance(sfLucene::getInstance('testLucene'));
}
$t->diag('testing constructors');
try {
    $criteria = new sfLuceneCriteria(sfLucene::getInstance('testLucene'));
    $t->pass('__construct() takes a sfLucene instance');
} catch (Exception $e) {
    $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');
    $sPartial = $partial;
    $sParams = $params;
}
class Foo
{
    public function getInternalPartial()
    {
        return 'FooPartial';
    }
}
class Bar
{
}
$foo = new Foo();
$bar = new Bar();
$t->diag('testing partial dependencies');
include_search_result($foo, 'query');
$values = include_partial(null, null, true);
$t->is($values['partial'], 'FooPartial', 'include_search_result() selects the correct partial');
$t->ok($values['params']['result'] === $foo, 'include_search_result() sends the same result');
$t->is($values['params']['query'], 'query', 'include_search_result() passes the query');
include_search_controls($foo);
$values = include_partial(null, null, true);
$t->is($values['partial'], 'sfLucene/controls', 'include_search_controls() selects the correct partial');
$t->ok($values['params']['form'] === $foo, 'include_search_controls() sends the same form');
include_search_pager($foo, $bar, 8);
$values = include_partial(null, null, true);
$t->is($values['partial'], 'sfLucene/pagerNavigation', 'include_search_pager() selects the correct partial');
$t->ok($values['params']['pager'] === $foo, 'include_search_pager() sends the same pager');
$t->ok($values['params']['form'] === $bar, 'include_search_pager() sends the same form');
$t->is($values['params']['radius'], 8, 'include_search_pager() sends the correct radius');
 * (c) 2007 - 2008 Carl Vondrick <*****@*****.**>
 *
 * 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: sfLuceneAdvancedFormTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(10, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$t->diag('testing constructor');
try {
    $form = new sfLuceneAdvancedForm();
    $t->pass('__construct() with no arguments does not throw an exception');
} catch (Exception $e) {
    $t->fail('__construct() with no arguments does not throw an exception');
}
$t->diag('testing initialization');
$t->isa_ok($form->getWidgetSchema(), 'sfWidgetFormSchema', 'widget schema is appropriate type');
$t->isa_ok($form->getValidatorSchema(), 'sfValidatorSchema', 'validator schema is appropriate type');
$t->isa_ok($form->getWidgetSchema()->getFormFormatter(), 'sfLuceneWidgetFormatterAdvanced', 'formatter is appropriate type');
$t->diag('testing categories');
$categories = array('foo', 'bar', 'baz', 'foobar');
$form->setCategories($categories);
$t->ok($form->getWidgetSchema()->offsetExists('category'), '->setCategories() adds "category" key to widget schema');
$t->is_deeply($form->getWidgetSchema()->offsetGet('category')->getOption('choices'), $categories, '->setCategories() configures widget with correct choices');
예제 #23
0
{
    public function setFields($fields)
    {
        $this->_fields = $fields;
    }
    public function getFieldValue($field)
    {
        if (!isset($this->{$field})) {
            throw new Exception('You said to');
        }
        return $this->{$field};
    }
}
$doc = new MockDocument();
$doc->setFields(array('sfl_type' => 'model', 'sfl_model' => 'FakeForum', 'title' => 'Registered title', 'description' => 'Registered <b>description</b>', 'id' => 42));
$t->diag('testing constructor');
class sfLuceneModelMockResult extends sfLuceneModelResult
{
}
try {
    $result = new sfLuceneModelMockResult($doc, $lucene);
    $t->pass('__construct() accepts a valid result and valid sfLucene instance');
} catch (Exception $e) {
    $t->fail('__construct() accepts a valid result and valid sfLucene instance');
}
$t->is($result->getInternalModel(), 'FakeForum', '->getInternalModel() returns the correct model');
// $h contains the FakeForum configuration
$h = $lucene->getParameter('models')->get('FakeForum');
$t->diag('testing ->getInternalTitle()');
$t->is($result->getInternalTitle(), 'Registered title', '->getInternalTitle() returns the title registered in the document');
$h->remove('title');
예제 #24
0
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id$
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(34, limeade_output::get());
class Foo
{
}
function inst()
{
    return sfLuceneCriteria::newInstance();
}
$t->isa_ok(sfLuceneCriteria::newInstance(), 'sfLuceneCriteria', '::newInstance() returns an sfLuceneCriteria object');
$criteria = inst();
$t->diag('testing ->getQuery()');
$t->ok(is_string($criteria->getQuery()), '->getQuery() returns an instance a string');
$t->diag('testing ->add()');
$criteria->add('test', sfLuceneCriteria::TYPE_AND);
$t->pass('->add() accepts a string');
$queries = inst()->add('foo')->add('bar')->getQuery();
$t->cmp_ok($queries, '===', 'foo AND bar', '->add() correctly parses and adds text queries');
$queries = inst()->add('foo')->add('bar', sfLuceneCriteria::TYPE_OR)->getQuery();
$t->cmp_ok($queries, '===', 'foo OR bar', '->add() correctly parses and adds text queries');
$query = inst();
$query->add('foo');
$criteria->add($query, null);
$t->pass('->add() accepts sfLuceneCriteria');
$luceneQuery = inst()->add($query);
$luceneQuery->add('bar', sfLuceneCriteria::TYPE_OR);
$subqueries = inst()->add($luceneQuery)->getQuery();
예제 #25
0
 * @package sfLucenePlugin
 * @subpackage Test
 * @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 = new limeade_test(9, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
class DummyForm extends sfLuceneForm
{
    public $setupCount = 0, $configureCount = 0;
    public function configure()
    {
        $this->configureCount++;
    }
    public function setup()
    {
        $this->setupCount++;
    }
}
$t->diag('testing constructor');
try {
    $form = new DummyForm();
    $t->pass('__construct() with no arguments does not throw an exception');
} catch (Exception $e) {
    $t->fail('__construct() with no arguments does not throw an exception');
}
$t->diag('testing categories');
try {
    $form->setCategories('foo');
    $t->fail('->setCategories() rejects invalid inputs');
} catch (Exception $e) {
    $t->pass('->setCategories() rejects invalid inputs');
}
$formFreeze = clone $form;
try {
    }
    public function _getDeleteQueue()
    {
        return $this->deleteQueue;
    }
    public function _getSearchInstances($node)
    {
        return $this->getSearchInstances($node);
    }
    public function clear()
    {
        $this->saveQueue = array();
        $this->deleteQueue = array();
    }
}
$t->diag('testing ::getInitializer()');
$t->isa_ok(sfLucenePropelBehavior::getInitializer(), 'sfLucenePropelInitializer', '::getInitializer() returns an instance of sfLucenePropelInitializer');
$t->diag('testing ->getSearchInstances()');
$behavior = new MockBehavior();
try {
    $behavior->_getSearchInstances(new Foo());
    $t->fail('->getSearchInstances() fails if node cannot be found');
} catch (Exception $e) {
    $t->pass('->getSearchInstances() fails if node cannot be found');
}
$instances = $behavior->_getSearchInstances($m1);
$t->ok($instances === array(sfLucene::getInstance('testLucene', 'en'), sfLucene::getInstance('testLucene', 'fr')), '->getSearchInstances() returns all search instances for a Propel model');
$t->is($behavior->_getSearchInstances($m2), $instances, '->getSearchInstances() returns same instances for the same model');
$t->diag('testing ->preSave()');
$behavior->preSave($m1);
$q = $behavior->_getSaveQueue();