function highlight_keywords($text, $keywords, $sprint = '<strong class="highlight">%s</strong>')
{
    $highlighter = new sfLuceneHighlighterXHTMLPart($text);
    $highlighter->setMasterDtd(sfConfig::get('app_lucene_xhtml_dtd', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'));
    $marker = new sfLuceneHighlighterMarkerSprint($sprint);
    $harness = new sfLuceneHighlighterMarkerHarness(array($marker));
    $keywords = sfLuceneHighlighterKeywordNamedInsensitive::explode($harness, $keywords);
    $highlighter->addKeywords($keywords);
    return $highlighter->highlight()->export();
}
$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();
$t->is($highlighter->export(), $expected, '->highlight() handles entities correctly');
$given = '<p>Présentation du document, dédié au foobar.</p>';
$expected = '<p>Présentation du document, dédié au <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() utf-8 characters');
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id: sfLuceneHighlighterXHTMLPartTest.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();
$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->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><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->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->addKeywords(array($keyword));
$highlighter->highlight();
$t->is($highlighter->export(), $expected, '->highlight() handles entities correctly');