+++ /dev/null
-
-Libraries 7.x-2.x, xxxx-xx-xx
------------------------------
-#1023258 by tstoeckler: Make 'files' consistently keyed by filename.
-#958162 by sun, tstoeckler: Add pre-detect callback group.
-#958162 by sun, tstoeckler: Make tests debuggable and provide libraries_info_defaults().
-#961476 by tstoeckler: Changed libraries_get_path() to return FALSE by default.
-#958162 by tstoeckler, sun, good_man: Allow to apply callbacks to libraries.
-#1125904 by tstoeckler, boombatower: Fix drush libraries-list.
-#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.
-#1064008 by tstoeckler, bfroehle: Fix outdated API examples in libraries.api.php.
-#1028744 by tstoeckler: Code clean-up.
-#1023322 by tstoeckler, sun: Fixed libraries shouldn't be loaded multiple times.
-#1024080 by hswong3i, tstoeckler: Fixed installation profile retrieval.
-#995988 by good_man: Wrong default install profile.
-#975498 by Gábor Hojtsy: Update JS/CSS-loading to new drupal_add_js/css() API.
-#958162 by tsteoeckler, sun: Consistent variable naming.
-#924130 by aaronbauman: Fixed libraries_get_path() should use drupal_static().
-#958162 by tstoeckler, sun: Code clean-up, tests revamp, more robust loading.
-#919632 by tstoeckler, sun: Allow library information to be stored in info files.
-by sun: Fixed testbot breaks upon directory name/info file name mismatch.
-#864376 by tstoeckler, sun: Code-cleanup, allow hard-coded 'version'.
-#939174 by sun, tstoeckler: Rename example.info to libraries_example.info.
-by sun: Fixed testbot breaks upon .info file without .module file.
-#542940 by tstoeckler, sun: Add libraries-list command.
-#919632 by tstoeckler: Add example library info file for testing purposes.
-#719896 by tstoeckler, sun: Documentation clean-up and tests improvement.
-#542940 by sun: Added initial Drush integration file.
-#719896 by tstoeckler, sun: Improved library detection and library loading.
-#855050 by Gábor Hojtsy: Avoid call-time pass by reference in libraries_detect().
-#719896 by tstoeckler, sun: Added starting point for hook_libraries_info().
-
-
-Libraries 7.x-1.x, xxxx-xx-xx
------------------------------
-
-
-Libraries 7.x-1.0, 2010-01-27
------------------------------
-#743522 by sun: Ported to D7.
-
-
-Libraries 6.x-1.0, 2010-01-27
------------------------------
-#1028744 by tstoeckler: Code clean-up.
-#496732 by tstoeckler, robphillips: Allow placing libraries in root directory.
-
-
-Libraries 6.x-1.0-ALPHA1, 2009-12-30
-------------------------------------
-#480440 by markus_petrux: Fixed base_path() not applied to default library path.
-#320562 by sun: Added basic functions.
-
-
--- SUMMARY --
-
-Libraries API provides external library handling for Drupal modules.
-
-For a full description visit the project page:
- http://drupal.org/project/libraries
-Bug reports, feature suggestions and latest developments:
- http://drupal.org/project/issues/libraries
-
-
--- REQUIREMENTS --
-
-* None.
-
-
--- INSTALLATION --
-
-* Install as usual, see http://drupal.org/node/70151 for further information.
-
-
--- CONTACT --
-
-Current maintainers:
-* Daniel F. Kudwien (sun) - http://drupal.org/user/54136
-* Tobias Stöckler (tstoeckler) - http://drupal.org/user/107158
-
-
-This project has been sponsored by:
-* UNLEASHED MIND
- Specialized in consulting and planning of Drupal powered sites, UNLEASHED
- MIND offers installation, development, theming, customization, and hosting
- to get you started. Visit http://www.unleashedmind.com for more information.
-
+See major version branches.
+++ /dev/null
-<?php
-
-/**
- * @file
- * Documents API functions for Libraries module.
- */
-
-/**
- * Return information about external libraries.
- *
- * @return
- * An associative array whose keys are internal names of libraries and whose
- * values are describing each library. Each key is the directory name below
- * the 'libraries' directory, in which the library may be found. Each value is
- * an associative array containing:
- * - name: The official, human-readable name of the library.
- * - vendor url: The URL of the homepage of the library.
- * - download url: The URL of a web page on which the library can be obtained.
- * - path: (optional) A relative path from the directory of the library to the
- * actual library. Only required if the extracted download package contains
- * the actual library files in a sub-directory.
- * - library path: (optional) The absolute path to the library directory. This
- * should not be declared normally, as it is automatically detected, to
- * allow for multiple possible library locations. A valid use-case is an
- * external library, in which case the full URL to the library should be
- * specified here.
- * - version: (optional) The version of the library. This should not be
- * declared normally, as it is automatically detected (see 'version
- * callback' below) to allow for version changes of libraries without code
- * changes of implementing modules and to support different versions of a
- * library simultaneously (though only one version can be installed per
- * site). A valid use-case is an external library whose version cannot be
- * determined programatically.
- * - version callback: (optional) The name of a function that detects and
- * returns the full version string of the library. The first argument is
- * always $library, an array containing all library information as described
- * here. There are two ways to declare the version callback's additional
- * arguments, either as a single $options parameter or as multiple
- * parameters, which correspond to the two ways to specify the argument
- * values (see 'version arguments'). Defaults to libraries_get_version().
- * - version arguments: A list of arguments to pass to the version callback.
- * Version arguments can be declared either as an associative array whose
- * keys are the argument names or as an indexed array without specifying
- * keys. If declared as an associative array, the arguments get passed to
- * the version callback as a single $options parameter whose keys are the
- * argument names (i.e. $options is identical to the specified array). If
- * declared as an indexed array, the array values get passed to the version
- * callback as seperate arguments in the order they were declared. The
- * default version callback libraries_get_version() expects a single,
- * associative array with named keys:
- * - file: The filename to parse for the version, relative to the library
- * path. For example: 'docs/changelog.txt'.
- * - pattern: A string containing a regular expression (PCRE) to match the
- * library version. For example: '@version\s+([0-9a-zA-Z\.-]+)@'.
- * - lines: (optional) The maximum number of lines to search the pattern in.
- * Defaults to 20.
- * - cols: (optional) The maximum number of characters per line to take into
- * account. Defaults to 200. In case of minified or compressed files, this
- * prevents reading the entire file into memory.
- * - files: An associative array of library files to load. Supported keys are:
- * - js: A list of JavaScript files to load, using the same syntax as Drupal
- * core's hook_library().
- * - css: A list of CSS files to load, using the same syntax as Drupal
- * core's hook_library().
- * - php: A list of PHP files to load.
- * - variants: (optional) An associative array of available library variants.
- * For example, the top-level 'files' property may refer to a default
- * variant that is compressed. If the library also ships with a minified and
- * uncompressed/source variant, those can be defined here. Each key should
- * describe the variant type, e.g. 'minified' or 'source'. Each value is an
- * associative array of top-level properties that are entirely overridden by
- * the variant, most often just 'files'. Additionally, each variant can
- * contain following properties:
- * - variant callback: (optional) The name of a function that detects the
- * variant and returns TRUE or FALSE, depending on whether the variant is
- * available or not. The first argument is always $library, an array
- * containing all library information as described here. The second
- * argument is always a string containing the variant name. There are two
- * ways to declare the variant callback's additinal arguments, either as a
- * single $options parameter or as multiple parameters, which correspond
- * to the two ways to specify the argument values (see 'variant
- * arguments'). If ommitted, the variant is expected to always be
- * available.
- * - variant arguments: A list of arguments to pass to the variant callback.
- * Variant arguments can be declared either as an associative array whose
- * keys are the argument names or as an indexed array without specifying
- * keys. If declared as an associative array, the arguments get passed to
- * the variant callback as a single $options parameter whose keys are the
- * argument names (i.e. $options is identical to the specified array). If
- * declared as an indexed array, the array values get passed to the
- * variant callback as seperate arguments in the order they were declared.
- * Variants can be version-specific (see 'versions').
- * - versions: (optional) An associative array of supported library versions.
- * Naturally, libraries evolve over time and so do their APIs. In case a
- * library changes between versions, different 'files' may need to be
- * loaded, different 'variants' may become available, or Drupal modules need
- * to load different integration files adapted to the new version. Each key
- * is a version *string* (PHP does not support floats as keys). Each value
- * is an associative array of top-level properties that are entirely
- * overridden by the version.
- * - integration files: (optional) An associative array whose keys are module
- * names and whose values are sets of files to load for the module, using
- * the same notion as the top-level 'files' property. Each specified file
- * should contain the path to the file relative to the module it belongs to.
- * - callbacks: An associative array whose keys are callback groups and whose
- * values are arrays of callbacks to apply to the library in that group.
- * Each callback receives the following arguments:
- * - $library: An array of library information belonging to the top-level
- * library, a specific version, a specific variant or a specific variant
- * of a specific version. Because library information such as the 'files'
- * property (see above) can be declared in all these different locations
- * of the library array, but a callback may have to act on all these
- * different parts of the library, it is called recursively for each
- * library with a certain part of the libraries array passed as $library
- * each time.
- * - $version: If the $library array belongs to a certain version (see
- * above), a string containing the version. This argument may be empty, so
- * NULL should be specified as the default value.
- * - $variant: If the $library array belongs to a certain variant (see
- * above), a string containing the variant name. This argument may be
- * empty, so NULL should be specified as the default value.
- * Valid callback groups are:
- * - info: Callbacks registered in this group are applied after the library
- * information has been retrieved via hook_libraries_info() or info files.
- * - pre-detect: Callbacks registered in this group are applied after the
- * library path has been determined and before the version callback is
- * invoked. At this point the following additional information is available:
- * - $library['library path']: The path on the file system to the library.
- * - post-detect: Callbacks registered in this group are applied after the
- * library has been successfully detected. At this point the library
- * contains the version-specific information, if specified, and following
- * additional information is available:
- * - $library['installed']: A boolean indicating whether the library is
- * installed or not.
- * - $library['version']: If it could be detected, a string containing the
- * version of the library.
- * - $library['variants'][$variant]['installed']: For each specified
- * variant, a boolean indicating whether the variant is installed or
- * not.
- * Note that in this group the 'versions' property is no longer available.
- * - load: Callbacks registered in this group are applied directly
- * before this library is loaded. At this point the library contains
- * variant-specific information, if specified. Note that in this group the
- * 'variants' property is no longer available.
- * Additional top-level properties can be registered as needed.
- *
- * @see hook_library()
- */
-function hook_libraries_info() {
- // The following is a full explanation of all properties. See below for more
- // concrete example implementations.
-
- // This array key lets Libraries API search for 'sites/all/libraries/example'
- // directory, which should contain the entire, original extracted library.
- $libraries['example'] = array(
- // Only used in administrative UI of Libraries API.
- 'name' => 'Example library',
- 'vendor url' => 'http://example.com',
- 'download url' => 'http://example.com/download',
- // Optional: If, after extraction, the actual library files are contained in
- // 'sites/all/libraries/example/lib', specify the relative path here.
- 'path' => 'lib',
- // Optional: Define a custom version detection callback, if required.
- 'version callback' => 'mymodule_get_version',
- // Specify arguments for the version callback. By default,
- // libraries_get_version() takes a named argument array:
- 'version arguments' => array(
- 'file' => 'docs/CHANGELOG.txt',
- 'pattern' => '@version\s+([0-9a-zA-Z\.-]+)@',
- 'lines' => 5,
- 'cols' => 20,
- ),
- // Default list of files of the library to load. Important: Only specify
- // third-party files belonging to the library here, not integration files of
- // your module.
- 'files' => array(
- // 'js' and 'css' follow the syntax of hook_library(), but file paths are
- // relative to the library path.
- 'js' => array(
- 'exlib.js',
- 'gadgets/foo.js',
- ),
- 'css' => array(
- 'lib_style.css',
- 'skin/example.css',
- ),
- // For PHP libraries, specify include files here, still relative to the
- // library path.
- 'php' => array(
- 'exlib.php',
- 'exlib.inc',
- ),
- ),
- // Optional: Specify alternative variants of the library, if available.
- 'variants' => array(
- // All properties defined for 'minified' override top-level properties.
- 'minified' => array(
- 'files' => array(
- 'js' => array(
- 'exlib.min.js',
- 'gadgets/foo.min.js',
- ),
- 'css' => array(
- 'lib_style.css',
- 'skin/example.css',
- ),
- ),
- 'variant callback' => 'mymodule_check_variant',
- 'variant arguments' => array(
- 'variant' => 'minified',
- ),
- ),
- ),
- // Optional, but usually required: Override top-level properties for later
- // versions of the library. The properties of the minimum version that is
- // matched override the top-level properties. Note:
- // - When registering 'versions', it usually does not make sense to register
- // 'files', 'variants', and 'integration files' on the top-level, as most
- // of those likely need to be different per version and there are no
- // defaults.
- // - The array keys have to be strings, as PHP does not support floats for
- // array keys.
- 'versions' => array(
- '2' => array(
- 'files' => array(
- 'js' => array('exlib.js'),
- 'css' => array('exlib_style.css'),
- ),
- ),
- '3.0' => array(
- 'files' => array(
- 'js' => array('exlib.js'),
- 'css' => array('lib_style.css'),
- ),
- ),
- '3.2' => array(
- 'files' => array(
- 'js' => array(
- 'exlib.js',
- 'gadgets/foo.js',
- ),
- 'css' => array(
- 'lib_style.css',
- 'skin/example.css',
- ),
- ),
- ),
- ),
- // Optional: Register files to auto-load for your module. All files must be
- // keyed by module, and follow the syntax of the 'files' property.
- 'integration files' => array(
- 'mymodule' => array(
- 'js' => array('ex_lib.inc'),
- ),
- ),
- // Optionally register callbacks to apply to the library during different
- // stages of its lifetime ('callback groups'). Here, a callback is
- // registered in the 'detect' group.
- 'callbacks' => array(
- 'detect' => array(
- 'mymodule_example_detect_callback',
- ),
- ),
- );
-
- // A very simple library. No changing APIs (hence, no versions), no variants.
- // Expected to be extracted into 'sites/all/libraries/simple'.
- $libraries['simple'] = array(
- 'name' => 'Simple library',
- 'vendor url' => 'http://example.com/simple',
- 'download url' => 'http://example.com/simple',
- 'version arguments' => array(
- 'file' => 'readme.txt',
- // Best practice: Document the actual version strings for later reference.
- // 1.x: Version 1.0
- 'pattern' => '/Version (\d+)/',
- 'lines' => 5,
- ),
- 'files' => array(
- 'js' => array('simple.js'),
- ),
- );
-
- // A library that (naturally) evolves over time with API changes.
- $libraries['tinymce'] = array(
- 'name' => 'TinyMCE',
- 'vendor url' => 'http://tinymce.moxiecode.com',
- 'download url' => 'http://tinymce.moxiecode.com/download.php',
- 'path' => 'jscripts/tiny_mce',
- // The regular expression catches two parts (the major and the minor
- // version), which libraries_get_version() doesn't allow.
- 'version callback' => 'tinymce_get_version',
- 'version arguments' => array(
- // It can be easier to parse the first characters of a minified file
- // instead of doing a multi-line pattern matching in a source file. See
- // 'lines' and 'cols' below.
- 'file' => 'jscripts/tiny_mce/tiny_mce.js',
- // Best practice: Document the actual version strings for later reference.
- // 2.x: this.majorVersion="2";this.minorVersion="1.3"
- // 3.x: majorVersion:'3',minorVersion:'2.0.1'
- 'pattern' => '@majorVersion[=:]["\'](\d).+?minorVersion[=:]["\']([\d\.]+)@',
- 'lines' => 1,
- 'cols' => 100,
- ),
- 'versions' => array(
- '2.1' => array(
- 'files' => array(
- 'js' => array('tiny_mce.js'),
- ),
- 'variants' => array(
- 'source' => array(
- 'files' => array(
- 'js' => array('tiny_mce_src.js'),
- ),
- ),
- ),
- 'integration files' => array(
- 'wysiwyg' => array(
- 'js' => array('editors/js/tinymce-2.js'),
- 'css' => array('editors/js/tinymce-2.css'),
- ),
- ),
- ),
- // Definition used if 3.1 or above is detected.
- '3.1' => array(
- // Does not support JS aggregation.
- 'files' => array(
- 'js' => array(
- 'tiny_mce.js' => array('preprocess' => FALSE),
- ),
- ),
- 'variants' => array(
- // New variant leveraging jQuery. Not stable yet; therefore not the
- // default variant.
- 'jquery' => array(
- 'files' => array(
- 'js' => array(
- 'tiny_mce_jquery.js' => array('preprocess' => FALSE),
- ),
- ),
- ),
- 'source' => array(
- 'files' => array(
- 'js' => array(
- 'tiny_mce_src.js' => array('preprocess' => FALSE),
- ),
- ),
- ),
- ),
- 'integration files' => array(
- 'wysiwyg' => array(
- 'js' => array('editors/js/tinymce-3.js'),
- 'css' => array('editors/js/tinymce-3.css'),
- ),
- ),
- ),
- ),
- );
- return $libraries;
-}
-
-/**
- * Alter the library information before detection and caching takes place.
- *
- * The library definitions are passed by reference. A common use-case is adding
- * a module's integration files to the library array, so that the files are
- * loaded whenever the library is. As noted above, it is important to declare
- * integration files inside of an array, whose key is the module name.
- *
- * @see hook_libraries_info()
- */
-function hook_libraries_info_alter(&$libraries) {
- $files = array(
- 'php' => array('example_module.php_spellchecker.inc'),
- );
- $libraries['php_spellchecker']['integration files']['example_module'] = $files;
-}
-
-/**
- * Specify paths to look for library info files.
- *
- * Libraries API looks in the following directories for library info files by
- * default:
- * - libraries
- * - profiles/$profile/libraries
- * - sites/all/libraries
- * - sites/$site/libraries
- * This hook allows you to specify additional locations to look for library info
- * files. This should only be used for modules that declare many libraries.
- * Modules that only implement a few libraries should implement
- * hook_libraries_info().
- *
- * @return
- * An array of paths.
- */
-function hook_libraries_paths() {
- // Taken from the Libraries test module, which needs to specify the path to
- // the test library.
- return array(drupal_get_path('module', 'libraries_test') . '/example');
-}
+++ /dev/null
-<?php
-
-/**
- * @file
- * Drush integration for Libraries API.
- */
-
-/**
- * Implements hook_drush_command().
- */
-function libraries_drush_command() {
- $items['libraries-list'] = array(
- 'callback' => 'libraries_drush_list',
- 'description' => dt('Lists registered library information.'),
- 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
- );
- /**$items['libraries-download'] = array(
- 'callback' => 'libraries_drush_download',
- 'description' => dt('Downloads a registered library into the libraries directory for the active site.'),
- 'arguments' => array(
- 'name' => dt('The internal name of the registered library.'),
- ),
- );*/
- return $items;
-}
-
-/**
- * Implements hook_drush_help().
- */
-function libraries_drush_help($section) {
- switch ($section) {
- case 'drush:libraries-list':
- return dt('Lists registered library information.');
-
- case 'drush:libraries-download':
- return dt('Downloads a registered library into the libraries directory for the active site.
-
-See libraries-list for a list of registered libraries.');
- }
-}
-
-/**
- * Lists registered library information.
- */
-function libraries_drush_list() {
- $libraries = array();
- foreach (libraries_info() as $name => $info) {
- $libraries[$name] = libraries_detect($name);
- }
- ksort($libraries);
-
- if (empty($libraries)) {
- drush_print('There are no registered libraries.');
- }
-
- else {
- $header = array('Name', 'Status', 'Version', 'Variants');
- $rows = array();
- foreach ($libraries as $name => $library) {
- // Status and version
- if ($library['installed']) {
- $status = 'OK';
- $version = $library['version'];
- }
- else {
- $status = drupal_ucfirst($library['error']);
- $version = (empty($library['version']) ? '-' : $library['version']);
- }
- // Variants
- $variants = array();
- foreach ($library['variants'] as $variant_name => $variant) {
- if ($variant['installed']) {
- $variants[] = $variant_name;
- }
- }
- if (empty($variants)) {
- $variants = '-';
- }
- else {
- $variants = implode(', ', $variants);
- }
-
- $rows[] = array($name, $status, $version, $variants);
- }
- $table = new Console_Table();
- drush_print($table->fromArray($header, $rows));
- }
-}
-
-/**
- * Downloads a library.
- *
- * @param $name
- * The internal name of the library to download.
- */
-function libraries_drush_download($name) {
- return;
-
- // @todo Looks wonky?
- if (!drush_shell_exec('type unzip')) {
- return drush_set_error(dt('Missing dependency: unzip. Install it before using this command.'));
- }
-
- // @todo Simply use current drush site.
- $args = func_get_args();
- if ($args[0]) {
- $path = $args[0];
- }
- else {
- $path = 'sites/all/libraries';
- }
-
- // Create the path if it does not exist.
- if (!is_dir($path)) {
- drush_op('mkdir', $path);
- drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
- }
-
- // Set the directory to the download location.
- $olddir = getcwd();
- chdir($path);
-
- $filename = basename(COLORBOX_DOWNLOAD_URI);
- $dirname = basename(COLORBOX_DOWNLOAD_URI, '.zip');
-
- // Remove any existing Colorbox plugin directory
- if (is_dir($dirname)) {
- drush_log(dt('A existing Colorbox plugin was overwritten at @path', array('@path' => $path)), 'notice');
- }
- // Remove any existing Colorbox plugin zip archive
- if (is_file($filename)) {
- drush_op('unlink', $filename);
- }
-
- // Download the zip archive
- if (!drush_shell_exec('wget '. COLORBOX_DOWNLOAD_URI)) {
- drush_shell_exec('curl -O '. COLORBOX_DOWNLOAD_URI);
- }
-
- if (is_file($filename)) {
- // Decompress the zip archive
- drush_shell_exec('unzip -qq -o '. $filename);
- // Remove the zip archive
- drush_op('unlink', $filename);
- }
-
- // Set working directory back to the previous working directory.
- chdir($olddir);
-
- if (is_dir($path .'/'. $dirname)) {
- drush_log(dt('Colorbox plugin has been downloaded to @path', array('@path' => $path)), 'success');
- }
- else {
- drush_log(dt('Drush was unable to download the Colorbox plugin to @path', array('@path' => $path)), 'error');
- }
-}
+++ /dev/null
-name = Libraries
-description = Allows version dependent and shared usage of external libraries.
-core = 7.x
-files[] = tests/libraries.test
+++ /dev/null
-<?php
-
-/**
- * @file
- * Install, uninstall, and update functions for libraries.module.
- */
-
-/**
- * Implements hook_schema().
- */
-function libraries_schema() {
- $schema['cache_libraries'] = drupal_get_schema_unprocessed('system', 'cache');
- $schema['cache_libraries']['description'] = 'Cache table to store library information';
- return $schema;
-}
-
-/**
- * Create the 'cache_libraries' table.
- */
-function libraries_update_7200() {
- if (!db_table_exists('cache_libraries')) {
- $specs = drupal_get_schema_unprocessed('system', 'cache');
- db_create_table('cache_libraries', $specs);
- }
-}
+++ /dev/null
-<?php
-
-/**
- * @file
- * External library handling for Drupal modules.
- */
-
-/**
- * Implements hook_flush_caches().
- */
-function libraries_flush_caches() {
- return array('cache_libraries');
-}
-
-/**
- * Gets the path of a library.
- *
- * @param $name
- * The machine name of a library to return the path for.
- * @param $base_path
- * Whether to prefix the resulting path with base_path().
- *
- * @return
- * The path to the specified library or FALSE if the library wasn't found.
- *
- * @ingroup libraries
- */
-function libraries_get_path($name, $base_path = FALSE) {
- $libraries = &drupal_static(__FUNCTION__);
-
- if (!isset($libraries)) {
- $libraries = libraries_get_libraries();
- }
-
- $path = ($base_path ? base_path() : '');
- if (!isset($libraries[$name])) {
- return FALSE;
- }
- else {
- $path .= $libraries[$name];
- }
-
- return $path;
-}
-
-/**
- * Returns an array of library directories.
- *
- * Returns an array of library directories from the all-sites directory
- * (i.e. sites/all/libraries/), the profiles directory, and site-specific
- * directory (i.e. sites/somesite/libraries/). The returned array will be keyed
- * by the library name. Site-specific libraries are prioritized over libraries
- * in the default directories. That is, if a library with the same name appears
- * in both the site-wide directory and site-specific directory, only the
- * site-specific version will be listed.
- *
- * @return
- * A list of library directories.
- *
- * @ingroup libraries
- */
-function libraries_get_libraries() {
- $directory = 'libraries';
- $searchdir = array();
- $profile = drupal_get_profile();
- $config = conf_path();
-
- // Similar to 'modules' and 'themes' directories in the root directory,
- // certain distributions may want to place libraries into a 'libraries'
- // directory in Drupal's root directory.
- $searchdir[] = $directory;
-
- // The 'profiles' directory contains pristine collections of modules and
- // themes as organized by a distribution. It is pristine in the same way
- // that /modules is pristine for core; users should avoid changing anything
- // there in favor of sites/all or sites/<domain> directories.
- if (file_exists("profiles/$profile/$directory")) {
- $searchdir[] = "profiles/$profile/$directory";
- }
-
- // Always search sites/all/*.
- $searchdir[] = 'sites/all/' . $directory;
-
- // Also search sites/<domain>/*.
- if (file_exists("$config/$directory")) {
- $searchdir[] = "$config/$directory";
- }
-
- // Retrieve list of directories.
- // @todo Core: Allow to scan for directories.
- $directories = array();
- $nomask = array('CVS');
- foreach ($searchdir as $dir) {
- if (is_dir($dir) && $handle = opendir($dir)) {
- while (FALSE !== ($file = readdir($handle))) {
- if (!in_array($file, $nomask) && $file[0] != '.') {
- if (is_dir("$dir/$file")) {
- $directories[$file] = "$dir/$file";
- }
- }
- }
- closedir($handle);
- }
- }
-
- return $directories;
-}
-
-/**
- * Looks for library info files.
- *
- * This function scans the following directories for info files:
- * - libraries
- * - profiles/$profilename/libraries
- * - sites/all/libraries
- * - sites/$sitename/libraries
- * - any directories specified via hook_libraries_info_file_paths()
- *
- * @return
- * An array of info files, keyed by library name. The values are the paths of
- * the files.
- */
-function libraries_scan_info_files() {
- $profile = drupal_get_profile();
- $config = conf_path();
-
- // Build a list of directories.
- $directories = module_invoke_all('libraries_info_file_paths');
- $directories[] = 'libraries';
- $directories[] = "profiles/$profile/libraries";
- $directories[] = 'sites/all/libraries';
- $directories[] = "$config/libraries";
-
- // Scan for info files.
- $files = array();
- foreach ($directories as $dir) {
- if (file_exists($dir)) {
- $files = array_merge($files, file_scan_directory($dir, '@^[a-z0-9._-]+\.libraries\.info$@', array(
- 'key' => 'name',
- 'recurse' => FALSE,
- )));
- }
- }
-
- foreach ($files as $filename => $file) {
- $files[basename($filename, '.libraries')] = $file;
- unset($files[$filename]);
- }
-
- return $files;
-}
-
-/**
- * Invokes library callbacks.
- *
- * @param $group
- * A string containing the group of callbacks that is to be applied. Should be
- * either 'info', 'pre-detect', 'post-detect', or 'load'.
- * @param $library
- * An array of library information, passed by reference.
- */
-function libraries_invoke($group, &$library) {
- foreach ($library['callbacks'][$group] as $callback) {
- libraries_traverse_library($library, $callback);
- }
-}
-
-/**
- * Helper function to apply a callback to all parts of a library.
- *
- * Because library declarations can include variants and versions, and those
- * version declarations can in turn include variants, modifying e.g. the 'files'
- * property everywhere it is declared can be quite cumbersome, in which case
- * this helper function is useful.
- *
- * @param $library
- * An array of library information, passed by reference.
- * @param $callback
- * A string containing the callback to apply to all parts of a library.
- */
-function libraries_traverse_library(&$library, $callback) {
- // Always apply the callback to the top-level library.
- $callback($library, NULL, NULL);
-
- // Apply the callback to versions.
- if (isset($library['versions'])) {
- foreach ($library['versions'] as $version_string => &$version) {
- $callback($version, $version_string, NULL);
- // Versions can include variants as well.
- if (isset($version['variants'])) {
- foreach ($version['variants'] as $version_variant_name => &$version_variant) {
- $callback($version_variant, $version_string, $version_variant_name);
- }
- }
- }
- }
-
- // Apply the callback to variants.
- if (isset($library['variants'])) {
- foreach ($library['variants'] as $variant_name => &$variant) {
- $callback($variant, NULL, $variant_name);
- }
- }
-}
-
-/**
- * Library info callback to make all 'files' properties consistent.
- *
- * This turns libraries' file information declared as e.g.
- * @code
- * $library['files']['js'] = array('example_1.js', 'example_2.js');
- * @endcode
- * into
- * @code
- * $library['files']['js'] = array(
- * 'example_1.js' => array(),
- * 'example_2.js' => array(),
- * );
- * @endcode
- * It does the same for the 'integration files' property.
- *
- * @param $library
- * An associative array of library information or a part of it, passed by
- * reference.
- * @param $version
- * If the library information belongs to a specific version, the version
- * string. NULL otherwise.
- * @param $variant
- * If the library information belongs to a specific variant, the variant name.
- * NULL otherwise.
- *
- * @see libraries_info()
- * @see libraries_invoke()
- */
-function libraries_prepare_files(&$library, $version = NULL, $variant = NULL) {
- // Both the 'files' property and the 'integration files' property contain file
- // declarations, and we want to make both consistent.
- $file_types = array();
- if (isset($library['files'])) {
- $file_types[] = &$library['files'];
- }
- if (isset($library['integration files'])) {
- // Integration files are additionally keyed by module.
- foreach ($library['integration files'] as &$integration_files) {
- $file_types[] = &$integration_files;
- }
- }
- foreach ($file_types as &$files) {
- // Go through all supported types of files.
- foreach (array('js', 'css', 'php') as $type) {
- if (isset($files[$type])) {
- foreach ($files[$type] as $key => $value) {
- // Unset numeric keys and turn the respective values into keys.
- if (is_numeric($key)) {
- $files[$type][$value] = array();
- unset($files[$type][$key]);
- }
- }
- }
- }
- }
-}
-
-/**
- * Returns information about registered libraries.
- *
- * The returned information is unprocessed, i.e. as registered by modules.
- *
- * @param $name
- * (optional) The machine name of a library to return registered information
- * for, or FALSE if no library with the given name exists. If omitted,
- * information about all libraries is returned.
- *
- * @return
- * An associative array containing registered information for all libraries,
- * or the registered information for the library specified by $name.
- *
- * @see hook_libraries_info()
- *
- * @todo Re-introduce support for include file plugin system - either by copying
- * Wysiwyg's code, or directly switching to CTools.
- */
-function libraries_info($name = NULL) {
- $libraries = &drupal_static(__FUNCTION__);
-
- if (!isset($libraries)) {
- $libraries = array();
- // Gather information from hook_libraries_info().
- foreach (module_implements('libraries_info') as $module) {
- foreach (module_invoke($module, 'libraries_info') as $machine_name => $properties) {
- $properties['module'] = $module;
- $libraries[$machine_name] = $properties;
- }
- }
- // Gather information from .info files.
- // .info files override module definitions.
- foreach (libraries_scan_info_files() as $machine_name => $file) {
- $properties = drupal_parse_info_file($file->uri);
- $properties['info file'] = $file->uri;
- $libraries[$machine_name] = $properties;
- }
-
- // Provide defaults.
- foreach ($libraries as $machine_name => &$properties) {
- libraries_info_defaults($properties, $machine_name);
- }
-
- // Allow modules to alter the registered libraries.
- drupal_alter('libraries_info', $libraries);
-
- // Invoke callbacks in the 'info' group.
- foreach ($libraries as &$properties) {
- libraries_invoke('info', $properties);
- }
- }
-
- if (isset($name)) {
- return !empty($libraries[$name]) ? $libraries[$name] : FALSE;
- }
- return $libraries;
-}
-
-/**
- * Applies default properties to a library definition.
- *
- * @library
- * An array of library information, passed by reference.
- * @name
- * The machine name of the passed-in library.
- */
-function libraries_info_defaults(&$library, $name) {
- $library += array(
- 'machine name' => $name,
- 'name' => $name,
- 'vendor url' => '',
- 'download url' => '',
- 'path' => '',
- 'library path' => NULL,
- 'version callback' => 'libraries_get_version',
- 'version arguments' => array(),
- 'files' => array(),
- 'variants' => array(),
- 'versions' => array(),
- 'integration files' => array(),
- 'callbacks' => array(),
- );
- $library['callbacks'] += array(
- 'info' => array(),
- 'pre-detect' => array(),
- 'post-detect' => array(),
- 'load' => array(),
- );
-
- // Add our own callbacks before any others.
- $library['callbacks']['info'] = array_merge(array('libraries_prepare_files'), $library['callbacks']['info']);
-
- return $library;
-}
-
-/**
- * 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
- * libraries_info() conditionally invoke libraries_detect($name). D7 only way:
- * Re-use drupal_static() of libraries_info() - but would still require to
- * update the (DB) cache (there likely will be one soon). Also, we probably do
- * not want to ALWAYS parse ALL possible libraries; rather, the
- * requesting/consuming module likely wants to know whether a list of
- * supported libraries (possibly those registered by itself, or in a certain
- * "category") is available... Food for thought.
- *
- * @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($name) {
- $library = libraries_info($name);
-
- $library['installed'] = FALSE;
-
- // Check whether the library exists.
- if (!isset($library['library path'])) {
- $library['library path'] = libraries_get_path($library['machine name']);
- }
- if ($library['library path'] === FALSE || !file_exists($library['library path'])) {
- $library['error'] = 'not found';
- $library['error message'] = t('The %library library could not be found.', array(
- '%library' => $library['name'],
- ));
- return $library;
- }
-
- // Invoke callbacks in the 'pre-detect' group.
- libraries_invoke('pre-detect', $library);
-
- // 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 the %library library could not be detected.', array(
- '%library' => $library['name'],
- ));
- return $library;
- }
- }
-
- // Determine to which supported version the installed version maps.
- if (!empty($library['versions'])) {
- ksort($library['versions']);
- $version = 0;
- foreach ($library['versions'] as $supported_version => $version_properties) {
- if (version_compare($library['version'], $supported_version, '>=')) {
- $version = $supported_version;
- }
- }
- if (!$version) {
- $library['error'] = 'not supported';
- $library['error message'] = t('The installed version %version of the %library library is not supported.', array(
- '%version' => $library['version'],
- '%library' => $library['name'],
- ));
- return $library;
- }
-
- // Apply version specific definitions and overrides.
- $library = array_merge($library, $library['versions'][$version]);
- unset($library['versions']);
- }
-
- // Check each variant if it is installed.
- if (!empty($library['variants'])) {
- foreach ($library['variants'] as $variant_name => &$variant) {
- // If no variant callback has been set, assume the variant to be
- // installed.
- if (!isset($variant['variant callback'])) {
- $variant['installed'] = TRUE;
- }
- else {
- // We support both a single parameter, which is an associative array,
- // and an indexed array of multiple parameters.
- if (isset($variant['variant arguments'][0])) {
- // Add the library as the first argument, and the variant name as the second.
- $variant['installed'] = call_user_func_array($variant['variant callback'], array_merge(array($library, $variant_name), $variant['variant arguments']));
- }
- else {
- $variant['installed'] = $variant['variant callback']($library, $variant_name, $variant['variant arguments']);
- }
- if (!$variant['installed']) {
- $variant['error'] = 'not found';
- $variant['error message'] = t('The %variant variant of the %library library could not be found.', array(
- '%variant' => $variant_name,
- '%library' => $library['name'],
- ));
- }
- }
- }
- }
-
- // If we end up here, the library should be usable.
- $library['installed'] = TRUE;
-
- // Invoke callbacks in the 'post-detect' group.
- libraries_invoke('post-detect', $library);
-
- return $library;
-}
-
-/**
- * Loads a library.
- *
- * @param $name
- * The name of the library to load.
- * @param $variant
- * The name of the variant to load. Note that only one variant of a library
- * can be loaded within a single request. The variant that has been passed
- * first is used; different variant names in subsequent calls are ignored.
- *
- * @return
- * An associative array of the library information as returned from
- * libraries_info(). The top-level properties contain the effective definition
- * of the library (variant) that has been loaded. Additionally:
- * - installed: Whether the library is installed, as determined by
- * libraries_detect_library().
- * - loaded: Either the amount of library files that have been loaded, or
- * FALSE if the library could not be loaded.
- * See hook_libraries_info() for more information.
- */
-function libraries_load($name, $variant = NULL) {
- $loaded = &drupal_static(__FUNCTION__, array());
-
- if (!isset($loaded[$name])) {
- $library = cache_get($name, 'cache_libraries');
- if ($library) {
- $library = $library->data;
- }
- else {
- $library = libraries_detect($name);
- cache_set($name, $library, 'cache_libraries');
- }
-
- // If a variant was specified, override the top-level properties with the
- // variant properties.
- if (isset($variant)) {
- // Ensure that the $variant key exists, and if it does not, set its
- // 'installed' property to FALSE by default. This will prevent the loading
- // of the library files below.
- $library['variants'] += array($variant => array('installed' => FALSE));
- $library = array_merge($library, $library['variants'][$variant]);
- }
- // Regardless of whether a specific variant was requested or not, there can
- // only be one variant of a library within a single request.
- unset($library['variants']);
-
- // If the library (variant) is installed, load it.
- $library['loaded'] = FALSE;
- if ($library['installed']) {
- // Invoke callbacks in the 'load' group.
- libraries_invoke('load', $library);
-
- $library['loaded'] = libraries_load_files($library);
- }
- $loaded[$name] = $library;
- }
-
- return $loaded[$name];
-}
-
-/**
- * Loads a library's files.
- *
- * @param $library
- * An array of library information as returned by libraries_info().
- *
- * @return
- * The number of loaded files.
- */
-function libraries_load_files($library) {
- // Load integration files.
- if (!empty($library['integration files'])) {
- foreach ($library['integration files'] as $module => $files) {
- libraries_load_files(array(
- 'files' => $files,
- 'path' => '',
- 'library path' => drupal_get_path('module', $module),
- ));
- }
- }
-
- // Construct the full path to the library for later use.
- $path = $library['library path'];
- $path = ($library['path'] !== '' ? $path . '/' . $library['path'] : $path);
-
- // Count the number of loaded files for the return value.
- $count = 0;
-
- // Load both the JavaScript and the CSS files.
- // The parameters for drupal_add_js() and drupal_add_css() require special
- // handling.
- // @see drupal_process_attached()
- foreach (array('js', 'css') as $type) {
- if (!empty($library['files'][$type])) {
- foreach ($library['files'][$type] as $data => $options) {
- // If the value is not an array, it's a filename and passed as first
- // (and only) argument.
- if (!is_array($options)) {
- // Prepend the library path to the file name.
- $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.
- if (is_numeric($data)) {
- $data = $options['data'];
- unset($options['data']);
- }
- // Apply the default group if the group isn't explicitly given.
- if (!isset($options['group'])) {
- $options['group'] = ($type == 'js') ? JS_DEFAULT : CSS_DEFAULT;
- }
- call_user_func('drupal_add_' . $type, $data, $options);
- $count++;
- }
- }
- }
-
- // Load PHP files.
- if (!empty($library['files']['php'])) {
- foreach ($library['files']['php'] as $file => $array) {
- $file_path = DRUPAL_ROOT . '/' . $path . '/' . $file;
- if (file_exists($file_path)) {
- require_once $file_path;
- $count++;
- }
- }
- }
-
- return $count;
-}
-
-/**
- * Gets the version information from an arbitrary library.
- *
- * @param $library
- * An associative array containing all information about the library.
- * @param $options
- * An associative array containing with the following keys:
- * - file: The filename to parse for the version, relative to the library
- * path. For example: 'docs/changelog.txt'.
- * - pattern: A string containing a regular expression (PCRE) to match the
- * library version. For example: '@version\s+([0-9a-zA-Z\.-]+)@'.
- * - lines: (optional) The maximum number of lines to search the pattern in.
- * Defaults to 20.
- * - cols: (optional) The maximum number of characters per line to take into
- * account. Defaults to 200. In case of minified or compressed files, this
- * prevents reading the entire file into memory.
- *
- * @return
- * A string containing the version of the library.
- *
- * @see libraries_get_path()
- */
-function libraries_get_version($library, $options) {
- // Provide defaults.
- $options += array(
- 'file' => '',
- 'pattern' => '',
- 'lines' => 20,
- 'cols' => 200,
- );
-
- $file = DRUPAL_ROOT . '/' . $library['library path'] . '/' . $options['file'];
- if (empty($options['file']) || !file_exists($file)) {
- return;
- }
- $file = fopen($file, 'r');
- while ($options['lines'] && $line = fgets($file, $options['cols'])) {
- if (preg_match($options['pattern'], $line, $version)) {
- fclose($file);
- return $version[1];
- }
- $options['lines']--;
- }
- fclose($file);
-}
+++ /dev/null
-
-Example library
-
-Version 1
-
-This file is an example file to test version detection.
-
-The various other files in this directory are to test the loading of JavaScript,
-CSS and PHP files.
-- JavaScript: The filenames of the JavaScript files are asserted to be in the
- raw HTML via SimpleTest. Since the filename could appear, for instance, in an
- error message, this is not very robust. Explicit testing of JavaScript,
- though, is not yet possible with SimpleTest. To allow for easier debugging, we
- place the following text on the page:
- "If this text shows up, no JavaScript test file was loaded."
- This text is replaced via JavaScript by a text of the form:
- "If this text shows up, [[file] was loaded successfully."
- [file] is either 'example_1.js', 'example_2.js', 'example_3.js',
- 'example_4.js' or 'libraries_test.js'. If you have SimpleTest's verbose mode
- enabled and see the above text in one of the debug pages, the noted JavaScript
- file was loaded successfully.
-- CSS: The filenames of the CSS files are asserted to be in the raw HTML via
- SimpleTest. Since the filename could appear, for instance, in an error
- message, this is not very robust. Explicit testing of CSS, though, is not yet
- possible with SimpleTest. Hence, the CSS files, if loaded, make the following
- text a certain color:
- "If one of the CSS test files has been loaded, this text will be colored:
- - example_1: red
- - example_2: green
- - example_3: orange
- - example_4: blue
- - libraries_test: purple"
- If you have SimpleTest's verbose mode enabled, and see the above text in a
- certain color (i.e. not in black), a CSS file was loaded successfully. Which
- file depends on the color as referenced in the text above.
-- PHP: The loading of PHP files is tested by defining a dummy function in the
- PHP files and then checking whether this function was defined using
- function_exists(). This can be checked programatically with SimpleTest.
-The loading of integration files is tested with the same method. The integration
-files are libraries_test.js, libraries_test.css, libraries_test.inc and are
-located in the tests directory alongside libraries_test.module (i.e. they are
-not in the same directory as this file).
+++ /dev/null
-
-/**
- * @file
- * Test CSS file for Libraries loading.
- *
- * Color the 'libraries-test-css' div red. See README.txt for more information.
- */
-
-.libraries-test-css {
- color: red;
-}
+++ /dev/null
-
-/**
- * @file
- * Test JavaScript file for Libraries loading.
- *
- * Replace the text in the 'libraries-test-javascript' div. See README.txt for
- * more information.
- */
-
-(function ($) {
-
-Drupal.behaviors.librariesTest = {
- attach: function(context, settings) {
- $('.libraries-test-javascript').text('If this text shows up, example_1.js was loaded successfully.')
- }
-};
-
-})(jQuery);
+++ /dev/null
-<?php
-
-/**
- * @file
- * Test PHP file for Libraries loading.
- */
-
-/**
- * Dummy function to see if this file was loaded.
- */
-function _libraries_test_example_1() {
-}
+++ /dev/null
-
-/**
- * @file
- * Test CSS file for Libraries loading.
- *
- * Color the 'libraries-test-css' div green. See README.txt for more information.
- */
-
-.libraries-test-css {
- color: green;
-}
+++ /dev/null
-
-/**
- * @file
- * Test JavaScript file for Libraries loading.
- *
- * Replace the text in the 'libraries-test-javascript' div. See README.txt for
- * more information.
- */
-
-(function ($) {
-
-Drupal.behaviors.librariesTest = {
- attach: function(context, settings) {
- $('.libraries-test-javascript').text('If this text shows up, example_2.js was loaded successfully.')
- }
-};
-
-})(jQuery);
+++ /dev/null
-<?php
-
-/**
- * @file
- * Test PHP file for Libraries loading.
- */
-
-/**
- * Dummy function to see if this file was loaded.
- */
-function _libraries_test_example_2() {
-}
+++ /dev/null
-
-/**
- * @file
- * Test CSS file for Libraries loading.
- *
- * Color the 'libraries-test-css' div orange. See README.txt for more information.
- */
-
-.libraries-test-css {
- color: orange;
-}
+++ /dev/null
-
-/**
- * @file
- * Test JavaScript file for Libraries loading.
- *
- * Replace the text in the 'libraries-test-javascript' div. See README.txt for
- * more information.
- */
-
-(function ($) {
-
-Drupal.behaviors.librariesTest = {
- attach: function(context, settings) {
- $('.libraries-test-javascript').text('If this text shows up, example_3.js was loaded successfully.')
- }
-};
-
-})(jQuery);
+++ /dev/null
-<?php
-
-/**
- * @file
- * Test PHP file for Libraries loading.
- */
-
-/**
- * Dummy function to see if this file was loaded.
- */
-function _libraries_test_example_3() {
-}
+++ /dev/null
-
-/**
- * @file
- * Test CSS file for Libraries loading.
- *
- * Color the 'libraries-test-css' div blue. See README.txt for more information.
- */
-
-.libraries-test-css {
- color: blue;
-}
+++ /dev/null
-
-/**
- * @file
- * Test JavaScript file for Libraries loading.
- *
- * Replace the text in the 'libraries-test-javascript' div. See README.txt for
- * more information.
- */
-
-(function ($) {
-
-Drupal.behaviors.librariesTest = {
- attach: function(context, settings) {
- $('.libraries-test-javascript').text('If this text shows up, example_4.js was loaded successfully.')
- }
-};
-
-})(jQuery);
+++ /dev/null
-<?php
-
-/**
- * @file
- * Test PHP file for Libraries loading.
- */
-
-/**
- * Dummy function to see if this file was loaded.
- */
-function _libraries_test_example_4() {
-}
+++ /dev/null
-
-; This is an example info file of a library used for testing purposes.
-name = Example info file
-
+++ /dev/null
-<?php
-
-/**
- * @file
- * Tests for Libraries API.
- */
-
-/**
- * Tests basic detection and loading of libraries.
- */
-class LibrariesTestCase extends DrupalWebTestCase {
- protected $profile = 'testing';
-
- public static function getInfo() {
- return array(
- 'name' => 'Libraries detection and loading',
- 'description' => 'Tests detection and loading of libraries.',
- 'group' => 'Libraries API',
- );
- }
-
- function setUp() {
- parent::setUp('libraries', 'libraries_test');
- }
-
- /**
- * Tests libraries detection and loading.
- *
- * @todo Better method name(s); split into detection/loading/overloading/etc.
- */
- function testLibraries() {
- // Test libraries_get_path().
- $this->assertEqual(libraries_get_path('example'), FALSE, 'libraries_get_path() returns FALSE for a missing library.');
-
- // Test libraries_prepare_files().
- $expected = array(
- 'files' => array(
- 'js' => array('example.js' => array()),
- 'css' => array('example.css' => array()),
- 'php' => array('example.php' => array()),
- ),
- );
- $library = array(
- 'files' => array(
- 'js' => array('example.js'),
- 'css' => array('example.css'),
- 'php' => array('example.php'),
- ),
- );
- libraries_prepare_files($library, NULL, NULL);
- $this->assertEqual($expected, $library, 'libraries_prepare_files() works correctly.');
-
- // Test that library information is found correctly.
- $expected = array(
- 'name' => 'Example files',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- 'version' => '1',
- 'files' => array(
- 'js' => array('example_1.js' => array()),
- 'css' => array('example_1.css' => array()),
- 'php' => array('example_1.php' => array()),
- ),
- 'module' => 'libraries_test',
- );
- libraries_info_defaults($expected, 'example_files');
- $library = libraries_info('example_files');
- $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
- $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library, $expected, 'Library information is correctly gathered.');
-
- // Test a library specified with an .info file gets detected.
- $expected = array(
- 'name' => 'Example info file',
- 'info file' => drupal_get_path('module', 'libraries_test') . '/example/example_info_file.libraries.info',
- );
- libraries_info_defaults($expected, 'example_info_file');
- $library = libraries_info('example_info_file');
- $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
- $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library, $expected, 'Library specified with an .info file found');
-
- // Test missing library.
- $library = libraries_detect('example_missing');
- $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library['error'], 'not found', 'Missing library not found.');
- $error_message = t('The %library library could not be found.', array(
- '%library' => $library['name'],
- ));
- $this->assertEqual($library['error message'], $error_message, 'Correct error message for a missing library.');
-
- // Test unknown library version.
- $library = libraries_detect('example_undetected_version');
- $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
- $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(
- '%library' => $library['name'],
- ));
- $this->assertEqual($library['error message'], $error_message, 'Correct error message for a library with an undetected version.');
-
- // Test unsupported library version.
- $library = libraries_detect('example_unsupported_version');
- $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
- $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(
- '%version' => $library['version'],
- '%library' => $library['name'],
- ));
- $this->assertEqual($library['error message'], $error_message, 'Correct error message for a library with an unsupported version.');
-
- // Test supported library version.
- $library = libraries_detect('example_supported_version');
- $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library['installed'], TRUE, 'Supported library version found.');
-
- // Test libraries_get_version().
- $library = libraries_detect('example_default_version_callback');
- $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library['version'], '1', 'Expected version returned by default version callback.');
-
- // Test a multiple-parameter version callback.
- $library = libraries_detect('example_multiple_parameter_version_callback');
- $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library['version'], '1', 'Expected version returned by multiple parameter version callback.');
-
- // Test a top-level files property.
- $library = libraries_detect('example_files');
- $files = array(
- 'js' => array('example_1.js' => array()),
- 'css' => array('example_1.css' => array()),
- 'php' => array('example_1.php' => array()),
- );
- $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library['files'], $files, 'Top-level files property works.');
-
- // Test version-specific library files.
- $library = libraries_detect('example_versions');
- $files = array(
- 'js' => array('example_2.js' => array()),
- 'css' => array('example_2.css' => array()),
- 'php' => array('example_2.php' => array()),
- );
- $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library['files'], $files, 'Version-specific library files found.');
-
- // Test missing variant.
- $library = libraries_detect('example_variant_missing');
- $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library['variants']['example_variant']['error'], 'not found', 'Missing variant not found');
- $error_message = t('The %variant variant of the %library library could not be found.', array(
- '%variant' => 'example_variant',
- '%library' => 'Example variant missing',
- ));
- $this->assertEqual($library['variants']['example_variant']['error message'], $error_message, 'Correct error message for a missing variant.');
-
- // Test existing variant.
- $library = libraries_detect('example_variant');
- $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library['variants']['example_variant']['installed'], TRUE, 'Existing variant found.');
-
- // Test the applying of callbacks.
- $expected = array(
- 'name' => 'Example callback',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- 'version' => '1',
- 'versions' => array(
- '1' => array(
- 'variants' => array(
- 'example_variant' => array(
- 'info callback' => 'not applied',
- 'pre-detect callback' => 'not applied',
- 'post-detect callback' => 'not applied',
- 'load callback' => 'not applied',
- ),
- ),
- 'info callback' => 'not applied',
- 'pre-detect callback' => 'not applied',
- 'post-detect callback' => 'not applied',
- 'load callback' => 'not applied',
- ),
- ),
- 'variants' => array(
- 'example_variant' => array(
- 'info callback' => 'not applied',
- 'pre-detect callback' => 'not applied',
- 'post-detect callback' => 'not applied',
- 'load callback' => 'not applied',
- ),
- ),
- 'callbacks' => array(
- 'info' => array('_libraries_test_info_callback'),
- 'pre-detect' => array('_libraries_test_pre_detect_callback'),
- 'post-detect' => array('_libraries_test_post_detect_callback'),
- 'load' => array('_libraries_test_load_callback'),
- ),
- 'info callback' => 'not applied',
- 'pre-detect callback' => 'not applied',
- 'post-detect callback' => 'not applied',
- 'load callback' => 'not applied',
- 'module' => 'libraries_test',
- );
- libraries_info_defaults($expected, 'example_callback');
-
- // Test a callback in the 'info' group.
- $expected['info callback'] = 'applied (top-level)';
- $expected['versions']['1']['info callback'] = 'applied (version 1)';
- $expected['versions']['1']['variants']['example_variant']['info callback'] = 'applied (version 1, variant example_variant)';
- $expected['variants']['example_variant']['info callback'] = 'applied (variant example_variant)';
- $library = libraries_info('example_callback');
- $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
- $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library, $expected, 'Prepare callback was applied correctly.');
-
- // Test a callback in the 'pre-detect' and 'post-detect' phase.
- // Successfully detected libraries should only contain version information
- // for the detected version and thus, be marked as installed.
- unset($expected['versions']);
- $expected['installed'] = TRUE;
- // Additionally, version-specific properties of the detected version are
- // supposed to override the corresponding top-level properties.
- $expected['info callback'] = 'applied (version 1)';
- $expected['variants']['example_variant']['installed'] = TRUE;
- $expected['variants']['example_variant']['info callback'] = 'applied (version 1, variant example_variant)';
- // Version-overloading takes place after the 'pre-detect' callbacks have
- // been applied.
- $expected['pre-detect callback'] = 'applied (version 1)';
- $expected['post-detect callback'] = 'applied (top-level)';
- $expected['variants']['example_variant']['pre-detect callback'] = 'applied (version 1, variant example_variant)';
- $expected['variants']['example_variant']['post-detect callback'] = 'applied (variant example_variant)';
- $library = libraries_detect('example_callback');
- $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
- $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library, $expected, 'Detect callback was applied correctly.');
-
- // Test a callback in the 'load' phase.
- // Successfully loaded libraries should only contain information about the
- // already loaded variant.
- unset($expected['variants']);
- $expected['loaded'] = 0;
- $expected['load callback'] = 'applied (top-level)';
- $library = libraries_load('example_callback');
- $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
- $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library, $expected, 'Load callback was applied correctly.');
- // This is not recommended usually and is only used for testing purposes.
- drupal_static_reset('libraries_load');
- // Successfully loaded library variants are supposed to contain the specific
- // variant information only.
- $expected['info callback'] = 'applied (version 1, variant example_variant)';
- $expected['pre-detect callback'] = 'applied (version 1, variant example_variant)';
- $expected['post-detect callback'] = 'applied (variant example_variant)';
- $library = libraries_load('example_callback', 'example_variant');
- $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
- $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
- $this->assertEqual($library, $expected, 'Load callback was applied correctly to a variant.');
-
- // Test loading of a simple library with a top-level files property.
- $this->drupalGet('libraries_test/files');
- $this->assertLibraryFiles('example_1', 'File loading');
-
- // Test loading of integration files.
- $this->drupalGet('libraries_test/integration_files');
- $this->assertRaw('libraries_test.js', 'Integration file loading: libraries_test.js found');
- $this->assertRaw('libraries_test.css', 'Integration file loading: libraries_test.css found');
- $this->assertRaw('libraries_test.inc', 'Integration file loading: libraries_test.inc found');
-
- // Test version overloading.
- $this->drupalGet('libraries_test/versions');
- $this->assertLibraryFiles('example_2', 'Version overloading');
-
- // Test variant loading.
- $this->drupalGet('libraries_test/variant');
- $this->assertLibraryFiles('example_3', 'Variant loading');
-
- // Test version overloading and variant loading.
- $this->drupalGet('libraries_test/versions_and_variants');
- $this->assertLibraryFiles('example_4', 'Concurrent version and variant overloading');
- }
-
- /**
- * Helper function to assert that a library was correctly loaded.
- *
- * Asserts that all the correct files were loaded and all the incorrect ones
- * were not.
- *
- * @param $name
- * The name of the files that should be loaded. The current testing system
- * knows of 'example_1', 'example_2', 'example_3' and 'example_4'. Each name
- * has an associated JavaScript, CSS and PHP file that will be asserted. All
- * other files will be asserted to not be loaded. See
- * tests/example/README.txt for more information on how the loading of the
- * files is tested.
- * @param $label
- * (optional) A label to prepend to the assertion messages, to make them
- * less ambiguous.
- * @param $extensions
- * (optional) The expected file extensions of $name. Defaults to
- * array('js', 'css', 'php').
- */
- function assertLibraryFiles($name, $label = '', $extensions = array('js', 'css', 'php')) {
- $names = drupal_map_assoc(array('example_1', 'example_2', 'example_3', 'example_4'));
- unset($names[$name]);
-
- // Test that the wrong files are not loaded.
- foreach ($names as $filename) {
- foreach ($extensions as $extension) {
- $message = "$filename.$extension not found";
- $message = ($label !== '' ? "$label: $message" : $message);
- $this->assertNoRaw("$filename.$extension", $message);
- }
- }
-
- // Test that the correct files are loaded.
- foreach ($extensions as $extension) {
- $message = "$name.$extension found";
- $message = ($label !== '' ? "$label: $message" : $message);
- $this->assertRaw("$name.$extension", $message);
- }
- }
-
-}
-
+++ /dev/null
-
-/**
- * @file
- * Test CSS file for Libraries loading.
- *
- * Color the 'libraries-test-css' div purple. See README.txt for more
- * information.
- */
-
-.libraries-test-css {
- color: purple;
-}
+++ /dev/null
-<?php
-
-/**
- * @file
- * Test PHP file for Libraries loading.
-
-/**
- * Dummy function to see if this file was loaded.
- */
-function _libraries_test_integration_file() {
-}
+++ /dev/null
-name = Libraries test module
-description = Tests library detection and loading.
-core = 7.x
-dependencies[] = libraries
-hidden = TRUE
+++ /dev/null
-
-/**
- * @file
- * Test JavaScript file for Libraries loading.
- *
- * Replace the text in the 'libraries-test-javascript' div. See README.txt for
- * more information.
- */
-
-(function ($) {
-
-Drupal.behaviors.librariesTest = {
- attach: function(context, settings) {
- $('.libraries-test-javascript').text('If this text shows up, libraries_test.js was loaded successfully.')
- }
-};
-
-})(jQuery);
+++ /dev/null
-<?php
-
-/**
- * @file
- * Tests the library detection and loading.
- */
-
-/**
- * Implements hook_libraries_info().
- */
-function libraries_test_libraries_info() {
- // Test library detection.
- $libraries['example_missing'] = array(
- 'name' => 'Example missing',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/missing',
- );
- $libraries['example_undetected_version'] = array(
- 'name' => 'Example undetected version',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests',
- 'version callback' => '_libraries_test_return_version',
- 'version arguments' => array(FALSE),
- );
- $libraries['example_unsupported_version'] = array(
- 'name' => 'Example unsupported version',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests',
- 'version callback' => '_libraries_test_return_version',
- 'version arguments' => array('1'),
- 'versions' => array(
- '2' => array(),
- ),
- );
-
- $libraries['example_supported_version'] = array(
- 'name' => 'Example supported version',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests',
- 'version callback' => '_libraries_test_return_version',
- 'version arguments' => array('1'),
- 'versions' => array(
- '1' => array(),
- ),
- );
-
- // Test the default version callback.
- $libraries['example_default_version_callback'] = array(
- 'name' => 'Example default version callback',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- 'version arguments' => array(
- 'file' => 'README.txt',
- // Version 1
- 'pattern' => '/Version (\d+)/',
- 'lines' => 5,
- ),
- );
-
- // Test a multiple-parameter version callback.
- $libraries['example_multiple_parameter_version_callback'] = array(
- 'name' => 'Example multiple parameter version callback',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- // Version 1
- 'version callback' => '_libraries_test_get_version',
- 'version arguments' => array('README.txt', '/Version (\d+)/', 5),
- );
-
- // Test a top-level files property.
- $libraries['example_files'] = array(
- 'name' => 'Example files',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- 'version' => '1',
- 'files' => array(
- 'js' => array('example_1.js'),
- 'css' => array('example_1.css'),
- 'php' => array('example_1.php'),
- ),
- );
-
- // Test loading of integration files.
- // Normally added by the corresponding module via hook_libraries_info_alter(),
- // these files should be automatically loaded when the library is loaded.
- $libraries['example_integration_files'] = array(
- 'name' => 'Example integration files',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- 'version' => '1',
- 'integration files' => array(
- 'libraries_test' => array(
- 'js' => array('libraries_test.js'),
- 'css' => array('libraries_test.css'),
- 'php' => array('libraries_test.inc'),
- ),
- ),
- );
-
- // Test version overloading.
- $libraries['example_versions'] = array(
- 'name' => 'Example versions',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- 'version' => '2',
- 'versions' => array(
- '1' => array(
- 'files' => array(
- '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'),
- ),
- ),
- ),
- );
-
- // Test variant detection.
- $libraries['example_variant_missing'] = array(
- 'name' => 'Example variant missing',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- 'version' => '1',
- 'variants' => array(
- 'example_variant' => array(
- 'files' => array(
- '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),
- ),
- ),
- );
-
- $libraries['example_variant'] = array(
- 'name' => 'Example variant',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- 'version' => '1',
- 'variants' => array(
- 'example_variant' => array(
- 'files' => array(
- '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),
- ),
- ),
- );
-
- // Test correct behaviour with multiple versions and multiple variants.
- $libraries['example_versions_and_variants'] = array(
- 'name' => 'Example versions and variants',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- 'version' => '2',
- 'versions' => array(
- '1' => array(
- 'variants' => array(
- 'example_variant_1' => array(
- 'files' => array(
- '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'),
- ),
- 'variant callback' => '_libraries_test_return_installed',
- 'variant arguments' => array(TRUE),
- ),
- ),
- ),
- '2' => array(
- 'variants' => array(
- 'example_variant_1' => array(
- 'files' => array(
- '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'),
- ),
- 'variant callback' => '_libraries_test_return_installed',
- 'variant arguments' => array(TRUE),
- ),
- ),
- ),
- ),
- );
-
- // Test the applying of callbacks.
- $libraries['example_callback'] = array(
- 'name' => 'Example callback',
- 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
- 'version' => '1',
- 'versions' => array(
- '1' => array(
- 'variants' => array(
- 'example_variant' => array(
- // These keys are for testing purposes only.
- 'info callback' => 'not applied',
- 'pre-detect callback' => 'not applied',
- 'post-detect callback' => 'not applied',
- 'load callback' => 'not applied',
- ),
- ),
- // These keys are for testing purposes only.
- 'info callback' => 'not applied',
- 'pre-detect callback' => 'not applied',
- 'post-detect callback' => 'not applied',
- 'load callback' => 'not applied',
- ),
- ),
- 'variants' => array(
- 'example_variant' => array(
- // These keys are for testing purposes only.
- 'info callback' => 'not applied',
- 'pre-detect callback' => 'not applied',
- 'post-detect callback' => 'not applied',
- 'load callback' => 'not applied',
- ),
- ),
- 'callbacks' => array(
- 'info' => array('_libraries_test_info_callback'),
- 'pre-detect' => array('_libraries_test_pre_detect_callback'),
- 'post-detect' => array('_libraries_test_post_detect_callback'),
- 'load' => array('_libraries_test_load_callback'),
- ),
- // These keys are for testing purposes only.
- 'info callback' => 'not applied',
- 'pre-detect callback' => 'not applied',
- 'post-detect callback' => 'not applied',
- 'load callback' => 'not applied',
- );
-
- return $libraries;
-}
-
-/**
- * Implements hook_libraries_info_file_paths()
- */
-function libraries_test_libraries_info_file_paths() {
- return array(drupal_get_path('module', 'libraries_test') . '/example');
-}
-
-/**
- * Gets the version of an example library.
- *
- * Returns exactly the version string entered as the $version parameter. This
- * function cannot be collapsed with _libraries_test_return_installed(), because
- * of the different arguments that are passed automatically.
- */
-function _libraries_test_return_version($library, $version) {
- return $version;
-}
-
-/**
- * Gets the version information from an arbitrary library.
- *
- * Test function for a version callback with multiple arguments. This is an
- * exact copy of libraries_get_version(), which uses a single $option argument,
- * except for the fact that it uses multiple arguments. Since we support both
- * type of version callbacks, detecting the version of a test library with this
- * function ensures that the arguments are passed correctly. This function might
- * be a useful reference for a custom version callback that uses multiple
- * parameters.
- *
- * @param $library
- * An associative array containing all information about the library.
- * @param $file
- * The filename to parse for the version, relative to the library path. For
- * example: 'docs/changelog.txt'.
- * @param pattern
- * A string containing a regular expression (PCRE) to match the library
- * version. For example: '/@version (\d+)\.(\d+)/'.
- * @param lines
- * (optional) The maximum number of lines to search the pattern in. Defaults
- * to 20.
- * @param cols
- * (optional) The maximum number of characters per line to take into account.
- * Defaults to 200. In case of minified or compressed files, this prevents
- * reading the entire file into memory.
- *
- * @return
- * A string containing the version of the library.
- *
- * @see libraries_get_version()
- */
-function _libraries_test_get_version($library, $file, $pattern, $lines = 20, $cols = 200) {
-
- $file = DRUPAL_ROOT . '/' . $library['library path'] . '/' . $file;
- if (!file_exists($file)) {
- return;
- }
- $file = fopen($file, 'r');
- while ($lines && $line = fgets($file, $cols)) {
- if (preg_match($pattern, $line, $version)) {
- fclose($file);
- return $version[1];
- }
- $lines--;
- }
- fclose($file);
-}
-
-/**
- * Detects the variant of an example library.
- *
- * Returns exactly the value of $installed, either TRUE or FALSE. This function
- * cannot be collapsed with _libraries_test_return_version(), because of the
- * different arguments that are passed automatically.
- */
-function _libraries_test_return_installed($library, $name, $installed) {
- return $installed;
-}
-
-/**
- * Sets the 'info callback' key.
- *
- * This function is used as a test callback for the 'info' callback group.
- *
- * @see _libraries_test_callback()
- */
-function _libraries_test_info_callback(&$library, $version, $variant) {
- _libraries_test_callback($library, $version, $variant, 'info');
-}
-
-/**
- * Sets the 'pre-detect callback' key.
- *
- * This function is used as a test callback for the 'pre-detect' callback group.
- *
- * @see _libraries_test_callback()
- */
-function _libraries_test_pre_detect_callback(&$library, $version, $variant) {
- _libraries_test_callback($library, $version, $variant, 'pre-detect');
-}
-
-/**
- * Sets the 'post-detect callback' key.
- *
- * This function is used as a test callback for the 'post-detect callback group.
- *
- * @see _libraries_test_callback()
- */
-function _libraries_test_post_detect_callback(&$library, $version, $variant) {
- _libraries_test_callback($library, $version, $variant, 'post-detect');
-}
-
-/**
- * Sets the 'load callback' key.
- *
- * This function is used as a test callback for the 'load' callback group.
- *
- * @see _libraries_test_callback()
- */
-function _libraries_test_load_callback(&$library, $version, $variant) {
- _libraries_test_callback($library, $version, $variant, 'load');
-}
-
-/**
- * Sets the '[group] callback' key, where [group] is prepare, detect, or load.
- *
- * This function is used as a test callback for the all callback groups.
- *
- * It sets the '[group] callback' (see above) key to 'applied ([part])' where
- * [part] is either 'top-level', 'version x.y' (where x.y is the passed-in
- * version string), 'variant example' (where example is the passed-in variant
- * name), or 'version x.y, variant example' (see above), depending on the part
- * of the library the passed-in library information belongs to.
- *
- * @param $library
- * An array of library information, which may be version- or variant-specific.
- * Passed by reference.
- * @param $version
- * The version the library information passed in $library belongs to, or NULL
- * if the passed library information is not version-specific.
- * @param $variant
- * The variant the library information passed in $library belongs to, or NULL
- * if the passed library information is not variant-specific.
- */
-function _libraries_test_callback(&$library, $version, $variant, $group) {
- $string = 'applied';
- if (isset($version) && isset($variant)) {
- $string .= " (version $version, variant $variant)";
- }
- elseif (isset($version)) {
- $string .= " (version $version)";
- }
- elseif (isset($variant)) {
- $string .= " (variant $variant)";
- }
- else {
- $string .= ' (top-level)';
- }
- $library["$group callback"] = $string;
-}
-
-/**
- * Implements hook_menu().
- */
-function libraries_test_menu() {
- $items['libraries_test/files'] = array(
- 'title' => 'Test files',
- 'page callback' => '_libraries_test_load',
- 'page arguments' => array('example_files'),
- 'access callback' => TRUE,
- );
- $items['libraries_test/integration_files'] = array(
- 'title' => 'Test integration files',
- 'page callback' => '_libraries_test_load',
- 'page arguments' => array('example_integration_files'),
- 'access callback' => TRUE,
- );
- $items['libraries_test/versions'] = array(
- 'title' => 'Test version loading',
- 'page callback' => '_libraries_test_load',
- 'page arguments' => array('example_versions'),
- 'access callback' => TRUE,
- );
- $items['libraries_test/variant'] = array(
- 'title' => 'Test variant loading',
- 'page callback' => '_libraries_test_load',
- 'page arguments' => array('example_variant', 'example_variant'),
- 'access callback' => TRUE,
- );
- $items['libraries_test/versions_and_variants'] = array(
- 'title' => 'Test concurrent version and variant loading',
- 'page callback' => '_libraries_test_load',
- 'page arguments' => array('example_versions_and_variants', 'example_variant_2'),
- 'access callback' => TRUE,
- );
- return $items;
-}
-
-/**
- * Loads a specified library (variant) for testing.
- *
- * JavaScript and CSS files can be checked directly by SimpleTest, so we only
- * need to manually check for PHP files. We provide information about the loaded
- * JavaScript and CSS files for easier debugging. See example/README.txt for
- * more information.
- */
-function _libraries_test_load($library, $variant = NULL) {
- libraries_load($library, $variant);
- // JavaScript and CSS files can be checked directly by SimpleTest, so we only
- // need to manually check for PHP files.
- $output = '';
-
- // For easer debugging of JS loading, a text is shown that the JavaScript will
- // replace.
- $output .= '<h2>JavaScript</h2>';
- $output .= '<div class="libraries-test-javascript">';
- $output .= 'If this text shows up, no JavaScript test file was loaded.';
- $output .= '</div>';
-
- // For easier debugging of CSS loading, the loaded CSS files will color the
- // following text.
- $output .= '<h2>CSS</h2>';
- $output .= '<div class="libraries-test-css">';
- $output .= 'If one of the CSS test files has been loaded, this text will be colored:';
- $output .= '<ul>';
- // Do not reference the actual CSS files (i.e. including '.css'), because that
- // breaks testing.
- $output .= '<li>example_1: red</li>';
- $output .= '<li>example_2: green</li>';
- $output .= '<li>example_3: orange</li>';
- $output .= '<li>example_4: blue</li>';
- $output .= '<li>libraries_test: purple</li>';
- $output .= '</ul>';
- $output .= '</div>';
-
- $output .= '<h2>PHP</h2>';
- $output .= '<div class="libraries-test-php">';
- $output .= 'The following is a list of all loaded test PHP files:';
- $output .= '<ul>';
- $files = get_included_files();
- foreach ($files as $file) {
- if (strpos($file, 'libraries/test') && !strpos($file, 'libraries_test.module')) {
- $output .= '<li>' . strstr($file, 'libraries/test') . '</li>';
- }
- }
- $output .= '</ul>';
- $output .= '</div>';
-
- return $output;
-}