annotate sites/all/modules/custom/solrconnect/tests/solr_document.test @ 0:015d06b10d37 default tip

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