mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
103 lines
3.2 KiB
PHP
103 lines
3.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
* Copyright (C) 2015 Champs-Libres Coopérative <info@champs-libres.coop>
|
|
*
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\Tests\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
use Chill\MainBundle\Search\SearchInterface;
|
|
|
|
|
|
|
|
/**
|
|
* Test the search controller
|
|
*
|
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
|
*/
|
|
class SearchControllerTest extends WebTestCase
|
|
{
|
|
|
|
/**
|
|
* Test the behaviour when no domain is provided in the search pattern :
|
|
* the default search should be enabled
|
|
*/
|
|
public function testSearchPath()
|
|
{
|
|
$client = $this->getAuthenticatedClient();
|
|
|
|
$crawler = $client->request('GET', '/fr/search', array('q' => 'default search'));
|
|
|
|
$this->assertTrue($client->getResponse()->isSuccessful(),
|
|
"The page is loaded without errors");
|
|
|
|
}
|
|
|
|
public function testSearchPathEmpty()
|
|
{
|
|
$client = $this->getAuthenticatedClient();
|
|
|
|
$crawler = $client->request('GET', '/fr/search?q=');
|
|
|
|
$this->assertGreaterThan(0, $crawler->filter('*:contains("Merci de fournir des termes de recherche.")')->count());
|
|
}
|
|
|
|
public function testDomainUnknow()
|
|
{
|
|
$client = $this->getAuthenticatedClient();
|
|
|
|
$crawler = $client->request('GET', '/fr/search', array('q' => '@unknow domain'));
|
|
|
|
$this->assertTrue($client->getResponse()->isSuccessful(),
|
|
"The page is loaded without errors");
|
|
$this->assertGreaterThan(0, $crawler->filter('*:contains("Le domaine de recherche "unknow" est inconnu.")')->count(),
|
|
"Message domain unknow is shown");
|
|
|
|
}
|
|
|
|
public function testParsingIncorrect()
|
|
{
|
|
$client = $this->getAuthenticatedClient();
|
|
|
|
$crawler = $client->request('GET', '/fr/search',
|
|
array('q' => '@domaine @domain double domaine'));
|
|
|
|
$this->assertGreaterThan(0, $crawler->filter('*:contains("Recherche invalide")')
|
|
->count());
|
|
}
|
|
|
|
public function testUnknowName()
|
|
{
|
|
$client = $this->getAuthenticatedClient();
|
|
|
|
$client->request('GET', '/fr/search',
|
|
array('q' => 'default search', 'name' => 'unknow'));
|
|
|
|
$this->assertTrue($client->getResponse()->isNotFound());
|
|
}
|
|
|
|
private function getAuthenticatedClient()
|
|
{
|
|
return static::createClient(array(), array(
|
|
'PHP_AUTH_USER' => 'center b_social',
|
|
'PHP_AUTH_PW' => 'password',
|
|
));
|
|
}
|
|
|
|
}
|