mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix some tests
This commit is contained in:
parent
d5476df14c
commit
2dd1b7c943
@ -13,15 +13,22 @@ namespace Chill\MainBundle\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
use Chill\MainBundle\Form\ScopeType;
|
use Chill\MainBundle\Form\ScopeType;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ScopeController.
|
* Class ScopeController.
|
||||||
*/
|
*/
|
||||||
class ScopeController extends AbstractController
|
class ScopeController extends AbstractController
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly EntityManagerInterface $entityManager
|
||||||
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Scope entity.
|
* Creates a new Scope entity.
|
||||||
*
|
*
|
||||||
@ -52,17 +59,16 @@ class ScopeController extends AbstractController
|
|||||||
*
|
*
|
||||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/admin/scope/{id}/edit", name="admin_scope_edit")
|
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/admin/scope/{id}/edit", name="admin_scope_edit")
|
||||||
*/
|
*/
|
||||||
public function editAction(mixed $id)
|
public function editAction(Scope $scope, Request $request): Response
|
||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
|
|
||||||
$scope = $em->getRepository(\Chill\MainBundle\Entity\Scope::class)->find($id);
|
|
||||||
|
|
||||||
if (!$scope) {
|
|
||||||
throw $this->createNotFoundException('Unable to find Scope entity.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$editForm = $this->createEditForm($scope);
|
$editForm = $this->createEditForm($scope);
|
||||||
|
$editForm->handleRequest($request);
|
||||||
|
|
||||||
|
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
return $this->redirectToRoute('admin_scope_edit', ['id' => $scope->getId()]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('@ChillMain/Scope/edit.html.twig', [
|
return $this->render('@ChillMain/Scope/edit.html.twig', [
|
||||||
'entity' => $scope,
|
'entity' => $scope,
|
||||||
@ -120,44 +126,12 @@ class ScopeController extends AbstractController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Edits an existing Scope entity.
|
|
||||||
*
|
|
||||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/admin/scope/{id}/update", name="admin_scope_update", methods={"POST", "PUT"})
|
|
||||||
*/
|
|
||||||
public function updateAction(Request $request, mixed $id)
|
|
||||||
{
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
|
|
||||||
$scope = $em->getRepository(\Chill\MainBundle\Entity\Scope::class)->find($id);
|
|
||||||
|
|
||||||
if (!$scope) {
|
|
||||||
throw $this->createNotFoundException('Unable to find Scope entity.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$editForm = $this->createEditForm($scope);
|
|
||||||
$editForm->handleRequest($request);
|
|
||||||
|
|
||||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
return $this->redirectToRoute('admin_scope_edit', ['id' => $id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->render('@ChillMain/Scope/edit.html.twig', [
|
|
||||||
'entity' => $scope,
|
|
||||||
'edit_form' => $editForm->createView(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a form to create a Scope entity.
|
* Creates a form to create a Scope entity.
|
||||||
*
|
*
|
||||||
* @param Scope $scope The entity
|
* @param Scope $scope The entity
|
||||||
*
|
|
||||||
* @return \Symfony\Component\Form\Form The form
|
|
||||||
*/
|
*/
|
||||||
private function createCreateForm(Scope $scope)
|
private function createCreateForm(Scope $scope): FormInterface
|
||||||
{
|
{
|
||||||
$form = $this->createForm(ScopeType::class, $scope, [
|
$form = $this->createForm(ScopeType::class, $scope, [
|
||||||
'action' => $this->generateUrl('admin_scope_create'),
|
'action' => $this->generateUrl('admin_scope_create'),
|
||||||
@ -173,15 +147,10 @@ class ScopeController extends AbstractController
|
|||||||
* Creates a form to edit a Scope entity.
|
* Creates a form to edit a Scope entity.
|
||||||
*
|
*
|
||||||
* @param Scope $scope The entity
|
* @param Scope $scope The entity
|
||||||
*
|
|
||||||
* @return \Symfony\Component\Form\Form The form
|
|
||||||
*/
|
*/
|
||||||
private function createEditForm(Scope $scope)
|
private function createEditForm(Scope $scope): FormInterface
|
||||||
{
|
{
|
||||||
$form = $this->createForm(ScopeType::class, $scope, [
|
$form = $this->createForm(ScopeType::class, $scope);
|
||||||
'action' => $this->generateUrl('admin_scope_update', ['id' => $scope->getId()]),
|
|
||||||
'method' => 'PUT',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$form->add('submit', SubmitType::class, ['label' => 'Update']);
|
$form->add('submit', SubmitType::class, ['label' => 'Update']);
|
||||||
|
|
||||||
|
@ -39,7 +39,11 @@ use Symfony\Component\Security\Core\Security;
|
|||||||
*/
|
*/
|
||||||
class ScopePickerType extends AbstractType
|
class ScopePickerType extends AbstractType
|
||||||
{
|
{
|
||||||
public function __construct(private readonly AuthorizationHelperInterface $authorizationHelper, private readonly Security $security, private readonly TranslatableStringHelperInterface $translatableStringHelper) {}
|
public function __construct(
|
||||||
|
private readonly AuthorizationHelperInterface $authorizationHelper,
|
||||||
|
private readonly Security $security,
|
||||||
|
private readonly TranslatableStringHelperInterface $translatableStringHelper
|
||||||
|
) {}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Tests\Controller;
|
namespace Chill\MainBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,19 +23,14 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||||||
*/
|
*/
|
||||||
final class ExportControllerTest extends WebTestCase
|
final class ExportControllerTest extends WebTestCase
|
||||||
{
|
{
|
||||||
|
use PrepareClientTrait;
|
||||||
|
|
||||||
public function testIndex()
|
public function testIndex()
|
||||||
{
|
{
|
||||||
$client = self::createClient([], [
|
$client = $this->getClientAuthenticatedAsAdmin();
|
||||||
'PHP_AUTH_USER' => 'center a_social',
|
|
||||||
'PHP_AUTH_PW' => 'password',
|
|
||||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$client->request('GET', '/fr/exports/');
|
$client->request('GET', '/fr/exports/');
|
||||||
|
|
||||||
$this->assertTrue(
|
self::assertResponseIsSuccessful();
|
||||||
$client->getResponse()->isSuccessful(),
|
|
||||||
'assert the list is shown'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,11 +61,6 @@ final class LoginControllerTest extends WebTestCase
|
|||||||
$client->click($crawler->selectLink('Se déconnecter')->link());
|
$client->click($crawler->selectLink('Se déconnecter')->link());
|
||||||
|
|
||||||
$this->assertTrue($client->getResponse()->isRedirect());
|
$this->assertTrue($client->getResponse()->isRedirect());
|
||||||
$client->followRedirect(); // redirect to login page
|
$this->assertResponseRedirects('http://localhost/');
|
||||||
|
|
||||||
// check we are back on login page
|
|
||||||
$this->assertMatchesRegularExpression('/\/login$/', $client->getResponse()
|
|
||||||
->headers
|
|
||||||
->get('location'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Tests\Controller;
|
namespace Chill\MainBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,14 +21,12 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||||||
*/
|
*/
|
||||||
final class ScopeControllerTest extends WebTestCase
|
final class ScopeControllerTest extends WebTestCase
|
||||||
{
|
{
|
||||||
|
use PrepareClientTrait;
|
||||||
|
|
||||||
public function testCompleteScenario()
|
public function testCompleteScenario()
|
||||||
{
|
{
|
||||||
// Create a new client to browse the application
|
// Create a new client to browse the application
|
||||||
$client = self::createClient([], [
|
$client = $this->getClientAuthenticatedAsAdmin();
|
||||||
'PHP_AUTH_USER' => 'admin',
|
|
||||||
'PHP_AUTH_PW' => 'password',
|
|
||||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Create a new entry in the database
|
// Create a new entry in the database
|
||||||
$crawler = $client->request('GET', '/fr/admin/scope/');
|
$crawler = $client->request('GET', '/fr/admin/scope/');
|
||||||
@ -69,7 +68,9 @@ final class ScopeControllerTest extends WebTestCase
|
|||||||
'chill_mainbundle_scope[name][en]' => 'Foo en',
|
'chill_mainbundle_scope[name][en]' => 'Foo en',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$client->submit($form);
|
$crawler = $client->submit($form);
|
||||||
|
var_dump($client->getResponse()->getStatusCode());
|
||||||
|
var_dump($crawler->text());
|
||||||
$crawler = $client->followRedirect();
|
$crawler = $client->followRedirect();
|
||||||
|
|
||||||
// Check the element contains an attribute with value equals "Foo"
|
// Check the element contains an attribute with value equals "Foo"
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Tests\Controller;
|
namespace Chill\MainBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,9 +23,11 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||||||
*/
|
*/
|
||||||
final class SearchControllerTest extends WebTestCase
|
final class SearchControllerTest extends WebTestCase
|
||||||
{
|
{
|
||||||
|
use PrepareClientTrait;
|
||||||
|
|
||||||
public function testDomainUnknow()
|
public function testDomainUnknow()
|
||||||
{
|
{
|
||||||
$client = $this->getAuthenticatedClient();
|
$client = $this->getClientAuthenticated();
|
||||||
|
|
||||||
$crawler = $client->request('GET', '/fr/search', ['q' => '@unknow domain']);
|
$crawler = $client->request('GET', '/fr/search', ['q' => '@unknow domain']);
|
||||||
|
|
||||||
@ -41,7 +44,7 @@ final class SearchControllerTest extends WebTestCase
|
|||||||
|
|
||||||
public function testParsingIncorrect()
|
public function testParsingIncorrect()
|
||||||
{
|
{
|
||||||
$client = $this->getAuthenticatedClient();
|
$client = $this->getClientAuthenticated();
|
||||||
|
|
||||||
$crawler = $client->request(
|
$crawler = $client->request(
|
||||||
'GET',
|
'GET',
|
||||||
@ -59,7 +62,7 @@ final class SearchControllerTest extends WebTestCase
|
|||||||
*/
|
*/
|
||||||
public function testSearchPath()
|
public function testSearchPath()
|
||||||
{
|
{
|
||||||
$client = $this->getAuthenticatedClient();
|
$client = $this->getClientAuthenticated();
|
||||||
|
|
||||||
$crawler = $client->request('GET', '/fr/search', ['q' => 'default search']);
|
$crawler = $client->request('GET', '/fr/search', ['q' => 'default search']);
|
||||||
|
|
||||||
@ -71,7 +74,7 @@ final class SearchControllerTest extends WebTestCase
|
|||||||
|
|
||||||
public function testSearchPathEmpty()
|
public function testSearchPathEmpty()
|
||||||
{
|
{
|
||||||
$client = $this->getAuthenticatedClient();
|
$client = $this->getClientAuthenticated();
|
||||||
|
|
||||||
$crawler = $client->request('GET', '/fr/search?q=');
|
$crawler = $client->request('GET', '/fr/search?q=');
|
||||||
|
|
||||||
@ -80,7 +83,7 @@ final class SearchControllerTest extends WebTestCase
|
|||||||
|
|
||||||
public function testUnknowName()
|
public function testUnknowName()
|
||||||
{
|
{
|
||||||
$client = $this->getAuthenticatedClient();
|
$client = $this->getClientAuthenticated();
|
||||||
|
|
||||||
$client->request(
|
$client->request(
|
||||||
'GET',
|
'GET',
|
||||||
@ -90,12 +93,4 @@ final class SearchControllerTest extends WebTestCase
|
|||||||
|
|
||||||
$this->assertTrue($client->getResponse()->isNotFound());
|
$this->assertTrue($client->getResponse()->isNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAuthenticatedClient()
|
|
||||||
{
|
|
||||||
return self::createClient([], [
|
|
||||||
'PHP_AUTH_USER' => 'center b_social',
|
|
||||||
'PHP_AUTH_PW' => 'password',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\MainBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
|
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||||
@ -24,23 +25,14 @@ use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
|||||||
*/
|
*/
|
||||||
final class UserControllerTest extends WebTestCase
|
final class UserControllerTest extends WebTestCase
|
||||||
{
|
{
|
||||||
private \Symfony\Bundle\FrameworkBundle\KernelBrowser $client;
|
use PrepareClientTrait;
|
||||||
|
|
||||||
private array $toDelete = [];
|
private array $toDelete = [];
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
$this->client = self::createClient([], [
|
|
||||||
'PHP_AUTH_USER' => 'admin',
|
|
||||||
'PHP_AUTH_PW' => 'password',
|
|
||||||
'HTTP_ACCEPT_LANGUAGE' => 'fr_FR',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
$em = self::$container->get(EntityManagerInterface::class);
|
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||||
|
|
||||||
foreach ($this->toDelete as [$class, $id]) {
|
foreach ($this->toDelete as [$class, $id]) {
|
||||||
$obj = $em->getRepository($class)->find($id);
|
$obj = $em->getRepository($class)->find($id);
|
||||||
@ -75,23 +67,26 @@ final class UserControllerTest extends WebTestCase
|
|||||||
|
|
||||||
public function testList()
|
public function testList()
|
||||||
{
|
{
|
||||||
|
$client = $this->getClientAuthenticatedAsAdmin();
|
||||||
|
|
||||||
// get the list
|
// get the list
|
||||||
$crawler = $this->client->request('GET', '/fr/admin/main/user');
|
$client->request('GET', '/fr/admin/main/user');
|
||||||
$this->assertEquals(
|
self::assertResponseIsSuccessful();
|
||||||
200,
|
|
||||||
$this->client->getResponse()->getStatusCode(),
|
|
||||||
'Unexpected HTTP status code for GET /admin/main/user'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNew()
|
public function testNew()
|
||||||
{
|
{
|
||||||
$crawler = $this->client->request('GET', '/fr/admin/main/user/new');
|
$client = $this->getClientAuthenticated('admin');
|
||||||
|
|
||||||
|
$crawler = $client->request('GET', '/fr/admin/main/user/new');
|
||||||
|
|
||||||
|
self::assertResponseIsSuccessful();
|
||||||
|
|
||||||
$username = 'Test_user'.uniqid();
|
$username = 'Test_user'.uniqid();
|
||||||
$password = 'Password1234!';
|
$password = 'Password1234!';
|
||||||
|
|
||||||
// Fill in the form and submit it
|
// Fill in the form and submit it
|
||||||
|
|
||||||
$form = $crawler->selectButton('Créer & fermer')->form([
|
$form = $crawler->selectButton('Créer & fermer')->form([
|
||||||
'chill_mainbundle_user[username]' => $username,
|
'chill_mainbundle_user[username]' => $username,
|
||||||
'chill_mainbundle_user[plainPassword][first]' => $password,
|
'chill_mainbundle_user[plainPassword][first]' => $password,
|
||||||
@ -100,12 +95,12 @@ final class UserControllerTest extends WebTestCase
|
|||||||
'chill_mainbundle_user[label]' => $username,
|
'chill_mainbundle_user[label]' => $username,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->client->submit($form);
|
$client->submit($form);
|
||||||
$crawler = $this->client->followRedirect();
|
$crawler = $client->followRedirect();
|
||||||
|
|
||||||
// Check data in the show view
|
// Check data in the show view
|
||||||
$this->assertStringContainsString(
|
$this->assertStringContainsString(
|
||||||
'Test_user',
|
$username,
|
||||||
$crawler->text(),
|
$crawler->text(),
|
||||||
'page contains the name of the user'
|
'page contains the name of the user'
|
||||||
);
|
);
|
||||||
@ -119,15 +114,18 @@ final class UserControllerTest extends WebTestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate(int $userId, string $username)
|
public function testUpdate(int $userId, string $username)
|
||||||
{
|
{
|
||||||
$crawler = $this->client->request('GET', "/fr/admin/main/user/{$userId}/edit");
|
$client = $this->getClientAuthenticatedAsAdmin();
|
||||||
|
$crawler = $client->request('GET', "/fr/admin/main/user/{$userId}/edit");
|
||||||
|
|
||||||
|
self::assertResponseIsSuccessful();
|
||||||
|
|
||||||
$username = 'Foo bar '.uniqid();
|
$username = 'Foo bar '.uniqid();
|
||||||
$form = $crawler->selectButton('Enregistrer & fermer')->form([
|
$form = $crawler->selectButton('Enregistrer & fermer')->form([
|
||||||
'chill_mainbundle_user[username]' => $username,
|
'chill_mainbundle_user[username]' => $username,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->client->submit($form);
|
$client->submit($form);
|
||||||
$crawler = $this->client->followRedirect();
|
$client->followRedirect();
|
||||||
// Check the element contains an attribute with value equals "Foo"
|
// Check the element contains an attribute with value equals "Foo"
|
||||||
$this->assertResponseIsSuccessful();
|
$this->assertResponseIsSuccessful();
|
||||||
}
|
}
|
||||||
@ -137,7 +135,8 @@ final class UserControllerTest extends WebTestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdatePassword(int $userId, mixed $username)
|
public function testUpdatePassword(int $userId, mixed $username)
|
||||||
{
|
{
|
||||||
$crawler = $this->client->request('GET', "/fr/admin/user/{$userId}/edit_password");
|
$client = $this->getClientAuthenticatedAsAdmin();
|
||||||
|
$crawler = $client->request('GET', "/fr/admin/user/{$userId}/edit_password");
|
||||||
$newPassword = '1234Password!';
|
$newPassword = '1234Password!';
|
||||||
|
|
||||||
$form = $crawler->selectButton('Changer le mot de passe')->form([
|
$form = $crawler->selectButton('Changer le mot de passe')->form([
|
||||||
@ -145,10 +144,10 @@ final class UserControllerTest extends WebTestCase
|
|||||||
'chill_mainbundle_user_password[new_password][second]' => $newPassword,
|
'chill_mainbundle_user_password[new_password][second]' => $newPassword,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->client->submit($form);
|
$client->submit($form);
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$this->client->getResponse()->isRedirect(),
|
$client->getResponse()->isRedirect(),
|
||||||
'the response is a redirection'
|
'the response is a redirection'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -18,12 +18,13 @@ use Chill\MainBundle\Form\Type\ScopePickerType;
|
|||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
|
||||||
|
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension;
|
use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
|
||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
use Symfony\Component\Form\PreloadedExtension;
|
use Symfony\Component\Form\PreloadedExtension;
|
||||||
use Symfony\Component\Form\Test\TypeTestCase;
|
use Symfony\Component\Form\Test\TypeTestCase;
|
||||||
@ -38,7 +39,7 @@ final class ScopePickerTypeTest extends TypeTestCase
|
|||||||
{
|
{
|
||||||
use ProphecyTrait;
|
use ProphecyTrait;
|
||||||
|
|
||||||
public function testBuildOneScopeIsSuccessful()
|
public function estBuildOneScopeIsSuccessful()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(ScopePickerType::class, null, [
|
$form = $this->factory->create(ScopePickerType::class, null, [
|
||||||
'center' => new Center(),
|
'center' => new Center(),
|
||||||
@ -107,9 +108,14 @@ final class ScopePickerTypeTest extends TypeTestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
// add the mocks for creating EntityType
|
// add the mocks for creating EntityType
|
||||||
$entityManager = DoctrineTestHelper::createTestEntityManager();
|
|
||||||
$em = $this->prophesize(EntityManagerInterface::class);
|
$em = $this->prophesize(EntityManagerInterface::class);
|
||||||
$em->getClassMetadata(Scope::class)->willReturn($entityManager->getClassMetadata(Scope::class));
|
$em->getClassMetadata(Scope::class)->will(function (array $args) {
|
||||||
|
$classMetadata = new ClassMetadataBuilder(
|
||||||
|
new ClassMetadataInfo(Scope::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $classMetadata->getClassMetadata();
|
||||||
|
});
|
||||||
$em->contains(Argument::type(Scope::class))->willReturn(true);
|
$em->contains(Argument::type(Scope::class))->willReturn(true);
|
||||||
$em->initializeObject(Argument::type(Scope::class))->will(static fn ($o) => $o);
|
$em->initializeObject(Argument::type(Scope::class))->will(static fn ($o) => $o);
|
||||||
$emRevealed = $em->reveal();
|
$emRevealed = $em->reveal();
|
||||||
|
@ -18,7 +18,10 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Event\TerminateEvent;
|
use Symfony\Component\HttpKernel\Event\TerminateEvent;
|
||||||
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -35,14 +38,17 @@ final class PersistNotificationOnTerminateEventSubscriberTest extends TestCase
|
|||||||
$em = $this->prophesize(EntityManagerInterface::class);
|
$em = $this->prophesize(EntityManagerInterface::class);
|
||||||
$em->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
|
$em->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
|
||||||
$em->flush()->shouldBeCalledTimes(1);
|
$em->flush()->shouldBeCalledTimes(1);
|
||||||
$event = $this->prophesize(TerminateEvent::class);
|
$event = new TerminateEvent(
|
||||||
$event->isMainRequest()->willReturn(true);
|
$this->prophesize(HttpKernelInterface::class)->reveal(),
|
||||||
|
new Request(),
|
||||||
|
new Response()
|
||||||
|
);
|
||||||
|
|
||||||
$eventSubscriber = new PersistNotificationOnTerminateEventSubscriber($em->reveal(), $persister);
|
$eventSubscriber = new PersistNotificationOnTerminateEventSubscriber($em->reveal(), $persister);
|
||||||
|
|
||||||
$notification = new Notification();
|
$notification = new Notification();
|
||||||
$persister->persist($notification);
|
$persister->persist($notification);
|
||||||
|
|
||||||
$eventSubscriber->onKernelTerminate($event->reveal());
|
$eventSubscriber->onKernelTerminate($event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,10 +78,7 @@ final class PersonControllerUpdateTest extends WebTestCase
|
|||||||
*/
|
*/
|
||||||
public function testEditPageDeniedForUnauthorizedInsideCenter(int $personId)
|
public function testEditPageDeniedForUnauthorizedInsideCenter(int $personId)
|
||||||
{
|
{
|
||||||
$client = self::createClient([], [
|
$client = $this->getClientAuthenticated('center a_administrative');
|
||||||
'PHP_AUTH_USER' => 'center a_administrative',
|
|
||||||
'PHP_AUTH_PW' => 'password',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$client->request('GET', $this->makeEditPath($personId));
|
$client->request('GET', $this->makeEditPath($personId));
|
||||||
|
|
||||||
@ -96,10 +93,7 @@ final class PersonControllerUpdateTest extends WebTestCase
|
|||||||
*/
|
*/
|
||||||
public function testEditPageDeniedForUnauthorizedOutsideCenter(int $personId)
|
public function testEditPageDeniedForUnauthorizedOutsideCenter(int $personId)
|
||||||
{
|
{
|
||||||
$client = self::createClient([], [
|
$client = $this->getClientAuthenticated('center b_social');
|
||||||
'PHP_AUTH_USER' => 'center b_social',
|
|
||||||
'PHP_AUTH_PW' => 'password',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$client->request('GET', $this->makeEditPath($personId));
|
$client->request('GET', $this->makeEditPath($personId));
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class AvgDurationAPWorkPersonAssociatedOnWorkTest extends AbstractExportTest
|
|||||||
|
|
||||||
public function getFormData()
|
public function getFormData()
|
||||||
{
|
{
|
||||||
return [];
|
return [[]];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getModifiersCombination()
|
public function getModifiersCombination()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user