diff --git a/library/Class/FileManager/Model.php b/library/Class/FileManager/Model.php index eee50fda58a8ad6dc359b947ac67dc513e065469..483a77a73a022fdf450b7b252eac81e48cf8cc2d 100644 --- a/library/Class/FileManager/Model.php +++ b/library/Class/FileManager/Model.php @@ -98,7 +98,6 @@ class Class_FileManager_ModelRelation { class Class_FileManager_ModelRelationText extends Class_FileManager_ModelRelation { - protected function _generateValue($model, $previous, $new) { return str_replace($previous, $new, call_user_func([$model, 'callGetterByAttributeName'], $this->_field)); @@ -117,13 +116,16 @@ class Class_FileManager_ModelRelationProfil { public function findAll($path) { $top_profiles = array_filter(Class_Profil::findTopProfils(), function($profile) use ($path) { + if ((new Class_Profil_Preferences_Record($profile))->contains($path)) + return true; + foreach(['header_img', 'favicon', 'logo_gauche_img', 'logo_droite_img', 'header_css', 'header_js'] as $key) { - if(false !== strpos($profile->getCfgSiteParam($key), $path)) + if (false !== strpos($profile->getCfgSiteParam($key), $path)) return true; } }); @@ -137,7 +139,6 @@ class Class_FileManager_ModelRelationProfil { : []; return array_merge($top_profiles, $sub_profiles); - } @@ -155,12 +156,14 @@ class Class_FileManager_ModelRelationProfil { 'header_js'] as $key) $model->setCfgSiteParam($key, str_replace($path, $by, $model->getCfgSiteParam($key))); + (new Class_Profil_Preferences_Record($model))->rename($path, $by); + $model->save(); } + public function rename($path, $by) { foreach($this->findAll($path) as $model) $this->_renameOne($model, $path, $by); } - } diff --git a/library/Class/Profil/Preferences/Record.php b/library/Class/Profil/Preferences/Record.php new file mode 100644 index 0000000000000000000000000000000000000000..8dce0b071574f2c65f783806a1cc0bc85eff4fa5 --- /dev/null +++ b/library/Class/Profil/Preferences/Record.php @@ -0,0 +1,91 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Profil_Preferences_Record { + protected + $_controller = 'recherche', + $_profile; + + + public function __construct($profile) { + $this->_profile = $profile; + } + + + public function contains($value) { + return $this->_containsXsl($value); + } + + + public function rename($path, $by) { + $this->_renameXsl($path, $by); + return $this; + } + + + protected function _containsXsl($path) { + $found = false; + $this->_withViewNoticePrefsDo( + function($action, $prefs) use($path, &$found) { + if ($found) + return; + + $found = $path == $prefs[Class_Notice_Xsl::KEY]; + }); + + return $found; + } + + + protected function _renameXsl($path, $by) { + $this->_withViewNoticePrefsDo( + function($action, $prefs) use($path, $by) { + if ($path == $prefs[Class_Notice_Xsl::KEY]) + $this->_profile + ->setCfgModulesPreferences([Class_Notice_Xsl::KEY => $by], + $this->_controller, $action); + } + ); + } + + + protected function _withViewNoticePrefsDo($closure) { + foreach($this->_viewNoticePrefs() as $action => $prefs) + if (array_key_exists(Class_Notice_Xsl::KEY, $prefs)) + $closure($action, $prefs); + } + + + protected function _viewNoticePrefs() { + $cfg_modules = $this->_profile->getCfgModulesAsArray(); + + if (!array_key_exists($this->_controller, $cfg_modules)) + return []; + + $valids = array_filter($cfg_modules[$this->_controller], + function($key) { return 0 === strpos($key, 'viewnotice'); }, + ARRAY_FILTER_USE_KEY); + + return array_filter($valids, + function($value) { return is_array($value); }); + } +} diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php index f8e932cfea60e8a250595a780e35e86f9c17c6b3..aca406855712afce0e1b929e58348b34794a4b34 100644 --- a/tests/application/modules/AbstractControllerTestCase.php +++ b/tests/application/modules/AbstractControllerTestCase.php @@ -35,7 +35,8 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe protected function _initMockProfil() { $this->fixture('Class_Profil', ['id' => 1, - 'libelle' => 'portail']); + 'libelle' => 'portail', + 'parent_id' => null]); $profil = $this->fixture('Class_Profil', ['id' => 2, @@ -59,7 +60,8 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe 'ref_tags' => '', 'mail_site' => 'nanook@afi-sa.net', 'browser' => 'opac', - 'cfg_modules' => []])->beCurrentProfil(); + 'cfg_modules' => [], + 'parent_id' => null])->beCurrentProfil(); diff --git a/tests/scenarios/Xsl/XslTest.php b/tests/scenarios/Xsl/XslTest.php index e95f04f370997e75fadc7e8fbbefd76d192697c0..fb6425121983d3188cbc60be5898f58b086bfd34 100644 --- a/tests/scenarios/Xsl/XslTest.php +++ b/tests/scenarios/Xsl/XslTest.php @@ -222,4 +222,71 @@ class XslNoticeajaxDetailDispatchWithoutXSLTest extends AbstractControllerTestCa public function plzInstallXSLErrorShouldBeDisplay() { $this->assertXPathContentContains('//p', "L'extension PHP XSL"); } +} + + + + +class XslFileManagerControllerWithXslInRechercheViewnoticeTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $disk = $this->mock() + ->whenCalled('directoryAt') + ->with('userfiles/bib1/xsl/toto.xsl') + ->answers(null) + + ->whenCalled('fileAt') + ->with('userfiles/bib1/xsl/toto.xsl') + ->answers((new Class_FileManager) + ->setId('userfiles/bib1/xsl/toto.xsl') + ->setPath('userfiles/bib1/xsl/toto.xsl') + ->setParentPath('userfiles/bib1/xsl') + ->setName('toto.xsl') + ->setDir(false) + ->setWritable(true) + ->setExtension('xsl')) + + ->whenCalled('rename') + ->answers(true); + + Class_FileManager::setFileSystem($disk); + + Class_Profil::getCurrentProfil() + ->setCfgModulesPreferences(['xslt' => 'userfiles/bib1/xsl/toto.xsl'], + 'recherche', 'viewnotice', 'Assimil'); + } + + + + /** @test */ + public function dispatchDeleteShouldDisplayDisabledDeleteButton() { + $this->dispatch('/admin/file-manager/delete?item=userfiles%2Fbib1%2Fxsl%2Ftoto.xsl', true); + $this->assertXPathContentContains('//div//button[@disabled]', 'Supprimer'); + } + + + /** @test */ + public function dispatchForceDeleteShouldRedirectWithErrorMessage() { + $this->dispatch('/admin/file-manager/force-delete?item=userfiles%2Fbib1%2Fxsl%2Ftoto.xsl', true); + $this->assertRedirectTo('/admin/file-manager/index?browser=userfiles%2Fbib1%2Fxsl%2Ftoto.xsl'); + $this->assertFlashMessengerContentContains('Impossible de supprimer'); + } + + + /** @test */ + public function dispatchPropertiesShouldContainsModels() { + $this->dispatch('/admin/file-manager/properties?item=userfiles%2Fbib1%2Fxsl%2Ftoto.xsl', true); + $this->assertXpathContentContains('//table//td', 'AFI', $this->_response->getBody()); + } + + + /** @test */ + public function renameTotoXslShouldUpdateProfile() { + $this->postDispatch('/admin/file-manager/rename?item=userfiles%2Fbib1%2Fxsl%2Ftoto.xsl', ['name' => 'titi']); + $xslt = Class_Profil::getCurrentProfil()->getModulePreference('recherche', 'viewnoticeAssimil', 'xslt'); + $this->assertContains('userfiles/bib1/xsl/titi.xsl', $xslt); + } } \ No newline at end of file