Skip to content
Snippets Groups Projects
Commit 195aa0c8 authored by Demian Katz's avatar Demian Katz
Browse files

More test coverage.

parent a13fa738
No related merge requests found
File added
File added
...@@ -248,14 +248,8 @@ class SpellingProcessorTest extends TestCase ...@@ -248,14 +248,8 @@ class SpellingProcessorTest extends TestCase
*/ */
public function testShingleSuggestion() public function testShingleSuggestion()
{ {
$spelling = $this->getFixture('spell2'); $this->runSpellingTest(
$query = $this->getFixture('query2'); 2,
$params = $this->getServiceManager()->get('VuFind\SearchParamsPluginManager')
->get('Solr');
$params->setBasicSearch($query->getString(), $query->getHandler());
$sp = new SpellingProcessor();
$suggestions = $sp->getSuggestions($spelling, $query);
$this->assertEquals(
array( array(
'preamble gribble' => array( 'preamble gribble' => array(
'freq' => 0, 'freq' => 0,
...@@ -267,9 +261,6 @@ class SpellingProcessorTest extends TestCase ...@@ -267,9 +261,6 @@ class SpellingProcessorTest extends TestCase
), ),
), ),
), ),
),
$sp->processSuggestions(
$suggestions, $spelling->getQuery(), $params
) )
); );
} }
...@@ -304,6 +295,89 @@ class SpellingProcessorTest extends TestCase ...@@ -304,6 +295,89 @@ class SpellingProcessorTest extends TestCase
$this->assertEquals(array('""'), $sp->tokenize('""')); $this->assertEquals(array('""'), $sp->tokenize('""'));
} }
/**
* Test inclusion of numeric terms.
*
* @return void
*/
public function testNumericInclusion()
{
$this->runSpellingTest(
3,
array(
'1234567980' => array(
'freq' => 0,
'suggestions' => array(
'12345678' => array(
'freq' => 1,
'new_term' => '12345678'
)
)
),
'sqid' => array(
'freq' => 0,
'suggestions' => array(
'squid' => array(
'freq' => 34,
'new_term' => 'squid'
)
)
),
),
array('limit' => 1, 'skip_numeric' => false, 'expand' => false)
);
}
/**
* Test exclusion of numeric terms.
*
* @return void
*/
public function testNumericExclusion()
{
$this->runSpellingTest(
3,
array(
'sqid' => array(
'freq' => 0,
'suggestions' => array(
'squid' => array(
'freq' => 34,
'new_term' => 'squid'
)
)
),
),
array('limit' => 1, 'skip_numeric' => true, 'expand' => false)
);
}
/**
* Generic test.
*
* @param int $testNum Test data number to load
* @param array $expected Expected output
* @param array $config SpellingProcessor configuration
*
* @return void
*/
protected function runSpellingTest($testNum, $expected, $config = array())
{
$spelling = $this->getFixture('spell' . $testNum);
$query = $this->getFixture('query' . $testNum);
$params = $this->getServiceManager()->get('VuFind\SearchParamsPluginManager')
->get('Solr');
$params->setBasicSearch($query->getString(), $query->getHandler());
$sp = new SpellingProcessor(new Config($config));
$suggestions = $sp->getSuggestions($spelling, $query);
$this->assertEquals(
$expected,
$sp->processSuggestions(
$suggestions, $spelling->getQuery(), $params
)
);
}
/** /**
* Get expected suggestions for the "query1" example. * Get expected suggestions for the "query1" example.
* *
......
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