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 | |
---|
32 | class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase |
---|
33 | { |
---|
34 | |
---|
35 | /** |
---|
36 | * @var Solarium_Result_Select |
---|
37 | */ |
---|
38 | protected $_result; |
---|
39 | |
---|
40 | protected $_numFound, $_docs, $_components, $_facetSet, $_moreLikeThis, |
---|
41 | $_highlighting, $_grouping, $_stats, $_debug; |
---|
42 | |
---|
43 | public function setUp() |
---|
44 | { |
---|
45 | $this->_numFound = 11; |
---|
46 | |
---|
47 | $this->_docs = array( |
---|
48 | new Solarium_Document_ReadOnly(array('id'=>1,'title'=>'doc1')), |
---|
49 | new Solarium_Document_ReadOnly(array('id'=>1,'title'=>'doc1')), |
---|
50 | ); |
---|
51 | |
---|
52 | $this->_facetSet = 'dummy-facetset-value'; |
---|
53 | $this->_moreLikeThis = 'dummy-facetset-value'; |
---|
54 | $this->_highlighting = 'dummy-highlighting-value'; |
---|
55 | $this->_grouping = 'dummy-grouping-value'; |
---|
56 | $this->_spellcheck = 'dummy-grouping-value'; |
---|
57 | $this->_stats = 'dummy-stats-value'; |
---|
58 | $this->_debug = 'dummy-debug-value'; |
---|
59 | |
---|
60 | $this->_components = array( |
---|
61 | Solarium_Query_Select::COMPONENT_FACETSET => $this->_facetSet, |
---|
62 | Solarium_Query_Select::COMPONENT_MORELIKETHIS => $this->_moreLikeThis, |
---|
63 | Solarium_Query_Select::COMPONENT_HIGHLIGHTING => $this->_highlighting, |
---|
64 | Solarium_Query_Select::COMPONENT_GROUPING => $this->_grouping, |
---|
65 | Solarium_Query_Select::COMPONENT_SPELLCHECK => $this->_spellcheck, |
---|
66 | Solarium_Query_Select::COMPONENT_STATS => $this->_stats, |
---|
67 | Solarium_Query_Select::COMPONENT_DEBUG => $this->_debug, |
---|
68 | ); |
---|
69 | |
---|
70 | $this->_result = new Solarium_Result_SelectDummy(1, 12, $this->_numFound, $this->_docs, $this->_components); |
---|
71 | } |
---|
72 | |
---|
73 | public function testGetNumFound() |
---|
74 | { |
---|
75 | $this->assertEquals($this->_numFound, $this->_result->getNumFound()); |
---|
76 | } |
---|
77 | |
---|
78 | public function testGetDocuments() |
---|
79 | { |
---|
80 | $this->assertEquals($this->_docs, $this->_result->getDocuments()); |
---|
81 | } |
---|
82 | |
---|
83 | public function testGetFacetSet() |
---|
84 | { |
---|
85 | $this->assertEquals($this->_facetSet, $this->_result->getFacetSet()); |
---|
86 | } |
---|
87 | |
---|
88 | public function testCount() |
---|
89 | { |
---|
90 | $this->assertEquals(count($this->_docs), count($this->_result)); |
---|
91 | } |
---|
92 | |
---|
93 | public function testGetComponents() |
---|
94 | { |
---|
95 | $this->assertEquals($this->_components, $this->_result->getComponents()); |
---|
96 | } |
---|
97 | |
---|
98 | public function testGetComponent() |
---|
99 | { |
---|
100 | $this->assertEquals( |
---|
101 | $this->_components[Solarium_Query_Select::COMPONENT_MORELIKETHIS], |
---|
102 | $this->_result->getComponent(Solarium_Query_Select::COMPONENT_MORELIKETHIS) |
---|
103 | ); |
---|
104 | } |
---|
105 | |
---|
106 | public function testGetInvalidComponent() |
---|
107 | { |
---|
108 | $this->assertEquals( |
---|
109 | null, |
---|
110 | $this->_result->getComponent('invalid') |
---|
111 | ); |
---|
112 | } |
---|
113 | |
---|
114 | public function testGetMoreLikeThis() |
---|
115 | { |
---|
116 | $this->assertEquals( |
---|
117 | $this->_components[Solarium_Query_Select::COMPONENT_MORELIKETHIS], |
---|
118 | $this->_result->getMoreLikeThis() |
---|
119 | ); |
---|
120 | } |
---|
121 | |
---|
122 | public function testGetHighlighting() |
---|
123 | { |
---|
124 | $this->assertEquals( |
---|
125 | $this->_components[Solarium_Query_Select::COMPONENT_HIGHLIGHTING], |
---|
126 | $this->_result->getHighlighting() |
---|
127 | ); |
---|
128 | } |
---|
129 | |
---|
130 | public function testGetGrouping() |
---|
131 | { |
---|
132 | $this->assertEquals( |
---|
133 | $this->_components[Solarium_Query_Select::COMPONENT_GROUPING], |
---|
134 | $this->_result->getGrouping() |
---|
135 | ); |
---|
136 | } |
---|
137 | |
---|
138 | public function testGetSpellcheck() |
---|
139 | { |
---|
140 | $this->assertEquals( |
---|
141 | $this->_components[Solarium_Query_Select::COMPONENT_SPELLCHECK], |
---|
142 | $this->_result->getSpellcheck() |
---|
143 | ); |
---|
144 | } |
---|
145 | |
---|
146 | public function testGetStats() |
---|
147 | { |
---|
148 | $this->assertEquals( |
---|
149 | $this->_components[Solarium_Query_Select::COMPONENT_STATS], |
---|
150 | $this->_result->getStats() |
---|
151 | ); |
---|
152 | } |
---|
153 | |
---|
154 | public function testGetDebug() |
---|
155 | { |
---|
156 | $this->assertEquals( |
---|
157 | $this->_components[Solarium_Query_Select::COMPONENT_DEBUG], |
---|
158 | $this->_result->getDebug() |
---|
159 | ); |
---|
160 | } |
---|
161 | |
---|
162 | public function testIterator() |
---|
163 | { |
---|
164 | $docs = array(); |
---|
165 | foreach($this->_result AS $key => $doc) |
---|
166 | { |
---|
167 | $docs[$key] = $doc; |
---|
168 | } |
---|
169 | |
---|
170 | $this->assertEquals($this->_docs, $docs); |
---|
171 | } |
---|
172 | |
---|
173 | public function testGetStatus() |
---|
174 | { |
---|
175 | $this->assertEquals( |
---|
176 | 1, |
---|
177 | $this->_result->getStatus() |
---|
178 | ); |
---|
179 | } |
---|
180 | |
---|
181 | public function testGetQueryTime() |
---|
182 | { |
---|
183 | $this->assertEquals( |
---|
184 | 12, |
---|
185 | $this->_result->getQueryTime() |
---|
186 | ); |
---|
187 | } |
---|
188 | |
---|
189 | } |
---|
190 | |
---|
191 | class Solarium_Result_SelectDummy extends Solarium_Result_Select |
---|
192 | { |
---|
193 | protected $_parsed = true; |
---|
194 | |
---|
195 | public function __construct($status, $queryTime, $numfound, $docs, $components) |
---|
196 | { |
---|
197 | $this->_numfound = $numfound; |
---|
198 | $this->_documents = $docs; |
---|
199 | $this->_components = $components; |
---|
200 | $this->_queryTime = $queryTime; |
---|
201 | $this->_status = $status; |
---|
202 | } |
---|
203 | |
---|
204 | } |
---|