source: sandbox/expresso-solr/expressoMail1_2/solrclient/tests/Solarium/Query/Select/Component/MoreLikeThisTest.php @ 7588

Revision 7588, 5.7 KB checked in by adir, 11 years ago (diff)

Ticket #000 - Adicionando a integracao de buscas com Solr na base a ser isnerida na comunidade

Line 
1<?php
2/**
3 * Copyright 2011 Bas de Nooijer. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 *    this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 *    this listof conditions and the following disclaimer in the documentation
13 *    and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 *
27 * The views and conclusions contained in the software and documentation are
28 * those of the authors and should not be interpreted as representing official
29 * policies, either expressed or implied, of the copyright holder.
30 */
31
32class Solarium_Query_Select_Component_MoreLikeThisTest extends PHPUnit_Framework_TestCase
33{
34
35    /**
36     * @var Solarium_Query_Select_Component_MoreLikeThis
37     */
38    protected $_mlt;
39
40    public function setUp()
41    {
42        $this->_mlt = new Solarium_Query_Select_Component_MoreLikeThis;
43    }
44
45    public function testConfigMode()
46    {
47        $options = array(
48            'fields' => 'fieldA,fieldB',
49            'minimumtermfrequency' => 10,
50            'minimumdocumentfrequency' => 2,
51            'minimumwordlength' => 3,
52            'maximumwordlength' => 10,
53            'maximumqueryterms' => 4,
54            'maximumnumberoftokens' => 20,
55            'boost' => 1.5,
56            'queryfields' => 'fieldC,fieldD',
57            'count' => 5,
58        );
59
60        $this->_mlt->setOptions($options);
61
62        $this->assertEquals($options['fields'], $this->_mlt->getFields());
63        $this->assertEquals($options['minimumtermfrequency'], $this->_mlt->getMinimumTermFrequency());
64        $this->assertEquals($options['minimumdocumentfrequency'], $this->_mlt->getMinimumDocumentFrequency());
65        $this->assertEquals($options['minimumwordlength'], $this->_mlt->getMinimumWordLength());
66        $this->assertEquals($options['maximumwordlength'], $this->_mlt->getMaximumWordLength());
67        $this->assertEquals($options['maximumqueryterms'], $this->_mlt->getMaximumQueryTerms());
68        $this->assertEquals($options['boost'], $this->_mlt->getBoost());
69        $this->assertEquals($options['queryfields'], $this->_mlt->getQueryFields());
70        $this->assertEquals($options['count'], $this->_mlt->getCount());
71    }
72
73    public function testGetType()
74    {
75        $this->assertEquals(Solarium_Query_Select::COMPONENT_MORELIKETHIS, $this->_mlt->getType());
76    }
77
78    public function testSetAndGetFields()
79    {
80        $value = 'name,description';
81        $this->_mlt->setFields($value);
82
83        $this->assertEquals(
84            $value,
85            $this->_mlt->getFields()
86        );
87    }
88
89    public function testSetAndGetMinimumTermFrequency()
90    {
91        $value = 2;
92        $this->_mlt->setMinimumTermFrequency($value);
93
94        $this->assertEquals(
95            $value,
96            $this->_mlt->getMinimumTermFrequency()
97        );
98    }
99
100    public function testMinimumDocumentFrequency()
101    {
102        $value = 4;
103        $this->_mlt->setMinimumDocumentFrequency($value);
104
105        $this->assertEquals(
106            $value,
107            $this->_mlt->getMinimumDocumentFrequency()
108        );
109    }
110
111    public function testSetAndGetMinimumWordLength()
112    {
113        $value = 3;
114        $this->_mlt->setMinimumWordLength($value);
115
116        $this->assertEquals(
117            $value,
118            $this->_mlt->getMinimumWordLength()
119        );
120    }
121
122    public function testSetAndGetMaximumWordLength()
123    {
124        $value = 15;
125        $this->_mlt->setMaximumWordLength($value);
126
127        $this->assertEquals(
128            $value,
129            $this->_mlt->getMaximumWordLength()
130        );
131    }
132
133    public function testSetAndGetMaximumQueryTerms()
134    {
135        $value = 5;
136        $this->_mlt->setMaximumQueryTerms($value);
137
138        $this->assertEquals(
139            $value,
140            $this->_mlt->getMaximumQueryTerms()
141        );
142    }
143
144    public function testSetAndGetMaximumNumberOfTokens()
145    {
146        $value = 5;
147        $this->_mlt->setMaximumNumberOfTokens($value);
148
149        $this->assertEquals(
150            $value,
151            $this->_mlt->getMaximumNumberOfTokens()
152        );
153    }
154
155    public function testSetAndGetBoost()
156    {
157        $value = true;
158        $this->_mlt->setBoost($value);
159
160        $this->assertEquals(
161            $value,
162            $this->_mlt->getBoost()
163        );
164    }
165
166    public function testSetAndGetQueryFields()
167    {
168        $value = 'content,name';
169        $this->_mlt->setQueryFields($value);
170
171        $this->assertEquals(
172            $value,
173            $this->_mlt->getQueryFields()
174        );
175    }
176
177    public function testSetAndGetCount()
178    {
179        $value = 8;
180        $this->_mlt->setCount($value);
181
182        $this->assertEquals(
183            $value,
184            $this->_mlt->getCount()
185        );
186    }
187   
188}
Note: See TracBrowser for help on using the repository browser.