solr_document.test 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @file
  4. * Unit tests for document object methods.
  5. *
  6. *
  7. */
  8. class DrupalSolrDocumentTest extends DrupalUnitTestCase {
  9. public static function getInfo() {
  10. return array(
  11. 'name' => 'ApacheSolrDocument Unit tests',
  12. 'description' => 'Unit test of ApacheSolrDocument',
  13. 'group' => 'ApacheSolr',
  14. );
  15. }
  16. protected function setUp() {
  17. parent::setUp();
  18. require_once dirname(dirname(realpath(__FILE__))) . '/apachesolr.module';
  19. require_once dirname(dirname(realpath(__FILE__))) . '/Apache_Solr_Document.php';
  20. }
  21. function testSolrDocument() {
  22. $document = new ApacheSolrDocument();
  23. $document->addField('ss_testing', 'testingvalue');
  24. $field_value = $document->getField('ss_testing');
  25. $this->assertEqual($field_value['value'][0], 'testingvalue', t('The field was correctly added and verified'));
  26. $document->clear();
  27. $document->addField('ss_testing', 'testingvalue', 10);
  28. $field_value = $document->getField('ss_testing');
  29. $this->assertEqual($field_value['value'][0], 'testingvalue', t('The field and boost were correctly added and verified'));
  30. $field_boost = $document->getFieldBoost('ss_testing');
  31. $this->assertEqual($field_boost, 10, t('The field boost was correctly added and verified'));
  32. $document->clear();
  33. $document->setMultiValue('sm_testing', 'testingvalue1');
  34. $document->setMultiValue('sm_testing', 'testingvalue2');
  35. $field_value = $document->getField('sm_testing');
  36. $this->assertTrue(in_array('testingvalue1', $field_value['value']), t('The multivalued field value was correctly added and verified'));
  37. $this->assertTrue(in_array('testingvalue2', $field_value['value']), t('The second multivalued field value was correctly added and verified'));
  38. $document->clear();
  39. $document->setMultiValue('sm_testing', 'testingvalue1', 10);
  40. $document->setMultiValue('sm_testing', 'testingvalue2', 20);
  41. $field_value = $document->getField('sm_testing');
  42. $this->assertTrue(in_array('testingvalue1', $field_value['value']), t('The multivalued field value and boost were correctly added and verified'));
  43. $this->assertTrue(in_array('testingvalue2', $field_value['value']), t('The second multivalued field value and boost were correctly added and verified'));
  44. $field_boost = $document->getFieldBoost('sm_testing');
  45. $this->assertEqual($field_boost, 200, t('The field boost was correctly multiplied and retrieved'));
  46. $document_field_names = $document->getFieldNames();
  47. $this->assertTrue(in_array('sm_testing', $document_field_names), t('The field name was found in the document'));
  48. $document_field_names = $document->getFieldValues();
  49. $this->assertTrue(in_array('testingvalue1', $document_field_names[0]), t('The field value was found in the document'));
  50. // Clear the complete document
  51. $document->clear();
  52. // Set and Get the document boost
  53. $document->setBoost('10');
  54. $document_boost = $document->getBoost();
  55. $this->assertEqual($document_boost, 10, t('The document boost was correctly added and verified'));
  56. $document->clear();
  57. $document_boost = $document->getBoost();
  58. $document_fields = $document->getFieldNames();
  59. $document_field_boosts = $document->getFieldBoosts();
  60. $this->assertFalse($document_boost, t('Document boost was successfully emptied'));
  61. $this->assertFalse($document_fields, t('Document fields were successfully emptied'));
  62. $this->assertFalse($document_field_boosts, t('Document field boosts were successfully emptied'));
  63. }
  64. function tearDown() {
  65. parent::tearDown();
  66. }
  67. }