Index: libraries.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/libraries/libraries.module,v retrieving revision 1.8 diff -u -p -r1.8 libraries.module --- libraries.module 10 Oct 2010 03:55:16 -0000 1.8 +++ libraries.module 15 Oct 2010 13:16:08 -0000 @@ -265,20 +265,22 @@ function libraries_detect_library(&$libr return; } - // Detect library version. - // We support both a single parameter, which is an associative array, and an - // indexed array of multiple parameters. - if (isset($library['version arguments'][0])) { - // Add the library as the first argument. - $library['version'] = call_user_func_array($library['version callback'], array_merge(array($library), $library['version arguments'])); - } - else { - $library['version'] = $library['version callback']($library, $library['version arguments']); - } - if (empty($library['version'])) { - $library['error'] = 'not detected'; - $library['error message'] = t('The version of %library could not be detected.', array('%library' => $library['title'])); - return; + // Detect library version, if not hardcoded. + if (!isset($library['version'])) { + // We support both a single parameter, which is an associative array, and an + // indexed array of multiple parameters. + if (isset($library['version arguments'][0])) { + // Add the library as the first argument. + $library['version'] = call_user_func_array($library['version callback'], array_merge(array($library), $library['version arguments'])); + } + else { + $library['version'] = $library['version callback']($library, $library['version arguments']); + } + if (empty($library['version'])) { + $library['error'] = 'not detected'; + $library['error message'] = t('The version of %library could not be detected.', array('%library' => $library['title'])); + return; + } } // Determine to which supported version the installed version maps. @@ -346,7 +348,11 @@ function libraries_detect_library(&$libr function libraries_load($library, $variant = NULL) { $library = libraries_info($library); libraries_detect_library($library); - libraries_load_files($library, $variant); + if ($library['installed']) { + libraries_load_files($library, $variant); + return TRUE; + } + return FALSE; } /** @@ -359,11 +365,11 @@ function libraries_load($library, $varia */ function libraries_load_files($library, $variant = NULL) { // Construct the full path to the library for later use. - $path = !empty($library['path']) ? $library['library path'] . '/' . $library['path'] : $library['library path']; + $path = (!empty($library['path']) ? $library['library path'] . '/' . $library['path'] : $library['library path']); // If a variant was specified, override the top-level properties with the // variant properties. - if (!empty($variant) && !empty($library['variants'][$variant]['installed'])) { + if (!empty($variant) && !empty($library['variants'][$variant]) && $library['variants'][$variant]['installed']) { $library = array_merge($library, $library['variants'][$variant]); } @@ -391,8 +397,9 @@ function libraries_load_files($library, $data = "$path/$options"; $options = NULL; } - // In some cases, the first parameter ($data) is an array. Arrays can't be - // passed as keys in PHP, so we have to get $data from the value array. + // In some cases, the first parameter ($data) is an array. Arrays can't + // be passed as keys in PHP, so we have to get $data from the value + // array. if (is_numeric($data)) { $data = $options['data']; unset($options['data']); Index: tests/libraries.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/libraries/tests/libraries.test,v retrieving revision 1.7 diff -u -p -r1.7 libraries.test --- tests/libraries.test 11 Oct 2010 14:31:06 -0000 1.7 +++ tests/libraries.test 15 Oct 2010 13:16:08 -0000 @@ -49,27 +49,30 @@ class LibrariesTestCase extends DrupalWe // Test missing library. $library = libraries_info('example_missing'); libraries_detect_library($library); - $error = t('%library could not be found.', array( + $this->assertEqual($library['error'], 'not found', 'Non-existing library not found.'); + $error_message = t('%library could not be found.', array( '%library' => $library['title'], )); - $this->assertEqual($library['error message'], $error, 'Non-existing library not found.'); + $this->assertEqual($library['error message'], $error_message, 'Correct error message for a missing library.'); // Test unknown library version. $library = libraries_info('example_undetected_version'); libraries_detect_library($library); - $error = t('The version of %library could not be detected.', array( + $this->assertEqual($library['error'], 'not detected', 'Library version not found.'); + $error_message = t('The version of %library could not be detected.', array( '%library' => $library['title'], )); - $this->assertEqual($library['error message'], $error, 'Library version not found.'); + $this->assertEqual($library['error message'], $error_message, 'Correct error message for a library with an undetected version.'); // Test unsupported library version. $library = libraries_info('example_unsupported_version'); libraries_detect_library($library); - $error = t('The installed version %version of %library is not supported.', array( + $this->assertEqual($library['error'], 'not supported', 'Library version not supported.'); + $error_message = t('The installed version %version of %library is not supported.', array( '%version' => $library['version'], '%library' => $library['title'], )); - $this->assertEqual($library['error message'], $error, 'Unsupported library version found.'); + $this->assertEqual($library['error message'], $error_message, 'Correct error message for a library with an unsupported version.'); // Test supported library version. $library = libraries_info('example_supported_version'); @@ -112,11 +115,12 @@ class LibrariesTestCase extends DrupalWe $library = libraries_info('example_variant_missing'); libraries_detect_library($library); $variants = array_keys($library['variants']); - $error = t('The %variant variant of %library could not be found.', array( + $this->assertEqual($library['variants']['example_variant']['error'], 'not found', 'Missing variant not found'); + $error_message = t('The %variant variant of %library could not be found.', array( '%variant' => $variants[0], '%library' => $library['title'], )); - $this->assertEqual($library['variants']['example_variant']['error message'], $error, 'Missing variant not found.'); + $this->assertEqual($library['variants']['example_variant']['error message'], $error_message, 'Correct error message for a missing variant.'); // Test existing variant. $library = libraries_info('example_variant'); Index: tests/libraries_test.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/libraries/tests/libraries_test.module,v retrieving revision 1.5 diff -u -p -r1.5 libraries_test.module --- tests/libraries_test.module 10 Oct 2010 03:55:16 -0000 1.5 +++ tests/libraries_test.module 15 Oct 2010 13:16:08 -0000 @@ -93,15 +93,9 @@ function libraries_test_libraries_info() 'version arguments' => array('2'), 'integration files' => array( 'libraries_test' => array( - 'js' => array( - 'libraries_test.js', - ), - 'css' => array( - 'libraries_test.css', - ), - 'php' => array( - 'libraries_test.inc', - ), + 'js' => array('libraries_test.js'), + 'css' => array('libraries_test.css'), + 'php' => array('libraries_test.inc'), ), ), ); @@ -115,28 +109,16 @@ function libraries_test_libraries_info() 'versions' => array( '1' => array( 'files' => array( - 'js' => array( - 'example_1.js', - ), - 'css' => array( - 'example_1.css', - ), - 'php' => array( - 'example_1.php', - ), + 'js' => array('example_1.js'), + 'css' => array('example_1.css'), + 'php' => array('example_1.php'), ), ), '2' => array( 'files' => array( - 'js' => array( - 'example_2.js', - ), - 'css' => array( - 'example_2.css', - ), - 'php' => array( - 'example_2.php', - ), + 'js' => array('example_2.js'), + 'css' => array('example_2.css'), + 'php' => array('example_2.php'), ), ), ), @@ -151,15 +133,9 @@ function libraries_test_libraries_info() 'variants' => array( 'example_variant' => array( 'files' => array( - 'js' => array( - 'example_3.js', - ), - 'css' => array( - 'example_3.css', - ), - 'php' => array( - 'example_3.php', - ), + 'js' => array('example_3.js'), + 'css' => array('example_3.css'), + 'php' => array('example_3.php'), ), 'variant callback' => '_libraries_test_return_installed', 'variant arguments' => array(FALSE), @@ -175,15 +151,9 @@ function libraries_test_libraries_info() 'variants' => array( 'example_variant' => array( 'files' => array( - 'js' => array( - 'example_3.js', - ), - 'css' => array( - 'example_3.css', - ), - 'php' => array( - 'example_3.php', - ), + 'js' => array('example_3.js'), + 'css' => array('example_3.css'), + 'php' => array('example_3.php'), ), 'variant callback' => '_libraries_test_return_installed', 'variant arguments' => array(TRUE), @@ -202,30 +172,18 @@ function libraries_test_libraries_info() 'variants' => array( 'example_variant_1' => array( 'files' => array( - 'js' => array( - 'example_1.js', - ), - 'css' => array( - 'example_1.css', - ), - 'php' => array( - 'example_1.php', - ), + 'js' => array('example_1.js'), + 'css' => array('example_1.css'), + 'php' => array('example_1.php'), ), 'variant callback' => '_libraries_test_return_installed', 'variant arguments' => array(TRUE), ), 'example_variant_2' => array( 'files' => array( - 'js' => array( - 'example_2.js', - ), - 'css' => array( - 'example_2.css', - ), - 'php' => array( - 'example_2.php', - ), + 'js' => array('example_2.js'), + 'css' => array('example_2.css'), + 'php' => array('example_2.php'), ), 'variant callback' => '_libraries_test_return_installed', 'variant arguments' => array(TRUE), @@ -236,30 +194,18 @@ function libraries_test_libraries_info() 'variants' => array( 'example_variant_1' => array( 'files' => array( - 'js' => array( - 'example_3.js', - ), - 'css' => array( - 'example_3.css', - ), - 'php' => array( - 'example_3.php', - ), + 'js' => array('example_3.js'), + 'css' => array('example_3.css'), + 'php' => array('example_3.php'), ), 'variant callback' => '_libraries_test_return_installed', 'variant arguments' => array(TRUE), ), 'example_variant_2' => array( 'files' => array( - 'js' => array( - 'example_4.js', - ), - 'css' => array( - 'example_4.css', - ), - 'php' => array( - 'example_4.php', - ), + 'js' => array('example_4.js'), + 'css' => array('example_4.css'), + 'php' => array('example_4.php'), ), 'variant callback' => '_libraries_test_return_installed', 'variant arguments' => array(TRUE),