mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
refactor search for using search by pertinence
This commit is contained in:
@@ -26,17 +26,17 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SearchProviderTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var SearchProvider
|
||||
* @var SearchProvider
|
||||
*/
|
||||
private $search;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->search = new SearchProvider();
|
||||
|
||||
|
||||
//add a default service
|
||||
$this->addSearchService(
|
||||
$this->createDefaultSearchService('I am default', 10), 'default'
|
||||
@@ -46,7 +46,7 @@ class SearchProviderTest extends TestCase
|
||||
$this->createNonDefaultDomainSearchService('I am domain bar', 20, FALSE), 'bar'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException \Chill\MainBundle\Search\UnknowSearchNameException
|
||||
*/
|
||||
@@ -54,11 +54,11 @@ class SearchProviderTest extends TestCase
|
||||
{
|
||||
$this->search->getByName("invalid name");
|
||||
}
|
||||
|
||||
|
||||
public function testSimplePattern()
|
||||
{
|
||||
$terms = $this->p("@person birthdate:2014-01-02 name:(my name) is not my name");
|
||||
|
||||
$terms = $this->p("@person birthdate:2014-01-02 name:\"my name\" is not my name");
|
||||
|
||||
$this->assertEquals(array(
|
||||
'_domain' => 'person',
|
||||
'birthdate' => '2014-01-02',
|
||||
@@ -66,40 +66,40 @@ class SearchProviderTest extends TestCase
|
||||
'name' => 'my name'
|
||||
), $terms);
|
||||
}
|
||||
|
||||
|
||||
public function testWithoutDomain()
|
||||
{
|
||||
$terms = $this->p('foo:bar residual');
|
||||
|
||||
|
||||
$this->assertEquals(array(
|
||||
'_domain' => null,
|
||||
'foo' => 'bar',
|
||||
'_default' => 'residual'
|
||||
), $terms);
|
||||
}
|
||||
|
||||
|
||||
public function testWithoutDefault()
|
||||
{
|
||||
$terms = $this->p('@person foo:bar');
|
||||
|
||||
|
||||
$this->assertEquals(array(
|
||||
'_domain' => 'person',
|
||||
'foo' => 'bar',
|
||||
'_default' => ''
|
||||
), $terms);
|
||||
}
|
||||
|
||||
|
||||
public function testCapitalLetters()
|
||||
{
|
||||
$terms = $this->p('Foo:Bar LOL marCi @PERSON');
|
||||
|
||||
|
||||
$this->assertEquals(array(
|
||||
'_domain' => 'person',
|
||||
'_default' => 'lol marci',
|
||||
'foo' => 'bar'
|
||||
), $terms);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException Chill\MainBundle\Search\ParsingException
|
||||
*/
|
||||
@@ -107,12 +107,11 @@ class SearchProviderTest extends TestCase
|
||||
{
|
||||
$term = $this->p("@person @report");
|
||||
}
|
||||
|
||||
|
||||
public function testDoubleParenthesis()
|
||||
{
|
||||
$terms = $this->p("@papamobile name:(my beautiful name) residual "
|
||||
. "surname:(i love techno)");
|
||||
|
||||
$terms = $this->p('@papamobile name:"my beautiful name" residual surname:"i love techno"');
|
||||
|
||||
$this->assertEquals(array(
|
||||
'_domain' => 'papamobile',
|
||||
'name' => 'my beautiful name',
|
||||
@@ -120,65 +119,65 @@ class SearchProviderTest extends TestCase
|
||||
'surname' => 'i love techno'
|
||||
), $terms);
|
||||
}
|
||||
|
||||
|
||||
public function testAccentued()
|
||||
{
|
||||
//$this->markTestSkipped('accentued characters must be implemented');
|
||||
|
||||
|
||||
$terms = $this->p('manço bélier aztèque à saloù ê');
|
||||
|
||||
|
||||
$this->assertEquals(array(
|
||||
'_domain' => NULL,
|
||||
'_default' => 'manco belier azteque a salou e'
|
||||
), $terms);
|
||||
}
|
||||
|
||||
|
||||
public function testAccentuedCapitals()
|
||||
{
|
||||
//$this->markTestSkipped('accentued characters must be implemented');
|
||||
|
||||
|
||||
$terms = $this->p('MANÉÀ oÛ lÎ À');
|
||||
|
||||
|
||||
$this->assertEquals(array(
|
||||
'_domain' => null,
|
||||
'_default' => 'manea ou li a'
|
||||
), $terms);
|
||||
}
|
||||
|
||||
|
||||
public function testTrimInParenthesis()
|
||||
{
|
||||
$terms = $this->p('foo:(bar )');
|
||||
|
||||
$terms = $this->p('foo:"bar "');
|
||||
|
||||
$this->assertEquals(array(
|
||||
'_domain' => null,
|
||||
'foo' => 'bar',
|
||||
'_default' => ''
|
||||
), $terms);
|
||||
}
|
||||
|
||||
|
||||
public function testTrimInDefault()
|
||||
{
|
||||
$terms = $this->p(' foo bar ');
|
||||
|
||||
|
||||
$this->assertEquals(array(
|
||||
'_domain' => null,
|
||||
'_default' => 'foo bar'
|
||||
), $terms);
|
||||
}
|
||||
|
||||
|
||||
public function testArgumentNameWithTrait()
|
||||
{
|
||||
$terms = $this->p('date-from:2016-05-04');
|
||||
|
||||
|
||||
$this->assertEquals(array(
|
||||
'_domain' => null,
|
||||
'date-from' => '2016-05-04',
|
||||
'_default' => ''
|
||||
), $terms);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the behaviour when no domain is provided in the search pattern :
|
||||
* Test the behaviour when no domain is provided in the search pattern :
|
||||
* the default search should be enabled
|
||||
*/
|
||||
public function testSearchResultDefault()
|
||||
@@ -186,12 +185,12 @@ class SearchProviderTest extends TestCase
|
||||
$response = $this->search->getSearchResults('default search');
|
||||
|
||||
//$this->markTestSkipped();
|
||||
|
||||
|
||||
$this->assertEquals(array(
|
||||
"I am default"
|
||||
), $response);
|
||||
), $response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException \Chill\MainBundle\Search\UnknowSearchDomainException
|
||||
*/
|
||||
@@ -200,49 +199,49 @@ class SearchProviderTest extends TestCase
|
||||
$response = $this->search->getSearchResults('@unknow domain');
|
||||
|
||||
//$this->markTestSkipped();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testSearchResultDomainSearch()
|
||||
{
|
||||
//add a search service which will be supported
|
||||
$this->addSearchService(
|
||||
$this->createNonDefaultDomainSearchService("I am domain foo", 100, TRUE), 'foo'
|
||||
);
|
||||
|
||||
|
||||
$response = $this->search->getSearchResults('@foo default search');
|
||||
|
||||
|
||||
$this->assertEquals(array(
|
||||
"I am domain foo"
|
||||
), $response);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testSearchWithinSpecificSearchName()
|
||||
{
|
||||
//add a search service which will be supported
|
||||
$this->addSearchService(
|
||||
$this->createNonDefaultDomainSearchService("I am domain foo", 100, TRUE), 'foo'
|
||||
);
|
||||
|
||||
|
||||
$response = $this->search->getResultByName('@foo search', 'foo');
|
||||
|
||||
|
||||
$this->assertEquals('I am domain foo', $response);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException \Chill\MainBundle\Search\ParsingException
|
||||
*/
|
||||
public function testSearchWithinSpecificSearchNameInConflictWithSupport()
|
||||
{
|
||||
$response = $this->search->getResultByName('@foo default search', 'bar');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* shortcut for executing parse method
|
||||
*
|
||||
*
|
||||
* @param unknown $pattern
|
||||
* @return string[]
|
||||
*/
|
||||
@@ -250,12 +249,12 @@ class SearchProviderTest extends TestCase
|
||||
{
|
||||
return $this->search->parse($pattern);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a search service to the chill.main.search_provider
|
||||
*
|
||||
*
|
||||
* Useful for mocking the SearchInterface
|
||||
*
|
||||
*
|
||||
* @param SearchInterface $search
|
||||
* @param string $name
|
||||
*/
|
||||
@@ -264,52 +263,52 @@ class SearchProviderTest extends TestCase
|
||||
$this->search
|
||||
->addSearchService($search, $name);
|
||||
}
|
||||
|
||||
|
||||
private function createDefaultSearchService($result, $order)
|
||||
{
|
||||
$mock = $this
|
||||
->getMockForAbstractClass('Chill\MainBundle\Search\AbstractSearch');
|
||||
|
||||
|
||||
//set the mock as default
|
||||
$mock->expects($this->any())
|
||||
->method('isActiveByDefault')
|
||||
->will($this->returnValue(TRUE));
|
||||
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method('getOrder')
|
||||
->will($this->returnValue($order));
|
||||
|
||||
|
||||
//set the return value
|
||||
$mock->expects($this->any())
|
||||
->method('renderResult')
|
||||
->will($this->returnValue($result));
|
||||
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
|
||||
private function createNonDefaultDomainSearchService($result, $order, $domain)
|
||||
{
|
||||
$mock = $this
|
||||
->getMockForAbstractClass('Chill\MainBundle\Search\AbstractSearch');
|
||||
|
||||
|
||||
//set the mock as default
|
||||
$mock->expects($this->any())
|
||||
->method('isActiveByDefault')
|
||||
->will($this->returnValue(FALSE));
|
||||
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method('getOrder')
|
||||
->will($this->returnValue($order));
|
||||
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method('supports')
|
||||
->will($this->returnValue($domain));
|
||||
|
||||
|
||||
//set the return value
|
||||
$mock->expects($this->any())
|
||||
->method('renderResult')
|
||||
->will($this->returnValue($result));
|
||||
|
||||
|
||||
return $mock;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user