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