TermTest.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Search_Lucene
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Zend_Search_Lucene_Index_Term
  24. */
  25. require_once 'Zend/Search/Lucene/Index/Term.php';
  26. /**
  27. * PHPUnit test case
  28. */
  29. require_once 'PHPUnit/Framework/TestCase.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Search_Lucene
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Search_Lucene
  37. */
  38. class Zend_Search_Lucene_Index_TermTest extends PHPUnit_Framework_TestCase
  39. {
  40. public function testCreate()
  41. {
  42. $term = new Zend_Search_Lucene_Index_Term('term_text');
  43. $this->assertTrue($term instanceof Zend_Search_Lucene_Index_Term);
  44. $this->assertEquals($term->text, 'term_text');
  45. $this->assertEquals($term->field, null);
  46. $term = new Zend_Search_Lucene_Index_Term('term_text', 'field_name');
  47. $this->assertEquals($term->text, 'term_text');
  48. $this->assertEquals($term->field, 'field_name');
  49. }
  50. public function testKey()
  51. {
  52. $term1_1 = new Zend_Search_Lucene_Index_Term('term_text1', 'field_name1');
  53. $term2_1 = new Zend_Search_Lucene_Index_Term('term_text2', 'field_name1');
  54. $term2_2 = new Zend_Search_Lucene_Index_Term('term_text2', 'field_name2');
  55. $term2_1Dup = new Zend_Search_Lucene_Index_Term('term_text2', 'field_name1');
  56. $this->assertEquals($term1_1->text > $term2_1->text, $term1_1->key() > $term2_1->key());
  57. $this->assertEquals($term1_1->text >= $term2_1->text, $term1_1->key() >= $term2_1->key());
  58. $this->assertEquals($term1_1->field > $term2_2->field, $term1_1->key() > $term2_2->key());
  59. $this->assertEquals($term1_1->field >= $term2_2->field, $term1_1->key() >= $term2_2->key());
  60. $this->assertEquals($term2_1->key(), $term2_1Dup->key());
  61. }
  62. public function testGetPrefix()
  63. {
  64. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('term_text', 10), 'term_text');
  65. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('term_text', 9), 'term_text');
  66. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('term_text', 4), 'term');
  67. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('term_text', 0), '');
  68. }
  69. public function testGetPrefixUtf8()
  70. {
  71. // UTF-8 string with non-ascii symbols (Russian alphabet)
  72. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('абвгдеёжзийклмнопрстуфхцчшщьыъэюя', 64), 'абвгдеёжзийклмнопрстуфхцчшщьыъэюя');
  73. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('абвгдеёжзийклмнопрстуфхцчшщьыъэюя', 33), 'абвгдеёжзийклмнопрстуфхцчшщьыъэюя');
  74. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('абвгдеёжзийклмнопрстуфхцчшщьыъэюя', 4), 'абвг');
  75. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('абвгдеёжзийклмнопрстуфхцчшщьыъэюя', 0), '');
  76. }
  77. }