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

Revision 7588, 6.1 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_GroupingTest extends PHPUnit_Framework_TestCase
33{
34
35    /**
36     * @var Solarium_Query_Select_Component_Grouping
37     */
38    protected $_grouping;
39
40    public function setUp()
41    {
42        $this->_grouping = new Solarium_Query_Select_Component_Grouping;
43    }
44
45    public function testConfigMode()
46    {
47        $options = array(
48            'fields' => array('fieldA','fieldB'),
49            'queries' => array('cat:3','cat:4'),
50            'limit' => 8,
51            'offset' => 1,
52            'sort' => 'score desc',
53            'mainresult' => false,
54            'numberofgroups' => true,
55            'cachepercentage' => 45,
56            'truncate' => true,
57        );
58
59        $this->_grouping->setOptions($options);
60
61        $this->assertEquals($options['fields'], $this->_grouping->getFields());
62        $this->assertEquals($options['queries'], $this->_grouping->getQueries());
63        $this->assertEquals($options['limit'], $this->_grouping->getLimit());
64        $this->assertEquals($options['offset'], $this->_grouping->getOffset());
65        $this->assertEquals($options['sort'], $this->_grouping->getSort());
66        $this->assertEquals($options['mainresult'], $this->_grouping->getMainResult());
67        $this->assertEquals($options['numberofgroups'], $this->_grouping->getNumberOfGroups());
68        $this->assertEquals($options['cachepercentage'], $this->_grouping->getCachePercentage());
69        $this->assertEquals($options['truncate'], $this->_grouping->getTruncate());
70    }
71
72    public function testGetType()
73    {
74        $this->assertEquals(Solarium_Query_Select::COMPONENT_GROUPING, $this->_grouping->getType());
75    }
76
77    public function testSetAndGetFieldsSingle()
78    {
79        $value = 'fieldC';
80        $this->_grouping->setFields($value);
81
82        $this->assertEquals(
83            array($value),
84            $this->_grouping->getFields()
85        );
86    }
87
88    public function testSetAndGetFieldsCommaSeparated()
89    {
90        $value = 'fieldD, fieldE';
91        $this->_grouping->setFields($value);
92
93        $this->assertEquals(
94            array(
95                'fieldD',
96                'fieldE',
97            ),
98            $this->_grouping->getFields()
99        );
100    }
101
102    public function testSetAndGetFieldsArray()
103    {
104        $values = array('fieldD', 'fieldE');
105        $this->_grouping->setFields($values);
106
107        $this->assertEquals(
108            $values,
109            $this->_grouping->getFields()
110        );
111    }
112
113    public function testSetAndGetQueriesSingle()
114    {
115        $value = 'cat:3';
116        $this->_grouping->setQueries($value);
117
118        $this->assertEquals(
119            array($value),
120            $this->_grouping->getQueries()
121        );
122    }
123
124    public function testSetAndGetQueriesArray()
125    {
126        $values = array('cat:5', 'cat:6');
127        $this->_grouping->setQueries($values);
128
129        $this->assertEquals(
130            $values,
131            $this->_grouping->getQueries()
132        );
133    }
134
135    public function testSetAndGetLimit()
136    {
137        $value = '12';
138        $this->_grouping->setLimit($value);
139
140        $this->assertEquals(
141            $value,
142            $this->_grouping->getLimit()
143        );
144    }
145
146    public function testSetAndGetOffset()
147    {
148        $value = '2';
149        $this->_grouping->setOffset($value);
150
151        $this->assertEquals(
152            $value,
153            $this->_grouping->getOffset()
154        );
155    }
156
157    public function testSetAndGetSort()
158    {
159        $value = 'price desc';
160        $this->_grouping->setSort($value);
161
162        $this->assertEquals(
163            $value,
164            $this->_grouping->getSort()
165        );
166    }
167
168    public function testSetAndGetMainResult()
169    {
170        $value = true;
171        $this->_grouping->setMainResult($value);
172
173        $this->assertEquals(
174            $value,
175            $this->_grouping->getMainResult()
176        );
177    }
178
179    public function testSetAndGetNumberOfGroups()
180    {
181        $value = true;
182        $this->_grouping->setNumberOfGroups($value);
183
184        $this->assertEquals(
185            $value,
186            $this->_grouping->getNumberOfGroups()
187        );
188    }
189
190    public function testSetAndGetCachePercentage()
191    {
192        $value = 40;
193        $this->_grouping->setCachePercentage($value);
194
195        $this->assertEquals(
196            $value,
197            $this->_grouping->getCachePercentage()
198        );
199    }
200
201    public function testSetAndGetTruncate()
202    {
203        $value = true;
204        $this->_grouping->setTruncate($value);
205
206        $this->assertEquals(
207            $value,
208            $this->_grouping->getTruncate()
209        );
210    }
211
212}
Note: See TracBrowser for help on using the repository browser.