PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/test/unit/indexer/sfLucenePropelIndexerHandlerTest.php

https://bitbucket.org/anycode/sfluceneplugin
PHP | 77 lines | 44 code | 20 blank | 13 comment | 1 complexity | efa4afb1ebdfd14a389b2331f45213b4 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the sfLucenePlugin package
  4. * (c) 2007 - 2008 Carl Vondrick <carl@carlsoft.net>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * @package sfLucenePlugin
  11. * @subpackage Test
  12. * @author Carl Vondrick
  13. * @version SVN: $Id: sfLucenePropelIndexerHandlerTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
  14. */
  15. require dirname(__FILE__) . '/../../bootstrap/unit.php';
  16. $t = new limeade_test(3, limeade_output::get());
  17. $limeade = new limeade_sf($t);
  18. $app = $limeade->bootstrap();
  19. $luceneade = new limeade_lucene($limeade);
  20. $luceneade->configure()->clear_sandbox()->load_models();
  21. class FooIndexer extends sfLucenePropelIndexerHandler
  22. {
  23. public $rebuilds = array();
  24. public function rebuildModel($name)
  25. {
  26. $this->rebuilds[] = $name;
  27. }
  28. }
  29. $search = sfLucene::getInstance('testLucene', 'en');
  30. $t->diag('testing ->rebuild()');
  31. $handler = new FooIndexer($search);
  32. $handler->rebuild();
  33. $t->is($handler->rebuilds, array('FakeForum'), '->rebuild() calls ->rebuildModel() for all models');
  34. $t->diag('testing ->rebuildModel()');
  35. $handler = new sfLucenePropelIndexerHandler($search);
  36. $search->getParameter('models')->get('FakeForum')->set('rebuild_limit', 5);
  37. $models = array();
  38. for ($x = 0; $x < 6; $x++)
  39. {
  40. $var = new FakeForum;
  41. $var->setCulture('en');
  42. $var->setTitle('foo');
  43. $var->setDescription('bar');
  44. $var->setCoolness(3);
  45. $var->save();
  46. $var->deleteIndex();
  47. $models[] = $var;
  48. }
  49. $search->commit();
  50. $t->is($search->numDocs(), 0, 'model setup leaves index empty');
  51. $handler->rebuildModel('FakeForum');
  52. $search->commit();
  53. $t->is($search->numDocs(), count($models), '->rebuildModel() builds all models');
  54. foreach ($models as $model)
  55. {
  56. $model->delete();
  57. }