{
    $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');
} catch (Exception $e) {
    $t->pass('__construct() rejects non-Propel models');
}
try {
    $indexer = new sfLucenePropelIndexer($lucene, $model);
<?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: sfLuceneHighlighterMarkerSprintTest.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();
try {
    $marker = new sfLuceneHighlighterMarkerSprint('[h]%s[/h]');
    $t->pass('__construct() accepts a pattern');
} catch (Exception $e) {
    $t->fail('__construct() accepts a pattern');
}
$t->is($marker->highlight('foobar'), '[h]foobar[/h]', '->highlight() highlights the string');
$t->isa_ok(sfLuceneHighlighterMarkerSprint::generate(array('[h]%s[/h]')), 'sfLuceneHighlighterMarkerHarness', '::generate() returns a highlighter marker harness');
$t->is(sfLuceneHighlighterMarkerSprint::generate(array('[h]%s[/h]'))->getHighlighter()->highlight('foobar'), '[h]foobar[/h]', '::generate() builds correct highlighters');
 * 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');
$t->ok($form->getValidatorSchema()->offsetExists('category'), '->setCategories() adds "category" key to validator schema');
$t->is_deeply($form->getValidatorSchema()->offsetGet('category')->getOption('choices'), $categories, '->setCategories() configures validator with correct choices');
$form->setCategories(array());
    $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');
} catch (Exception $e) {
    $t->pass('::getInstance() fails to rebuild index if index is already open');
}
try {
    $e = $t->no_exception('::getInstance() allows to rebuild index if closed');
    $new = sfLucene::getInstance('testLucene', 'fr', true);
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
try {
    sfContext::getInstance()->getUser()->setCulture('en');
    $t->is(sfLucene::getInstance('testLucene')->getParameter('culture'), 'en', '::getInstance() can guess the culture');
} catch (Exception $e) {
    $t->fail('::getInstance() can guess the culture');
}
if ($new) {
<?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';
$t = new limeade_test(1, limeade_output::get());
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
class MockResult extends sfLuceneDocument
{
    public function __construct($a)
    {
    }
}
$doc = new MockResult('a');
try {
    new sfLuceneActionResult($doc, $lucene);
    $t->pass('__construct() can be called');
} catch (Exception $e) {
    $t->fail('__construct() can be called');
}
 *
 * 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(15, limeade_output::get());
$highlighter = new sfLuceneHighlighterMarkerDry();
try {
    $kw = new sfLuceneHighlighterKeywordNamedInsensitive($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', 0, 6), new sfLuceneHighlighterToken($kw, 'foobar', 22, 28), new sfLuceneHighlighterToken($kw, 'foobar', 57, 63));
$t->is($got, $expected, '->tokenize() returns correct positions for case-insensitivity');
$t->is_deeply($kw->tokenize('nothing interesting here.  move along!'), array(), '->tokenize() returns nothing if it does not appear in the string');
$t->is($kw->tokenize('mr foobar, where are the foobars?'), array(new sfLuceneHighlighterToken($kw, 'foobar', 3, 9)), '->tokenize() only tokenizes exact matches');
$lighters = array(new sfLuceneHighlighterMarkerUppercase(), new sfLuceneHighlighterMarkerSprint('[h]%s[/h]'));
$harness = new sfLuceneHighlighterMarkerHarness($lighters);
$keywords = sfLuceneHighlighterKeywordNamedInsensitive::generate($harness, array('a', 'b', 'c'));
$t->is(count($keywords), 3, '::generate() returns the same number of initial keywords');
 * @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');
    $t->fail('__construct() must reject invalid writers');
} catch (Exception $e) {
    $t->pass('__construct() must reject invalid writers');
}
try {
 * @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');
$t->diag('testing ->addFacetField() and ->addFacetQuery() reset');
$criteria->addFacetField('another_field', true);
$criteria->addFacetQuery('the_price:[0 TO 100]', true);
 */
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');
$t->ok($c->getHolder() === $holder, '->getHolder() returns the same holder');
$t->diag('testing ->add() and ->subtract()');
$t->is($c->add()->getCount(), 6, '->add() adds one to the count');
$t->is($c->add(5)->getCount(), 11, '->add() can add more than one to the count');
$t->is($c->subtract()->getCount(), 10, '->subtract() subtracts one from the count');
{
}
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));
$t->is(array_keys($factory->getHandlers()), array('model'), '->getHandlers() can eliminate handlers');
$h->get('factories')->set('indexers', array('pdf' => array('Foo', 'FooIndexer')));
$handlers = $factory->getHandlers();
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(null, limeade_output::get());
$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');
Exemple #12
0
$factory = new MockIndexerFactory($handlers, $lucene);
$originalFactory = $lucene->getIndexerFactory();
$lucene->forceIndexerFactory($factory);
$lucene->getCategoriesHarness()->getCategory('foo');
$lucene->getCategoriesHarness()->save();
$lucene->rebuildIndex();
$t->is($factory->deleteLock, true, '->rebuildIndex() enables the delete lock');
$t->ok($handlers[0]->count == 1 && $handlers[0]->count == 1, '->rebuildIndex() calls each handler\'s ->rebuild() only once');
$t->is($lucene->getCategoriesHarness()->getAllCategories(), array(), '->rebuildIndex() clears the category list');
$lucene->forceIndexerFactory($originalFactory);
$t->diag('testing wrappers');
if ($lucene->getSearchService()->ping()) {
    $t->diag('Solr available');
    try {
        $lucene->optimize();
        $t->pass('->optimize() optimizes the index without exception');
    } catch (Exception $e) {
        $t->fail('->optimize() optimizes the index without exception : ' . $e->getMessage());
    }
    try {
        $t->is($lucene->count(), 3, '->count() returns the document count');
        $t->pass('->count() counts the index without exception');
    } catch (Exception $e) {
        $t->skip('->count() returns the document count');
        $t->fail('->count() counts the index without exception');
    }
    try {
        $t->is($lucene->numDocs(), 3, '->numDocs() returns the document count');
        $t->pass('->numDocs() counts the index without exception');
    } catch (Exception $e) {
        $t->skip('->numDocs() returns the document count');
$highlighter = new sfLuceneHighlighterXML($xml);
$highlighter->addKeywords(array($keyword, $keyword2));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() handles entities correctly');
$xml = '<?xml version="1.0" encoding="utf-8"?>
<root>
  <child>hellÆ bäz</child>
  <child>i am fööbär</child>
</root>
';
$expected = '<?xml version="1.0" encoding="utf-8"?>
<root>
  <child>hellÆ <s>bäz</s></child>
  <child>i am <h>fööbär</h></child>
</root>
';
$keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'fööbär');
$keyword2 = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<s>%s</s>'), 'bäz');
$highlighter = new sfLuceneHighlighterXML($xml);
$highlighter->addKeywords(array($keyword, $keyword2));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() handles UTF8 characters correctly');
try {
    $h = new sfLuceneHighlighterXML('<foo>&ddd;<foo></baz></bar>');
    $h->highlight();
    $t->fail('->highlight() rejects invalid XML');
} catch (Exception $e) {
    $t->pass('->highlight() rejects invalid XML');
}
$highlighter = new sfLuceneHighlighterXML($xml);
$t->is($highlighter->__toString(), $xml, 'highlighter implements __toString()');
    // $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>');
try {
    $highlight->execute($chain);
    $t->pass('highlighter accepts content if it is malformed');
} catch (Exception $e) {
    $t->fail('highlighter accepts content if it is malformed');
}
$t->is($response->getContent(), '<html><body>&foobar; </foo></body></html>', 'highlighter does not touch malformed content');
$t->isa_ok(notify(), 'sfEvent', 'highlighter notifies application log of malformed content');
$response->setContent('<html><body>Hello</body></html>');
try {
    $highlight->execute($chain);
    $t->pass('highlighter accepts content with a complete body tag set');
} catch (sfException $e) {
    $t->fail('highlighter accepts content with a complete body tag set');
}
$response->setContent('<html><body>I am <b>cool</b>!</body></html>');
try {
    $highlight->execute($chain);
 *
 * 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(8, limeade_output::get());
$kw = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerDry(), 'foo');
try {
    $token = new sfLuceneHighlighterToken($kw, 'foo', 10, 15);
    $t->pass('__construct() accepts a valid text and positions');
} catch (Exception $e) {
    $t->fail('__construct() accepts a valid text and positions');
}
try {
    new sfLuceneHighlighterToken($kw, 'foo', 20, 10);
    $t->fail('__construct() rejects end positions that are less than the start position');
} catch (Exception $e) {
    $t->pass('__construct() rejects end positions that are less than the start position');
}
$t->is($token->getKeyword(), $kw, '->getKeyword() returns the keyword');
$t->is($token->getText(), 'foo', '->getText() returns the token text');
$t->is($token->getStart(), 10, '->getStart() returns the start position');
$t->is($token->getEnd(), 15, '->getEnd() returns the end position');
$t->is($token->getLength(), 5, '->getLength() returns the length');
$tokens = array(new sfLuceneHighlighterToken($kw, 'foo', 0, 3), new sfLuceneHighlighterToken($kw, 'foo', 50, 53), new sfLuceneHighlighterToken($kw, 'foo', 10, 13), new sfLuceneHighlighterToken($kw, 'foo', 10, 13), new sfLuceneHighlighterToken($kw, 'foo', 25, 28));
 * 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: 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()');
}
 */
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id$
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(2, limeade_output::get());
$config = new sfLuceneProjectConfigHandler();
$response = $config->execute(array(dirname(__FILE__) . '/../../fixtures/config/project.yml'));
file_put_contents(sys_get_temp_dir() . '/search.yml.php', $response);
require sys_get_temp_dir() . '/search.yml.php';
unlink(sys_get_temp_dir() . '/search.yml.php');
$t->ok(isset($config), '->execute() creates a $config variable');
$expected = array('testLucene' => array('models' => array('FakeModel' => array('fields' => array('id' => array('type' => 'text', 'boost' => null, 'transform' => NULL, 'multiValued' => false, 'required' => false, 'stored' => false, 'default' => null, 'alias' => NULL, 'omitNorms' => NULL), 'title' => array('type' => 'text', 'boost' => null, 'transform' => NULL, 'multiValued' => false, 'required' => false, 'stored' => false, 'default' => null, 'alias' => NULL, 'omitNorms' => true), 'description' => array('type' => 'text', 'boost' => 3, 'transform' => NULL, 'multiValued' => false, 'required' => false, 'stored' => false, 'default' => null, 'alias' => NULL, 'omitNorms' => false)), 'title' => 'title', 'description' => 'description', 'categories' => array(0 => 'Forum'), 'route' => 'forum/showForum?id=%id%', 'validator' => 'isIndexable', 'rebuild_limit' => 5, 'peer' => 'FakeForumTable', 'partial' => 'forumResult', 'callback' => NULL, 'indexer' => NULL)), 'index' => array('encoding' => 'UTF-8', 'cultures' => array(0 => 'en', 1 => 'fr'), 'mb_string' => true, 'param' => array(), 'host' => 'localhost', 'port' => '8983', 'base_url' => '/solr'), 'interface' => array('categories' => true, 'advanced' => true), 'factories' => array('indexers' => array(), 'results' => array())), 'barLucene' => array('models' => array('FakeModel' => array('fields' => array(), 'partial' => NULL, 'callback' => NULL, 'route' => NULL, 'indexer' => NULL, 'title' => NULL, 'description' => NULL, 'peer' => 'FakeModelTable', 'rebuild_limit' => 50, 'validator' => NULL, 'categories' => array())), 'index' => array('encoding' => 'utf-8', 'cultures' => array(0 => 'en'), 'mb_string' => false, 'param' => array(), 'host' => 'localhost', 'port' => '8983', 'base_url' => '/solr'), 'factories' => array('indexers' => array(), 'results' => array())), 'fooLucene' => array('models' => array(), 'index' => array('encoding' => 'utf-8', 'cultures' => array(0 => 'en'), 'mb_string' => false, 'param' => array(), 'host' => 'localhost', 'port' => '8983', 'base_url' => '/solr'), 'factories' => array('indexers' => array(), 'results' => array())));
if ($config != $expected) {
    // expected file
    $expected_file = sys_get_temp_dir() . '/search.yml.php.expected';
    file_put_contents($expected_file, var_export($expected, 1));
    // config file
    $config_file = sys_get_temp_dir() . '/search.yml.php';
    file_put_contents($config_file, var_export($config, 1));
    $cmd = sprintf('diff -y %s %s', $expected_file, $config_file);
    system($cmd);
    $t->fail('->execute() writes the correct configuration from the YAML file');
    unlink($expected_file);
    unlink($config_file);
} else {
    $t->pass('->execute() writes the correct configuration from the YAML file');
}
 * @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');
} catch (Exception $e) {
    $t->pass('__construct() must have a search instance');
}
try {
    $results = new sfLucenePager(range(0, 1000), $lucene);
 * @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');
$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');
    $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();
    {
        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');
$t->is($result->getInternalTitle(), 'Registered title', '->getInternalTitle() can guess the title');
$fields = clone $h->get('fields');
$h->get('fields')->clear();
try {
    $t->is($result->getInternalTitle(), 'No title available.', '->getInternalTitle() executes with no possible title');
} catch (Exception $e) {
 *
 * 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: sfLuceneHighlighterMarkerHarnessTest.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();
$lighters = array(new sfLuceneHighlighterMarkerDry(), new sfLuceneHighlighterMarkerUppercase(), new sfLuceneHighlighterMarkerSprint('[h]%s[/h]'));
try {
    $harness = new sfLuceneHighlighterMarkerHarness($lighters);
    $t->pass('__construct() accepts an array of highlighters');
} catch (Exception $e) {
    $t->fail('__construct() accepts an array of highlighters');
}
try {
    new sfLuceneHighlighterMarkerHarness(array());
    $t->fail('__construct() rejects an empty array of highlighters');
} catch (Exception $e) {
    $t->pass('__construct() rejects an empty array of highlighters');
}
$t->is($harness->getHighlighter(), $lighters[0], '->getHighlighter() returns the first highlighter initially');
$t->is($harness->getHighlighter(), $lighters[1], '->getHighlighter() increments the internal pointer');
$t->is($harness->getHighlighter(), $lighters[2], '->getHighlighter() reaches the end of the array');
$t->is($harness->getHighlighter(), $lighters[0], '->getHighlighter() returns to the first highlighter at the end');
$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) {
    $ex->caught($e);
}
$mockresult->sfl_description = 'foo bar <b>baz</b>';
$t->is($result->getInternalDescription(), 'foo bar baz', '->getInternalDescription() strips out HTML tags');
$t->diag('testing ->getInternalTitle()');
try {
    $result->getInternalTitle();
    $t->pass('->getInternalTitle() executes even if there is no title');
} catch (Exception $e) {
    $t->fail('->getInternalTitle() executes even if there is no title');
}
$mockresult->sfl_title = 'foo bar <b>baz</b>';
$t->is($result->getInternalTitle(), 'foo bar <b>baz</b>', '->getInternalTitle() does not strip out HTML tags');
$t->diag('testing mixins');
function mixin_listener(sfEvent $event)
{
    if ($event['method'] == 'goodMethod') {
        $args = $event['arguments'];
        $event->setReturnValue($args[0] + 1);
        return true;
    }
}
$lucene->getEventDispatcher()->connect('sf_lucene_result.method_not_found', 'mixin_listener');
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();
$t->cmp_ok($subqueries, '==', '((foo) OR bar)', '->getQuery() correctly combines sfLuceneCriteria queries');
try {
    $criteria->add($criteria, true);
    $t->fail('->add() rejects itself');
$nresult = new MockResult('foobar');
$results[3] = $nresult;
$t->is($results[3]->getResult(), $nresult, 'sfLuceneResults implements the ArrayAccess setter interface');
unset($results[3]);
$t->ok(!isset($results[3]), 'sfLuceneResults implements the ArrayAccess unset() interface');
$t->diag('testing mixins');
function callListener($event)
{
    if ($event['method'] == 'goodMethod') {
        $args = $event['arguments'];
        $event->setReturnValue($args[0] + 1);
        return true;
    }
    return false;
}
$search->getEventDispatcher()->connect('results.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');
}
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 {
    $form->setCategories(array('foo', 'bar', 'baz'));
    $t->pass('->setCategories() accepts valid inputs');
} catch (Exception $e) {
    }
    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();
$t->is($q[0], $m1, '->preSave() adds model to queue if it does not already exist');
$t->is(count($q), 1, '->preSave() adds the model to queue only once');
$behavior->preSave($m1);
$t->is(count($behavior->_getSaveQueue()), 1, '->preSave() does not add model again if it already exists');
$behavior->preSave($m2);
$q = $behavior->_getSaveQueue();
$t->is($q[0], $m1, '->preSave() keeps unresolved models in queue');
$t->is($q[1], $m2, '->preSave() adds new models alongside old models');