Commit f08245e1 authored by tstoeckler's avatar tstoeckler

Issue #1050076 by tstoeckler: Re-utilize libraries_detect() and remove...

Issue #1050076 by tstoeckler: Re-utilize libraries_detect() and remove libraries_detect_library(). **API CHANGE**
parent aea3addf
Libraries 7.x-2.x, xxxx-xx-xx
-----------------------------
#1050076 by tstoeckler: Re-utilize libraries_detect() and remove libraries_detect_library().
#466090 by tstoeckler: Add update function.
#466090 by tstoeckler: Allow cache to be flushed.
#466090 by tstoeckler, sun: Cache library information.
......
......@@ -219,7 +219,7 @@ function libraries_info($name = NULL) {
}
/**
* Detect libraries and library versions.
* Tries to detect a library and its installed version.
*
* @todo We need to figure out whether, and if, how we want to retain the
* processed information. I.e. either use a static cache here, or make
......@@ -231,27 +231,27 @@ function libraries_info($name = NULL) {
* supported libraries (possibly those registered by itself, or in a certain
* "category") is available... Food for thought.
*
* @param $libraries
* An array of libraries to detect, as returned from libraries_info().
* @param $name
* The machine name of a library to return registered information for.
*
* @return
* An associative array containing registered information for the library
* specified by $name. In addition to the keys returned by libraries_info()
* libraries contain the following keys:
* - installed: A boolean indicating whether the library is installed. Note
* that not only the top-level library, but also each variant contains this
* key.
* - version: If the version could be detected, the full version string.
* - error: If an error occurred during library detection, one of the
* following error statuses: "not found", "not detected", "not supported".
* - error message: If an error occurred during library detection, a detailed
* error message.
*
* @see libraries_info()
*/
function libraries_detect($libraries) {
foreach ($libraries as $name => &$library) {
libraries_detect_library($library);
cache_set($name, $library, 'cache_libraries');
}
return $libraries;
}
function libraries_detect($name) {
$library = libraries_info($name);
/**
* Tries to detect a library and its installed version.
*
* @param $library
* An associative array describing a single library, as returned from
* libraries_info().
*/
function libraries_detect_library(&$library) {
$library['installed'] = FALSE;
// Check whether the library exists.
......@@ -263,7 +263,7 @@ function libraries_detect_library(&$library) {
$library['error message'] = t('The %library library could not be found.', array(
'%library' => $library['name'],
));
return;
return $library;
}
// Detect library version, if not hardcoded.
......@@ -282,7 +282,7 @@ function libraries_detect_library(&$library) {
$library['error message'] = t('The version of the %library library could not be detected.', array(
'%library' => $library['name'],
));
return;
return $library;
}
}
......@@ -301,7 +301,7 @@ function libraries_detect_library(&$library) {
'%version' => $library['version'],
'%library' => $library['name'],
));
return;
return $library;
}
// Apply version specific definitions and overrides.
......@@ -372,8 +372,7 @@ function libraries_load($name, $variant = NULL) {
$library = $library->data;
}
else {
$library = libraries_info($name);
libraries_detect_library($library);
$library = libraries_detect($name);
cache_set($name, $library, 'cache_libraries');
}
......
......@@ -59,8 +59,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
$this->assertEqual($library, $expected, 'Library specified with an .info file found');
// Test missing library.
$library = libraries_info('example_missing');
libraries_detect_library($library);
$library = libraries_detect('example_missing');
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['error'], 'not found', 'Missing library not found.');
$error_message = t('The %library library could not be found.', array(
......@@ -69,8 +68,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
$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);
$library = libraries_detect('example_undetected_version');
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['error'], 'not detected', 'Undetected version detected as such.');
$error_message = t('The version of the %library library could not be detected.', array(
......@@ -79,8 +77,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
$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);
$library = libraries_detect('example_unsupported_version');
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['error'], 'not supported', 'Unsupported version detected as such.');
$error_message = t('The installed version %version of the %library library is not supported.', array(
......@@ -90,26 +87,22 @@ class LibrariesTestCase extends DrupalWebTestCase {
$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');
libraries_detect_library($library);
$library = libraries_detect('example_supported_version');
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['installed'], TRUE, 'Supported library version found.');
// Test libraries_get_version().
$library = libraries_info('example_default_version_callback');
libraries_detect_library($library);
$library = libraries_detect('example_default_version_callback');
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['version'], '1', 'Expected version returned by default version callback.');
// Test a multiple-parameter version callback.
$library = libraries_info('example_multiple_parameter_version_callback');
libraries_detect_library($library);
$library = libraries_detect('example_multiple_parameter_version_callback');
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['version'], '1', 'Expected version returned by multiple parameter version callback.');
// Test a top-level files property.
$library = libraries_info('example_files');
libraries_detect_library($library);
$library = libraries_detect('example_files');
$files = array(
'js' => array('example_1.js'),
'css' => array('example_1.css'),
......@@ -119,8 +112,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
$this->assertEqual($library['files'], $files, 'Top-level files property works.');
// Test version-specific library files.
$library = libraries_info('example_versions');
libraries_detect_library($library);
$library = libraries_detect('example_versions');
$files = array(
'js' => array('example_2.js'),
'css' => array('example_2.css'),
......@@ -130,8 +122,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
$this->assertEqual($library['files'], $files, 'Version-specific library files found.');
// Test missing variant.
$library = libraries_info('example_variant_missing');
libraries_detect_library($library);
$library = libraries_detect('example_variant_missing');
$variants = array_keys($library['variants']);
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['variants']['example_variant']['error'], 'not found', 'Missing variant not found');
......@@ -142,8 +133,7 @@ class LibrariesTestCase extends DrupalWebTestCase {
$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');
libraries_detect_library($library);
$library = libraries_detect('example_variant');
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['variants']['example_variant']['installed'], TRUE, 'Existing variant found.');
......
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