Ejemplo n.º 1
0
        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) {
    $t->fail('->getInternalTitle() executes with no possible title');
}
$h->set('fields', $fields);
$t->diag('testing ->getInternalUri()');
/**
 * @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';
$params = array('a', 'b', 'c');
$listener = new FooListener();
$target->connect('bar', array($listener, 'listen'));
$source->notify(new sfEvent($subject, 'foo', $params));
$t->isa_ok($listener->event, 'sfEvent', 'calling a linked event calls target');
$t->is($listener->event->getSubject(), $subject, 'calling a linked event sends correct subject');
$t->is($listener->event->getName(), 'bar', 'calling a linked event sends correct name');
$t->is($listener->event->getParameters(), $params, 'calling a linked event sends correct parameters');
Ejemplo n.º 3
0
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) {
    $t->ok($new->getParameter('is_new'), 'property "is_new" is true on a new index');
    $t->is($new->numDocs(), 0, '->numDocs() indicates index is empty');
} else {
    $t->skip('index has new status new status on new index');
    $t->skip('->numDocs() indicates index is empty');
}
$t->diag('testing ::getAllInstances()');
try {
    $t->no_exception('::getAllInstance() executes without exception');
    $instances = sfLucene::getAllInstances();
    $e->no();
<?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');
    <style type="text/stylesheet" xml:space="preserve">
      foobar
    </style>
    <textarea>
      foobar
    </textarea>
    <!-- foobar -->
    <strong class="foobar">bar</strong>
  </body>
</html>
';
$keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'foobar');
$highlighter = new sfLuceneHighlighterXHTML($xml);
$highlighter->addKeywords(array($keyword));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() highlights only the HTML content and works with the namespace correctly');
// ********************************************
// ********************************************
$xml = '
<html>
  <head>
    <title>foobar</title>
  </head>
  <body>
    <p>I am prety foobar</p>
  </body>
</html>
';
$expected = '<?xml version="1.0"?>
<html>
  <head>
 * @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()');
$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);
 *
 * 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');
$highlighter = new sfLuceneHighlighterHTMLPart($given);
$highlighter->addKeywords(array($keyword));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() handles entities correctly');
Ejemplo n.º 8
0
    'description' => false,
    'id' => false,
    'name' => false,
    'sfl_type' => false,
    'sfl_guid' => false,
    'skills' => false,
  ),
))
VAR_DUMP;
}
$standard_response = sprintf($standard_response, 3, implode(", ", $results));
$response = new sfLuceneResponse($standard_response);
$search = sfLucene::getInstance('index', 'en', $app_configuration);
$results = new sfLuceneResults($response, $search);
$t->diag('testing ->getSearch(), ->toArray()');
$t->is($results->getSearch(), $search, '->getSearch() returns the same search instance');
foreach ($results->toArray() as $pos => $result) {
    $t->is(var_export($result, 1), $expected_objects[$pos], '->toArray() pos #' . $pos);
}
$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;
//   }
//
//   $t->is(var_export($value->getResult(), 1 ), $expected_objects[$key], '->getResult() pos #'.$key);
}
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');
$t->diag('testing ArrayAccess interface');
 * @version SVN: $Id: sfLuceneEventConnectorLoggerTest.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();
class FooListener
{
    public $event;
    public function listen($event)
    {
        $this->event = $event;
    }
}
$source = new sfEventDispatcher();
$target = new sfEventDispatcher();
$formatter = new sfFormatter();
$connector = new sfLuceneEventConnectorLogger($source, 'foo', $target, 'bar', $formatter);
$t->ok($source->hasListeners('foo'), '__construct() connects a listener to the source');
$subject = 'Fabien';
$params = array('What is %s dude?  I am %d years %s now', 'down', '5', 'young');
$listener = new FooListener();
$target->connect('bar', array($listener, 'listen'));
$source->notify(new sfEvent($subject, 'foo', $params));
$t->isa_ok($listener->event, 'sfEvent', 'calling a linked event calls target');
$t->is($listener->event->getSubject(), $subject, 'calling a linked event sends correct subject');
$t->is($listener->event->getName(), 'bar', 'calling a linked event sends correct name');
$t->is($listener->event->getParameters(), array('What is down dude?  I am 5 years young now'), 'calling a linked logged event parses message correctly');
$connector = new sfLuceneEventConnectorLogger($source, 'foo', $target, 'bar', $formatter, 'Section');
$source->notify(new sfEvent($subject, 'foo', $params));
$t->is($listener->event->getParameters(), array('>> Section What is down dude?  I am 5 years young now'), 'calling a linked logged event parses message correctly');
 * (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');
$t->isa_ok($d->getFileObject('foo', false), 'sfLuceneFileStorage', '->getFileObject() returns an instance of sfLuceneFileStorage if told not to share');
touch($luceneade->sandbox_dir . '/really/long/path/to/something/bar');
$t->isa_ok($d->getFileObject('bar'), 'sfLuceneFileStorage', '->getFileObject() returns an instance of sfLuceneFileStorage if the file exists but not handled');
<?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: sfLuceneHighlighterMarkerDryTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
require dirname(__FILE__) . '/../../../bootstrap/unit.php';
$t = new limeade_test(3, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
$marker = new sfLuceneHighlighterMarkerDry();
$t->is($marker->highlight('foobar'), 'foobar', '->highlight() does nothing');
$t->isa_ok(sfLuceneHighlighterMarkerDry::generate(), 'sfLuceneHighlighterMarkerHarness', '::generate() returns a highlighter marker harness');
$t->is(sfLuceneHighlighterMarkerDry::generate()->getHighlighter()->highlight('foobar'), 'foobar', '::generate() builds correct highlighters');
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id$
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(4, limeade_output::get());
$dtd = $_SERVER['SYMFONY'] . '/test/w3c/TR/xhtml1/DTD/xhtml1-transitional.dtd';
$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 sfLuceneHighlighterXHTMLPart($given);
$highlighter->setMasterDtd($dtd);
$highlighter->addKeywords(array($keyword));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() highlights a part of the document and returns just that part');
$given = '<html><body><p>This is part of a document, dedicated to foobar.</p></body></html>';
$expected = '<html xmlns="http://www.w3.org/1999/xhtml"><body><p>This is part of a document, dedicated to <h>foobar</h>.</p></body></html>';
$keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'foobar');
$highlighter = new sfLuceneHighlighterXHTMLPart($given);
$highlighter->setMasterDtd($dtd);
$highlighter->addKeywords(array($keyword));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() does not fail if it is really a full document');
$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');
$highlighter = new sfLuceneHighlighterXHTMLPart($given);
$highlighter->setMasterDtd($dtd);
$highlighter->addKeywords(array($keyword));
$highlighter->highlight();
Ejemplo n.º 14
0
try {
    $ex = $t->no_exception('__construct() accepts a valid result and valid sfLucene instance');
    new sfLuceneResult($mockresult, $lucene);
    $ex->no();
} catch (Exception $e) {
    $ex->caught($e);
}
$mockresult->sfl_type = 'action';
$t->isa_ok(sfLuceneResult::getInstance($mockresult, $lucene), 'sfLuceneActionResult', '::getInstance() returns an instance of sfLuceneActionResult for "type" = action');
$mockresult->sfl_type = 'model';
$t->isa_ok(sfLuceneResult::getInstance($mockresult, $lucene), 'sfLuceneDoctrineResult', '::getInstance() returns an instance of sfLuceneModelResult for "type" = model');
$mockresult->sfl_type = 'regular';
$result = sfLuceneResult::getInstance($mockresult, $lucene);
$t->isa_ok($result, 'sfLuceneResult', '::getInstance() returns an instance of sfLuceneResult for "type" = regular');
$t->diag('testing ->getSearch(), ->getResult()');
$t->is($result->getSearch(), $lucene, '->getSearch() returns the same instance of sfLucene as initialized with');
$t->is($result->getResult(), $mockresult, '->getResult() returns the same instace of the result as initialized with');
$t->diag('testing simple ->get*()');
$t->is($result->getScore(), 43, '->getScore() gets the percentage from decimal and rounds');
$t->is($result->getInternalPartial(), 'sfLucene/regularResult', '->getInternalPartial() returns the correct partial name');
$t->diag('testing dynamic ->getXXX()');
$mockresult->sequence = '123';
$t->is($result->getSequence(), '123', '->getXXX() returns property XXX on document');
$t->ok($result->hasSequence(), '->hasXXX() returns true if document has property XXX');
$mockresult->super_duper_man = 'Fabien Potencier';
$t->is($result->getSuperDuperMan(), 'Fabien Potencier', '->getXXX() returns property XXX for camel case');
$t->ok($result->hasSuperDuperMan(), '->hasXXX() returns if document has property XXX for camel case');
try {
    $ex = $t->exception('->getXXX() fails if the property does not exist');
    $result->getSomethingReallyBad();
    $ex->no();
<?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');
<?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');
Ejemplo n.º 17
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(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');
$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());
$t->ok(!$form->getWidgetSchema()->offsetExists('category'), '->setCategories() removes "category" key from widget schema');
$t->ok(!$form->getValidatorSchema()->offsetExists('category'), '->setCategories() removes "category" key from validator schema');
$t->diag('testing url string generation');
$form = new sfLuceneSimpleForm();
$form->setCategories(array('baz'));
$form->bind(array('query' => 'foobar', 'category' => 'baz', 'page' => 2));
$t->is($form->getQueryString(), 'form%5Bquery%5D=foobar&amp;form%5Bcategory%5D=baz&amp;form%5Bpage%5D=2', '->getQueryString() returns querystring');
$t->is($form->getQueryString(5), 'form%5Bquery%5D=foobar&amp;form%5Bcategory%5D=baz&amp;form%5Bpage%5D=5', '->getQueryString() returns querystring with altered page');
 * 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();
$t->is($highlighter->export(), 'i am <h>foobar</h> and my friend is <s>baz</s>', '->highlight() handles multiple keywords');
$highlighter = new sfLuceneHighlighterString('there is <em>some</em> <strong>html</strong> here');
$t->is($highlighter->strip()->export(), 'there is some html here', '->strip() strips out the HTML');
$keywords = array(new sfLuceneHighlighterKeywordNamedInsensitive(new sfLuceneHighlighterMarkerDry(), 'lorem'), new sfLuceneHighlighterKeywordNamedInsensitive(new sfLuceneHighlighterMarkerDry(), 'dictum'));
$highlighter = new sfLuceneHighlighterString('Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras rhoncus fermentum diam. Mauris lobortis. Integer eros. Nulla facilisi. Nulla ultrices, massa eget vehicula tincidunt, dui lorem dictum arcu, et molestie risus sem non odio. Quisque venenatis odio nec orci. Aenean diam nulla, auctor ac, molestie et, venenatis ut, libero. Sed tellus risus, adipiscing ut, sagittis at, feugiat eget, sem. Nullam metus risus, dignissim ac, pellentesque a, euismod in, turpis. Donec auctor elit nec sem.');
        $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);
    $t->pass('highlighter accepts content with a complete body tag set and other carats');
} catch (sfException $e) {
    $t->fail('highlighter accepts content with a complete body tag set and other carats');
}
    $t->ok($queries[0] == $query, '->add() correctly adds a Zend query');
} catch (Exception $e) {
    $t->fail('->add() accepts a Zend query');
    $t->skip('->add() correctly adds a Zend query');
}
try {
    $criteria->add(inst(), null);
    $t->pass('->add() accepts sfLuceneCriteria');
    $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
    $query->addTerm(new Zend_Search_Lucene_Index_Term('word1'), true);
    $query->addTerm(new Zend_Search_Lucene_Index_Term('word2'), null);
    $query->addTerm(new Zend_Search_Lucene_Index_Term('word3'), false);
    $luceneQuery = inst()->add($query);
    $subqueries = inst()->add($luceneQuery)->getQuery()->getSubqueries();
    $subqueries = $subqueries[0]->getSubqueries();
    $t->is($subqueries[0], $query, '->add() correctly combines sfLuceneCriteria queries');
} catch (Exception $e) {
    $t->fail('->add() accepts sfLuceneCriteria');
    $t->skip('->add() correctly combines sfLuceneCriteria queries');
}
try {
    $criteria->add($criteria, true);
    $t->fail('->add() rejects itself');
} catch (Exception $e) {
    $t->pass('->add() rejects itself');
}
try {
    $criteria->add('hello ~ & ! ( ');
    $t->fail('->add() rejects bad syntax');
} catch (Exception $e) {
    $t->pass('->add() rejects bad syntax');
 */
