Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
File extensions are no longer forced from mime-type on download, exte…
Browse files Browse the repository at this point in the history
…nsion used from mediafile instead.
  • Loading branch information
rblanker committed Jul 12, 2016
1 parent 3e0fb61 commit 8a335a0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
Expand Up @@ -1180,11 +1180,7 @@ class mediamosa_asset_mediafile {

// No extension yet? Try to get one based on mimetype.
if (empty($file_ext)) {
$mime_type = self::get_mime_type($mediafile[mediamosa_asset_mediafile_db::ID]);

if (!empty($mime_type)) {
$file_ext = self::get_file_extension_by_mimetype($mime_type);
}
$file_ext = $mediafile[mediamosa_asset_mediafile_db::FILE_EXTENSION];
}

// Some must return specific extensions.
Expand Down
Binary file not shown.
Expand Up @@ -148,5 +148,53 @@ class MediaMosaAssetMediafileDownloadTestCaseEga extends MediaMosaTestCaseEga {
t('Delete the mediafile on SAN/NAS: @filename', array('@filename' => mediamosa_io::realpath_safe($mediafile_uri)))
);
}

// Docx upload check.
$upload = $this->uploadTestFile(array(
'downloadable' => TRUE,
'filename' => $this->getTestDoc_Docx()
));
$asset_id = $upload['asset_id'];
$mediafile_id = $upload['mediafile_id'];

// Get the mediafile.
$mediafile = $this->getMediafile($mediafile_id);

// Check the values.
foreach (array(mediamosa_asset_mediafile_db::IS_DOWNLOADABLE => mediamosa_asset_mediafile_db::IS_DOWNLOADABLE_TRUE) as $key => $value) {
$this->assertTrue(
$mediafile[$key] == $value,
t("The @key has the good value (@value) after change.", array('@key' => $key, '@value' => $value))
);
}

// Ask mediafile download url.
$parameters = array(
mediamosa_rest_call_media_view::RESPONSE => mediamosa_media::RESPONSE_DOWNLOAD,
mediamosa_rest_call_media_view::MEDIAFILE_ID => $mediafile_id,
);
$xml = $this->do_media_view($asset_id, $parameters);

// Check the download url.
$download = (string) $xml->items->item->output;
$this->assertTrue(
!empty($download),
t('Download url is exists: @download', array('@download' => $download))
);

$this->var_export($download);

// Download the file.
$result = mediamosa_http::drupal_http_request($download);

$this->var_export($result->headers);
$this->var_export($_SERVER);
if (isset($_SERVER['REDIRECT_STATUS'])) {
$this->assertTrue($_SERVER['REDIRECT_STATUS'] == 200, 'Got 200 HTTP response download.');
}
$this->assertTrue($result->headers['content-type'] == 'application/octet-stream', 'Got download.');
$this->assertTrue(mediamosa_unicode::strpos($result->headers['content-disposition'], '.docx"') !== FALSE, 'Is correct extension.');


}
}
Expand Up @@ -1058,11 +1058,27 @@ class MediaMosaTestCase extends DrupalWebTestCase {
$this->pass(t('Got test audio @audio.', array('@audio' => $filename)));
return $filename;
}

/**
* Return the path+filename to the test audio (mp3).
*
* @return string
* The filename path.
*/
protected function getTestDoc_Docx() {
$filename = drupal_get_path('module', 'mediamosa') . '/lib/testfiles/testing.docx';
$this->pass(t('Got test doc @doc.', array('@doc' => $filename)));
return $filename;
}

/**
* Create a random app or specified one.
*
* @param array $a_attributes
* @param array $fields
* Basic app parameters like the DB version (mediamosa_app_db).
*
* @return array
* The node as array.
*/
protected function createApp($fields = array()) {

Expand Down

0 comments on commit 8a335a0

Please sign in to comment.