Commit c620d93b authored by Markus Kalkbrenner's avatar Markus Kalkbrenner Committed by GitHub

completed sugester component and improved tests (#542)

parent 84b4ed17
<?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
*
* @link http://www.solarium-project.org/
*/
namespace Solarium\Component\RequestBuilder;
use Solarium\Component\Suggester as SuggesterComponent;
use Solarium\Core\Client\Request;
/**
* Add select component Spellcheck to the request.
*/
class Suggester implements ComponentRequestBuilderInterface
{
/**
* Add request settings for Spellcheck.
*
* @param SuggesterComponent $component
* @param Request $request
*
* @return Request
*/
public function buildComponent($component, $request)
{
$request->addParam('suggest', 'true');
$request->addParam('suggest.dictionary', $component->getDictionary());
$request->addParam('suggest.q', $component->getQuery());
$request->addParam('suggest.count', $component->getCount());
$request->addParam('suggest.cfq', $component->getContextFilterQuery());
$request->addParam('suggest.build', $component->getBuild());
$request->addParam('suggest.reload', $component->getReload());
return $request;
}
}
...@@ -42,7 +42,6 @@ namespace Solarium\Component\ResponseParser; ...@@ -42,7 +42,6 @@ namespace Solarium\Component\ResponseParser;
use Solarium\Core\Query\AbstractQuery; use Solarium\Core\Query\AbstractQuery;
use Solarium\Component\Spellcheck as SpellcheckComponent; use Solarium\Component\Spellcheck as SpellcheckComponent;
use Solarium\Component\Result\Spellcheck as SpellcheckResult;
use Solarium\Component\Result\Spellcheck\Result; use Solarium\Component\Result\Spellcheck\Result;
use Solarium\Component\Result\Spellcheck\Collation; use Solarium\Component\Result\Spellcheck\Collation;
use Solarium\Component\Result\Spellcheck\Suggestion; use Solarium\Component\Result\Spellcheck\Suggestion;
...@@ -114,10 +113,10 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf ...@@ -114,10 +113,10 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
$correctlySpelled = $data['spellcheck']['correctlySpelled']; $correctlySpelled = $data['spellcheck']['correctlySpelled'];
} }
return new SpellcheckResult\Result($suggestions, $collations, $correctlySpelled); return new Result($suggestions, $collations, $correctlySpelled);
} else {
return;
} }
return null;
} }
/** /**
......
<?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
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Component\ResponseParser;
use Solarium\Core\Query\AbstractQuery;
use Solarium\Component\Suggester as SuggesterComponent;
use Solarium\Component\Result\Suggester\Result;
use Solarium\Core\Query\AbstractResponseParser;
use Solarium\QueryType\Suggester\Result\Dictionary;
use Solarium\QueryType\Suggester\Result\Term;
/**
* Parse select component Highlighting result from the data.
*/
class Suggester extends AbstractResponseParser implements ComponentParserInterface
{
/**
* Parse result data into result objects.
*
* @param AbstractQuery $query
* @param SuggesterComponent $suggester
* @param array $data
*
* @return Result|null
*/
public function parse($query, $suggester, $data)
{
$dictionaries = [];
$allSuggestions = [];
if (isset($data['suggest']) && is_array($data['suggest'])) {
foreach ($data['suggest'] as $dictionary => $dictionaryResults) {
$terms = [];
foreach ($dictionaryResults as $term => $termData) {
$allSuggestions[] = $this->createTerm($termData);
$terms[$term] = $this->createTerm($termData);
}
$dictionaries[$dictionary] = $this->createDictionary($terms);
}
return new Result($dictionaries, $allSuggestions);
}
return null;
}
private function createDictionary(array $terms)
{
return new Dictionary(
$terms
);
}
private function createTerm(array $termData)
{
return new Term(
$termData['numFound'],
$termData['suggestions']
);
}
}
<?php
namespace Solarium\Component\Result\Suggester;
use Solarium\QueryType\Suggester\Result\Dictionary;
/**
* Component suggester result.
*/
class Result implements \IteratorAggregate, \Countable
{
/**
* Suggester results.
*
* @var array
*/
protected $results;
/**
* Suggester flat results.
*
* @var array
*/
protected $all;
/**
* Constructor.
*
* @param array $results
* @param array $all
*/
public function __construct($results, $all)
{
$this->results = $results;
$this->all = $all;
}
/**
* Get all results.
*
* @return array
*/
public function getResults()
{
return $this->results;
}
/**
* Get flat results.
*
* @return array
*/
public function getAll()
{
return $this->all;
}
/**
* Get results for a specific dictionary.
*
* @param string $dictionary
*
* @return Dictionary|null
*/
public function getDictionary($dictionary)
{
if (isset($this->results[$dictionary])) {
return $this->results[$dictionary];
} else {
return null;
}
}
/**
* IteratorAggregate implementation.
*
* @return \ArrayIterator
*/
public function getIterator()
{
return new \ArrayIterator($this->results);
}
/**
* Countable implementation.
*
* @return int
*/
public function count()
{
return count($this->results);
}
}
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
namespace Solarium\Component; namespace Solarium\Component;
use Solarium\Component\RequestBuilder\Spellcheck as RequestBuilder; use Solarium\Component\RequestBuilder\Suggester as RequestBuilder;
use Solarium\Component\ResponseParser\Spellcheck as ResponseParser; use Solarium\Component\ResponseParser\Suggester as ResponseParser;
use Solarium\QueryType\Suggester\QueryTrait; use Solarium\QueryType\Suggester\QueryTrait;
/** /**
......
...@@ -29,8 +29,9 @@ ...@@ -29,8 +29,9 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\QueryType\Select\Query\Component; namespace Solarium\Tests\Component;
use Solarium\Component\AbstractComponentAwareQuery;
use Solarium\Component\Debug; use Solarium\Component\Debug;
use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Query\Query;
...@@ -60,7 +61,7 @@ class DebugTest extends \PHPUnit_Framework_TestCase ...@@ -60,7 +61,7 @@ class DebugTest extends \PHPUnit_Framework_TestCase
public function testGetType() public function testGetType()
{ {
$this->assertEquals( $this->assertEquals(
Query::COMPONENT_DEBUG, AbstractComponentAwareQuery::COMPONENT_DEBUG,
$this->debug->getType() $this->debug->getType()
); );
} }
......
...@@ -29,8 +29,9 @@ ...@@ -29,8 +29,9 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\QueryType\Select\Query\Component; namespace Solarium\Tests\Component;
use Solarium\Component\AbstractComponentAwareQuery;
use Solarium\Component\MoreLikeThis; use Solarium\Component\MoreLikeThis;
use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Query\Query;
...@@ -76,7 +77,7 @@ class MoreLikeThisTest extends \PHPUnit_Framework_TestCase ...@@ -76,7 +77,7 @@ class MoreLikeThisTest extends \PHPUnit_Framework_TestCase
public function testGetType() public function testGetType()
{ {
$this->assertEquals(Query::COMPONENT_MORELIKETHIS, $this->mlt->getType()); $this->assertEquals(AbstractComponentAwareQuery::COMPONENT_MORELIKETHIS, $this->mlt->getType());
} }
public function testGetResponseParser() public function testGetResponseParser()
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\QueryType\Select\RequestBuilder\Component; namespace Solarium\Tests\Component\RequestBuilder;
use Solarium\Component\RequestBuilder\Debug as RequestBuilder; use Solarium\Component\RequestBuilder\Debug as RequestBuilder;
use Solarium\Component\Debug as Component; use Solarium\Component\Debug as Component;
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\QueryType\Select\RequestBuilder\Component; namespace Solarium\Tests\Component\RequestBuilder;
use Solarium\Component\RequestBuilder\MoreLikeThis as RequestBuilder; use Solarium\Component\RequestBuilder\MoreLikeThis as RequestBuilder;
use Solarium\Component\MoreLikeThis as Component; use Solarium\Component\MoreLikeThis as Component;
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\QueryType\Select\RequestBuilder\Component; namespace Solarium\Tests\Component\RequestBuilder;
use Solarium\Component\RequestBuilder\Spellcheck as RequestBuilder; use Solarium\Component\RequestBuilder\Spellcheck as RequestBuilder;
use Solarium\Component\Spellcheck as Component; use Solarium\Component\Spellcheck as Component;
......
<?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\Component\RequestBuilder;
use Solarium\Component\RequestBuilder\Suggester as RequestBuilder;
use Solarium\Component\Suggester as Component;
use Solarium\Core\Client\Request;
class SuggesterTest extends \PHPUnit_Framework_TestCase
{
public function testBuildComponent()
{
$builder = new RequestBuilder();
$request = new Request();
$component = new Component();
$component->setDictionary('suggest');
$component->setQuery('ap ip');
$component->setCount(13);
$component->setContextFilterQuery('foo bar');
$component->setBuild('true');
$component->setReload('false');
$request = $builder->buildComponent($component, $request);
$this->assertEquals(
array(
'suggest' => 'true',
'suggest.dictionary' => 'suggest',
'suggest.q' => 'ap ip',
'suggest.count' => 13,
'suggest.cfq' => 'foo bar',
'suggest.build' => 'true',
'suggest.reload' => 'false',
),
$request->getParams()
);
}
}
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\QueryType\Select\ResponseParser\Component; namespace Solarium\Tests\Component\ResponseParser;
use Solarium\Component\ResponseParser\Debug as Parser; use Solarium\Component\ResponseParser\Debug as Parser;
use Solarium\Component\Result\Debug\Detail; use Solarium\Component\Result\Debug\Detail;
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\QueryType\Select\ResponseParser\Component; namespace Solarium\Tests\Component\ResponseParser;
use Solarium\Component\ResponseParser\MoreLikeThis as Parser; use Solarium\Component\ResponseParser\MoreLikeThis as Parser;
use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Query\Query;
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\QueryType\Select\ResponseParser\Component; namespace Solarium\Tests\Component\ResponseParser;
use Solarium\Component\ResponseParser\Spellcheck as Parser; use Solarium\Component\ResponseParser\Spellcheck as Parser;
use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Query\Query;
......
<?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\Component\ResponseParser;
use Solarium\Component\ResponseParser\Suggester;
use Solarium\QueryType\Select\Query\Query;
use Solarium\QueryType\Suggester\Result\Dictionary;
use Solarium\QueryType\Suggester\Result\Term;
class SuggesterTest extends \PHPUnit_Framework_TestCase
{
protected $parser;
protected $query;
public function setUp()
{
$this->query = new Query();
$this->parser = new Suggester();
}
/**
* @dataProvider providerParse
*/
public function testParse($data)
{
$result = $this->parser->parse($this->query, null, $data);
$expected = new Dictionary([
'foo' => new Term(2, [['term' => 'foo'], ['term' => 'foobar']]),
'zoo' => new Term(1, [['term' => 'zoo keeper']]),
]);
$this->assertEquals($expected, $result->getDictionary('dictionary1'));
$expected = new Dictionary([
'free' => new Term(2, [['term' => 'free beer'], ['term' => 'free software']]),
]);
$this->assertEquals($expected, $result->getDictionary('dictionary2'));
$allExpected = array(
new Term(2, [['term' => 'foo'], ['term' => 'foobar']]),
new Term(1, [['term' => 'zoo keeper']]),
new Term(2, [['term' => 'free beer'], ['term' => 'free software']]),
);
$this->assertEquals($allExpected, $result->getAll());
}
public function providerParse()
{
return array(
0 => array(
'data' => array(
'suggest' => array(
'dictionary1' => array(
'foo' => array(
'numFound' => 2,
'suggestions' => array(
array(
'term' => 'foo',
),
array(
'term' => 'foobar',
),
),
),
'zoo' => array(
'numFound' => 1,
'suggestions' => array(
array(
'term' => 'zoo keeper',
),
),
),
),
'dictionary2' => array(
'free' => array(
'numFound' => 2,
'suggestions' => array(
array(
'term' => 'free beer',
),
array(
'term' => 'free software',
),
),
),
),
),
),
),
);
}
public function testParseNoData()
{
$result = $this->parser->parse($this->query, null, array());
$this->assertEquals(null, $result);
}
}
<?php
namespace Solarium\Tests\Component\Result\Suggester;
use Solarium\Component\Result\Suggester\Result;
use Solarium\QueryType\Suggester\Result\Dictionary;
use Solarium\QueryType\Suggester\Result\Term;
class ResultTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Result
*/
protected $result;
public function setUp()
{
$this->docs = array(
'dictionary1' => new Dictionary([
'foo' => new Term(2, [['term' => 'foo'], ['term' => 'foobar']]),
'zoo' => new Term(1, [['term' => 'zoo keeper']]),
]),
'dictionary2' => new Dictionary([
'free' => new Term(2, [['term' => 'free beer'], ['term' => 'free software']]),
]),
);
$all = array(
new Term(2, [['term' => 'foo'], ['term' => 'foobar']]),
new Term(1, [['term' => 'zoo keeper']]),
new Term(2, [['term' => 'free beer'], ['term' => 'free software']]),
);
$this->result = new Result($this->docs, $all);
}
public function testGetDictionary()
{
$this->assertEquals($this->docs['dictionary1'], $this->result->getDictionary('dictionary1'));
}
public function testIterator()
{
$docs = array();
foreach ($this->result as $key => $doc) {
$docs[$key] = $doc;
}
$this->assertEquals($this->docs, $docs);
}
public function testCount()
{
$this->assertEquals(count($this->docs), count($this->result));
}
}
<?php <?php
namespace Solarium\Tests\QueryType\Select\Query\Component; namespace Solarium\Tests\Component;
use Solarium\Component\Spatial; use Solarium\Component\Spatial;
use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Query\Query;
......
...@@ -29,8 +29,9 @@ ...@@ -29,8 +29,9 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\QueryType\Select\Query\Component; namespace Solarium\Tests\Component;
use Solarium\Component\AbstractComponentAwareQuery;
use Solarium\Component\Spellcheck; use Solarium\Component\Spellcheck;
use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Query\Query;
...@@ -49,7 +50,7 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase ...@@ -49,7 +50,7 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
public function testGetType() public function testGetType()
{ {
$this->assertEquals(Query::COMPONENT_SPELLCHECK, $this->spellCheck->getType()); $this->assertEquals(AbstractComponentAwareQuery::COMPONENT_SPELLCHECK, $this->spellCheck->getType());
} }
public function testGetResponseParser() public function testGetResponseParser()
......
<?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\Component;
use Solarium\Component\AbstractComponentAwareQuery;
use Solarium\Component\Suggester;
use Solarium\QueryType\Select\Query\Query;
class SuggesterTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Spellcheck
*/
protected $suggester;
public function setUp()
{
$this->suggester = new Suggester();
$this->suggester->setQueryInstance(new Query);
}
public function testGetType()
{
$this->assertEquals(AbstractComponentAwareQuery::COMPONENT_SUGGESTER, $this->suggester->getType());
}
public function testGetResponseParser()
{
$this->assertInstanceOf(
'Solarium\Component\ResponseParser\Suggester',
$this->suggester->getResponseParser()
);
}
public function testGetRequestBuilder()
{
$this->assertInstanceOf(
'Solarium\Component\RequestBuilder\Suggester',
$this->suggester->getRequestBuilder()
);
}
public function testSetAndGetQuery()
{
$value = 'testquery';
$this->suggester->setQuery($value);
$this->assertEquals(
$value,
$this->suggester->getQuery()
);
}
public function testSetAndGetQueryWithBind()
{
$this->suggester->setQuery('id:%1%', array(678));
$this->assertEquals('id:678', $this->suggester->getQuery());
}
public function testSetAndGetContextFilterQuery()
{
$value = 'context filter query';
$this->suggester->setContextFilterQuery($value);
$this->assertEquals(
$value,
$this->suggester->getContextFilterQuery()
);
}
public function testSetAndGetBuild()
{
$value = true;
$this->suggester->setBuild($value);
$this->assertEquals(
$value,
$this->suggester->getBuild()
);
}
public function testSetAndGetReload()
{
$value = false;
$this->suggester->setReload($value);
$this->assertEquals(
$value,
$this->suggester->getReload()
);
}
public function testSetAndGetDictionary()
{
$value = 'myDictionary';
$this->suggester->setDictionary($value);
$this->assertEquals(
$value,
$this->suggester->getDictionary()
);
}
public function testSetAndGetCount()
{
$value = 11;
$this->suggester->setCount($value);
$this->assertEquals(
$value,
$this->suggester->getCount()
);
}
}
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