Commit 2f0fee1f authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch 'dev#71600_fix_filemanager' into 'master'

Dev#71600 fix filemanager

See merge request afi/opacce!2496
parents b1a8507c 281a78dc
- ticket #71600 : Explorateur de fichiers : correction des liens de téléchargement d'images qui comportaient un espace dans le nom.
\ No newline at end of file
......@@ -23,7 +23,7 @@ class Class_FileManager extends Class_Entity {
use Trait_Translator;
protected static $_file_system;
const REGEX_NAME = '/^[a-z0-9][a-z0-9_\-\. ]+$/i';
const REGEX_NAME = '/^[a-z0-9][a-z0-9_\-\.]+$/i';
protected $_attribs = ['Id' => '',
'Realpath' => '',
'Path' => '',
......@@ -411,7 +411,7 @@ class Class_FileManager extends Class_Entity {
public function getUrl() {
return urlencode($this->getPath());
return rawurlencode($this->getPath());
}
......
......@@ -31,7 +31,7 @@ class ZendAfi_Form_Admin_FileManager_Folder extends ZendAfi_Form {
'allowEmpty' => false,
'required' => true,
'validators' => [(new Zend_Validate_Regex(Class_FileManager::REGEX_NAME))
->setMessage($this->_('Le nom du dossier peut contenir uniquement des lettres, des chiffres et les caratères "_", "-", " ", ".". Exemple : "mon_dossier"'))]])
->setMessage($this->_('Le nom du dossier peut contenir uniquement des lettres, des chiffres et les caratères "_", "-", ".". Exemple : "mon_dossier"'))]])
->addUniqDisplayGroup('new_folder');
}
}
\ No newline at end of file
......@@ -43,6 +43,8 @@ class ZendAfi_Form_Admin_FileManager_Import extends ZendAfi_Form {
$extensions = Class_AdminVar::get('ALLOWED_FILES_EXTENSIONS_FOR_IMPORT');
return $element
->addValidator((new Zend_Validate_Regex(Class_FileManager::REGEX_NAME))
->setMessage($form->_('Le nom peut contenir uniquement des lettres, des chiffres et les caratères "_", "-", " ", ".". Exemple : "mon_fichier.jpg"')))
->addValidator((new Zend_Validate_File_Count(1))
->setMessage($form->_('Un seul fichier doit être transféré.')))
......
......@@ -31,7 +31,7 @@ class ZendAfi_Form_Admin_FileManager_Rename extends ZendAfi_Form {
'allowEmpty' => false,
'required' => true,
'validators' => [(new Zend_Validate_Regex(Class_FileManager::REGEX_NAME))
->setMessage($this->_('Le nom peut contenir uniquement des lettres, des chiffres et les caratères "_", "-", " ", ".". Exemple : "mon_fichier.2"'))]])
->setMessage($this->_('Le nom peut contenir uniquement des lettres, des chiffres et les caratères "_", "-", ".". Exemple : "mon_fichier.jpg"'))]])
->addUniqDisplayGroup('rename_file');
}
}
\ No newline at end of file
......@@ -491,11 +491,19 @@ class FileManagerControllerDropDispatchTest extends FileManagerControllerTestCas
/** @test */
public function postDispatchCreateFolderShouldAddNewFolder() {
$this->postDispatch('/admin/file-manager/create?into=userfiles%2Fimage%2Fwhite',
['folder' => 'new folder']);
['folder' => 'new_folder']);
$this->assertredirect();
}
/** @test */
public function postDispatchCreateFolderShouldNotAddNewFolderWithWhiteSpace() {
$this->postDispatch('/admin/file-manager/create?into=userfiles%2Fimage%2Fwhite',
['folder' => 'new folder']);
$this->assertXpathContentContains('//ul/li', 'Le nom du dossier peut contenir uniquement des lettres, des chiffres et');
}
/** @test */
public function dispatchRenameShouldDisplayRenameForm() {
$this->dispatch('/admin/file-manager/rename?item=userfiles%2Fimage%2Fwhite', true);
......@@ -1489,9 +1497,9 @@ class FileManagerControllerWithSpecialCharTest extends FileManagerControllerTest
public function setUp() {
parent::setUp();
$image = (new Class_FileManager)
->setId('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->setPath('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->setParentPath('userfiles/my\'direct"ory')
->setId('userfiles/my \'direct"ory/new\'_ima"ge.jpg')
->setPath('userfiles/my \'direct"ory/new\'_ima"ge.jpg')
->setParentPath('userfiles/my \'direct"ory')
->setName('new\'_ima"ge.jpg')
->setDir(false)
->setExtension('jpg')
......@@ -1500,36 +1508,36 @@ class FileManagerControllerWithSpecialCharTest extends FileManagerControllerTest
Class_FileManager::getFileSystem()
->whenCalled('directoryAt')
->with('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->with('userfiles/my \'direct"ory/new\'_ima"ge.jpg')
->answers(null)
->whenCalled('fileAt')
->with('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->with('userfiles/my \'direct"ory/new\'_ima"ge.jpg')
->answers($image)
->whenCalled('directoryAt')
->with('userfiles/my\'direct"ory')
->with('userfiles/my \'direct"ory')
->answers(null)
->whenCalled('fileAt')
->with('userfiles/my\'direct"ory')
->with('userfiles/my \'direct"ory')
->answers(null);
$this->dispatch('/admin/file-manager/index?browser=userfiles%2Fmy%27direct"ory%2Fnew%27_ima"ge.jpg&selectable_extensions=jpg;png', true);
$this->dispatch('/admin/file-manager/index?browser=userfiles%2Fmy+%27direct"ory%2Fnew%27_ima"ge.jpg&selectable_extensions=jpg;png', true);
}
/** @test */
public function selectButtonShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@onclick, "$(this).selectItemForCKEditor(")][contains(@onclick, "/userfiles/my%27direct%22ory/new%27_ima%22ge.jpg")]', 'Sélectionner');
$this->assertXPathContentContains('//div//a[contains(@onclick, "$(this).selectItemForCKEditor(")][contains(@onclick, "/userfiles/my %27direct%22ory/new%27_ima%22ge.jpg")]', 'Sélectionner');
}
/** @test */
public function accessInNewTabShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@href, "/userfiles%2Fmy%27direct%22ory%2Fnew%27_ima%22ge.jpg?version=")][@target="_blank"]', 'Accéder à ');
$this->assertXPathContentContains('//div//a[contains(@href, "/userfiles%2Fmy%20%27direct%22ory%2Fnew%27_ima%22ge.jpg?version=")][@target="_blank"]', 'Accéder à ');
}
/** @test */
public function downloadLinkShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@href, "/userfiles%2Fmy%27direct%22ory%2Fnew%27_ima%22ge.jpg")]', 'Télécharger');
$this->assertXPathContentContains('//div//a[contains(@href, "/userfiles%2Fmy%20%27direct%22ory%2Fnew%27_ima%22ge.jpg")]', 'Télécharger');
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment