From 7b63295badc54e8cd477dee1044452af328bb4f3 Mon Sep 17 00:00:00 2001
From: Patrick Barroca <pbarroca@afi-sa.fr>
Date: Mon, 9 Jul 2018 17:30:44 +0200
Subject: [PATCH] dev #74786 : fix failures

---
 .../digital_resources/Cvs/tests/CvsTest.php   | 22 ++++++++++---------
 tests/library/Class/UserDatasTest.php         |  8 ++++---
 tests/library/Class/UsersNonValidTest.php     |  5 ++---
 tests/library/Class/UsersTest.php             |  8 +++++--
 .../Class/WebService/SIGB/KohaRestfulTest.php | 17 +++++++++++---
 .../WebService/SIGB/OpsysServiceTest.php      |  6 ++---
 6 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/library/digital_resources/Cvs/tests/CvsTest.php b/library/digital_resources/Cvs/tests/CvsTest.php
index 0f11c771ba1..b1bec27ccd8 100644
--- a/library/digital_resources/Cvs/tests/CvsTest.php
+++ b/library/digital_resources/Cvs/tests/CvsTest.php
@@ -759,6 +759,10 @@ class CvsLinkWithBorrowerTest extends CvsActivatedTestCase {
   public function setUp() {
     parent::setUp();
 
+    $this->fixture('Class_Bib',
+                   ['id' => 34,
+                    'libelle' => 'Annecy']);
+
     $jerry = $this->fixture('Class_Users',
                             ['id' => 4,
                              'idabon' => 34,
@@ -768,15 +772,11 @@ class CvsLinkWithBorrowerTest extends CvsActivatedTestCase {
                              'nom' => 'Khan',
                              'mail' => 'feu@essence.fr',
                              'password' => 'secret',
+                             'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
+                             'id_site' => 34,
                              'date_fin' => '2023-09-02',
                              'naissance' => '1977-06-27']);
 
-    $jerry->setBib($this->fixture('Class_Bib',
-                                  ['id' => 34,
-                                   'libelle' => 'Annecy']));
-
-    $jerry->beAbonneSIGB();
-
     ZendAfi_Auth::getInstance()->logUser($jerry);
 
     $this->_cvs = new Cvs_Service;
@@ -860,6 +860,10 @@ class CvsServiceWithBorrowerAndLibraryLabelTest extends CvsActivatedTestCase {
 
     Class_AdminVar::set('Cvs_BMLABEL', 'Chinon-Vienne-Loire');
 
+    $this->fixture('Class_Bib',
+                   ['id' => 34,
+                    'libelle' => 'Annecy']);
+
     $jerry = $this->fixture('Class_Users',
                             ['id' => 4,
                              'idabon' => 34,
@@ -868,14 +872,12 @@ class CvsServiceWithBorrowerAndLibraryLabelTest extends CvsActivatedTestCase {
                              'prenom' => 'Jerry',
                              'nom' => 'Khan',
                              'mail' => 'feu@essence.fr',
+                             'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
+                             'id_site' => 34,
                              'password' => 'secret',
                              'date_fin' => '2023-09-02',
                              'naissance' => '1977-06-27']);
 
-    $jerry->setBib($this->fixture('Class_Bib',
-                                  ['id' => 34,
-                                   'libelle' => 'Annecy']));
-
     ZendAfi_Auth::getInstance()->logUser($jerry);
 
     $this->_cvs = new Cvs_Service;
diff --git a/tests/library/Class/UserDatasTest.php b/tests/library/Class/UserDatasTest.php
index 23b4ff0f5da..a3b2319c04a 100644
--- a/tests/library/Class/UserDatasTest.php
+++ b/tests/library/Class/UserDatasTest.php
@@ -46,11 +46,13 @@ class UserDatasTest extends UserDatasTestCase {
 
     $this->fixture('Class_Users', ['id' => 45,
                                    'login' => 'actarus',
-                                   'password' => 'vega4ever']);
+                                   'password' => 'vega4ever',
+                                   'mail' => 'vegarulez@moon.sky']);
 
     $this->fixture('Class_Users', ['id' => 46,
                                    'login' => 'venusia',
-                                   'password' => 'vega4ever']);
+                                   'password' => 'vega4ever',
+                                   'mail' => 'vegarulez@moon.sky']);
 
 
     $this->_sql->whenCalled('fetchOne')
@@ -85,7 +87,7 @@ class UserDatasTest extends UserDatasTestCase {
 
   /** @test */
   public function givingToMultipleTargetsShouldDoNothing() {
-    $this->assertFalse($this->_datas->giveTo(['password' => 'vega4ever'], true));
+    $this->assertFalse($this->_datas->giveTo(['mail' => 'vegarulez@moon.sky'], true));
     $this->assertEquals('Too many targets', $this->_datas->getError());
   }
 
diff --git a/tests/library/Class/UsersNonValidTest.php b/tests/library/Class/UsersNonValidTest.php
index cca90045c74..02112526c7d 100644
--- a/tests/library/Class/UsersNonValidTest.php
+++ b/tests/library/Class/UsersNonValidTest.php
@@ -66,8 +66,7 @@ class Class_UsersNonValidActivateTest extends ModelTestCase {
 
 
   /** @test */
-  public function userPasswordShouldBeIfeelgood() {
-    $this->assertEquals('ifeelgood', $this->_new_user->getPassword());
+  public function userPasswordShouldBeIfeelgoodHashed() {
+    $this->assertTrue($this->_new_user->verifyPassword('ifeelgood'));
   }
 }
-?>
\ No newline at end of file
diff --git a/tests/library/Class/UsersTest.php b/tests/library/Class/UsersTest.php
index a218fca6542..12c8bca0498 100644
--- a/tests/library/Class/UsersTest.php
+++ b/tests/library/Class/UsersTest.php
@@ -825,14 +825,18 @@ class UsersGetUsersWithBlowfishPasswordTest extends ModelTestCase {
     $this->fixture('Class_Users',
                    ['id' => 1,
                     'login' => 'Biquette',
+                    'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
+                    'id_site' => 1,
+                    'idabon' => '3',
                     'password' => '.ACeW295qSfRJuTd04i/zwjjNI67ZUmVIHe']);
 
     $this->fixture('Class_Users',
                    ['id' => 2,
                     'login' => 'Biquette',
+                    'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
+                    'id_site' => 1,
+                    'idabon' => '12',
                     'password' => '$2a$08$gPuCFG7FU2psZ52z5R.ACeW295qSfRJuTd04i/zwjjNI67ZUmVIHe']);
-
-
   }
 
 
diff --git a/tests/library/Class/WebService/SIGB/KohaRestfulTest.php b/tests/library/Class/WebService/SIGB/KohaRestfulTest.php
index 93c4a3a81bd..39339c1d134 100644
--- a/tests/library/Class/WebService/SIGB/KohaRestfulTest.php
+++ b/tests/library/Class/WebService/SIGB/KohaRestfulTest.php
@@ -443,6 +443,8 @@ class KohaRestfulChangePasswordTest extends KohaRestfulTestCase {
     $user = $this->fixture('Class_Users',
                            ['id' => 34,
                             'login' => 'harlock',
+                            'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
+                            'id_site' => 1,
                             'password' => 'arcadia',
                             'idabon' => 'AO989IE']);
 
@@ -456,9 +458,12 @@ class KohaRestfulChangePasswordTest extends KohaRestfulTestCase {
       ->answers(json_encode([['success' =>  ['password' => '$2a$08$o0BrhvBevJBbWcYJElH3IevoytrdwnkZUQLwNcxQt3GhAjtht3RoK']]]))
       ->beStrict();
 
-    $user
-      ->setPassword('ce1snm2p')
-      ->save();
+
+    $user->setPassword('ce1snm2p');
+    $borrower->updateFromUser($user);
+    $user->save();
+    Class_Users::clearCache();
+    $borrower->save();
   }
 
 
@@ -466,4 +471,10 @@ class KohaRestfulChangePasswordTest extends KohaRestfulTestCase {
   public function userPasswordShouldBeCe1snm2p() {
     $this->assertEquals('ce1snm2p', Class_Users::find(34)->getPassword());
   }
+
+
+  /** @test */
+  public function kohaShouldHaveBeenCalled() {
+    $this->assertTrue($this->mock_web_client->methodHasBeenCalled('putData'));
+  }
 }
\ No newline at end of file
diff --git a/tests/library/Class/WebService/SIGB/OpsysServiceTest.php b/tests/library/Class/WebService/SIGB/OpsysServiceTest.php
index 874aea44d7e..81a8167d631 100644
--- a/tests/library/Class/WebService/SIGB/OpsysServiceTest.php
+++ b/tests/library/Class/WebService/SIGB/OpsysServiceTest.php
@@ -698,12 +698,12 @@ class OpsysServiceEmprAuthentifierTestCreateEmprunteur extends OpsysServiceWithS
       ->answers($result);
 
     try {
-      Class_Users::find(123)
+      $user = Class_Users::find(123)
         ->setFicheSIGB(['fiche' => $this->emprunteur])
         ->setIntBib(Class_IntBib::newInstanceWithId(2, ['comm_sigb' => Class_IntBib::COM_OPSYS,
                                                         'comm_params' => serialize([ 'url_serveur' => "http://localhost:8088/mockServiceRechercheSoap?WSDL",
-                                                                                     'catalogue_web' => '1'])]))
-        ->save();
+                                                                                     'catalogue_web' => '1'])]));
+      $this->emprunteur->updateFromUser($user)->save();
       $this->fail();
     } catch (Exception $e) {
       $this->assertEquals("(1) zork", $e->getMessage());
-- 
GitLab