'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), ), ), ), ), ); // This library is used together with libraries_info() to be populated with // the defaults. $libraries['example_empty'] = array(); 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; } /** * 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 .= '