Commit 75c98e4f authored by jmuzz's avatar jmuzz Committed by Devin Carlson

Issue #2215619 by zhuber, netbek, jmuzz, Devin Carlson: Fixed query alter...

Issue #2215619 by zhuber, netbek, jmuzz, Devin Carlson: Fixed query alter preventing files from being displayed if more than one scheme is enabled.
parent d246c78b
......@@ -93,14 +93,13 @@ function media_query_media_browser_alter($query) {
if (count($mimetypes)) {
$local_and->condition($alias . '.filemime', $mimetypes, 'IN');
}
$local_or->condition($local_and);
$local_and = db_and();
}
else {
$local_or->condition($alias . '.uri', db_like($scheme . '://') . '%', 'LIKE');
}
}
if ($local_and->count()) {
$local_or->condition($local_and);
}
$or->condition($local_or);
}
......
......@@ -629,10 +629,17 @@ class MediaBrowserSettingsTestCase extends MediaFileFieldTestCase {
* Tests the media browser settings.
*/
function testBrowserSettings() {
// Perform the tests with all permutations of $scheme, $type and $extension.
foreach (array('public', 'private') as $scheme) {
foreach (array('image', 'document') as $type) {
foreach (array('jpg', 'txt') as $extension) {
$settings = array(
'scheme' => array('public', 'private'),
'type' => array('image', 'document'),
'extension' => array('jpg', 'txt'),
);
// Perform the tests with unique permutations of $scheme, $type and
// $extension.
foreach ($settings['scheme'] as $scheme) {
foreach ($settings['type'] as $type) {
foreach ($settings['extension'] as $extension) {
$file = $this->createFileEntity(array('scheme' => $scheme, 'uid' => $this->admin_user->uid, 'type' => $type, 'filemime' => media_get_extension_mimetype($extension)));
$options = array(
......@@ -661,6 +668,36 @@ class MediaBrowserSettingsTestCase extends MediaFileFieldTestCase {
}
}
// Perform the tests with none and all of the restrictions.
foreach (array('none', 'all') as $restrictions) {
$options = array(
'query' => array(
'enabledPlugins' => array(
'media_default--media_browser_1' => 'media_default--media_browser_1',
),
),
);
switch ($restrictions) {
case 'none':
$options['query']['schemes'] = array();
$options['query']['types'] = array();
$options['query']['file_extensions'] = array();
break;
case 'all':
$options['query']['schemes'] = $settings['scheme'];
$options['query']['types'] = $settings['type'];
$options['query']['file_extensions'] = implode(' ', $settings['extension']);
break;
}
// Verify that all of the files are displayed.
$this->drupalGet('media/browser', $options);
$this->assertResponse(200);
$files = $this->xpath('//ul[@class="media-list-thumbnails"]/li/div[@data-fid]');
$this->assertEqual(count($files), 8, format_string('All of the files were displayed when %restrictions of the restrictions were enabled.', array('%restrictions' => $restrictions)));
}
// Verify that extension restrictions do not affect remote files.
$scheme = 'dummy-remote';
$type = 'video';
......
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