/*
 * 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: sfLuceneResultsTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(13, 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');
class MockResult extends Zend_Search_Lucene_Search_QueryHit
{
    public $name;
    public function __construct($a)
    {
        $this->name = $a;
    }
    public function getDocument()
    {
        return new MockDocument();
/*
 * 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: 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()
    {
/*
 * 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: 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');
/*
 * 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(4, limeade_output::get());
$xml = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>foobar</title>
  </head>
  <body>
    <p>I am prety foobar</p>
    <script>
      foobar
    </script>
    <style type="text/stylesheet">
      foobar
    </style>
    <textarea>
/*
 * 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: sfLuceneEventConnectorTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(5, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
class FooListener
{
    public $event;
    public function listen($event)
    {
        $this->event = $event;
    }
}
$source = new sfEventDispatcher();
$target = new sfEventDispatcher();
$connector = new sfLuceneEventConnector($source, 'foo', $target, 'bar');
$t->ok($source->hasListeners('foo'), '__construct() connects a listener to the source');
$subject = 'Fabien';
/*
 * 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: 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');
<?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');
<?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: sfLuceneHighlighterKeywordZendTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../../bootstrap/unit.php';
$t = new limeade_test(1, limeade_output::get());
$t->todo('Implementation');
/*
 * 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: 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');
/*
 * 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(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;
/*
 * 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: 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');
<?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: sfLuceneLazyLoadingTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../bootstrap/unit.php';
$t = new limeade_test(2, limeade_output::get());
$limeade = new limeade_sf($t);
$limeade->bootstrap();
$luceneade = new limeade_lucene($limeade);
$luceneade->configure()->clear_sandbox()->load_models();
$forum = new FakeForum();
$t->not_like_included('#/Zend/Search/Lucene/#', 'Zend libraries were not loaded when just reading from a model');
$forum->setTitle('test');
$forum->saveIndex();
$t->like_included('#/Zend/Search/Lucene/#', 'Zend libraries were loaded when writing to the index');
$forum->deleteIndex();
/*
 * 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: sfLuceneSimpleFormTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(12, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$t->diag('testing constructor');
try {
    $form = new sfLuceneSimpleForm();
    $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(), 'sfLuceneWidgetFormatterSimple', 'formatter is appropriate type');
$t->diag('testing categories');
$categories = array('foo', 'bar', 'baz', 'foobar');
<?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');
/*
 * 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(8, limeade_output::get());
$keywords = array(new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerUppercase(), 'foobar'), new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('"%s"'), 'foobarbaz'));
$highlighter = new sfLuceneHighlighterString('Once foo married bar, they become a foobar, conquering the world.');
$highlighter->addKeywords($keywords);
$highlighter->highlight();
$t->is($highlighter->export(), 'Once foo married bar, they become a FOOBAR, conquering the world.', '->highlight() correctly highlights the string');
$t->is($highlighter->getKeywords(), $keywords, '->getKeywords() returns the array of keywords');
$highlighter = new sfLuceneHighlighterstring('Please wait for foobar to turn not into foobar, but only a foobarbaz with is foobar but just foobarbaz');
$highlighter->addKeywords($keywords);
$highlighter->highlight();
$t->is($highlighter->export(), 'Please wait for FOOBAR to turn not into FOOBAR, but only a "foobarbaz" with is FOOBAR but just "foobarbaz"', '->highlight() handles changing data length');
$keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'foobar');
$keyword2 = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<s>%s</s>'), 'baz');
$highlighter = new sfLuceneHighlighterString('i am foobar and my friend is baz');
$highlighter->addKeywords(array($keyword, $keyword2));
$highlighter->highlight();
/*
 * 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: 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');
/*
 * 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: sfLuceneHighlighterHTMLPartTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(2, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$given = '<p>This is part of a document, dedicated to foobar.</p><p>Look, a foobar</p>';
$expected = '<p>This is part of a document, dedicated to <h>foobar</h>.</p>
<p>Look, a <h>foobar</h></p>
';
$keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'foobar');
$highlighter = new sfLuceneHighlighterHTMLPart($given);
$highlighter->addKeywords(array($keyword));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() highlights a part of the document and returns just that part');
$given = '<p>This is p&agrave;rt of a document, dedicated to foobar.</p>';
$expected = '<p>This is p&agrave;rt of a document, dedicated to <h>foobar</h>.</p>
';
$keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'foobar');
/*
 * 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(2, limeade_output::get());
$xml = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>foobar</title>
  </head>
  <body>
    <p>I am prety foobar</p>
    <script>
      foobar
    </script>
    <style type="text/stylesheet">
      foobar
    </style>
    <textarea>
<?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(3, limeade_output::get());
$marker = new sfLuceneHighlighterMarkerUppercase();
$t->is($marker->highlight('foobar'), 'FOOBAR', '->highlight() converts the string to uppercase');
$t->isa_ok(sfLuceneHighlighterMarkerUppercase::generate(), 'sfLuceneHighlighterMarkerHarness', '::generate() returns a highlighter marker harness');
$t->is(sfLuceneHighlighterMarkerUppercase::generate()->getHighlighter()->highlight('foobar'), 'FOOBAR', '::generate() builds correct highlighters');
<?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');
}
/*
 * 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(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');
/*
 * 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(2, limeade_output::get());
$given = '<p>This is part of a document, dedicated to foobar.</p><p>Look, a foobar</p>';
$expected = '<p>This is part of a document, dedicated to <h>foobar</h>.</p><p>Look, a <h>foobar</h></p>';
$keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'foobar');
$highlighter = new sfLuceneHighlighterHTMLPart($given);
$highlighter->addKeywords(array($keyword));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() highlights a part of the document and returns just that part');
$given = '<p>This is p&agrave;rt of a document foobar, dedic&agrave;ted to foobar.</p>';
$expected = '<p>This is p&agrave;rt of a document foobar, dedic&agrave;ted to <h>foobar</h>.</p>';
$keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'foobar');
$highlighter = new sfLuceneHighlighterHTMLPart($given, null, 'UTF-8');
$highlighter->addKeywords(array($keyword));
$highlighter->highlight();
#$t->is($highlighter->export(), $expected, '->highlight() handles entities correctly');
$t->todo('->highlight() handles entities correctly - domdocument replace html entities');
/*
 * 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: 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');
}
<?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: sfLuceneFileStorageTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../../bootstrap/unit.php';
$t = new limeade_test(1, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$luceneade = new limeade_lucene($limeade);
$luceneade->configure()->clear_sandbox();
clearstatcache();
touch($luceneade->sandbox_dir . '/foo');
chmod($luceneade->sandbox_dir . '/foo', 0666);
clearstatcache();
new sfLuceneFileStorage($luceneade->sandbox_dir . '/foo');
clearstatcache();
$t->is(substr(sprintf('%o', fileperms($luceneade->sandbox_dir . '/foo')), -4), '0777', '__construct() sets permission to 0777');
/*
 * 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: 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');
<?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');
/*
 * 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(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();
/*
 * 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: sfLuceneHighlighterKeywordNamedTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../../bootstrap/unit.php';
$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()');
/*
 * 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: sfLuceneFormTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$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');
/*
 * 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: sfLuceneDirectoryStorageTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../../bootstrap/unit.php';
$t = new limeade_test(7, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$luceneade = new limeade_lucene($limeade);
$luceneade->configure()->clear_sandbox();
clearstatcache();
$d = new sfLuceneDirectoryStorage($luceneade->sandbox_dir . '/really/long/path/to/something');
clearstatcache();
$t->is(substr(sprintf('%o', fileperms($luceneade->sandbox_dir . '/really/long/path/to/something')), -4), '0777', '__construct() sets permission to 0777');
$file = $d->createFile('foo');
$t->isa_ok($file, 'sfLuceneFileStorage', '->createFile() returns an instance of sfLuceneFileStorage');
$t->is(substr(sprintf('%o', fileperms($luceneade->sandbox_dir . '/really/long/path/to/something/foo')), -4), '0777', '->createFile() sets permission to 0777');
$file = $d->createFile('foo');
$t->is(substr(sprintf('%o', fileperms($luceneade->sandbox_dir . '/really/long/path/to/something/foo')), -4), '0777', '->createFile() sets permission to 0777 if it\'s created again');
clearstatcache();
$t->is($d->getFileObject('foo'), $file, '->getFileObject() returns the same instance of the file handler');