mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-01 12:33:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,41 +1,51 @@
|
||||
<?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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Search;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
|
||||
/**
|
||||
* Test Person search
|
||||
* Test Person search.
|
||||
*
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class PersonSearchTest extends WebTestCase
|
||||
{
|
||||
public function testDefaultAccented()
|
||||
{
|
||||
$this->markTestSkipped('skipped until adapted to new fixtures');
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person manço');
|
||||
|
||||
$this->assertRegExp('/MANÇO/', $crawlerSpecial->filter('.list-with-period')->text());
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person manco');
|
||||
|
||||
$this->assertRegExp('/MANÇO/', $crawlerNoSpecial->filter('.list-with-period')->text());
|
||||
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person Étienne');
|
||||
|
||||
$this->assertRegExp('/Étienne/', $crawlerSpecial->filter('.list-with-period')->text());
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person etienne');
|
||||
|
||||
$this->assertRegExp('/Étienne/', $crawlerNoSpecial->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testExpected()
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
|
||||
$crawler = $client->request('GET', '/fr/search', array(
|
||||
'q' => '@person Depardieu'
|
||||
));
|
||||
$crawler = $client->request('GET', '/fr/search', [
|
||||
'q' => '@person Depardieu',
|
||||
]);
|
||||
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
@@ -44,30 +54,9 @@ class PersonSearchTest extends WebTestCase
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
|
||||
$crawler = $client->request('GET', '/fr/search', array(
|
||||
'q' => '@person Depardieu', 'name' => 'person_regular'
|
||||
));
|
||||
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchByLastName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu');
|
||||
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNameLower()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Gérard');
|
||||
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNamePartim()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Ger');
|
||||
$crawler = $client->request('GET', '/fr/search', [
|
||||
'q' => '@person Depardieu', 'name' => 'person_regular',
|
||||
]);
|
||||
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
@@ -78,12 +67,19 @@ class PersonSearchTest extends WebTestCase
|
||||
|
||||
$this->assertRegExp('/MANÇO/', $crawlerSpecial->filter('.list-with-period')->text());
|
||||
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person lastname:manco');
|
||||
|
||||
$this->assertRegExp('/MANÇO/', $crawlerNoSpecial->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchBirthdate()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person birthdate:1948-12-27');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawler->filter('.list-with-period')->text());
|
||||
$this->assertRegExp('/Bart/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstName()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Jean');
|
||||
@@ -91,6 +87,24 @@ class PersonSearchTest extends WebTestCase
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNameAccented()
|
||||
{
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person firstname:Gérard');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawlerSpecial->filter('.list-with-period')->text());
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person firstname:Gerard');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawlerNoSpecial->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNameLower()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Gérard');
|
||||
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNameLower2()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:jean');
|
||||
@@ -98,6 +112,13 @@ class PersonSearchTest extends WebTestCase
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNamePartim()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:Ger');
|
||||
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNamePartim2()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person firstname:ean');
|
||||
@@ -105,51 +126,16 @@ class PersonSearchTest extends WebTestCase
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchByFirstNameAccented()
|
||||
public function testSearchByLastName()
|
||||
{
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person firstname:Gérard');
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawlerSpecial->filter('.list-with-period')->text());
|
||||
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person firstname:Gerard');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawlerNoSpecial->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchCombineLastnameAndNationality()
|
||||
{
|
||||
$this->markTestSkipped("skipped until adapted to new fixtures");
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu nationality:RU');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawler->filter('.list-with-period')->text());
|
||||
//if this is a AND clause, Jean Depardieu should not appears
|
||||
$this->assertNotRegExp('/Jean/', $crawler->filter('.list-with-period')->text(),
|
||||
"assert clause firstname and nationality are AND");
|
||||
}
|
||||
|
||||
public function testSearchCombineLastnameAndFirstName()
|
||||
{
|
||||
$this->markTestSkipped("skipped until adapted to new fixtures");
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu firstname:Jean');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
|
||||
//if this is a AND clause, Jean Depardieu should not appears
|
||||
$this->assertNotRegExp('/Gérard/', $crawler->filter('.list-with-period')->text(),
|
||||
"assert clause firstname and nationality are AND");
|
||||
}
|
||||
|
||||
public function testSearchBirthdate()
|
||||
{
|
||||
$crawler = $this->generateCrawlerForSearch('@person birthdate:1948-12-27');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawler->filter('.list-with-period')->text());
|
||||
$this->assertRegExp('/Bart/', $crawler->filter('.list-with-period')->text());
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchCombineBirthdateAndLastName()
|
||||
{
|
||||
$this->markTestSkipped("skipped until adapted to new fixtures");
|
||||
$this->markTestSkipped('skipped until adapted to new fixtures');
|
||||
$crawler = $this->generateCrawlerForSearch('@person birthdate:1948-12-27 lastname:(Van Snick)');
|
||||
|
||||
$this->assertRegExp('/Bart/', $crawler->filter('.list-with-period')->text());
|
||||
@@ -158,16 +144,44 @@ class PersonSearchTest extends WebTestCase
|
||||
|
||||
public function testSearchCombineGenderAndLastName()
|
||||
{
|
||||
$this->markTestSkipped("skipped until adapted to new fixtures");
|
||||
$this->markTestSkipped('skipped until adapted to new fixtures');
|
||||
$crawler = $this->generateCrawlerForSearch('@person gender:woman lastname:(Depardieu)');
|
||||
|
||||
$this->assertRegExp('/Charline/', $crawler->filter('.list-with-period')->text());
|
||||
$this->assertNotRegExp('/Gérard/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testSearchCombineLastnameAndFirstName()
|
||||
{
|
||||
$this->markTestSkipped('skipped until adapted to new fixtures');
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu firstname:Jean');
|
||||
|
||||
$this->assertRegExp('/Depardieu/', $crawler->filter('.list-with-period')->text());
|
||||
//if this is a AND clause, Jean Depardieu should not appears
|
||||
$this->assertNotRegExp(
|
||||
'/Gérard/',
|
||||
$crawler->filter('.list-with-period')->text(),
|
||||
'assert clause firstname and nationality are AND'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSearchCombineLastnameAndNationality()
|
||||
{
|
||||
$this->markTestSkipped('skipped until adapted to new fixtures');
|
||||
$crawler = $this->generateCrawlerForSearch('@person lastname:Depardieu nationality:RU');
|
||||
|
||||
$this->assertRegExp('/Gérard/', $crawler->filter('.list-with-period')->text());
|
||||
//if this is a AND clause, Jean Depardieu should not appears
|
||||
$this->assertNotRegExp(
|
||||
'/Jean/',
|
||||
$crawler->filter('.list-with-period')->text(),
|
||||
'assert clause firstname and nationality are AND'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSearchMultipleTrigramUseAndClauseInDefault()
|
||||
{
|
||||
$this->markTestSkipped("skipped until adapted to new fixtures");
|
||||
$this->markTestSkipped('skipped until adapted to new fixtures');
|
||||
$crawler = $this->generateCrawlerForSearch('@person cha dep');
|
||||
|
||||
$this->assertRegExp('/Charline/', $crawler->filter('.list-with-period')->text());
|
||||
@@ -175,50 +189,33 @@ class PersonSearchTest extends WebTestCase
|
||||
$this->assertNotRegExp('/Jean/', $crawler->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
public function testDefaultAccented()
|
||||
{
|
||||
$this->markTestSkipped("skipped until adapted to new fixtures");
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person manço');
|
||||
|
||||
$this->assertRegExp('/MANÇO/', $crawlerSpecial->filter('.list-with-period')->text());
|
||||
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person manco');
|
||||
|
||||
$this->assertRegExp('/MANÇO/', $crawlerNoSpecial->filter('.list-with-period')->text());
|
||||
|
||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person Étienne');
|
||||
|
||||
$this->assertRegExp('/Étienne/', $crawlerSpecial->filter('.list-with-period')->text());
|
||||
|
||||
|
||||
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person etienne');
|
||||
|
||||
$this->assertRegExp('/Étienne/', $crawlerNoSpecial->filter('.list-with-period')->text());
|
||||
}
|
||||
|
||||
/**
|
||||
* test that person which a user cannot see are not displayed in results
|
||||
* test that person which a user cannot see are not displayed in results.
|
||||
*/
|
||||
public function testSearchWithAuthorization()
|
||||
{
|
||||
$crawlerCanSee = $this->generateCrawlerForSearch('Gérard', 'center a_social');
|
||||
$crawlerCannotSee = $this->generateCrawlerForSearch('Gérard', 'center b_social');
|
||||
|
||||
$this->assertRegExp('/DEPARDIEU/', $crawlerCanSee->text(),
|
||||
'center a_social may see "Depardieu" in center a');
|
||||
$this->assertNotRegExp('/DEPARDIEU/', $crawlerCannotSee->text(),
|
||||
'center b_social may not see "Depardieu" in center b');
|
||||
|
||||
$this->assertRegExp(
|
||||
'/DEPARDIEU/',
|
||||
$crawlerCanSee->text(),
|
||||
'center a_social may see "Depardieu" in center a'
|
||||
);
|
||||
$this->assertNotRegExp(
|
||||
'/DEPARDIEU/',
|
||||
$crawlerCannotSee->text(),
|
||||
'center b_social may not see "Depardieu" in center b'
|
||||
);
|
||||
}
|
||||
|
||||
private function generateCrawlerForSearch($pattern, $username = 'center a_social')
|
||||
{
|
||||
$client = $this->getAuthenticatedClient($username);
|
||||
|
||||
$crawler = $client->request('GET', '/fr/search', array(
|
||||
'q' => $pattern,
|
||||
));
|
||||
$crawler = $client->request('GET', '/fr/search', [
|
||||
'q' => $pattern,
|
||||
]);
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
@@ -226,14 +223,15 @@ class PersonSearchTest extends WebTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $username
|
||||
*
|
||||
* @return \Symfony\Component\BrowserKit\Client
|
||||
*/
|
||||
private function getAuthenticatedClient($username = 'center a_social')
|
||||
{
|
||||
return static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => $username,
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
return static::createClient([], [
|
||||
'PHP_AUTH_USER' => $username,
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user