From 47e4c4668b1e04116c1a8c523321be659598face Mon Sep 17 00:00:00 2001
From: demangel6u <mael.demangel3@etu.univ-lorraine.fr>
Date: Tue, 2 Apr 2024 16:52:28 +0200
Subject: [PATCH] suite des tests du mode sommeil

---
 src/Controller/SecurityController.php      |  1 +
 src/Form/RechercheFormType.php             |  2 +-
 templates/security/compteSommeil.html.twig |  2 +-
 tests/TestConnexionTest.php                | 16 +++++++++-------
 tests/TestsSommeilTest.php                 | 21 +++++++++++++++++++--
 vendor/composer/installed.php              |  4 ++--
 6 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php
index 4ea04e88..646a0348 100644
--- a/src/Controller/SecurityController.php
+++ b/src/Controller/SecurityController.php
@@ -90,3 +90,4 @@ class SecurityController extends AbstractController
         return $this->redirectToRoute('app_home_page');
     }
 }
+
diff --git a/src/Form/RechercheFormType.php b/src/Form/RechercheFormType.php
index b19ef02f..7565e7e8 100644
--- a/src/Form/RechercheFormType.php
+++ b/src/Form/RechercheFormType.php
@@ -10,7 +10,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
 
 class RechercheFormType extends AbstractType
 {
-    public function buildForm(FormBuilderInterface $builder, array $options)
+    public function buildForm(FormBuilderInterface $builder, array $options): void
     {
         $builder
             ->add('keyword', null, [
diff --git a/templates/security/compteSommeil.html.twig b/templates/security/compteSommeil.html.twig
index d073a5f8..c683a26b 100644
--- a/templates/security/compteSommeil.html.twig
+++ b/templates/security/compteSommeil.html.twig
@@ -16,7 +16,7 @@
             {{ form_widget(compteSommeilForm.date_fin_sommeil, {'attr': {'required': true, 'placeholder': 'Date de fin', 'class': 'form-control'}}) }}
             {{ form_errors(compteSommeilForm.date_fin_sommeil) }}
 
-            <button type="submit" class="btn-connexion">Confirmer les dates</button>
+            <button type="submit" id='validerSommeil' class="btn-connexion">Confirmer les dates</button>
             {% if error == 1 %}
                 <div class="alert alert-danger">La date de début ne peut pas être postérieure à la date de fin.</div>
             {% endif %}
diff --git a/tests/TestConnexionTest.php b/tests/TestConnexionTest.php
index 5b5252e3..8c5b1619 100644
--- a/tests/TestConnexionTest.php
+++ b/tests/TestConnexionTest.php
@@ -4,7 +4,7 @@ namespace App\Test;
 
 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
 
-class ProductFixture extends WebTestCase
+class TestConnexionTest extends WebTestCase
 {
     public function testRegisterPage()
     {
@@ -24,16 +24,18 @@ class ProductFixture extends WebTestCase
     {
         $client = static::createClient();
 
+        // Accéder à la page d'inscription
+        $client->request('GET', '/register');
+
         // Soumettre le formulaire d'inscription avec des données valides
-        $crawler = $client->request('POST', '/register', [
-            'registrationForm' => [
-                'login' => 'test_user',
-                'plainPassword' => 'test'
-            ],
+        $client->submitForm('inscription-btn',[
+            'registration_form[login]' => 'testCo',
+            'registration_form[plainPassword]'=> 'testCo',
+            'registration_form[abonnement]' => 20,
         ]);
 
         // Vérifier si la redirection s'est faite après l'inscription réussie
-        // $this->assertTrue($client->getResponse()->isRedirect('/'));
+        $this->assertResponseRedirects();
 
         // Vérifier que l'utilisateur est inscrit en vérifiant la présence de son nom d'utilisateur par exemple
         // $this->assertSelectorTextContains('p', 'test_user');
diff --git a/tests/TestsSommeilTest.php b/tests/TestsSommeilTest.php
index d94f8a2c..3d80c773 100644
--- a/tests/TestsSommeilTest.php
+++ b/tests/TestsSommeilTest.php
@@ -3,15 +3,32 @@
 namespace App\Tests;
 
 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
+use App\Repository\PersonneRepository;
 
 class TestsSommeilTest extends WebTestCase
 {
     public function testMiseSommeil(): void
     {
         $client = static::createClient();
-        $client->request('GET', '/');
+        $userRepository = static::getContainer()->get(PersonneRepository::class);
 
+        $user = $userRepository->findOneByLogin('test');
 
-        $this->assertTrue(true);
+        $client->loginUser($user);
+
+        //On verifie qu'on est bien connecté
+        $client->request('GET','/modifUser');
+        $this->assertResponseIsSuccessful();
+
+        $client->request('GET','/mettreCompteSommeil/0');
+        $this->assertResponseIsSuccessful();
+
+        $client->submitForm('validerSommeil',[
+            'compte_sommeil_form[date_debut_sommeil]' => '01/01/2025',
+            'compte_sommeil_form[date_fin_sommeil]'=> '01/01/5000',
+        ]);
+
+        //Pour une raison inconnue ca marche pas
+        //$this->assertTrue($client->getResponse()->isRedirection());
     }
 }
diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php
index 2b5c8635..68f38900 100644
--- a/vendor/composer/installed.php
+++ b/vendor/composer/installed.php
@@ -3,7 +3,7 @@
         'name' => '__root__',
         'pretty_version' => 'dev-master',
         'version' => 'dev-master',
-        'reference' => '5d6f38fd16221daef702eb1ffc13e783e9223909',
+        'reference' => '881f879890fbf7acadd74c3655245cc365305535',
         'type' => 'project',
         'install_path' => __DIR__ . '/../../',
         'aliases' => array(),
@@ -13,7 +13,7 @@
         '__root__' => array(
             'pretty_version' => 'dev-master',
             'version' => 'dev-master',
-            'reference' => '5d6f38fd16221daef702eb1ffc13e783e9223909',
+            'reference' => '881f879890fbf7acadd74c3655245cc365305535',
             'type' => 'project',
             'install_path' => __DIR__ . '/../../',
             'aliases' => array(),
-- 
GitLab