PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/test/unit/util/sfLuceneToolkitTest.php

https://bitbucket.org/anycode/sfluceneplugin
PHP | 93 lines | 53 code | 25 blank | 15 comment | 0 complexity | 1f269f5eaf9976c0c8c207f5e667bc9b 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: sfLuceneToolkitTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
  14. */
  15. require dirname(__FILE__) . '/../../bootstrap/unit.php';
  16. $t = new limeade_test(14, limeade_output::get());
  17. $limeade = new limeade_sf($t);
  18. $app = $limeade->bootstrap();
  19. $luceneade = new limeade_lucene($limeade);
  20. $luceneade->configure()->clear_sandbox();
  21. $t->diag('testing ::loadZend()');
  22. sfConfig::set('app_lucene_zend_location', '/tmp');
  23. try {
  24. $e = $t->exception('::loadZend() fails with non-existant Zend path');
  25. sfLuceneToolkit::loadZend();
  26. $e->no();
  27. } catch (Exception $ex) {
  28. $e->caught($ex);
  29. }
  30. $limeade->config()->remove('app_lucene_zend_location');
  31. $t->not_like_included('#/Zend/Search/Lucene/#', 'Zend Search Lucene is not loaded after failed run');
  32. $t->not_in_include_path('Zend/Search/Lucene.php', 'Zend Search Lucene is not in the include path after failed run');
  33. sfLuceneToolkit::loadZend();
  34. $t->like_included('#/Zend/Search/Lucene/#','::loadZend() loads Zend Search Lucene');
  35. $t->in_include_path('Zend/Search/Lucene.php', '::loadZend() configures include path');
  36. $t->diag('testing ::getDirtyIndexRemains()');
  37. $luceneade->clear_sandbox();
  38. $root = sfConfig::get('sf_data_dir') . '/index/';
  39. // build valid indexes structure
  40. sfLucene::getInstance('testLucene','en')->getLucene();
  41. sfLucene::getInstance('testLucene','fr')->getLucene();
  42. // build invalid indexes structures
  43. file_put_contents($root.'testLucene/en/random_file', 'r@nd()');
  44. mkdir($root.'testLucene/foo', 0777, true);
  45. file_put_contents($root.'testLucene/foo/bar', 'foo');
  46. mkdir($root.'badIndex/en', 0777, true);
  47. file_put_contents($root.'badIndex/bar', 'foo');
  48. $dirty = sfLuceneToolkit::getDirtyIndexRemains();
  49. $t->ok(in_array($root.'testLucene/foo', $dirty), '::getDirtyIndexRemains() schedules valid indexes but invalid cultures for deletion');
  50. $t->ok(in_array($root.'badIndex', $dirty), '::getDirtyIndexRemains() schedules the entire of a bad index for deletion');
  51. $t->ok(!in_array($root.'testLucene', $dirty), '::getDirtyIndexRemains() did not schedule an entire valid index for deletion');
  52. $t->ok(!in_array($root.'testLucene/en', $dirty), '::getDirtyIndexRemains() did not schedule a valid index and valid culture for deletion');
  53. $t->ok(!in_array($root.'testLucene/fr', $dirty), '::getDirtyIndexRemains() did not schedule another valid index and valid culture for deletion');
  54. $t->ok(!in_array($root.'testLucene/en/random_file', $dirty), '::getDirtyIndexRemains() did not schedule an alien file in a valid index and valid culture for deletion');
  55. $t->diag('testing ::getApplicationInstance');
  56. $t->ok(sfLuceneToolkit::getApplicationInstance('en') === sfLucene::getInstance('testLucene', 'en'), '::getApplicationInstance() guesses the first index with no configuration parameter set');
  57. sfConfig::set('app_lucene_index', 'fooLucene');
  58. $t->ok(sfLuceneToolkit::getApplicationInstance('en') === sfLucene::getInstance('fooLucene', 'en'), '::getApplicationInstance() acknowledges manual override from app.yml');
  59. $limeade->config()->remove('app_lucene_index');
  60. $cswap = $app->cswap($luceneade->config_dir . '/search.yml')->write('<?php $config = array();');
  61. try {
  62. $e = $t->exception('::getApplicationInstance() fails if search.yml is empty');
  63. sfLuceneToolkit::getApplicationInstance();
  64. $e->no();
  65. } catch (Exception $ex) {
  66. $e->caught($ex);
  67. }
  68. $cswap->restore();