/**
 * @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()');
}
$bh->delete();
$t->is($bh->read(), null, '->delete() causes ->read() to return null');
/**
 * @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');
$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->isa_ok($keywords[0], 'sfLuceneHighlighterKeywordNamedInsensitive', '::generate() returns instances of sfLuceneHighlighterKeywordNamedInsensitive');
$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');
$keywords = sfLuceneHighlighterKeywordNamedInsensitive::explode($harness, 'foobar António baz.....symf0ny');
    $t->fail('__construct() accepts an array');
}
$t->diag('testing basic pagination functions');
try {
    $results->setPage(2);
    $t->pass('->setPage() accepts a integer page');
} catch (Exception $e) {
    $t->fail('->setPage() accepts a integer page');
}
try {
    $results->setMaxPerPage(10);
    $t->pass('->setMaxPerPage() accepts an integer per page');
} catch (Exception $e) {
    $t->fail('->setMaxPerPage() accepts an integer per page');
}
$t->is($results->getPage(), 2, '->getPage() returns current page');
$t->is($results->getMaxPerPage(), 10, '->getMaxPerPage() returns the max per page');
$t->is($results->getNbResults(), 1001, '->getNbResults() returns the total number of results');
$t->ok($results->haveToPaginate(), '->haveToPaginate() returns correct value');
$results->setPage(0);
$t->is($results->getPage(), 1, '->setPage() to 0 sets the page to 1');
$results->setPage(100000);
$t->is($results->getPage(), 101, '->setPage() above to upper bound resets to last page');
$results->setPage(2);
$t->diag('testing ->getResults()');
$t->is_deeply($results->getResults()->toArray(), range(10, 20), '->getResults() returns the correct range');
$results->setPage(3);
$t->is_deeply($results->getResults()->toArray(), range(20, 30), '->getResults() returns the correct range after page change');
$results->setMaxPerPage(0);
$t->is_deeply($results->getResults()->toArray(), range(0, 1000), '->getResults() returns all results if the max per page is 0');
$results->setMaxPerPage(10);
 *
 * 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');
    </textarea>
    <!-- foobar -->
    <strong class="foobar">bar</strong>
  </body>
</html>
';
$expected = '<!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 <h>foobar</h></p><script>
      foobar
    </script><style type="text/stylesheet">
      foobar
    </style><textarea>
      foobar
    </textarea><!-- foobar --><strong class="foobar">bar</strong></body></html>
';
$keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'foobar');
$highlighter = new sfLuceneHighlighterHTML($xml);
$highlighter->addKeywords(array($keyword));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() highlights only the HTML content and works with the namespace correctly');
// ********************************************
// ********************************************
$xml = '<p>I am pretty foobar</p>';
$expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>I am pretty <h>foobar</h></p></body></html>
';
$keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'foobar');
$highlighter = new sfLuceneHighlighterHTML($xml);
$highlighter->addKeywords(array($keyword));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() transforms and highlights the document if it is invalid HTML');
 * @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');
/*
 * 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');
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) {
    $t->fail('->setCategories() accepts valid inputs');
}
$t->is($form->hasCategories(), true, '->hasCategories() returns true when categories are set');
$t->is($form->setupCount, $formFreeze->setupCount + 1, '->setCategories() runs ->setup()');
$t->is($form->configureCount, $formFreeze->configureCount + 1, '->setCategories() runs ->configure()');
$t->is_deeply($form->getCategories(), array('foo', 'bar', 'baz'), '->getCategories() returns the categories');
try {
    $form->setCategories(array());
    $t->pass('->setCategories() accepts an empty array');
} catch (Exception $e) {
    $t->fail('->setCategories() accepts valid inputs');
}
$t->is($form->hasCategories(), false, '->hasCategories() returns true when categories are set');
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');
$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');