From 51ed0da9b3ad3136075b2b14ea78619809ed6c04 Mon Sep 17 00:00:00 2001
From: Henri-Damien LAURENT <hdlaurent@afi-sa.net>
Date: Wed, 16 Aug 2023 10:46:19 +0000
Subject: [PATCH] hotline#179137 : Cas C3rb : attributes changes

---
 VERSIONS_HOTLINE/179137                       |  1 +
 library/Class/IdentityProvider/C3rb.php       |  7 ++---
 library/Class/WebService/C3rb.php             |  4 ++-
 ...IdentityProviderAuthenticationC3rbTest.php | 29 ++++++++++++++-----
 4 files changed, 28 insertions(+), 13 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/179137

diff --git a/VERSIONS_HOTLINE/179137 b/VERSIONS_HOTLINE/179137
new file mode 100644
index 00000000000..f33bcb5f4ce
--- /dev/null
+++ b/VERSIONS_HOTLINE/179137
@@ -0,0 +1 @@
+ - correctif #179137 : Connecteur C3RB : modification des attributs
\ No newline at end of file
diff --git a/library/Class/IdentityProvider/C3rb.php b/library/Class/IdentityProvider/C3rb.php
index c2818eb433e..d1581c426b4 100644
--- a/library/Class/IdentityProvider/C3rb.php
+++ b/library/Class/IdentityProvider/C3rb.php
@@ -31,10 +31,9 @@ class Class_IdentityProvider_C3rb extends Class_IdentityProvider_Default {
 
 
   public static function getMapping() : array {
-    return ['nom'  => 'nom',
-            'prenom' => 'prenom',
-            'mail'=> 'mail',
+    return ['mail'=> 'mail',
             'naissance' => 'birth',
-            'idabon' => 'cb'];
+            'idabon' => 'cb',
+            'date_fin' => 'date_renouv'];
   }
 }
diff --git a/library/Class/WebService/C3rb.php b/library/Class/WebService/C3rb.php
index 81666758d21..f6294a8d92c 100644
--- a/library/Class/WebService/C3rb.php
+++ b/library/Class/WebService/C3rb.php
@@ -42,7 +42,9 @@ class Class_WebService_C3rb extends Class_WebService_Cas2 {
 
 
   protected function _validateValue(?string $value, string $function_name) {
-    return (($function_name == 'naissance') && $value)
+    return ((($function_name == 'naissance')
+             || ($function_name=='date_fin'))
+            && $value)
       ? date('Y-m-d', strtotime($value))
       : $value;
   }
diff --git a/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationC3rbTest.php b/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationC3rbTest.php
index 98ac86de101..f2ccb32258a 100644
--- a/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationC3rbTest.php
+++ b/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationC3rbTest.php
@@ -109,9 +109,10 @@ class IdentityProviderAuthenticationC3rbToBokehTestCase
     <cas:attributes>
       <cas:user>myawesomeuser</cas:user>
       <cas:mail>awesome@user.fr</cas:mail>
+      <cas:nom>My</cas:nom>
+      <cas:prenom>Awesome</cas:prenom>
       <cas:birth>01/01/2001</cas:birth>
-      <cas:nom>Awesome</cas:nom>
-      <cas:prenom>My</cas:prenom>
+      <cas:date_renouv>01/01/2024</cas:date_renouv>
       <cas:cb>T1</cas:cb>
     </cas:attributes>
   </cas:authenticationSuccess>
@@ -144,14 +145,14 @@ class IdentityProviderAuthenticationC3rbToBokehTestCase
 
 
   /** @test */
-  public function userNameShouldBeAwesome() {
-    $this->assertEquals('Awesome', Class_Users::getIdentity()->getNom());
+  public function userNameShouldBeEmpty() {
+    $this->assertEmpty(Class_Users::getIdentity()->getNom());
   }
 
 
   /** @test */
-  public function userFirstnameShouldBeMy() {
-    $this->assertEquals('My', Class_Users::getIdentity()->getPrenom());
+  public function userFirstnameShouldBeEmpty() {
+    $this->assertEmpty(Class_Users::getIdentity()->getPrenom());
   }
 
 
@@ -161,6 +162,12 @@ class IdentityProviderAuthenticationC3rbToBokehTestCase
   }
 
 
+  /** @test */
+  public function userDateFinShouldBe() {
+    $this->assertEquals('2024-01-01', Class_Users::getIdentity()->getDateFin());
+  }
+
+
   /** @test */
   public function userBirthShouldBe20010101() {
     $this->assertEquals('2001-01-01', Class_Users::getIdentity()->getNaissance());
@@ -208,6 +215,7 @@ class IdentityProviderAuthenticationC3rbToBokehUpdateTestCase
       <cas:birth></cas:birth>
       <cas:nom>Awesome</cas:nom>
       <cas:prenom>MyEdited</cas:prenom>
+      <cas:date_renouv>01/01/2024</cas:date_renouv>
       <cas:cb>T1</cas:cb>
     </cas:attributes>
   </cas:authenticationSuccess>
@@ -245,8 +253,8 @@ class IdentityProviderAuthenticationC3rbToBokehUpdateTestCase
 
 
   /** @test */
-  public function userFirstnameShouldBeMyEdited() {
-    $this->assertEquals('MyEdited', Class_Users::getIdentity()->getPrenom());
+  public function userFirstnameShouldBeMy() {
+    $this->assertEquals('My', Class_Users::getIdentity()->getPrenom());
   }
 
 
@@ -255,4 +263,9 @@ class IdentityProviderAuthenticationC3rbToBokehUpdateTestCase
     $this->assertEquals('', Class_Users::getIdentity()->getNaissance());
   }
 
+
+  /** @test */
+  public function userDateFinShouldExpectation() {
+    $this->assertEquals('2024-01-01', Class_Users::getIdentity()->getDateFin());
+  }
 }
-- 
GitLab