-
{{ 'Search a person'|trans }}
+ {{ 'Search'|trans }}
-
diff --git a/Search/AbstractSearch.php b/Search/AbstractSearch.php
new file mode 100644
index 000000000..b39b20dc8
--- /dev/null
+++ b/Search/AbstractSearch.php
@@ -0,0 +1,38 @@
+
+ *
+ * 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;
+
+use Chill\MainBundle\Search\SearchInterface;
+
+/**
+ * This class implements abstract search with most common responses.
+ *
+ * you should use this abstract class instead of SearchInterface : if the signature of
+ * search interface change, the generic method will be implemented here.
+ *
+ * @author Julien Fastré
+ *
+ */
+abstract class AbstractSearch implements SearchInterface
+{
+
+}
\ No newline at end of file
diff --git a/Search/SearchInterface.php b/Search/SearchInterface.php
new file mode 100644
index 000000000..c102f229e
--- /dev/null
+++ b/Search/SearchInterface.php
@@ -0,0 +1,76 @@
+
+ *
+ * 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;
+
+/**
+ * This interface must be implemented on services which provide search results.
+ *
+ * @todo : write doc and add a link to documentation
+ *
+ * @author Julien Fastré
+ *
+ */
+interface SearchInterface #-> good name ?
+{
+ /*
+ * return the result in a html string. The string will be inclued (as raw)
+ * into a global view.
+ *
+ * The global view may be :
+ * {% for result as resultsFromDifferentSearchInterface %}
+ * {{ result|raw }}
+ * {% endfor %}
+ *
+ * @param string $pattern the string to search
+ * @param int $start the first result (for pagination)
+ * @param int $limit the number of result (for pagination)
+ * @param array $option the options, specific for each search
+ * @return string, an HTML string
+ */
+ public function renderResult($pattern, $start=0, $limit=50, array $options = array());
+
+ /*
+ * we may desactive the search interface by default. in this case,
+ * the search will be launch and rendered only with "advanced search"
+ *
+ * this may be activated/desactived from bundle definition in config.yml
+ *
+ * @return boolean
+ */
+ public function isActiveByDefault();
+
+ /*
+ * a string used in advanced search to activate the search
+ *
+ * @return string a string which will be translated by twig
+ */
+ public function getLabel();
+
+ /*
+ * the order in which the results will appears in the global view
+ *
+ * (this may be eventually defined in config.yml)
+ *
+ * @return int
+ */
+ public function getOrder();
+}
diff --git a/Search/SearchProvider.php b/Search/SearchProvider.php
new file mode 100644
index 000000000..fcf24dd06
--- /dev/null
+++ b/Search/SearchProvider.php
@@ -0,0 +1,58 @@
+get('chill.main.search_provider')
+ */
+class SearchProvider
+{
+ /**
+ *
+ * @var SearchInterface[]
+ */
+ private $searchServices = array();
+
+ /*
+ * return search services in an array, ordered by
+ * the order key (defined in service definition)
+ * the conflicts in keys (twice the same order) are resolved
+ * within the compiler : the function will preserve all services
+ * defined (if two services have the same order, the will increment
+ * the order of the second one.
+ *
+ * @return SearchInterface[], with an int as array key
+ */
+ public function getByOrder()
+ {
+ //sort the array
+ uasort($this->searchServices, function(SearchInterface $a, SearchInterface $b) {
+ if ($a->getOrder() == $b->getOrder()) {
+ return 0;
+ }
+ return ($a->getOrder() < $b->getOrder()) ? -1 : 1;
+ });
+
+ return $this->searchServices;
+ }
+
+ /*
+ * return search services with a specific name, defined in service
+ * definition.
+ *
+ * @return SearchInterface
+ */
+ public function getByName($name)
+ {
+ return $this->searchServices[$name];
+ }
+
+ public function addSearchService(SearchInterface $service, $name)
+ {
+ $this->searchServices[$name] = $service;
+ }
+}
\ No newline at end of file
diff --git a/Tests/Controller/LoginControllerTest.php b/Tests/Controller/LoginControllerTest.php
index 682cadf3b..a7d161dd8 100644
--- a/Tests/Controller/LoginControllerTest.php
+++ b/Tests/Controller/LoginControllerTest.php
@@ -9,13 +9,21 @@ class LoginControllerTest extends WebTestCase
{
public function testLogin()
{
- $client = static::createClient();
+ $client = static::createClient(array(
+ 'framework' => array(
+ 'default_locale' => 'en',
+ 'translator' => array(
+ 'fallback' => 'en'
+ )
+ ),
+
+ ));
//load login page and submit form
$crawler = $client->request('GET', '/login');
$this->assertTrue($client->getResponse()->isSuccessful());
- $buttonCrawlerNode = $crawler->selectButton('Login');
+ $buttonCrawlerNode = $crawler->selectButton('login');
$form = $buttonCrawlerNode->form();
$client->submit($form, array(
@@ -40,7 +48,7 @@ class LoginControllerTest extends WebTestCase
$logoutLinkFilter = $crawler->filter('a:contains("Logout")');
//check there is > 0 logout link
- $this->assertGreaterThan(0, $logoutLinkFilter->count());
+ $this->assertGreaterThan(0, $logoutLinkFilter->count(), 'check that a logout link is present');
//click on logout link
$client->followRedirects(false);
diff --git a/Tests/Fixtures/App/config/config.yml b/Tests/Fixtures/App/config/config.yml
index 4f378c3c6..dadcba67a 100644
--- a/Tests/Fixtures/App/config/config.yml
+++ b/Tests/Fixtures/App/config/config.yml
@@ -7,8 +7,8 @@ framework:
form: true
csrf_protection: true
session: ~
- default_locale: fr
- translator: { fallback: fr }
+ default_locale: en
+ translator: { fallback: en }
profiler: { only_exceptions: false }
templating:
engines: ['twig']