} catch (sfException $e) { $t->fail('highlighter accepts content with a complete body tag set and other carats'); } $t->diag('testing highlighting'); $response->setContent('<html><body>highlight the keyword</body></html>'); $request->setParameter('h', 'keyword'); $highlight->execute($chain); $t->is($response->getContent(), "<?xml version=\"1.0\"?>\n<html><body>highlight the <highlighted>keyword</highlighted></body></html>\n", 'highlighter highlights a single keyword'); $response->setContent('<html><body>highlight the keyword yay!</body></html>'); $request->setParameter('h', 'highlight KEYWORD'); $highlight->execute($chain); $t->is($response->getContent(), "<?xml version=\"1.0\"?>\n<html><body><highlighted>highlight</highlighted> the <highlighted2>keyword</highlighted2> yay!</body></html>\n", 'highlighter highlights multiple keywords'); $response->setContent('<html><body>~notice~ keyword</body></html>'); $request->setParameter('h', 'keyword'); $highlight->execute($chain); $t->like($response->getContent(), '#<body><keywords><highlighted>keyword</highlighted></keywords><remove>~remove~</remove>#', 'highlighter adds notice string'); $response->setContent('<html><head><title>foobar</title></head><body>keyword</body></html>'); $highlight->execute($chain); $t->like($response->getContent(), '#<link .*?href=".*?search\\.css".*?/>\\n</head>#', 'highlighter adds search stylesheet'); $response->setContent('<html><head><title>foobar</title></head><body>~notice~ google search test</body></html>'); $request->getParameterHolder()->remove('h'); $_SERVER['HTTP_REFERER'] = 'http://www.google.com/search?num=50&hl=en&safe=off&q=google&btnG=Search'; $highlight->execute($chain); $t->like($response->getContent(), '#<highlighted>google</highlighted> search test#', 'highlighter highlights results from Google'); $t->like($response->getContent(), '#<from>Google</from><keywords><highlighted>google</highlighted></keywords><remove>~remove~</remove>#', 'highlighter adds correct notice for results from Google'); $t->like($response->getContent(), '#<link .*?href=".*?search\\.css".*?/>\\n</head>#', 'highlighter adds search stylesheet for results from Google'); $t->diag('testing conditions when no highlighting occurs'); $request->getParameterHolder()->remove('h'); $_SERVER['HTTP_REFERER'] = null; $response->setContent('<head></head><body>~notice~ keywords</body>'); $highlight->execute($chain);
$t->no_exception('::getAllInstance() executes without exception'); $instances = sfLucene::getAllInstances(); $e->no(); } catch (Exception $ex) { $instances = array(); $e->caught($ex); } $t->is_deeply($instances, array(sfLucene::getInstance('testLucene', 'en'), sfLucene::getInstance('testLucene', 'fr'), sfLucene::getInstance('fooLucene', 'en')), '::getAllInstances() returns all instances'); $t->is_deeply(sfLucene::getAllNames(), array('testLucene', 'fooLucene'), '::getAllNames() returns all configured names'); $t->diag('testing ->loadConfig()'); $h = $lucene->getParameterHolder(); $t->isa_ok($h, 'sfParameterHolder', '->getParameterHolder() returns a parameter holder'); $t->is($h->get('name'), 'testLucene', 'property "name" is the name of the index'); $t->is($h->get('culture'), 'en', 'property "culture" is the culture of the index'); $t->is($h->get('enabled_cultures'), array('en', 'fr'), 'property "enabled_cultures" contains all enabled cultures'); $t->like($h->get('index_location'), '#/index/testLucene/en$#', 'property "index_location" is the correct path'); $t->is($h->get('encoding'), 'UTF-8', 'property "encoding" is the encoding'); $t->is($h->get('stop_words'), array('and', 'the'), 'property "stop_words" contains the stop words'); $t->is($h->get('short_words'), 2, 'property "short_words" is the short word limit'); $t->is($h->get('mb_string'), true, 'property "mb_string" indicates if to use mb_string functions'); $t->isa_ok($h->get('models'), 'sfParameterHolder', 'property "models" is a sfParameterHolder'); $t->isa_ok($h->get('models')->get('FakeForum'), 'sfParameterHolder', 'properties of "models" are sfParameterHolders'); $m = $h->get('models')->get('FakeForum'); $t->is($m->get('title'), 'title', 'model property "title" is the correct title field'); $t->is($m->get('description'), 'description', 'model property "description" is the correct description field'); $t->is($m->get('categories'), array('Forum'), 'model property "categories" contains the correct categories'); $t->is($m->get('route'), 'forum/showForum?id=%id%', 'model property "route" is the correct route'); $t->is($m->get('validator'), 'isIndexable', 'model property "validator" is the correct validator'); $t->is($m->get('peer'), 'FakeForumPeer', 'model property "peer" is the correct peer'); $t->is($m->get('rebuild_limit'), 5, 'model property "rebuild_limit" is the correct rebuild limit'); $t->is($m->get('partial'), 'forumResult', 'model property "partial" is the correct partial');
* @package sfLucenePlugin * @subpackage Test * @author Carl Vondrick * @version SVN: $Id$ */ require dirname(__FILE__) . '/../../../bootstrap/unit.php'; $t = new limeade_test(3, limeade_output::get()); class Foo { public $executed = false; public function execute() { $this->executed = true; } } $context = sfContext::createInstance($app_configuration); $context->getResponse()->setContent('foobar 2357'); $filter = new sfLuceneRenderingFilter($context); $chain = new Foo(); try { ob_start(); $filter->execute($chain); $content = ob_get_clean(); $t->pass('->execute() runs without an exception'); $t->like($content, '/^foobar 2357.*/', '->execute() sends response content'); } catch (Exception $e) { ob_end_clean(); $t->fail('->execute() runs without an exception'); $t->skip('->execute() sends response content'); } $t->ok($chain->executed, '->execute() runs ->execute() on the chain');