Commit d94979aa authored by schausson's avatar schausson

Added unit tests for QueryType\Select\Query\Component\BoostQuery, based on FilterQueryTest.

Added unit tests for QueryType\Select\Query\Component\DisMax::addBoostQuery, addBoostQueries.
parent b6e753c8
<?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.
*/
namespace Solarium\Tests\QueryType\Select\Query\Component;
use Solarium\QueryType\Select\Query\Component\BoostQuery;
class BoostQueryTest extends \PHPUnit_Framework_TestCase
{
protected $boostQuery;
public function setUp()
{
$this->boostQuery = new BoostQuery;
}
public function testConfigMode()
{
$fq = new BoostQuery(array('key' => 'k1', 'query'=> 'id:[10 TO 20]'));
$this->assertEquals('k1', $fq->getKey());
$this->assertEquals('id:[10 TO 20]', $fq->getQuery());
}
public function testSetAndGetKey()
{
$this->boostQuery->setKey('testkey');
$this->assertEquals('testkey', $this->boostQuery->getKey());
}
public function testSetAndGetQuery()
{
$this->boostQuery->setQuery('category:1');
$this->assertEquals('category:1', $this->boostQuery->getQuery());
}
public function testSetAndGetQueryWithBind()
{
$this->boostQuery->setQuery('id:%1%', array(678));
$this->assertEquals('id:678', $this->boostQuery->getQuery());
}
}
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
namespace Solarium\Tests\QueryType\Select\Query\Component; namespace Solarium\Tests\QueryType\Select\Query\Component;
use Solarium\QueryType\Select\Query\Component\BoostQuery;
use Solarium\QueryType\Select\Query\Component\DisMax; use Solarium\QueryType\Select\Query\Component\DisMax;
use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Query\Query;
...@@ -195,6 +196,101 @@ class DisMaxTest extends \PHPUnit_Framework_TestCase ...@@ -195,6 +196,101 @@ class DisMaxTest extends \PHPUnit_Framework_TestCase
); );
} }
public function testAddBoostQueryWithArray()
{
$query = 'cat:1^3';
$key = 'cat';
$this->disMax->addBoostQuery(array('query' => $query, 'key' => $key));
$this->assertEquals(
$query,
$this->disMax->getBoostQuery($key)
);
}
public function testAddBoostQueryWithObject()
{
$query = 'cat:1^3';
$key = 'cat';
$bq = new BoostQuery();
$bq -> setKey($key);
$bq -> setQuery($query);
$this->disMax->addBoostQuery($bq);
$this->assertEquals(
$query,
$this->disMax->getBoostQuery($key)
);
}
public function testAddBoostQueryWithoutKey()
{
$bq = new BoostQuery;
$bq->setQuery('category:1');
$this->setExpectedException('Solarium\Exception\InvalidArgumentException');
$this->disMax->addBoostQuery($bq);
}
public function testAddBoostQueryWithUsedKey()
{
$bq1 = new BoostQuery;
$bq1->setKey('bq1')->setQuery('category:1');
$bq2 = new BoostQuery;
$bq2->setKey('bq1')->setQuery('category:2');
$this->disMax->addBoostQuery($bq1);
$this->setExpectedException('Solarium\Exception\InvalidArgumentException');
$this->disMax->addBoostQuery($bq2);
}
public function testAddBoostQueriesWithInnerKeys()
{
$bqs = array(
array('key' => 'key1', 'query' => 'cat:1'),
array('key' => 'key2', 'query' => 'cat:2')
);
$this->disMax->addBoostQueries($bqs);
$bqs2 = array();
foreach ($bqs as $bq) {
$bqs2[$bq['key']] = new BoostQuery($bq);
}
$this->assertEquals(
$bqs2,
$this->disMax->getBoostQueries()
);
}
public function testAddBoostQueriesWithOuterKeys()
{
$bqs = array(
'key1' => array('query' => 'cat:1'),
'key2' => array('query' => 'cat:2')
);
$this->disMax->addBoostQueries($bqs);
$bqs2 = array();
foreach ($bqs as $key => $bq) {
$bq['key'] = $key;
$bqs2[$key] = new BoostQuery($bq);
}
$this->assertEquals(
$bqs2,
$this->disMax->getBoostQueries()
);
}
public function testSetAndGetBoostFunctions() public function testSetAndGetBoostFunctions()
{ {
$value = 'funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2'; $value = 'funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2';
......
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