コード例 #1
0
    $t->skip('->numDocs() indicates index is empty');
}
$t->diag('testing ::getAllInstances()');
try {
    $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');
コード例 #2
0
 * @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');
コード例 #3
0
/**
 * @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();
$t->cmp_ok($queries, '===', 'foo AND bar', '->add() correctly parses and adds text queries');
$queries = inst()->add('foo')->add('bar', sfLuceneCriteria::TYPE_OR)->getQuery();
$t->cmp_ok($queries, '===', 'foo OR bar', '->add() correctly parses and adds text queries');
$query = inst();
$query->add('foo');
$criteria->add($query, null);
$t->pass('->add() accepts sfLuceneCriteria');
$luceneQuery = inst()->add($query);
コード例 #4
0
/**
 * @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');
コード例 #5
0
/**
 * @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');
$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');
コード例 #6
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';
$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');
 * @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->is(count($keywords), 4, '::explode() correctly splits the query into separate words');
$t->is($keywords[1]->getName(), 'António', '::explode() handles UTF8 strings correctly');
$t->is($keywords[2]->getName(), 'baz', '::explode() breaks correctly after a UTF8 string');
$t->is($keywords[3]->getName(), 'symf0ny', '::explode() breaks correctly after non-word but non-space character and handles numbers correctly');
コード例 #8
0
 */
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');
$t->diag('testing ->getQuery()');
$t->ok(is_string($criteria->getQuery()), '->getQuery() returns an instance a string');
$criteria->addFacetField('language');
$criteria->addFacetField('task');
$criteria->addFacetQuery('price:[0 TO 100]');
$criteria->addFacetQuery('price:[100 TO 200]');
$expected = array('fl' => array(0 => '*,score'), 'sort' => array(0 => 'score desc'), 'facet' => array(0 => 'true'), 'facet.field' => array(0 => 'language', 1 => 'task'), 'facet.query' => array(0 => 'price:[0 TO 100]', 1 => 'price:[100 TO 200]'));
$t->is_deeply($criteria->getParams(), $expected, '->getParams() return the parameters array');
$t->diag('testing ->addFacetField() and ->addFacetQuery() reset');
$criteria->addFacetField('another_field', true);
$criteria->addFacetQuery('the_price:[0 TO 100]', true);
$expected = array('fl' => array(0 => '*,score'), 'sort' => array(0 => 'score desc'), 'facet' => array(0 => 'true'), 'facet.field' => array(0 => 'another_field'), 'facet.query' => array(0 => 'the_price:[0 TO 100]'));
$t->is_deeply($criteria->getParams(), $expected, '->getParams() return the parameters array with reseted values');
コード例 #9
0
$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');
} catch (Exception $e) {
    $t->fail('__construct() takes a sfLuce instance');
}
$t->isa_ok(sfLuceneCriteria::newInstance(sfLucene::getInstance('testLucene')), 'sfLuceneCriteria', '::newInstance() returns an sfLuceneCriteria object');
$t->diag('testing ->getQuery()');
$t->isa_ok($criteria->getQuery(), 'Zend_Search_Lucene_Search_Query_Boolean', '->getQuery() returns an instance of ZSL_Search_Query_Boolean');
$t->diag('testing ->add()');
try {
    $criteria->add('test', true);
    $t->pass('->add() accepts a string');
    $queries = inst()->add('foo')->add('bar')->getQuery()->getSubqueries();
    $t->ok($queries[0] == Zend_Search_Lucene_Search_QueryParser::parse('foo'), '->add() correctly parses and adds text queries');
    $t->ok($queries[1] == Zend_Search_Lucene_Search_QueryParser::parse('bar'), '->add() correctly parses and adds text queries and keeps them in order');
} catch (Exception $e) {
    $e->printStackTrace();
    $t->fail('->add() accepts a string');
    $t->skip('->add() correctly parses and adds text queries');
    $t->skip('->add() correctly parses and adds text queries and keeps them in order');
}
<?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');
コード例 #11
0
    }
    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->diag('testing highlighting');
コード例 #12
0
 * (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');
コード例 #13
0
class MockResult extends sfLuceneDocument
{
}
$mockresult = new MockResult($lucene->getLucene());
$mockresult->score = 0.425;
$mockresult->id = 1;
$t->diag('testing constructor');
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');
コード例 #14
0
} catch (Exception $e) {
    $t->fail('construct() accepts an instance of sfLucene');
}
$t->diag('testing ->getHandlers()');
$handlers = $factory->getHandlers();
$t->is(array_keys($handlers), array('model', 'action'), '->getHandlers() returns instances of the model and action handler by default');
$t->ok($handlers['model'] == new sfLucenePropelIndexerHandler($search), '->getHandlers() returns a valid model handler');
$t->ok($handlers['action'] == new sfLuceneActionIndexerHandler($search), '->getHandlers() returns a valid action handler');
$h->get('factories')->set('indexers', array('action' => array('Foo', 'FooIndexer')));
$handlers = $factory->getHandlers();
$t->ok($handlers['action'] == new Foo($search), '->getHandlers() can overload built-in handlers');
$h->get('factories')->set('indexers', array('action' => null));
$t->is(array_keys($factory->getHandlers()), array('model'), '->getHandlers() can eliminate handlers');
$h->get('factories')->set('indexers', array('pdf' => array('Foo', 'FooIndexer')));
$handlers = $factory->getHandlers();
$t->is(array_keys($handlers), array('model', 'action', 'pdf'), '->getHandlers() can add new handlers');
$t->ok($handlers['pdf'] == new Foo($search), '->getHandlers() can add new handlers correctly');
$t->diag('testing ->getModel()');
$model = new FakeForum();
$t->isa_ok($factory->getModel($model), 'sfLucenePropelIndexer', '->getModel() returns the Propel indexer by default');
$h->get('models')->get('FakeForum')->set('indexer', 'Foo');
$t->isa_ok($factory->getModel($model), 'Foo', '->getModel() can overload the indexer on the model level');
$h->get('models')->get('FakeForum')->remove('indexer');
$h->get('factories')->set('indexers', array('model' => array('FooHandler', 'Foo')));
$t->isa_ok($factory->getModel($model), 'Foo', '->getModel() can overload the indexer on the search level');
$h->get('models')->get('FakeForum')->set('indexer', 'Bar');
$t->isa_ok($factory->getModel($model), 'Bar', '->getModel() gives higher priority to model level than search level');
$t->diag('testing ->getAction()');
$t->isa_ok($factory->getAction('foo', 'bar'), 'sfLuceneActionIndexer', '->getAction() returns the action indexer by default');
$h->get('factories')->set('indexers', array('action' => array('FooHandler', 'Foo')));
$t->isa_ok($factory->getAction('foo', 'bar'), 'Foo', '->getAction() can overload the indexer');
コード例 #15
0
ファイル: sfLuceneTest.php プロジェクト: rande/sfSolrPlugin
$t->skip('->numDocs() TODO !! indicates index is empty');
$t->diag('testing ::getAllInstances()');
try {
    $e = $t->no_exception('::getAllInstance() executes without exception');
    $instances = sfLucene::getAllInstances($app_configuration);
    $e->no();
} catch (Exception $ex) {
    $instances = array();
    $e->caught($ex);
}
$t->is_deeply($instances, array(sfLucene::getInstance('index', 'en', $app_configuration), sfLucene::getInstance('index', 'fr', $app_configuration), sfLucene::getInstance('fooLucene', 'en', $app_configuration)), '::getAllInstances() returns all instances');
$t->is_deeply(sfLucene::getAllNames($app_configuration), array('index', 'fooLucene'), '::getAllNames() returns all configured names');
$t->diag('testing ->loadConfig()');
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
$h = $lucene->getParameterHolder();
$t->isa_ok($h, 'sfParameterHolder', '->getParameterHolder() returns a parameter holder');
$t->is($h->get('name'), 'index', '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->is($h->get('encoding'), 'UTF-8', 'property "encoding" is the encoding');
$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');
コード例 #16
0
    public function _getDeleteQueue()
    {
        return $this->deleteQueue;
    }
    public function _getSearchInstances($node)
    {
        return $this->getSearchInstances($node);
    }
    public function clear()
    {
        $this->saveQueue = array();
        $this->deleteQueue = array();
    }
}
$t->diag('testing ::getInitializer()');
$t->isa_ok(sfLucenePropelBehavior::getInitializer(), 'sfLucenePropelInitializer', '::getInitializer() returns an instance of sfLucenePropelInitializer');
$t->diag('testing ->getSearchInstances()');
$behavior = new MockBehavior();
try {
    $behavior->_getSearchInstances(new Foo());
    $t->fail('->getSearchInstances() fails if node cannot be found');
} catch (Exception $e) {
    $t->pass('->getSearchInstances() fails if node cannot be found');
}
$instances = $behavior->_getSearchInstances($m1);
$t->ok($instances === array(sfLucene::getInstance('testLucene', 'en'), sfLucene::getInstance('testLucene', 'fr')), '->getSearchInstances() returns all search instances for a Propel model');
$t->is($behavior->_getSearchInstances($m2), $instances, '->getSearchInstances() returns same instances for the same model');
$t->diag('testing ->preSave()');
$behavior->preSave($m1);
$q = $behavior->_getSaveQueue();
$t->is($q[0], $m1, '->preSave() adds model to queue if it does not already exist');