Commit eca3407d authored by Bas de Nooijer's avatar Bas de Nooijer

- small bugfixes

- code style fixes
- unittest improvements
parent cc91f30d
...@@ -115,7 +115,7 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request ...@@ -115,7 +115,7 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
case Solarium_Query_Select_Component_Facet::QUERY: case Solarium_Query_Select_Component_Facet::QUERY:
$this->addFacetQuery($facet); $this->addFacetQuery($facet);
break; break;
case Solarium_Query_Select_Component_Facet::MULTIQUERY: case Solarium_Query_Select_Component_Facet::MULTIQUERY:
$this->addFacetMultiQuery($facet); $this->addFacetMultiQuery($facet);
break; break;
default: default:
...@@ -177,7 +177,7 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request ...@@ -177,7 +177,7 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
*/ */
public function addFacetMultiQuery($facet) public function addFacetMultiQuery($facet)
{ {
foreach($facet->getQueries() AS $facetQuery) { foreach ($facet->getQueries() AS $facetQuery) {
$this->addFacetQuery($facetQuery); $this->addFacetQuery($facetQuery);
} }
} }
......
...@@ -615,7 +615,7 @@ class Solarium_Query_Select extends Solarium_Query ...@@ -615,7 +615,7 @@ class Solarium_Query_Select extends Solarium_Query
*/ */
protected function _createComponents($configs) protected function _createComponents($configs)
{ {
foreach($configs AS $type => $config) foreach ($configs AS $type => $config)
{ {
$this->getComponent($type, true, $config); $this->getComponent($type, true, $config);
} }
......
...@@ -221,7 +221,7 @@ class Solarium_Query_Select_Component_Facet_MultiQuery extends Solarium_Query_Se ...@@ -221,7 +221,7 @@ class Solarium_Query_Select_Component_Facet_MultiQuery extends Solarium_Query_Se
* @param array $facetQueries * @param array $facetQueries
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface * @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/ */
public function setFacetQueries($facetQueries) public function setQueries($facetQueries)
{ {
$this->clearQueries(); $this->clearQueries();
return $this->addQueries($facetQueries); return $this->addQueries($facetQueries);
......
...@@ -113,6 +113,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase ...@@ -113,6 +113,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
{ {
$this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_Field(array('key' => 'f1', 'field' => 'owner'))); $this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_Field(array('key' => 'f1', 'field' => 'owner')));
$this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_Query(array('key' => 'f2', 'query' => 'category:23'))); $this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_Query(array('key' => 'f2', 'query' => 'category:23')));
$this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_MultiQuery(array('key' => 'f3', 'query' => array('f4' =>array('query' => 'category:40')))));
$request = new Solarium_Client_Request_Select($this->_options, $this->_query); $request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$this->assertEquals( $this->assertEquals(
...@@ -121,7 +122,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase ...@@ -121,7 +122,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
); );
$this->assertEquals( $this->assertEquals(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.field={!key=f1}owner&facet.query={!key=f2}category:23', 'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40',
urldecode($request->getUri()) urldecode($request->getUri())
); );
} }
......
...@@ -99,6 +99,21 @@ class Solarium_Query_Select_Component_FacetSetTest extends PHPUnit_Framework_Tes ...@@ -99,6 +99,21 @@ class Solarium_Query_Select_Component_FacetSetTest extends PHPUnit_Framework_Tes
); );
} }
public function testAddFacetsWithConfig()
{
$facets = array(
array('type' => 'query', 'key' => 'f1', 'query' => 'category:1'),
'f2' => array('type' => 'query', 'query' => 'category:2')
);
$this->_facetSet->addFacets($facets);
$this->assertEquals(
2,
count($this->_facetSet->getFacets())
);
}
public function testRemoveFacet() public function testRemoveFacet()
{ {
$fq1 = new Solarium_Query_Select_Component_Facet_Query; $fq1 = new Solarium_Query_Select_Component_Facet_Query;
......
...@@ -433,6 +433,12 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -433,6 +433,12 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
); );
} }
public function testGetInvalidComponentAutoload()
{
$this->setExpectedException('Solarium_Exception');
$this->_query->getComponent('invalid', true);
}
public function testRemoveComponent() public function testRemoveComponent()
{ {
$mlt = new Solarium_Query_Select_Component_MoreLikeThis; $mlt = new Solarium_Query_Select_Component_MoreLikeThis;
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Result_Select_Facet_MultiQueryTest extends PHPUnit_Framework_TestCase
{
protected $_values, $_facet;
public function setUp()
{
$this->_values = array(
'a' => 12,
'b' => 5,
'c' => 3,
);
$this->_facet = new Solarium_Result_Select_Facet_MultiQuery($this->_values);
}
public function testGetValues()
{
$this->assertEquals($this->_values, $this->_facet->getValues());
}
public function testCount()
{
$this->assertEquals(count($this->_values), count($this->_facet));
}
public function testIterator()
{
$values = array();
foreach($this->_facet AS $key => $value)
{
$values[$key] = $value;
}
$this->assertEquals($this->_values, $values);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment