diff --git a/Search/UnknowSearchDomainException.php b/Search/UnknowSearchDomainException.php
new file mode 100644
index 000000000..c03e09923
--- /dev/null
+++ b/Search/UnknowSearchDomainException.php
@@ -0,0 +1,35 @@
+
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+namespace Chill\MainBundle\Search;
+
+/**
+ * Throw by search provider when the search name is not found
+ *
+ * @author Julien Fastré
+ */
+class UnknowSearchNameException extends \Exception
+{
+ public function __construct($name)
+ {
+ parent::__construct( "The module search with name $name "
+ . "is not found");
+ }
+}
diff --git a/Tests/Search/SearchProviderTest.php b/Tests/Search/SearchProviderTest.php
index 5cf68ba52..6d4e15058 100644
--- a/Tests/Search/SearchProviderTest.php
+++ b/Tests/Search/SearchProviderTest.php
@@ -20,13 +20,30 @@
namespace Chill\MainBundle\Test\Search;
use Chill\MainBundle\Search\SearchProvider;
+use Chill\MainBundle\Search\SearchInterface;
class SearchProviderTest extends \PHPUnit_Framework_TestCase
{
+
+ /**
+ *
+ * @var SearchProvider
+ */
+ private $search;
+
public function setUp()
{
$this->search = new SearchProvider();
+
+ //add a default service
+ $this->addSearchService(
+ $this->createDefaultSearchService('I am default', 10), 'default'
+ );
+ //add a domain service
+ $this->addSearchService(
+ $this->createDefaultSearchService('I am domain bar', 20), 'bar'
+ );
}
/**
@@ -148,6 +165,74 @@ class SearchProviderTest extends \PHPUnit_Framework_TestCase
), $terms);
}
+ /**
+ * Test the behaviour when no domain is provided in the search pattern :
+ * the default search should be enabled
+ */
+ public function testDefaultSearch()
+ {
+ $response = $this->search->getSearchResults('default search');
+
+ $this->markTestSkipped();
+
+ $this->assertEquals(array(
+ "I am default"
+ ), $response);
+ }
+
+ /**
+ * @expectedException \Chill\MainBundle\Search\UnknowSearchDomainException
+ */
+ public function testDomainUnknow()
+ {
+ $response = $this->search->getSearchResults('@unknow domain');
+
+ $this->markTestSkipped();
+
+ }
+
+ public function testDomainSearch()
+ {
+ //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()
+ {
+ $this->markTestSkipped();
+ //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(array(
+ 'I am domain foo'
+ ), $response);
+
+ }
+
+ /**
+ * @expectedException \Chill\MainBundle\Search\ParsingException
+ */
+ public function testSearchWithinSpecificSearchNameInConflictWithSupport()
+ {
+ $this->markTestSkipped();
+
+ $response = $this->search->getResultByName('@foo default search', 'bar');
+
+ }
+
/**
* shortcut for executing parse method
*
@@ -158,4 +243,66 @@ class SearchProviderTest extends \PHPUnit_Framework_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
+ */
+ private function addSearchService(SearchInterface $search, $name)
+ {
+ $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;
+ }
}
\ No newline at end of file