source: sandbox/expresso-solr/expressoMail1_2/solrclient/tests/Solarium/Client/ResponseParser/Select/Component/FacetSetTest.php @ 7588

Revision 7588, 5.0 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_Client_ResponseParser_Select_Component_FacetSetTest extends PHPUnit_Framework_TestCase
33{
34
35    protected $_parser, $_facetSet;
36
37    public function setUp()
38    {
39        $this->_parser = new Solarium_Client_ResponseParser_Select_Component_FacetSet;
40
41        $this->_facetSet = new Solarium_Query_Select_Component_FacetSet();
42        $this->_facetSet->createFacet('field', array('key' => 'keyA', 'field' => 'fieldA'));
43        $this->_facetSet->createFacet('query', array('key' => 'keyB'));
44        $this->_facetSet->createFacet('multiquery', array('key' => 'keyC', 'query' => array('keyC_A' => array('query' => 'id:1'), 'keyC_B' => array('query' => 'id:2'))));
45        $this->_facetSet->createFacet('range', array('key' => 'keyD'));
46    }
47
48    public function testParse()
49    {
50        $data = array(
51            'facet_counts' =>  array(
52                'facet_fields' => array(
53                    'keyA' => array(
54                        'value1',
55                        12,
56                        'value2',
57                        3,
58                    ),
59                ),
60                'facet_queries' => array(
61                    'keyB' => 23,
62                    'keyC_A' => 25,
63                    'keyC_B' => 16,
64                ),
65                'facet_ranges' => array(
66                    'keyD' => array(
67                        'before' => 3,
68                        'after' => 5,
69                        'between' => 4,
70                        'counts' => array(
71                            '1.0',
72                            1,
73                            '101.0',
74                            2,
75                            '201.0',
76                            1,
77                        )
78                    )
79                )
80            )
81        );
82
83        $result = $this->_parser->parse(null, $this->_facetSet, $data);
84        $facets = $result->getFacets();
85
86        $this->assertEquals(array('keyA','keyB','keyC','keyD'), array_keys($facets));
87
88        $this->assertEquals(
89            array('value1' => 12, 'value2' => 3),
90            $facets['keyA']->getValues()
91        );
92
93        $this->assertEquals(
94            23,
95            $facets['keyB']->getValue()
96        );
97
98        $this->assertEquals(
99            array('keyC_A' => 25, 'keyC_B' => 16),
100            $facets['keyC']->getValues()
101        );
102
103        $this->assertEquals(
104            array('1.0' => 1, '101.0' => 2, '201.0' => 1),
105            $facets['keyD']->getValues()
106        );
107
108        $this->assertEquals(
109            3,
110            $facets['keyD']->getBefore()
111        );
112
113        $this->assertEquals(
114            4,
115            $facets['keyD']->getBetween()
116        );
117
118        $this->assertEquals(
119            5,
120            $facets['keyD']->getAfter()
121        );
122    }
123
124    public function testParseNoData()
125    {
126        $result = $this->_parser->parse(null, $this->_facetSet, array());
127        $this->assertEquals(array(), $result->getFacets());
128    }
129
130    public function testInvalidFacetType()
131    {
132        $facetStub = $this->getMock('Solarium_Query_Select_Component_Facet_Field');
133        $facetStub->expects($this->once())
134             ->method('getType')
135             ->will($this->returnValue('invalidfacettype'));
136        $facetStub->expects($this->any())
137             ->method('getKey')
138             ->will($this->returnValue('facetkey'));
139
140        $this->_facetSet->addFacet($facetStub);
141
142        $this->setExpectedException('Solarium_Exception');
143        $this->_parser->parse(null, $this->_facetSet, array());
144    }
145
146}
Note: See TracBrowser for help on using the repository browser.