mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 22:35:01 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,36 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Repository\AddressRepository;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class AddressControllerTest extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
|
||||
{
|
||||
private KernelBrowser $client;
|
||||
|
||||
use PrepareClientTrait;
|
||||
|
||||
private KernelBrowser $client;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->client = $this->getClientAuthenticated();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateAddressIds
|
||||
* @param int $addressId
|
||||
*/
|
||||
public function testDuplicate(int $addressId)
|
||||
{
|
||||
$this->client->request('POST', "/api/1.0/main/address/$addressId/duplicate.json");
|
||||
|
||||
$this->assertResponseIsSuccessful('test that duplicate is successful');
|
||||
}
|
||||
|
||||
public function generateAddressIds()
|
||||
{
|
||||
self::bootKernel();
|
||||
@@ -43,7 +42,17 @@ class AddressControllerTest extends \Symfony\Bundle\FrameworkBundle\Test\WebTest
|
||||
->getResult();
|
||||
|
||||
foreach ($addresses as $a) {
|
||||
yield [ $a->getId() ];
|
||||
yield [$a->getId()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateAddressIds
|
||||
*/
|
||||
public function testDuplicate(int $addressId)
|
||||
{
|
||||
$this->client->request('POST', "/api/1.0/main/address/{$addressId}/duplicate.json");
|
||||
|
||||
$this->assertResponseIsSuccessful('test that duplicate is successful');
|
||||
}
|
||||
}
|
||||
|
@@ -1,52 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CenterControllerTest extends WebTestCase
|
||||
{
|
||||
public function testCompleteScenario()
|
||||
{
|
||||
// Create a new client to browse the application
|
||||
$client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'admin',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR'
|
||||
));
|
||||
$client = static::createClient([], [
|
||||
'PHP_AUTH_USER' => 'admin',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR',
|
||||
]);
|
||||
|
||||
// Create a new entry in the database
|
||||
$crawler = $client->request('GET', '/fr/admin/center/');
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(),
|
||||
"Unexpected HTTP status code for GET /fr/admin/center/");
|
||||
$this->assertEquals(
|
||||
200,
|
||||
$client->getResponse()->getStatusCode(),
|
||||
'Unexpected HTTP status code for GET /fr/admin/center/'
|
||||
);
|
||||
$crawler = $client->click($crawler->selectLink('Créer un nouveau centre')->link());
|
||||
|
||||
// Fill in the form and submit it
|
||||
$form = $crawler->selectButton('Créer')->form(array(
|
||||
'chill_mainbundle_center[name]' => 'Test center',
|
||||
));
|
||||
$form = $crawler->selectButton('Créer')->form([
|
||||
'chill_mainbundle_center[name]' => 'Test center',
|
||||
]);
|
||||
|
||||
$client->submit($form);
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
// Check data in the show view
|
||||
$this->assertGreaterThan(0,
|
||||
$crawler->filter('td:contains("Test center")')->count(),
|
||||
'Missing element td:contains("Test center")');
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$crawler->filter('td:contains("Test center")')->count(),
|
||||
'Missing element td:contains("Test center")'
|
||||
);
|
||||
|
||||
// Edit the entity
|
||||
$crawler = $client->click($crawler->selectLink('Modifier')->link());
|
||||
|
||||
$form = $crawler->selectButton('Mettre à jour')->form(array(
|
||||
'chill_mainbundle_center[name]' => 'Foo',
|
||||
));
|
||||
$form = $crawler->selectButton('Mettre à jour')->form([
|
||||
'chill_mainbundle_center[name]' => 'Foo',
|
||||
]);
|
||||
|
||||
$client->submit($form);
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
// Check the element contains an attribute with value equals "Foo"
|
||||
$this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(),
|
||||
'Missing element [value="Foo"]');
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$crawler->filter('[value="Foo"]')->count(),
|
||||
'Missing element [value="Foo"]'
|
||||
);
|
||||
|
||||
$crawler = $client->request('GET', '/fr/admin/center/');
|
||||
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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\MainBundle\Tests\Controller;
|
||||
@@ -22,24 +12,26 @@ namespace Chill\MainBundle\Tests\Controller;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* Test the export
|
||||
* Test the export.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ExportControllerTest extends WebTestCase
|
||||
{
|
||||
public function testIndex()
|
||||
{
|
||||
$client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR'
|
||||
));
|
||||
|
||||
$client = static::createClient([], [
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR',
|
||||
]);
|
||||
|
||||
$client->request('GET', '/fr/exports/');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful(),
|
||||
"assert the list is shown");
|
||||
$this->assertTrue(
|
||||
$client->getResponse()->isSuccessful(),
|
||||
'assert the list is shown'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,10 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class LoginControllerTest extends WebTestCase
|
||||
{
|
||||
public function testLogin()
|
||||
@@ -14,47 +25,44 @@ class LoginControllerTest extends WebTestCase
|
||||
//load login page and submit form
|
||||
$crawler = $client->request('GET', '/login');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
|
||||
$buttonCrawlerNode = $crawler->selectButton('login');
|
||||
$form = $buttonCrawlerNode->form();
|
||||
|
||||
$client->submit($form, array(
|
||||
'_username' => 'center a_social',
|
||||
'_password' => 'password'
|
||||
));
|
||||
|
||||
|
||||
$client->submit($form, [
|
||||
'_username' => 'center a_social',
|
||||
'_password' => 'password',
|
||||
]);
|
||||
|
||||
//the response is a redirection
|
||||
$this->assertTrue($client->getResponse()->isRedirect());
|
||||
|
||||
|
||||
//the response is not a login page, but on a new page
|
||||
$this->assertNotRegExp('/\/login$/', $client->getResponse()
|
||||
->headers
|
||||
->get('location'));
|
||||
|
||||
->headers
|
||||
->get('location'));
|
||||
|
||||
//on the home page, there must be a logout link
|
||||
$client->followRedirects(true);
|
||||
$crawler = $client->request('GET', '/');
|
||||
|
||||
|
||||
$this->assertRegExp('/center a_social/', $client->getResponse()
|
||||
->getContent());
|
||||
->getContent());
|
||||
$logoutLinkFilter = $crawler->filter('a:contains("Se déconnecter")');
|
||||
|
||||
|
||||
//check there is > 0 logout link
|
||||
$this->assertGreaterThan(0, $logoutLinkFilter->count(), 'check that a logout link is present');
|
||||
|
||||
|
||||
//click on logout link
|
||||
$client->followRedirects(false);
|
||||
$client->click($crawler->selectLink('Se déconnecter')->link());
|
||||
|
||||
|
||||
$this->assertTrue($client->getResponse()->isRedirect());
|
||||
$client->followRedirect(); #redirect to login page
|
||||
|
||||
$client->followRedirect(); //redirect to login page
|
||||
|
||||
//check we are back on login page
|
||||
$this->assertRegExp('/\/login$/', $client->getResponse()
|
||||
->headers
|
||||
->get('location'));
|
||||
|
||||
|
||||
->headers
|
||||
->get('location'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,15 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class PermissionsGroupControllerTest extends WebTestCase
|
||||
{
|
||||
public function testEmpty()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
/*
|
||||
public function testCompleteScenario()
|
||||
{
|
||||
@@ -55,5 +67,5 @@ class PermissionsGroupControllerTest extends WebTestCase
|
||||
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
@@ -1,30 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ScopeControllerTest extends WebTestCase
|
||||
{
|
||||
public function testCompleteScenario()
|
||||
{
|
||||
// Create a new client to browse the application
|
||||
$client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'admin',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR'
|
||||
));
|
||||
$client = static::createClient([], [
|
||||
'PHP_AUTH_USER' => 'admin',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR',
|
||||
]);
|
||||
|
||||
// Create a new entry in the database
|
||||
$crawler = $client->request('GET', '/fr/admin/scope/');
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(),
|
||||
"Unexpected HTTP status code for GET /fr/admin/scope/");
|
||||
$this->assertEquals(
|
||||
200,
|
||||
$client->getResponse()->getStatusCode(),
|
||||
'Unexpected HTTP status code for GET /fr/admin/scope/'
|
||||
);
|
||||
$crawler = $client->click($crawler->selectLink('Créer un nouveau cercle')->link());
|
||||
// Fill in the form and submit it
|
||||
$form = $crawler->selectButton('Créer')->form(array(
|
||||
'chill_mainbundle_scope[name][fr]' => 'Test en fr',
|
||||
'chill_mainbundle_scope[name][en]' => 'Test en en'
|
||||
));
|
||||
$form = $crawler->selectButton('Créer')->form([
|
||||
'chill_mainbundle_scope[name][fr]' => 'Test en fr',
|
||||
'chill_mainbundle_scope[name][en]' => 'Test en en',
|
||||
]);
|
||||
|
||||
$client->submit($form/*, array(
|
||||
'chill_mainbundle_scope' => array(
|
||||
@@ -36,25 +50,26 @@ class ScopeControllerTest extends WebTestCase
|
||||
)
|
||||
)*/);
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
|
||||
// Check data in the show view
|
||||
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test en fr")')->count(),
|
||||
'Missing element td:contains("Test en fr")');
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$crawler->filter('td:contains("Test en fr")')->count(),
|
||||
'Missing element td:contains("Test en fr")'
|
||||
);
|
||||
|
||||
// Edit the entity
|
||||
$crawler = $client->click($crawler->selectLink('Modifier')->link());
|
||||
|
||||
$form = $crawler->selectButton('Mettre à jour')->form(array(
|
||||
'chill_mainbundle_scope[name][fr]' => 'Foo',
|
||||
'chill_mainbundle_scope[name][en]' => 'Foo en',
|
||||
));
|
||||
|
||||
$form = $crawler->selectButton('Mettre à jour')->form([
|
||||
'chill_mainbundle_scope[name][fr]' => 'Foo',
|
||||
'chill_mainbundle_scope[name][en]' => 'Foo en',
|
||||
]);
|
||||
|
||||
$client->submit($form);
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
// Check the element contains an attribute with value equals "Foo"
|
||||
$this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,15 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Bundle\ChillMainBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class SearchApiControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
public function generateSearchData()
|
||||
{
|
||||
yield ['per', ['person', 'thirdparty']];
|
||||
|
||||
yield ['per', ['thirdparty']];
|
||||
|
||||
yield ['per', ['person']];
|
||||
|
||||
yield ['fjklmeqjfkdqjklrmefdqjklm', ['person', 'thirdparty']];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateSearchData
|
||||
*/
|
||||
@@ -20,17 +42,9 @@ class SearchApiControllerTest extends WebTestCase
|
||||
$client->request(
|
||||
Request::METHOD_GET,
|
||||
'/api/1.0/search.json',
|
||||
[ 'q' => $pattern, 'type' => $types ]
|
||||
['q' => $pattern, 'type' => $types]
|
||||
);
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function generateSearchData()
|
||||
{
|
||||
yield ['per', ['person', 'thirdparty'] ];
|
||||
yield ['per', ['thirdparty'] ];
|
||||
yield ['per', ['person'] ];
|
||||
yield ['fjklmeqjfkdqjklrmefdqjklm', ['person', 'thirdparty'] ];
|
||||
}
|
||||
}
|
||||
|
@@ -1,102 +1,98 @@
|
||||
<?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\MainBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\MainBundle\Search\SearchInterface;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test the search controller
|
||||
* Test the search controller.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class SearchControllerTest extends WebTestCase
|
||||
{
|
||||
|
||||
public function testDomainUnknow()
|
||||
{
|
||||
$client = $this->getAuthenticatedClient();
|
||||
|
||||
$crawler = $client->request('GET', '/fr/search', ['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',
|
||||
['q' => '@domaine @domain double domaine']
|
||||
);
|
||||
|
||||
$this->assertGreaterThan(0, $crawler->filter('*:contains("Recherche invalide")')
|
||||
->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behaviour when no domain is provided in the search pattern :
|
||||
* the default search should be enabled
|
||||
* 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");
|
||||
|
||||
$crawler = $client->request('GET', '/fr/search', ['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'));
|
||||
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/fr/search',
|
||||
['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',
|
||||
));
|
||||
return static::createClient([], [
|
||||
'PHP_AUTH_USER' => 'center b_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,15 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use function array_key_exists;
|
||||
use function json_decode;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class UserApiControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
/**
|
||||
* @depends testIndex
|
||||
*
|
||||
* @param mixed $existingUser
|
||||
*/
|
||||
public function testEntity($existingUser)
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
$client->request(Request::METHOD_GET, '/api/1.0/main/user/' . $existingUser['id'] . '.json');
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
@@ -18,26 +45,14 @@ class UserApiControllerTest extends WebTestCase
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
$data = \json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertTrue(\array_key_exists('count', $data));
|
||||
$data = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertTrue(array_key_exists('count', $data));
|
||||
$this->assertGreaterThan(0, $data['count']);
|
||||
$this->assertTrue(\array_key_exists('results', $data));
|
||||
$this->assertTrue(array_key_exists('results', $data));
|
||||
|
||||
return $data['results'][0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testIndex
|
||||
*/
|
||||
public function testEntity($existingUser)
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
$client->request(Request::METHOD_GET, '/api/1.0/main/user/'.$existingUser['id'].'.json');
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
}
|
||||
|
||||
public function testWhoami()
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
@@ -7,6 +14,10 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class UserControllerTest extends WebTestCase
|
||||
{
|
||||
private $client;
|
||||
@@ -17,102 +28,11 @@ class UserControllerTest extends WebTestCase
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->client = static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'admin',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR'
|
||||
));
|
||||
}
|
||||
|
||||
public function testList()
|
||||
{
|
||||
// get the list
|
||||
$crawler = $this->client->request('GET', '/fr/admin/main/user');
|
||||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(),
|
||||
"Unexpected HTTP status code for GET /admin/main/user");
|
||||
}
|
||||
|
||||
public function testNew()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/admin/main/user/new');
|
||||
|
||||
$username = 'Test_user'. uniqid();
|
||||
$password = 'Password1234!';
|
||||
// Fill in the form and submit it
|
||||
$form = $crawler->selectButton('Créer')->form(array(
|
||||
'chill_mainbundle_user[username]' => $username,
|
||||
'chill_mainbundle_user[plainPassword][first]' => $password,
|
||||
'chill_mainbundle_user[plainPassword][second]' => $password,
|
||||
'chill_mainbundle_user[email]' => $username.'@gmail.com',
|
||||
'chill_mainbundle_user[label]' => $username,
|
||||
|
||||
));
|
||||
|
||||
$this->client->submit($form);
|
||||
$crawler = $this->client->followRedirect();
|
||||
|
||||
// Check data in the show view
|
||||
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test_user")')->count(),
|
||||
'Missing element td:contains("Test user")');
|
||||
|
||||
//test the auth of the new client
|
||||
$this->isPasswordValid($username, $password);
|
||||
}
|
||||
|
||||
protected function isPasswordValid($username, $password)
|
||||
{
|
||||
/* @var $passwordEncoder \Symfony\Component\Security\Core\Encoder\UserPasswordEncoder */
|
||||
$passwordEncoder = self::$container
|
||||
->get(UserPasswordEncoderInterface::class);
|
||||
|
||||
$user = self::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(array('username' => $username));
|
||||
|
||||
$this->assertTrue($passwordEncoder->isPasswordValid($user, $password));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider dataGenerateUserId
|
||||
*/
|
||||
public function testUpdate(int $userId, string $username)
|
||||
{
|
||||
$crawler = $this->client->request('GET', "/fr/admin/main/user/$userId/edit");
|
||||
|
||||
$username = 'Foo bar '.uniqid();
|
||||
$form = $crawler->selectButton('Enregistrer & fermer')->form(array(
|
||||
'chill_mainbundle_user[username]' => $username,
|
||||
));
|
||||
|
||||
$this->client->submit($form);
|
||||
$crawler = $this->client->followRedirect();
|
||||
// Check the element contains an attribute with value equals "Foo"
|
||||
$this->assertGreaterThan(0, $crawler->filter('[data-username="'.$username.'"]')->count(),
|
||||
'Missing element [data-username="Foo bar"]');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider dataGenerateUserId
|
||||
*/
|
||||
public function testUpdatePassword(int $userId, $username)
|
||||
{
|
||||
$crawler = $this->client->request('GET', "/fr/admin/user/$userId/edit_password");
|
||||
$newPassword = '1234Password!';
|
||||
|
||||
$form = $crawler->selectButton('Changer le mot de passe')->form(array(
|
||||
'chill_mainbundle_user_password[new_password][first]' => $newPassword,
|
||||
'chill_mainbundle_user_password[new_password][second]' => $newPassword,
|
||||
));
|
||||
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isRedirect(),
|
||||
"the response is a redirection");
|
||||
|
||||
$this->isPasswordValid($username, $newPassword);
|
||||
$this->client = static::createClient([], [
|
||||
'PHP_AUTH_USER' => 'admin',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR',
|
||||
]);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
@@ -120,7 +40,7 @@ class UserControllerTest extends WebTestCase
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
foreach ($this->toDelete as list($class, $id)) {
|
||||
foreach ($this->toDelete as [$class, $id]) {
|
||||
$obj = $em->getRepository($class)->find($id);
|
||||
$em->remove($obj);
|
||||
}
|
||||
@@ -134,15 +54,118 @@ class UserControllerTest extends WebTestCase
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$user = new User();
|
||||
$user->setUsername('Test_user '.uniqid());
|
||||
$user->setPassword(self::$container->get(UserPasswordEncoderInterface::class)->encodePassword($user,
|
||||
'password'));
|
||||
$user->setUsername('Test_user ' . uniqid());
|
||||
$user->setPassword(self::$container->get(UserPasswordEncoderInterface::class)->encodePassword(
|
||||
$user,
|
||||
'password'
|
||||
));
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
$this->toDelete[] = [User::class, $user->getId()];
|
||||
|
||||
yield [ $user->getId(), $user->getUsername() ];
|
||||
yield [$user->getId(), $user->getUsername()];
|
||||
}
|
||||
|
||||
public function testList()
|
||||
{
|
||||
// get the list
|
||||
$crawler = $this->client->request('GET', '/fr/admin/main/user');
|
||||
$this->assertEquals(
|
||||
200,
|
||||
$this->client->getResponse()->getStatusCode(),
|
||||
'Unexpected HTTP status code for GET /admin/main/user'
|
||||
);
|
||||
}
|
||||
|
||||
public function testNew()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/admin/main/user/new');
|
||||
|
||||
$username = 'Test_user' . uniqid();
|
||||
$password = 'Password1234!';
|
||||
// Fill in the form and submit it
|
||||
$form = $crawler->selectButton('Créer')->form([
|
||||
'chill_mainbundle_user[username]' => $username,
|
||||
'chill_mainbundle_user[plainPassword][first]' => $password,
|
||||
'chill_mainbundle_user[plainPassword][second]' => $password,
|
||||
'chill_mainbundle_user[email]' => $username . '@gmail.com',
|
||||
'chill_mainbundle_user[label]' => $username,
|
||||
]);
|
||||
|
||||
$this->client->submit($form);
|
||||
$crawler = $this->client->followRedirect();
|
||||
|
||||
// Check data in the show view
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$crawler->filter('td:contains("Test_user")')->count(),
|
||||
'Missing element td:contains("Test user")'
|
||||
);
|
||||
|
||||
//test the auth of the new client
|
||||
$this->isPasswordValid($username, $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGenerateUserId
|
||||
*/
|
||||
public function testUpdate(int $userId, string $username)
|
||||
{
|
||||
$crawler = $this->client->request('GET', "/fr/admin/main/user/{$userId}/edit");
|
||||
|
||||
$username = 'Foo bar ' . uniqid();
|
||||
$form = $crawler->selectButton('Enregistrer & fermer')->form([
|
||||
'chill_mainbundle_user[username]' => $username,
|
||||
]);
|
||||
|
||||
$this->client->submit($form);
|
||||
$crawler = $this->client->followRedirect();
|
||||
// Check the element contains an attribute with value equals "Foo"
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$crawler->filter('[data-username="' . $username . '"]')->count(),
|
||||
'Missing element [data-username="Foo bar"]'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGenerateUserId
|
||||
*
|
||||
* @param mixed $username
|
||||
*/
|
||||
public function testUpdatePassword(int $userId, $username)
|
||||
{
|
||||
$crawler = $this->client->request('GET', "/fr/admin/user/{$userId}/edit_password");
|
||||
$newPassword = '1234Password!';
|
||||
|
||||
$form = $crawler->selectButton('Changer le mot de passe')->form([
|
||||
'chill_mainbundle_user_password[new_password][first]' => $newPassword,
|
||||
'chill_mainbundle_user_password[new_password][second]' => $newPassword,
|
||||
]);
|
||||
|
||||
$this->client->submit($form);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->client->getResponse()->isRedirect(),
|
||||
'the response is a redirection'
|
||||
);
|
||||
|
||||
$this->isPasswordValid($username, $newPassword);
|
||||
}
|
||||
|
||||
protected function isPasswordValid($username, $password)
|
||||
{
|
||||
/* @var $passwordEncoder \Symfony\Component\Security\Core\Encoder\UserPasswordEncoder */
|
||||
$passwordEncoder = self::$container
|
||||
->get(UserPasswordEncoderInterface::class);
|
||||
|
||||
$user = self::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->findOneBy(['username' => $username]);
|
||||
|
||||
$this->assertTrue($passwordEncoder->isPasswordValid($user, $password));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user