From a9dd827106f612bec08ebe6bda472ef592cb023f Mon Sep 17 00:00:00 2001
From: Laurent Laffont <llaffont@afi-sa.fr>
Date: Thu, 25 Jul 2019 18:08:18 +0200
Subject: [PATCH] hotline #90556 fix domain thumbnail move in file explorer

---
 cosmogramme/VERSIONS_HOTLINE/90556            |  1 +
 library/Class/FileManager/Model.php           |  6 ++-
 .../controllers/FileManagerControllerTest.php | 37 +++++++++++++------
 3 files changed, 32 insertions(+), 12 deletions(-)
 create mode 100644 cosmogramme/VERSIONS_HOTLINE/90556

diff --git a/cosmogramme/VERSIONS_HOTLINE/90556 b/cosmogramme/VERSIONS_HOTLINE/90556
new file mode 100644
index 00000000000..b9e7bff34fa
--- /dev/null
+++ b/cosmogramme/VERSIONS_HOTLINE/90556
@@ -0,0 +1 @@
+ - ticket #90556 : Explorateur de fichiers : correction de la mise à jour du chemin des vignettes des domaines lors du déplacement du fichier
\ No newline at end of file
diff --git a/library/Class/FileManager/Model.php b/library/Class/FileManager/Model.php
index 483a77a73a0..f8312a8f757 100644
--- a/library/Class/FileManager/Model.php
+++ b/library/Class/FileManager/Model.php
@@ -84,9 +84,10 @@ class Class_FileManager_ModelRelation {
 
 
   protected function _generateValue($model, $previous, $new) {
-    return $new;
+    return '/' . $new;
   }
 
+
   public function rename($path, $by) {
     foreach($this->findAll($path) as $model) {
       call_user_func([$model, 'callSetterByAttributeName'], $this->_field, $this->_generateValue($model, $path, $by));
@@ -97,6 +98,7 @@ class Class_FileManager_ModelRelation {
 
 
 
+
 class Class_FileManager_ModelRelationText extends Class_FileManager_ModelRelation {
   protected function _generateValue($model, $previous, $new) {
     return str_replace($previous, $new,
@@ -105,6 +107,8 @@ class Class_FileManager_ModelRelationText extends Class_FileManager_ModelRelatio
 }
 
 
+
+
 class Class_FileManager_ModelRelationProfil {
   protected $_filemanager;
 
diff --git a/tests/application/modules/admin/controllers/FileManagerControllerTest.php b/tests/application/modules/admin/controllers/FileManagerControllerTest.php
index 202d28404d7..a846da1b3a5 100644
--- a/tests/application/modules/admin/controllers/FileManagerControllerTest.php
+++ b/tests/application/modules/admin/controllers/FileManagerControllerTest.php
@@ -1678,7 +1678,6 @@ class FileManagerControllerWithImageInDomainTest extends FileManagerControllerTe
 
 class FileManagerControllerMoveActionWithLinkedDataIbDBTest extends FileManagerControllerTestCase {
   protected
-    $_domain,
     $_top_profile,
     $_article;
 
@@ -1697,11 +1696,20 @@ class FileManagerControllerMoveActionWithLinkedDataIbDBTest extends FileManagerC
                                           'header_img' => 'https://bokeh/userfiles/image/white.png']);
 
 
-    $this->_domain = $this->fixture('Class_Catalogue',
-                                    ['id' => 5,
-                                     'libelle' => 'Banner domain',
-                                     'indexer' => false,
-                                     'url_img' => 'https://bokeh/userfiles/image/white.png']);
+    $this->fixture('Class_Catalogue',
+                   ['id' => 5,
+                    'libelle' => 'Banner domain',
+                    'indexer' => false,
+                    'url_img' => 'https://bokeh/userfiles/image/white.png']);
+
+
+    $this->fixture('Class_Catalogue',
+                   ['id' => 6,
+                    'libelle' => 'Other domain',
+                    'indexer' => false,
+                    'url_img' => '/userfiles/image/white.png']);
+
+
 
     $disk = Class_FileManager::getFileSystem()
       ->whenCalled('directoryAt')
@@ -1744,28 +1752,35 @@ class FileManagerControllerMoveActionWithLinkedDataIbDBTest extends FileManagerC
   /** @test */
   public function articleContentShouldHaveBeenUpdated() {
     $this->dispatch('/admin/file-manager/move?item=userfiles%2Fimage%2Fwhite.png&into=userfiles', true);
-    $this->assertContains('userfiles/white.png', $this->_article->getContenu());
+    $this->assertContains('https://bokeh/userfiles/white.png', $this->_article->getContenu());
   }
 
 
   /** @test */
   public function domainThumbnailShouldHaveBeenUpdated() {
     $this->dispatch('/admin/file-manager/move?item=userfiles%2Fimage%2Fwhite.png&into=userfiles', true);
-    $this->assertContains('userfiles/white.png', $this->_domain->getUrlImg());
+    $this->assertEquals('/userfiles/white.png', Class_Catalogue::find(5)->getUrlImg());
+  }
+
+
+  /** @test */
+  public function otherDomainThumbnailShouldHaveBeenUpdated() {
+    $this->dispatch('/admin/file-manager/move?item=userfiles%2Fimage%2Fwhite.png&into=userfiles', true);
+    $this->assertEquals('/userfiles/white.png', Class_Catalogue::find(6)->getUrlImg());
   }
 
 
   /** @test */
   public function profileImageShouldHaveBeenUpdated() {
     $this->dispatch('/admin/file-manager/move?item=userfiles%2Fimage%2Fwhite.png&into=userfiles', true);
-    $this->assertContains('userfiles/white.png', $this->_top_profile->getCfgSiteParam('header_img'));
+    $this->assertEquals('https://bokeh/userfiles/white.png', $this->_top_profile->getCfgSiteParam('header_img'));
   }
 
 
   /** @test */
   public function renameProfileImageShouldHaveBeenUpdated() {
     $this->postDispatch('/admin/file-manager/rename?item=userfiles%2Fimage%2Fwhite.png', ['name' => 'yellow.2']);
-    $this->assertContains('userfiles/image/yellow.2.png', $this->_top_profile->getCfgSiteParam('header_img'));
+    $this->assertEquals('https://bokeh/userfiles/image/yellow.2.png', $this->_top_profile->getCfgSiteParam('header_img'));
   }
 
 
@@ -1773,7 +1788,7 @@ class FileManagerControllerMoveActionWithLinkedDataIbDBTest extends FileManagerC
   public function renameProfileImageWithDoubleQuotesShouldNotBeenUpdated() {
     $this->postDispatch('/admin/file-manager/rename?item=userfiles%2Fimage%2Fwhite.png&name=wrong',
                         ['name' => 'yell"ow.2']);
-    $this->assertContains('userfiles/image/white.png', $this->_top_profile->getCfgSiteParam('header_img'));
+    $this->assertEquals('https://bokeh/userfiles/image/white.png', $this->_top_profile->getCfgSiteParam('header_img'));
   }
 }
 
-- 
GitLab