TermTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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-2015 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. * @category Zend
  28. * @package Zend_Search_Lucene
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Search_Lucene
  33. */
  34. class Zend_Search_Lucene_Index_TermTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function testCreate()
  37. {
  38. $term = new Zend_Search_Lucene_Index_Term('term_text');
  39. $this->assertTrue($term instanceof Zend_Search_Lucene_Index_Term);
  40. $this->assertEquals($term->text, 'term_text');
  41. $this->assertEquals($term->field, null);
  42. $term = new Zend_Search_Lucene_Index_Term('term_text', 'field_name');
  43. $this->assertEquals($term->text, 'term_text');
  44. $this->assertEquals($term->field, 'field_name');
  45. }
  46. public function testKey()
  47. {
  48. $term1_1 = new Zend_Search_Lucene_Index_Term('term_text1', 'field_name1');
  49. $term2_1 = new Zend_Search_Lucene_Index_Term('term_text2', 'field_name1');
  50. $term2_2 = new Zend_Search_Lucene_Index_Term('term_text2', 'field_name2');
  51. $term2_1Dup = new Zend_Search_Lucene_Index_Term('term_text2', 'field_name1');
  52. $this->assertEquals($term1_1->text > $term2_1->text, $term1_1->key() > $term2_1->key());
  53. $this->assertEquals($term1_1->text >= $term2_1->text, $term1_1->key() >= $term2_1->key());
  54. $this->assertEquals($term1_1->field > $term2_2->field, $term1_1->key() > $term2_2->key());
  55. $this->assertEquals($term1_1->field >= $term2_2->field, $term1_1->key() >= $term2_2->key());
  56. $this->assertEquals($term2_1->key(), $term2_1Dup->key());
  57. }
  58. public function testGetPrefix()
  59. {
  60. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('term_text', 10), 'term_text');
  61. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('term_text', 9), 'term_text');
  62. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('term_text', 4), 'term');
  63. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('term_text', 0), '');
  64. }
  65. public function testGetPrefixUtf8()
  66. {
  67. // UTF-8 string with non-ascii symbols (Russian alphabet)
  68. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('абвгдеёжзийклмнопрстуфхцчшщьыъэюя', 64), 'абвгдеёжзийклмнопрстуфхцчшщьыъэюя');
  69. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('абвгдеёжзийклмнопрстуфхцчшщьыъэюя', 33), 'абвгдеёжзийклмнопрстуфхцчшщьыъэюя');
  70. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('абвгдеёжзийклмнопрстуфхцчшщьыъэюя', 4), 'абвг');
  71. $this->assertEquals(Zend_Search_Lucene_Index_Term::getPrefix('абвгдеёжзийклмнопрстуфхцчшщьыъэюя', 0), '');
  72. }
  73. }