<?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$
 */
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');
 * (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());
$t->todo('Create test for propel indexer handler');
// $limeade = new limeade_sf($t);
// $app = $limeade->bootstrap();
//
// $luceneade = new limeade_lucene($limeade);
// $luceneade->configure()->clear_sandbox()->load_models();
//
// class FooIndexer extends sfLucenePropelIndexerHandler
// {
//   public $rebuilds = array();
//
//   public function rebuildModel($name)
//   {
//     $this->rebuilds[] = $name;
//   }
// }
 */
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id$
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
//
// class Foo { }
// class Bar { }
//
// class sfLuceneActionIndexer { }
//
$t = new limeade_test(1, limeade_output::get());
$t->todo('Fix these tests');
//
// $search = sfLucene::getInstance('index', 'fr', $app_configuration);
// $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()');
//
 */
require dirname(__FILE__) . '/../../../bootstrap/unit.php';
$t = new limeade_test(5, limeade_output::get());
$limeade = new limeade_sf($t);
$app = $limeade->bootstrap();
class FooFilter extends sfLuceneExecutionFilter
{
    // public interface to executeView
    public function ev($moduleName, $actionName, $viewName, $viewAttributes)
    {
        return $this->executeView($moduleName, $actionName, $viewName, $viewAttributes);
    }
}
$moduleName = 'test';
$actionName = 'foo';
$context = sfContext::getInstance();
$actionInstance = $context->getController()->getAction($moduleName, $actionName);
$context->getController()->getActionStack()->addEntry($moduleName, $actionName, $actionInstance);
$filter = new FooFilter($context);
$chain = new sfFilterChain();
try {
    $ex = $t->no_exception('->execute() runs without exception');
    $filter->execute($chain);
    $ex->no();
} catch (Exception $e) {
    $ex->caught($e);
}
$t->todo('->executeView() sets decorator to false');
$t->todo('->executeView() handles RENDER_NONE mode');
$t->todo('->executeView() handles RENDER_CLIENT mode');
$t->todo('->executeView() handles RENDER_VAR mode');
$t->ok(!$doc->getDocument()->getField('title')->isBinary, 'field type "Unindexed" is not binary');
$h->get('fields')->get('title')->set('type', 'binary');
$indexer->delete();
$indexer->insert();
$lucene->commit();
$doc = getDoc($lucene, $indexer->getModelGuid());
$t->ok($doc->getDocument()->getField('title')->isStored, 'field type "Binary" is stored');
$t->ok(!$doc->getDocument()->getField('title')->isIndexed, 'field type "Binary" is not indexed');
$t->ok(!$doc->getDocument()->getField('title')->isTokenized, 'field type "Binary" is not tokenized');
$t->ok($doc->getDocument()->getField('title')->isBinary, 'field type "Binary" is binary');
$h->get('fields')->get('title')->set('type', 'unstored');
$indexer->delete();
$indexer->insert();
$lucene->commit();
$doc = getDoc($lucene, $indexer->getModelGuid());
$t->todo('field type "Unstored" is not stored');
$t->todo('field type "Unstored" is indexed');
$t->todo('field type "Unstored" is tokenized');
$t->todo('field type "Unstored" is not binary');
$h->get('fields')->get('title')->set('type', 'text');
$indexer->delete();
$indexer->insert();
$lucene->commit();
$doc = getDoc($lucene, $indexer->getModelGuid());
$t->ok($doc->getDocument()->getField('title')->isStored, 'field type "Keyword" is stored');
$t->ok($doc->getDocument()->getField('title')->isIndexed, 'field type "Keyword" is indexed');
$t->ok($doc->getDocument()->getField('title')->isTokenized, 'field type "Keyword" is tokenized');
$t->ok(!$doc->getDocument()->getField('title')->isBinary, 'field type "Keyword" is not binary');
$indexer->delete();
$t->diag('testing ->insert(), document fields');
$model->setTitle('foobar!');
';
$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"?>
<root>
  <child>hellÆ bäz</child>
  <child>i am fööbär</child>
</root>
';
$expected = '<?xml version="1.0"?>
<root>
  <child>hellÆ <s>bäz</s></child>
  <child>i am <h>fööbär</h></child>
</root>
';
$highlighter = new sfLuceneHighlighterXML($xml);
$highlighter->addKeywords(array($keyword, $keyword2));
$highlighter->highlight();
//$t->is($highlighter->export(), $expected, '->highlight() handles UTF8 characters correctly');
$t->todo('->highlight() handles UTF8 characters correctly (pending elegant solution)');
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()');