Commit 01c05ed2 authored by Bas de Nooijer's avatar Bas de Nooijer

- lots of refactoring for the new solarium 2.0 structure

- added plugin system
- lots of unittest changes
- still very much a work in progress, largely untested!
parent 2f1edbf2
......@@ -92,6 +92,13 @@ class Solarium_Client extends Solarium_Configurable
),
);
/**
* Registered plugin instances
*
* @var array
*/
protected $_plugins = array();
/**
* Adapter instance
*
......@@ -213,6 +220,80 @@ class Solarium_Client extends Solarium_Configurable
return $this->_queryTypes;
}
/**
* Register a plugin
*
* @param string $key
* @param string $class
* @param array $options
* @return Solarium_Client Provides fluent interface
*/
public function registerPlugin($key, $class, $options = array())
{
$plugin = new $class($this, $options);
$this->_plugins[$key] = $plugin;
return $this;
}
/**
* Get all registered querytypes
*
* @return array
*/
public function getPlugins()
{
return $this->_plugins;
}
/**
* Get a plugin instance
*
* @param string $key
* @return array|null
*/
public function getPlugin($key)
{
if (isset($this->_plugins[$key])) {
return $this->_plugins[$key];
} else {
return null;
}
}
/**
* Remove a plugin instance
*
* @param string $key
* @return Solarium_Client Provides fluent interface
*/
public function removePlugin($key)
{
if (isset($this->_plugins[$key])) {
unset($this->_plugins[$key]);
}
return $this;
}
/**
* Forward events to plugins
*
* @param string $event
* @param array $params
* @param bool $resultOverride
* @return void|mixed
*/
protected function _callPlugins($event, $params, $resultOverride = false)
{
foreach($this->_plugins AS $plugin) {
$result = call_user_func_array(array($plugin,$event),$params);
if ($result !== null && $resultOverride) {
return $result;
}
}
}
/**
* Creates a request based on a query instance
*
......@@ -223,6 +304,9 @@ class Solarium_Client extends Solarium_Configurable
*/
public function createRequest($query)
{
$pluginResult = $this->_callPlugins('preCreateRequest', array($query), true);
if($pluginResult !== null) return $pluginResult;
$queryType = $query->getType();
if (!isset($this->_queryTypes[$queryType])) {
throw new Solarium_Exception('No requestbuilder registered for querytype: '. $queryType);
......@@ -230,8 +314,11 @@ class Solarium_Client extends Solarium_Configurable
$requestBuilderClass = $this->_queryTypes[$queryType]['requestbuilder'];
$requestBuilder = new $requestBuilderClass;
$request = $requestBuilder->build($query);
return $requestBuilder->build($query);
$this->_callPlugins('postCreateRequest', array($query, $request));
return $request;
}
/**
......@@ -243,8 +330,15 @@ class Solarium_Client extends Solarium_Configurable
*/
public function createResult($query, $response)
{
$pluginResult = $this->_callPlugins('preCreateResult', array($query, $response), true);
if($pluginResult !== null) return $pluginResult;
$resultClass = $query->getResultClass();
return new $resultClass($this, $query, $response);
$result = new $resultClass($this, $query, $response);
$this->_callPlugins('postCreateResult', array($query, $response, $result));
return $result;
}
/**
......@@ -255,10 +349,17 @@ class Solarium_Client extends Solarium_Configurable
*/
public function execute($query)
{
$pluginResult = $this->_callPlugins('preExecute', array($query), true);
if($pluginResult !== null) return $pluginResult;
$request = $this->createRequest($query);
$response = $this->executeRequest($request);
return $this->createResult($query, $response);
$result = $this->createResult($query, $response);
$this->_callPlugins('postExecute', array($query, $result));
return $result;
}
/**
......@@ -269,7 +370,14 @@ class Solarium_Client extends Solarium_Configurable
*/
public function executeRequest($request)
{
return $this->getAdapter()->execute($request);
$pluginResult = $this->_callPlugins('preExecuteRequest', array($request), true);
if($pluginResult !== null) return $pluginResult;
$response = $this->getAdapter()->execute($request);
$this->_callPlugins('postExecuteRequest', array($request, $response));
return $response;
}
/**
......
......@@ -184,7 +184,7 @@ class Solarium_Client_Request extends Solarium_Configurable
*/
public function addParam($key, $value, $overwrite = false)
{
if (!empty($value)) {
if ($value !== '' && $value !== null) {
if (!$overwrite && isset($this->_params[$key])) {
if (!is_array($this->_params[$key])) {
$this->_params[$key] = array($this->_params[$key]);
......
......@@ -73,4 +73,41 @@ abstract class Solarium_Client_RequestBuilder
return $value;
}
/**
* Render a boolean attribute
*
* For use in building XML messages
*
* @param string $name
* @param boolean $value
* @return string
*/
public function boolAttrib($name, $value)
{
if (null !== $value) {
$value = (true == $value) ? 'true' : 'false';
return $this->attrib($name, $value);
} else {
return '';
}
}
/**
* Render an attribute
*
* For use in building XML messages
*
* @param string $name
* @param striung $value
* @return string
*/
public function attrib($name, $value)
{
if (null !== $value) {
return ' ' . $name . '="' . $value . '"';
} else {
return '';
}
}
}
\ No newline at end of file
......@@ -45,27 +45,18 @@ class Solarium_Client_RequestBuilder_Ping extends Solarium_Client_RequestBuilder
{
/**
* Get uri
* Build request for a ping query
*
* Uses the default {@link buildUri()} method, no special uri needed in this
* case.
*
* @return string
* @param Solarium_Query_Ping $query
* @return Solarium_Client_Request
*/
public function getUri()
public function build($query)
{
return $this->buildUri();
}
$request = new Solarium_Client_Request;
$request->setHandler($query->getHandler());
$request->setMethod(Solarium_Client_Request::METHOD_HEAD);
/**
* Get HTTP request method
*
* Ping has no useful result data, so a more optimal HEAD request is used.
*
* @return string
*/
public function getMethod()
{
return self::HEAD;
return $request;
}
}
\ No newline at end of file
......@@ -64,7 +64,7 @@ class Solarium_Client_RequestBuilder_Select extends Solarium_Client_RequestBuild
// add sort fields to request
$sort = array();
foreach ($query->getSortFields() AS $field => $order) {
foreach ($query->getSorts() AS $field => $order) {
$sort[] = $field . ' ' . $order;
}
if (count($sort) !== 0) {
......
......@@ -45,30 +45,20 @@ class Solarium_Client_RequestBuilder_Update extends Solarium_Client_RequestBuild
{
/**
* Get HTTP request method
* Build request for an update query
*
* Update uses raw POST data so a POST method has to be used.
*
* @return string
* @param Solarium_Query_Update $query
* @return Solarium_Client_Request
*/
public function getMethod()
public function build($query)
{
return self::POST;
}
/**
* Get uri
*
* Return the default url with the addition of the wt param.
* This enables a JSON response, that is the easiest and most efficient
* format to decode in the response handler.
*
* @return string
*/
public function getUri()
{
$this->_params = array('wt' => 'json');
return $this->buildUri();
$request = new Solarium_Client_Request;
$request->setHandler($query->getHandler());
$request->setMethod(Solarium_Client_Request::METHOD_POST);
$request->addParam('wt', 'json');
$request->setRawData($this->getRawData($query));
return $request;
}
/**
......@@ -76,13 +66,14 @@ class Solarium_Client_RequestBuilder_Update extends Solarium_Client_RequestBuild
*
* Each commandtype is delegated to a separate builder method.
*
* @param Solarium_Query_Update $query
* @throws Solarium_Exception
* @return string
*/
public function getRawData()
public function getRawData($query)
{
$xml = '<update>';
foreach ($this->_query->getCommands() AS $command) {
foreach ($query->getCommands() AS $command) {
switch ($command->getType()) {
case Solarium_Query_Update_Command::ADD:
$xml .= $this->buildAddXml($command);
......
......@@ -68,9 +68,11 @@ class Solarium_Configurable
*/
public function __construct($options = null)
{
$this->setOptions($options);
$this->_init();
if (null !== $options) {
$this->setOptions($options);
} else {
$this->_init();
}
}
/**
......
<?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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @package Solarium
*/
/**
* Base class for plugins
*
* @package Solarium
* @subpackage Plugin
*/
abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
{
/**
* Client instance
*
* @var Solarium_Client
*/
protected $_client;
/**
* Constructor
*
* @param Solarium_Client $client
* @param array $options
*/
public function __construct($client, $options)
{
$this->_client = $client;
parent::__construct($options);
}
/**
*
* @param Solarium_Query $query
* @return void|Solarium_Client_Request
*/
public function preCreateRequest($query)
{ }
/**
* @param Solarium_Query $query
* @param Solarium_Client_Request $request
* @return void
*/
public function postCreateRequest($query, $request)
{ }
/**
* @param Solarium_Client_Request $request
* @return void|Solarium_Client_Response
*/
public function preExecuteRequest($request)
{ }
/**
* @param Solarium_Client_Request $request
* @param Solarium_Client_Response $response
* @return void
*/
public function postExecuteRequest($request, $response)
{ }
/**
* @param Solarium_Query $query
* @param Solarium_Client_Response $response
* @return void|Solarium_Result
*/
public function preCreateResult($query, $response)
{ }
/**
* @param Solarium_Query $query
* @param Solarium_Client_Response $response
* @param Solarium_Result $result
* @return void
*/
public function postCreateResult($query, $response, $result)
{ }
/**
* @param Solarium_Query $query
* @return void|Solarium_Result
*/
public function preExecute($query)
{ }
/**
* @param Solarium_Query $query
* @param Solarium_Result $result
* @return void
*/
public function postExecute($query, $result)
{ }
}
\ No newline at end of file
......@@ -123,11 +123,11 @@ class Solarium_Query_Select extends Solarium_Query
protected $_fields = array();
/**
* Fields to sort on
* Items to sort on
*
* @var array
*/
protected $_sortFields = array();
protected $_sorts = array();
/**
* Filterqueries
......@@ -169,7 +169,7 @@ class Solarium_Query_Select extends Solarium_Query
$this->addFilterQueries($value);
break;
case 'sort':
$this->addSortFields($value);
$this->addSorts($value);
break;
case 'fields':
$this->addFields($value);
......@@ -386,84 +386,84 @@ class Solarium_Query_Select extends Solarium_Query
}
/**
* Add a sort field
* Add a sort
*
* @param string $field
* @param string $sort
* @param string $order
* @return Solarium_Query Provides fluent interface
*/
public function addSortField($field, $order)
public function addSort($sort, $order)
{
$this->_sortFields[$field] = $order;
$this->_sorts[$sort] = $order;
return $this;
}
/**
* Add multiple sort fields
* Add multiple sorts
*
* The input array must contain fieldnames as keys and the order as values.
* The input array must contain sort items as keys and the order as values.
*
* @param array $sortFields
* @param array $sorts
* @return Solarium_Query Provides fluent interface
*/
public function addSortFields(array $sortFields)
public function addSorts(array $sorts)
{
foreach ($sortFields AS $sortField => $sortOrder) {
$this->addSortField($sortField, $sortOrder);
foreach ($sorts AS $sort => $order) {
$this->addSort($sort, $order);
}
return $this;
}
/**
* Remove a sortfield
* Remove a sort
*
* @param string $field
* @param string $sort
* @return Solarium_Query Provides fluent interface
*/
public function removeSortField($field)
public function removeSort($sort)
{
if (isset($this->_sortFields[$field])) {
unset($this->_sortFields[$field]);
if (isset($this->_sorts[$sort])) {
unset($this->_sorts[$sort]);
}
return $this;
}
/**
* Remove all sortfields
* Remove all sorts
*
* @return Solarium_Query Provides fluent interface
*/
public function clearSortFields()
public function clearSorts()
{
$this->_sortFields = array();
$this->_sorts = array();
return $this;
}
/**
* Get a list of the sortfields
* Get a list of the sorts
*
* @return array
*/
public function getSortFields()
public function getSorts()
{
return $this->_sortFields;
return $this->_sorts;
}
/**
* Set multiple sortfields
* Set multiple sorts
*
* This overwrites any existing sortfields
* This overwrites any existing sorts
*
* @param array $fields
* @param array $sorts
* @return Solarium_Query Provides fluent interface
*/
public function setSortFields($fields)
public function setSorts($sorts)
{
$this->clearSortFields();
$this->addSortFields($fields);
$this->clearSorts();
$this->addSorts($sorts);
return $this;
}
......
<?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_Client_AdapterTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Client_Adapter
*/
protected $_adapter;
public function setUp()
{
$client = new Solarium_Client();
$this->_adapter = $client->getAdapter();
}
public function testSetAndGetHost()
{
$this->_adapter->setHost('myhost');
$this->assertEquals('myhost', $this->_adapter->getHost());
}
public function testSetAndGetPort()
{
$this->_adapter->setPort(8080);
$this->assertEquals(8080, $this->_adapter->getPort());
}
public function testSetAndGetPath()
{
$this->_adapter->setPath('/mysolr');
$this->assertEquals('/mysolr', $this->_adapter->getPath());
}
public function testSetAndGetPathWithTrailingSlash()
{
$this->_adapter->setPath('/mysolr/');
$this->assertEquals('/mysolr', $this->_adapter->getPath());
}
public function testSetAndGetCore()
{
$this->_adapter->setCore('core1');
$this->assertEquals('core1', $this->_adapter->getCore());
}
}
class TestAdapter extends Solarium_Client_Adapter
{
public function execute($request)
{
}
}
\ No newline at end of file
......@@ -29,25 +29,23 @@
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_Response_UpdateTest extends PHPUnit_Framework_TestCase
class Solarium_Client_RequestBuilder_PingTest extends PHPUnit_Framework_TestCase
{
public function testGetResult()
public function testBuild()
{
$query = new Solarium_Query_Update;
$data = array('responseHeader' => array('status' => 0, 'QTime' => 145));
$response = new Solarium_Client_Response_Update($query, $data);
$result = $response->getResult();
$builder = new Solarium_Client_RequestBuilder_Ping;
$request = $builder->build(new Solarium_Query_Ping);
$this->assertEquals(
0,
$result->getStatus()
'admin/ping?',
$request->getUri()
);
$this->assertEquals(
145,
$result->getQueryTime()
Solarium_Client_Request::METHOD_HEAD,
$request->getMethod()
);
}
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCase
{
/**
......@@ -37,30 +37,29 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
*/
protected $_query;
protected $_options = array(
'host' => '127.0.0.1',
'port' => 80,
'path' => '/solr',
'core' => null,
);
/**
* @var Solarium_Client_RequestBuilder_Select
*/
protected $_builder;
public function setUp()
{
$this->_query = new Solarium_Query_Select;
$this->_builder = new Solarium_Client_RequestBuilder_Select;
}
public function testGetMethod()
{
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
Solarium_Client_Request::GET,
Solarium_Client_Request::METHOD_GET,
$request->getMethod()
);
}
public function testSelectUrlWithDefaultValues()
{
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
null,
......@@ -68,16 +67,16 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json',
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json',
urldecode($request->getUri())
);
}
public function testSelectUrlWithSort()
{
$this->_query->addSortField('id', Solarium_Query_Select::SORT_ASC);
$this->_query->addSortField('name', Solarium_Query_Select::SORT_DESC);
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$this->_query->addSort('id', Solarium_Query_Select::SORT_ASC);
$this->_query->addSort('name', Solarium_Query_Select::SORT_DESC);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
null,
......@@ -85,18 +84,18 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&sort=id asc,name desc',
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&sort=id asc,name desc',
urldecode($request->getUri())
);
}
public function testSelectUrlWithSortAndFilters()
{
$this->_query->addSortField('id', Solarium_Query_Select::SORT_ASC);
$this->_query->addSortField('name', Solarium_Query_Select::SORT_DESC);
$this->_query->addSort('id', Solarium_Query_Select::SORT_ASC);
$this->_query->addSort('name', Solarium_Query_Select::SORT_DESC);
$this->_query->addFilterQuery(new Solarium_Query_Select_FilterQuery(array('key' => 'f1', 'query' => 'published:true')));
$this->_query->addFilterQuery(new Solarium_Query_Select_FilterQuery(array('key' => 'f2', 'tag' => array('t1','t2'), 'query' => 'category:23')));
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
null,
......@@ -104,7 +103,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&sort=id asc,name desc&fq=published:true&fq={!tag=t1,t2}category:23',
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&sort=id asc,name desc&fq=published:true&fq={!tag=t1,t2}category:23',
urldecode($request->getUri())
);
}
......@@ -113,8 +112,8 @@ 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_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);
$this->_query->getFacetSet()->addFacet(new Solarium_Query_Select_Component_Facet_MultiQuery(array('key' => 'f3', 'query' => array('f4' => array('query' => 'category:40')))));
$request = $this->_builder->build($this->_query);
$this->assertEquals(
null,
......@@ -122,7 +121,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
);
$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&facet.query={!key=f4}category:40',
'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())
);
}
......@@ -141,7 +140,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
)
));
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
null,
......@@ -149,7 +148,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.range={!key=f1}price&f.price.facet.range.start=1&f.price.facet.range.end=100&f.price.facet.range.gap=10&f.price.facet.range.other=all&f.price.facet.range.include=outer',
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.range={!key=f1}price&f.price.facet.range.start=1&f.price.facet.range.end=100&f.price.facet.range.gap=10&f.price.facet.range.other=all&f.price.facet.range.include=outer',
urldecode($request->getUri())
);
}
......@@ -161,7 +160,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_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 = $this->_builder->build($this->_query);
$this->assertEquals(
null,
......@@ -169,7 +168,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.missing=1&facet.limit=10&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40',
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.missing=1&facet.limit=10&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40',
urldecode($request->getUri())
);
}
......@@ -178,7 +177,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
{
$this->_query->getFacetSet()->addFacet(new UnknownFacet(array('key' => 'f1', 'field' => 'owner')));
$this->setExpectedException('Solarium_Exception');
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$request = $this->_builder->build($this->_query);
$request->getUri();
}
......@@ -196,7 +195,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
$mlt->setQueryFields('description');
$mlt->setCount(6);
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
null,
......@@ -204,7 +203,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&mlt=true&mlt.fl=description,name&mlt.mintf=1&mlt.mindf=3&mlt.minwl=2&mlt.maxwl=15&mlt.maxqt=4&mlt.maxntp=5&mlt.boost=1&mlt.qf=description&mlt.count=6',
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&mlt=true&mlt.fl=description,name&mlt.mintf=1&mlt.mindf=3&mlt.minwl=2&mlt.maxwl=15&mlt.maxqt=4&mlt.maxntp=5&mlt.boost=1&mlt.qf=description&mlt.count=6',
urldecode($request->getUri())
);
}
......
......@@ -29,37 +29,39 @@
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
class Solarium_Client_RequestBuilder_UpdateTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Update
*/
protected $_query;
protected $_options = array(
'host' => '127.0.0.1',
'port' => 80,
'path' => '/solr',
'core' => null,
);
/**
* @var Solarium_Client_RequestBuilder_Update
*/
protected $_builder;
public function setUp()
{
$this->_query = new Solarium_Query_Update;
$this->_builder = new Solarium_Client_RequestBuilder_Update;
}
public function testGetMethod()
{
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
Solarium_Client_Request::POST,
Solarium_Client_Request::METHOD_POST,
$request->getMethod()
);
}
public function testGetUri()
{
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
'http://127.0.0.1:80/solr/update?wt=json',
'update?wt=json',
$request->getUri()
);
}
......@@ -68,12 +70,10 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
{
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => 1)));
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<add><doc><field name="id">1</field></doc></add>',
$request->buildAddXml($command)
$this->_builder->buildAddXml($command)
);
}
......@@ -82,11 +82,9 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
$command = new Solarium_Query_Update_Command_Add(array('overwrite' => true,'commitwithin' => 100));
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => 1)));
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<add overwrite="true" commitWithin="100"><doc><field name="id">1</field></doc></add>',
$request->buildAddXml($command)
$this->_builder->buildAddXml($command)
);
}
......@@ -95,11 +93,9 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => 1, 'text' => 'test < 123 > test')));
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<add><doc><field name="id">1</field><field name="text">test &lt; 123 &gt; test</field></doc></add>',
$request->buildAddXml($command)
$this->_builder->buildAddXml($command)
);
}
......@@ -108,11 +104,9 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => array(1,2,3), 'text' => 'test < 123 > test')));
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<add><doc><field name="id">1</field><field name="id">2</field><field name="id">3</field><field name="text">test &lt; 123 &gt; test</field></doc></add>',
$request->buildAddXml($command)
$this->_builder->buildAddXml($command)
);
}
......@@ -123,11 +117,9 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument($doc);
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<add><doc boost="2.5"><field name="id">1</field></doc></add>',
$request->buildAddXml($command)
$this->_builder->buildAddXml($command)
);
}
......@@ -138,11 +130,9 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument($doc);
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<add><doc><field name="id" boost="2.1">1</field></doc></add>',
$request->buildAddXml($command)
$this->_builder->buildAddXml($command)
);
}
......@@ -151,22 +141,20 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
$command = new Solarium_Query_Update_Command_Add;
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => 1)));
$command->addDocument(new Solarium_Document_ReadWrite(array('id' => 2)));
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<add><doc><field name="id">1</field></doc><doc><field name="id">2</field></doc></add>',
$request->buildAddXml($command)
$this->_builder->buildAddXml($command)
);
}
public function testBuildDeleteXml()
{
$command = new Solarium_Query_Update_Command_Delete;
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<delete></delete>',
$request->buildDeleteXml($command)
$this->_builder->buildDeleteXml($command)
);
}
......@@ -174,11 +162,10 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
{
$command = new Solarium_Query_Update_Command_Delete;
$command->addId(123);
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<delete><id>123</id></delete>',
$request->buildDeleteXml($command)
$this->_builder->buildDeleteXml($command)
);
}
......@@ -187,11 +174,10 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
$command = new Solarium_Query_Update_Command_Delete;
$command->addId(123);
$command->addId(456);
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<delete><id>123</id><id>456</id></delete>',
$request->buildDeleteXml($command)
$this->_builder->buildDeleteXml($command)
);
}
......@@ -199,11 +185,10 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
{
$command = new Solarium_Query_Update_Command_Delete;
$command->addQuery('*:*');
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<delete><query>*:*</query></delete>',
$request->buildDeleteXml($command)
$this->_builder->buildDeleteXml($command)
);
}
......@@ -212,11 +197,10 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
$command = new Solarium_Query_Update_Command_Delete;
$command->addQuery('published:false');
$command->addQuery('id:[10 TO 20]');
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<delete><query>published:false</query><query>id:[10 TO 20]</query></delete>',
$request->buildDeleteXml($command)
$this->_builder->buildDeleteXml($command)
);
}
......@@ -227,11 +211,10 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
$command->addId(456);
$command->addQuery('published:false');
$command->addQuery('id:[10 TO 20]');
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<delete><id>123</id><id>456</id><query>published:false</query><query>id:[10 TO 20]</query></delete>',
$request->buildDeleteXml($command)
$this->_builder->buildDeleteXml($command)
);
}
......@@ -240,80 +223,72 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
$command = new Solarium_Query_Update_Command_Delete;
$command->addId('special<char>id');
$command->addQuery('id:special<char>id');
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<delete><id>special&lt;char&gt;id</id><query>id:special&lt;char&gt;id</query></delete>',
$request->buildDeleteXml($command)
$this->_builder->buildDeleteXml($command)
);
}
public function testBuildOptimizeXml()
{
$command = new Solarium_Query_Update_Command_Optimize;
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<optimize/>',
$request->buildOptimizeXml($command)
$this->_builder->buildOptimizeXml($command)
);
}
public function testBuildOptimizeXmlWithParams()
{
$command = new Solarium_Query_Update_Command_Optimize(array('waitflush'=>true,'waitsearcher'=>false,'maxsegments'=>10));
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<optimize waitFlush="true" waitSearcher="false" maxSegments="10"/>',
$request->buildOptimizeXml($command)
$this->_builder->buildOptimizeXml($command)
);
}
public function testBuildCommitXml()
{
$command = new Solarium_Query_Update_Command_Commit;
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<commit/>',
$request->buildCommitXml($command)
$this->_builder->buildCommitXml($command)
);
}
public function testBuildCommitXmlWithParams()
{
$command = new Solarium_Query_Update_Command_Commit(array('waitflush'=>true,'waitsearcher'=>false,'expungedeletes'=>true));
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<commit waitFlush="true" waitSearcher="false" expungeDeletes="true"/>',
$request->buildCommitXml($command)
$this->_builder->buildCommitXml($command)
);
}
public function testBuildRollbackXml()
{
$command = new Solarium_Query_Update_Command_Rollback;
$request = new Solarium_Client_Request_Update($this->_options, $this->_query);
$this->assertEquals(
'<rollback/>',
$request->buildRollbackXml($command)
$this->_builder->buildRollbackXml($command)
);
}
public function testCompleteRequest()
{
$query = new Solarium_Query_Update;
$query->addDeleteById(1);
$query->addRollback();
$query->addDeleteQuery('*:*');
$query->addDocument(new Solarium_Document_ReadWrite(array('id' => 1)));
$query->addCommit();
$query->addOptimize();
$request = new Solarium_Client_Request_Update($this->_options, $query);
$this->_query->addDeleteById(1);
$this->_query->addRollback();
$this->_query->addDeleteQuery('*:*');
$this->_query->addDocument(new Solarium_Document_ReadWrite(array('id' => 1)));
$this->_query->addCommit();
$this->_query->addOptimize();
$this->assertEquals(
'<update>'
. '<delete><id>1</id></delete>'
......@@ -323,18 +298,16 @@ class Solarium_Client_Request_UpdateTest extends PHPUnit_Framework_TestCase
. '<commit/>'
. '<optimize/>'
. '</update>',
$request->getRawData()
$this->_builder->getRawData($this->_query)
);
}
public function testInvalidCommandInRequest()
{
$query = new Solarium_Query_Update;
$query->add('invalidcommand',new InvalidCommand);
$this->_query->add('invalidcommand',new InvalidCommand);
$this->setExpectedException('Solarium_Exception');
$request = new Solarium_Client_Request_Update($this->_options, $query);
$request->getRawData();
$this->_builder->build($this->_query);
}
}
......
......@@ -29,39 +29,36 @@
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_Request_PingTest extends PHPUnit_Framework_TestCase
class Solarium_Client_RequestBuilderTest extends PHPUnit_Framework_TestCase
{
protected $_query;
protected $_builder;
protected $_options = array(
'host' => '127.0.0.1',
'port' => 80,
'path' => '/solr',
'core' => null,
);
public function setUp()
public function setup()
{
$this->_query = new Solarium_Query_Ping;
$this->_builder = new TestRequestBuilder;
}
public function testGetMethod()
public function testRenderLocalParams()
{
$request = new Solarium_Client_Request_Ping($this->_options, $this->_query);
$myParams = array('tag' => 'mytag', 'ex' => array('exclude1','exclude2'));
$this->assertEquals(
Solarium_Client_Request::HEAD,
$request->getMethod()
'{!tag=mytag ex=exclude1,exclude2}myValue',
$this->_builder->renderLocalParams('myValue', $myParams)
);
}
public function testGetUri()
public function testRenderLocalParamsWithoutParams()
{
$request = new Solarium_Client_Request_Ping($this->_options, $this->_query);
$this->assertEquals(
'http://127.0.0.1:80/solr/admin/ping?',
$request->getUri()
'myValue',
$this->_builder->renderLocalParams('myValue')
);
}
}
class TestRequestBuilder extends Solarium_Client_RequestBuilder{
}
\ No newline at end of file
......@@ -34,167 +34,25 @@ class Solarium_Client_RequestTest extends PHPUnit_Framework_TestCase
protected $_request;
protected $_options = array(
'host' => '127.0.0.1',
'port' => 80,
'path' => '/solr',
'core' => null,
);
protected function _getRequest($options, $class = 'Solarium_Client_Request_Ping')
public function setup()
{
$query = new Solarium_Query;
$query->setHandler('mypath');
return new $class($options, $query);
$this->_request = new Solarium_Client_Request;
}
public function testGetMethod()
{
$this->assertEquals(
Solarium_Client_Request::HEAD,
$this->_getRequest($this->_options)->getMethod()
Solarium_Client_Request::METHOD_GET,
$this->_request->getMethod()
);
}
public function testGetUri()
{
$this->assertEquals(
'http://127.0.0.1:80/solr/mypath?',
$this->_getRequest($this->_options)->getUri()
);
}
public function testGetUriWithCore()
{
$options = $this->_options;
$options['core'] = 'core0';
$this->assertEquals(
'http://127.0.0.1:80/solr/core0/mypath?',
$this->_getRequest($options)->getUri()
);
}
public function testBoolAttrib()
{
$this->assertEquals(
' name="false"',
$this->_getRequest($this->_options)->boolAttrib('name', false)
);
}
public function testBoolAttribNoValue()
{
$this->assertEquals(
'',
$this->_getRequest($this->_options)->boolAttrib('name', null)
);
}
public function testAttrib()
{
$this->assertEquals(
' name="myvalue"',
$this->_getRequest($this->_options)->attrib('name', 'myvalue')
);
}
public function testAttribNoValue()
{
$this->assertEquals(
'',
$this->_getRequest($this->_options)->attrib('name', null)
);
}
public function testGetUriWithParams()
{
$this->assertEquals(
'http://127.0.0.1:80/solr/mypath?wt=json&fq=category%3A1&fq=published%3Atrue',
$this->_getRequest($this->_options, 'TestRequest')->getUri()
'?',
$this->_request->getUri()
);
}
public function testGetRawData()
{
$this->assertEquals(
'<data>xyz</data>',
$this->_getRequest($this->_options, 'TestRequest')->getRawData()
);
}
public function testRenderLocalParams()
{
$myParams = array('tag' => 'mytag', 'ex' => array('exclude1','exclude2'));
$this->assertEquals(
'{!tag=mytag ex=exclude1,exclude2}myValue',
$this->_getRequest($this->_options)->renderLocalParams('myValue', $myParams)
);
}
public function testRenderLocalParamsWithoutParams()
{
$this->assertEquals(
'myValue',
$this->_getRequest($this->_options)->renderLocalParams('myValue')
);
}
public function testAddParamWithNewParam()
{
$request = $this->_getRequest($this->_options);
$request->addParam('myparam',1);
$this->assertEquals(
$request->getParams(),
array('myparam' => 1)
);
}
public function testAddParamNoValue()
{
$request = $this->_getRequest($this->_options);
$request->addParam('myparam',1);
$request->addParam('mysecondparam',"");
$this->assertEquals(
$request->getParams(),
array('myparam' => 1)
);
}
public function testAddParamWithExistingParam()
{
$request = $this->_getRequest($this->_options);
$request->addParam('myparam',1);
$request->addParam('myparam',2);
$this->assertEquals(
$request->getParams(),
array('myparam' => array(1,2))
);
}
}
class TestRequest extends Solarium_Client_Request
{
protected $_params = array(
'wt' => 'json',
'fq' => array('category:1','published:true')
);
public function getUri()
{
return $this->buildUri();
}
public function getRawData()
{
return '<data>xyz</data>';
}
}
\ No newline at end of file
......@@ -29,14 +29,12 @@
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_Response_SelectTest extends PHPUnit_Framework_TestCase
class Solarium_Client_ResponseParser_SelectTest extends PHPUnit_Framework_TestCase
{
public function testGetResult()
public function testParse()
{
$query = new Solarium_Query_Select;
$response = new Solarium_Client_Response_Select($query);
$this->assertThat($response->getResult(), $this->isInstanceOf($query->getResultClass()));
}
}
<?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_Client_ResponseParser_UpdateTest extends PHPUnit_Framework_TestCase
{
public function testParse()
{
}
}
......@@ -32,24 +32,38 @@
class Solarium_Client_ResponseTest extends PHPUnit_Framework_TestCase
{
public function testConstructor()
protected $_headers, $_data;
/**
* @var Solarium_Client_Response
*/
protected $_response;
public function setUp()
{
$query = new Solarium_Query_Update;
$data = array('response' => null);
$response = new MyTestResponse($query, $data);
$this->assertEquals(
array($query, $data),
$response->getResult()
);
$this->_headers = array('HTTP/1.0 304 Not Modified');
$this->_data = '{"responseHeader":{"status":0,"QTime":1,"params":{"wt":"json","q":"mdsfgdsfgdf"}},"response":{"numFound":0,"start":0,"docs":[]}}';
$this->_response = new Solarium_Client_Response($this->_data, $this->_headers);
}
}
public function testGetStatusCode()
{
$this->assertEquals(304, $this->_response->getStatusCode());
}
class MyTestResponse extends Solarium_Client_Response
{
public function getResult()
public function testGetStatusMessage()
{
$this->assertEquals('Not Modified', $this->_response->getStatusMessage());
}
public function testGetHeaders()
{
$this->assertEquals($this->_headers, $this->_response->getHeaders());
}
public function testGetBody()
{
return array($this->_query, $this->_data);
$this->assertEquals($this->_data, $this->_response->getBody());
}
}
\ No newline at end of file
......@@ -32,41 +32,6 @@
class Solarium_ClientTest extends PHPUnit_Framework_TestCase
{
public function testSetAndGetHost()
{
$client = new Solarium_Client();
$client->setHost('myhost');
$this->assertEquals('myhost', $client->getHost());
}
public function testSetAndGetPort()
{
$client = new Solarium_Client();
$client->setPort(8080);
$this->assertEquals(8080, $client->getPort());
}
public function testSetAndGetPath()
{
$client = new Solarium_Client();
$client->setPath('/mysolr');
$this->assertEquals('/mysolr', $client->getPath());
}
public function testSetAndGetPathWithTrailingSlash()
{
$client = new Solarium_Client();
$client->setPath('/mysolr/');
$this->assertEquals('/mysolr', $client->getPath());
}
public function testSetAndGetCore()
{
$client = new Solarium_Client();
$client->setCore('core1');
$this->assertEquals('core1', $client->getCore());
}
public function testGetAdapterWithDefaultAdapter()
{
$client = new Solarium_Client();
......@@ -91,117 +56,15 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$this->assertThat($client->getAdapter(), $this->isInstanceOf($adapterClass));
}
public function testOptionForwardingToAdapter()
{
$client = new Solarium_Client();
$options = $client->getOptions();
// initialising at adapter creation
$observer = $this->getMock('Solarium_Client_Adapter_Http', array('setOptions'));
$observer->expects($this->once())
->method('setOptions')
->with($this->equalTo($options));
$client->setAdapter($observer);
}
public function testOptionForwardingToAdapterAfterChange()
{
$newHostValue = 'myCustomHost';
$client = new Solarium_Client;
$options = $client->getOptions();
$options['host'] = $newHostValue;
$observer = $this->getMock('Solarium_Client_Adapter_Http', array('setOptions'));
$observer->expects($this->at(1))
->method('setOptions')
->with($this->equalTo($options));
$client->setAdapter($observer);
$client->setHost($newHostValue); // this change should trigger a new adapter->setOptions call
}
public function testSelect()
{
$client = new Solarium_Client;
$query = new Solarium_Query_Select;
// initialising at adapter creation
$observer = $this->getMock('Solarium_Client_Adapter_Http', array('select'));
$observer->expects($this->once())
->method('select')
->with($this->equalTo($query));
$client->setAdapter($observer);
$client->select($query);
}
public function testPing()
{
$client = new Solarium_Client;
$query = new Solarium_Query_Ping;
// initialising at adapter creation
$observer = $this->getMock('Solarium_Client_Adapter_Http', array('ping'));
$observer->expects($this->once())
->method('ping')
->with($this->equalTo($query));
$client->setAdapter($observer);
$client->ping($query);
}
public function testUpdate()
{
$client = new Solarium_Client;
$query = new Solarium_Query_Update;
// initialising at adapter creation
$observer = $this->getMock('Solarium_Client_Adapter_Http', array('update'));
$observer->expects($this->once())
->method('update')
->with($this->equalTo($query));
$client->setAdapter($observer);
$client->update($query);
}
public function testSetAndGetAdapterOptions()
{
$options = array('useragent' => 'myAgent');
$client = new Solarium_Client();
$client->setAdapterOptions($options);
$this->assertEquals($options, $client->getAdapterOptions());
}
public function testSetAndGetAdapterOptionsWithObject()
{
$options = array('useragent' => 'myAgent');
$optionObject = new myConfig($options);
$client = new Solarium_Client();
$client->setAdapterOptions($optionObject);
$this->assertEquals($options, $client->getAdapterOptions());
}
}
class MyAdapter extends Solarium_Client_Adapter_Http{
public function select($query)
public function execute($request)
{
$response = new Solarium_Client_Response('{}', array('HTTP/1.1 200 OK'));
return $response;
}
public function ping($query)
{
}
public function update($query)
{
}
}
class myConfig{
......
......@@ -45,7 +45,7 @@ class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestC
public function testGetType()
{
$this->assertEquals(
Solarium_Query_Select_Component::DISMAX,
Solarium_Query_Select::COMPONENT_DISMAX,
$this->_disMax->getType()
);
}
......
......@@ -41,7 +41,7 @@ class Solarium_Query_Select_Component_FacetSetTest extends PHPUnit_Framework_Tes
public function testGetType()
{
$this->assertEquals(Solarium_Query_Select_Component::FACETSET, $this->_facetSet->getType());
$this->assertEquals(Solarium_Query_Select::COMPONENT_FACETSET, $this->_facetSet->getType());
}
public function testSetAndGetSort()
......
......@@ -41,7 +41,7 @@ class Solarium_Query_Select_Component_HighlightingTest extends PHPUnit_Framework
public function testGetType()
{
$this->assertEquals(Solarium_Query_Select_Component::HIGHLIGHTING, $this->_hlt->getType());
$this->assertEquals(Solarium_Query_Select::COMPONENT_HIGHLIGHTING, $this->_hlt->getType());
}
public function testSetAndGetFields()
......
......@@ -41,7 +41,7 @@ class Solarium_Query_Select_Component_MoreLikeThisTest extends PHPUnit_Framework
public function testGetType()
{
$this->assertEquals(Solarium_Query_Select_Component::MORELIKETHIS, $this->_mlt->getType());
$this->assertEquals(Solarium_Query_Select::COMPONENT_MORELIKETHIS, $this->_mlt->getType());
}
public function testSetAndGetFields()
......
......@@ -116,86 +116,86 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
$this->assertEquals(array('field3','field4'), $this->_query->getFields());
}
public function testAddSortField()
public function testAddSort()
{
$this->_query->addSortField('field1', Solarium_Query_Select::SORT_DESC);
$this->_query->addSort('field1', Solarium_Query_Select::SORT_DESC);
$this->assertEquals(
array('field1' => Solarium_Query_Select::SORT_DESC),
$this->_query->getSortFields()
$this->_query->getSorts()
);
}
public function testAddSortFields()
public function testAddSorts()
{
$sortFields = array(
$sorts = array(
'field1' => Solarium_Query_Select::SORT_DESC,
'field2' => Solarium_Query_Select::SORT_ASC
);
$this->_query->addSortFields($sortFields);
$this->_query->addSorts($sorts);
$this->assertEquals(
$sortFields,
$this->_query->getSortFields()
$sorts,
$this->_query->getSorts()
);
}
public function testRemoveSortField()
public function testRemoveSort()
{
$sortFields = array(
$sorts = array(
'field1' => Solarium_Query_Select::SORT_DESC,
'field2' => Solarium_Query_Select::SORT_ASC
);
$this->_query->addSortFields($sortFields);
$this->_query->removeSortField('field1');
$this->_query->addSorts($sorts);
$this->_query->removeSort('field1');
$this->assertEquals(
array('field2' => Solarium_Query_Select::SORT_ASC),
$this->_query->getSortFields()
$this->_query->getSorts()
);
}
public function testRemoveInvalidSortField()
public function testRemoveInvalidSort()
{
$sortFields = array(
$sorts = array(
'field1' => Solarium_Query_Select::SORT_DESC,
'field2' => Solarium_Query_Select::SORT_ASC
);
$this->_query->addSortFields($sortFields);
$this->_query->removeSortField('invalidfield'); //continue silently
$this->_query->addSorts($sorts);
$this->_query->removeSort('invalidfield'); //continue silently
$this->assertEquals(
$sortFields,
$this->_query->getSortFields()
$sorts,
$this->_query->getSorts()
);
}
public function testClearSortFields()
public function testClearSorts()
{
$sortFields = array(
$sorts = array(
'field1' => Solarium_Query_Select::SORT_DESC,
'field2' => Solarium_Query_Select::SORT_ASC
);
$this->_query->addSortFields($sortFields);
$this->_query->clearSortFields();
$this->_query->addSorts($sorts);
$this->_query->clearSorts();
$this->assertEquals(
array(),
$this->_query->getSortFields()
$this->_query->getSorts()
);
}
public function testSetSortFields()
public function testSetSorts()
{
$sortFields = array(
$sorts = array(
'field1' => Solarium_Query_Select::SORT_DESC,
'field2' => Solarium_Query_Select::SORT_ASC
);
$this->_query->addSortFields($sortFields);
$this->_query->setSortFields(array('field3' => Solarium_Query_Select::SORT_ASC));
$this->_query->addSorts($sorts);
$this->_query->setSorts(array('field3' => Solarium_Query_Select::SORT_ASC));
$this->assertEquals(
array('field3' => Solarium_Query_Select::SORT_ASC),
$this->_query->getSortFields()
$this->_query->getSorts()
);
}
......@@ -370,7 +370,7 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
$config['sort'],
$query->getSortFields()
$query->getSorts()
);
$this->assertEquals(
......
......@@ -34,16 +34,25 @@ class Solarium_QueryTest extends PHPUnit_Framework_TestCase
public function testSetAndGetHandler()
{
$query = new Solarium_Query;
$query = new TestQuery;
$query->setHandler('myhandler');
$this->assertEquals('myhandler', $query->getHandler());
}
public function testSetAndGetResultClass()
{
$query = new Solarium_Query;
$query = new TestQuery;
$query->setResultClass('myResultClass');
$this->assertEquals('myResultClass', $query->getResultClass());
}
}
class TestQuery extends Solarium_Query
{
public function getType()
{
return 'testType';
}
}
\ No newline at end of file
......@@ -29,24 +29,27 @@
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Result_QueryTest extends PHPUnit_Framework_TestCase
class Solarium_Result_QueryTypeTest extends PHPUnit_Framework_TestCase
{
protected $_result;
public function setUp()
public function testParseLazyLoading()
{
$this->_result = new Solarium_Result_Query(0,45);
}
public function testGetStatus()
public function testParseResponse()
{
$this->assertEquals(0, $this->_result->getStatus());
}
public function testGetQueryTime()
public function testMapData()
{
$this->assertEquals(45, $this->_result->getQueryTime());
}
}
class TestQueryType extends Solarium_Result_QueryType
{
}
\ No newline at end of file
......@@ -29,9 +29,9 @@
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
class Solarium_Result_SelectTest extends Solarium_Result_QueryTypeTest
{
/*
protected $_result, $_docs, $_facets;
public function setUp()
......@@ -48,7 +48,7 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
);
$this->_components = array(
Solarium_Query_Select_Component::MORELIKETHIS => new Solarium_Result_Select_MoreLikeThis(array())
Solarium_Query_Select::COMPONENT_MORELIKETHIS => new Solarium_Result_Select_MoreLikeThis(array())
);
$this->_result = new Solarium_Result_Select(0,45,100, $this->_docs, $this->_facets, $this->_components);
......@@ -92,8 +92,8 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
public function testGetComponent()
{
$this->assertEquals(
$this->_components[Solarium_Query_Select_Component::MORELIKETHIS],
$this->_result->getComponent(Solarium_Query_Select_Component::MORELIKETHIS)
$this->_components[Solarium_Query_Select::COMPONENT_MORELIKETHIS],
$this->_result->getComponent(Solarium_Query_Select::COMPONENT_MORELIKETHIS)
);
}
......@@ -108,7 +108,7 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
public function testGetMoreLikeThis()
{
$this->assertEquals(
$this->_components[Solarium_Query_Select_Component::MORELIKETHIS],
$this->_components[Solarium_Query_Select::COMPONENT_MORELIKETHIS],
$this->_result->getMoreLikeThis()
);
}
......@@ -123,5 +123,5 @@ class Solarium_Result_SelectTest extends Solarium_Result_QueryTest
$this->assertEquals($this->_docs, $docs);
}
*/
}
......@@ -29,12 +29,12 @@
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Result_UpdateTest extends Solarium_Result_QueryTest
class Solarium_Result_UpdateTest extends Solarium_Result_QueryTypeTest
{
public function setUp()
{
$this->_result = new Solarium_Result_Update(0,45);
}
}
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