Commit 26c07ad9 authored by efalcy's avatar efalcy
Browse files

hotline #75696 :fix upload pdf file on album

parent a3eb3ce7
- ticket #75696 : Corrige l'upload d'un fichier pdf dans un album.
\ No newline at end of file
......@@ -145,7 +145,7 @@ class Class_Album extends Storm_Model_Abstract {
/** @var Class_Upload */
protected $_uploadHandler;
protected $_uploadHandler = [];
protected $_marc;
......@@ -853,13 +853,13 @@ class Class_Album extends Storm_Model_Abstract {
* @return Class_Upload
*/
public function getUploadHandler($name) {
if (null === $this->_uploadHandler) {
$this->_uploadHandler = Class_Upload::newInstanceFor($name)
if (!isset($this->_uploadHandler[$name])) {
$this->_uploadHandler[$name] = Class_Upload::newInstanceFor($name)
->setBaseName($this->getId())
->setBasePath($this->getBasePath());
}
return $this->_uploadHandler;
return $this->_uploadHandler[$name];
}
......@@ -873,8 +873,8 @@ class Class_Album extends Storm_Model_Abstract {
* @category testing
* @param Class_Upload $handler
*/
public function setUploadHandler($handler) {
$this->_uploadHandler = $handler;
public function setUploadHandler($handler, $name) {
$this->_uploadHandler[$name] = $handler;
return $this;
}
......
......@@ -56,6 +56,11 @@ class Class_FileWriter {
return move_uploaded_file($source,$destination);
}
public function moveFile($source,$destination) {
return @rename($source,$destination);
}
}
?>
\ No newline at end of file
......@@ -3503,4 +3503,98 @@ class Admin_AlbumControllerAjaxSearchTest extends Admin_AbstractControllerTestCa
public function shouldReturnAlbumsJson() {
$this->assertEquals('[{"label":"Albums non class\u00e9s > Hello moon","value":2},{"label":"Albums non class\u00e9s > Hello world","value":1}]', $this->_response->getBody());
}
}
\ No newline at end of file
}
class Admin_AlbumControllerPostEditWithFilesAlbumMesBDTest extends Admin_AlbumControllerTestCase {
public function setUp() {
parent::setUp();
Class_UploadMover_HttpPost::setFileWriter($this->mock()
->whenCalled('moveUploadedFile')
->answers(true)
->whenCalled('fileExists')
->answers(true));
}
protected function postAlbum() {
$this->postDispatch('/admin/album/edit_album/id/43',
['titre' => 'Mes BD',
'cat_id' => 2,
'description' => "Les préférées de l'année",
'tags' => 'selection',
'type_doc_id' => 201,
'created_at' => '06/10/2017',
'visible' => '1',
'status' => Class_Album::STATUS_VALIDATED,
'annee' => 1998,
'matiere' => '5;6',
'dewey' => '15',
'genre' => '12',
'cote' => 'MS003',
'droits' => '2',
'droits_precision' => 'GNU AFERO',
'provenance' => 'Annecy',
'bibliotheques' => '1;23;7']);
}
/** @test */
function fileWithNoSizeShouldReturnError() {
$_FILES['fichier'] = ['size' => 0,
'name' => '',
'tmp_name' => '',
'error' => 4];
$_FILES['pdf'] = ['size' => 0,
'type' => 'application/pdf',
'name' => 'toto.jpg',
'tmp_name' => '/toto.jpg',
'error' => 0];
$this->postAlbum();
$this->assertXPathContentContains('//ul[@class="errors"]//li',
'Le fichier était vide');
}
/** @test */
function onlyPdfSendShouldWork() {
$_FILES['fichier'] = ['size' => 0,
'name' => '',
'tmp_name' => '',
'error' => 4];
$_FILES['pdf'] = ['size' => 100,
'type' => 'application/pdf',
'name' => 'mypdf.pdf',
'tmp_name' => '/mypdf.pdf',
'error' => 0];
$this->postAlbum();
$this->assertEquals('43_mypdf.pdf',Class_Album::find(43)->getPdf());
$this->assertEquals('',Class_Album::find(43)->getFile());
}
/** @test */
function onlyPictureSendShouldWork() {
$_FILES['fichier'] = ['size' => 100,
'name' => 'mypic.jpg',
'tmp_name' => 'mypic.jpg',
'error' => 0];
$_FILES['pdf'] = ['size' => 0,
'name' => '',
'tmp_name' => '',
'error' => 4];
$this->postAlbum();
$this->assertEquals('43_mypic.jpg',Class_Album::find(43)->getFile());
$this->assertEquals('souvigny.pdf',Class_Album::find(43)->getPdf());
}
}
......@@ -284,7 +284,7 @@ class AlbumHarlockReceivingFileTest extends AlbumHarlockFileUploadHandlerTestCas
->method('setAllowedExtensions')
->will($this->returnValue($this->_handler));
$this->assertFalse($this->_album->setUploadHandler($this->_handler)->receiveFile());
$this->assertFalse($this->_album->setUploadHandler($this->_handler,'fichier')->receiveFile());
}
}
......@@ -316,7 +316,7 @@ class AlbumHarlockReceivingPdfTest extends AlbumHarlockFileUploadHandlerTestCase
->method('setAllowedExtensions')
->will($this->returnValue($this->_handler));
$this->assertFalse($this->_album->setUploadHandler($this->_handler)->receivePdf());
$this->assertFalse($this->_album->setUploadHandler($this->_handler, 'pdf')->receivePdf());
}
}
......
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