function libraries_test_libraries_info in Libraries API 8.3
Implements hook_libraries_info().
File
- tests/
modules/ libraries_test/ libraries_test.module, line 14 - Tests the library detection and loading.
Code
function libraries_test_libraries_info() {
// Test library detection.
$libraries['example_missing'] = [
'name' => 'Example missing',
'library path' => drupal_get_path('module', 'libraries') . '/tests/missing',
];
$libraries['example_undetected_version'] = [
'name' => 'Example undetected version',
'library path' => drupal_get_path('module', 'libraries') . '/tests',
'version callback' => '_libraries_test_return_version',
'version arguments' => [
FALSE,
],
];
$libraries['example_unsupported_version'] = [
'name' => 'Example unsupported version',
'library path' => drupal_get_path('module', 'libraries') . '/tests',
'version callback' => '_libraries_test_return_version',
'version arguments' => [
'1',
],
'versions' => [
'2' => [],
],
];
$libraries['example_supported_version'] = [
'name' => 'Example supported version',
'library path' => drupal_get_path('module', 'libraries') . '/tests',
'version callback' => '_libraries_test_return_version',
'version arguments' => [
'1',
],
'versions' => [
'1' => [],
],
];
// Test the default version callback.
$libraries['example_default_version_callback'] = [
'name' => 'Example default version callback',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version arguments' => [
'file' => 'README.txt',
// Version 1
'pattern' => '/Version (\\d+)/',
'lines' => 5,
],
];
// Test a multiple-parameter version callback.
$libraries['example_multiple_parameter_version_callback'] = [
'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' => [
'README.txt',
'/Version (\\d+)/',
5,
],
];
// Test a top-level files property.
$libraries['example_files'] = [
'name' => 'Example files',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '1',
'files' => [
'js' => [
'example_1.js',
],
'css' => [
'example_1.css',
],
'php' => [
'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'] = [
'name' => 'Example integration files',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '1',
'integration files' => [
'libraries_test' => [
'js' => [
'libraries_test.js',
],
'css' => [
'libraries_test.css',
],
'php' => [
'libraries_test.inc',
],
],
],
];
// Test version overloading.
$libraries['example_versions'] = [
'name' => 'Example versions',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '2',
'versions' => [
'1' => [
'files' => [
'js' => [
'example_1.js',
],
'css' => [
'example_1.css',
],
'php' => [
'example_1.php',
],
],
],
'2' => [
'files' => [
'js' => [
'example_2.js',
],
'css' => [
'example_2.css',
],
'php' => [
'example_2.php',
],
],
],
],
];
// Test variant detection.
$libraries['example_variant_missing'] = [
'name' => 'Example variant missing',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '1',
'variants' => [
'example_variant' => [
'files' => [
'js' => [
'example_3.js',
],
'css' => [
'example_3.css',
],
'php' => [
'example_3.php',
],
],
'variant callback' => '_libraries_test_return_installed',
'variant arguments' => [
FALSE,
],
],
],
];
$libraries['example_variant'] = [
'name' => 'Example variant',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '1',
'variants' => [
'example_variant' => [
'files' => [
'js' => [
'example_3.js',
],
'css' => [
'example_3.css',
],
'php' => [
'example_3.php',
],
],
'variant callback' => '_libraries_test_return_installed',
'variant arguments' => [
TRUE,
],
],
],
];
// Test correct behaviour with multiple versions and multiple variants.
$libraries['example_versions_and_variants'] = [
'name' => 'Example versions and variants',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '2',
'versions' => [
'1' => [
'variants' => [
'example_variant_1' => [
'files' => [
'js' => [
'example_1.js',
],
'css' => [
'example_1.css',
],
'php' => [
'example_1.php',
],
],
'variant callback' => '_libraries_test_return_installed',
'variant arguments' => [
TRUE,
],
],
'example_variant_2' => [
'files' => [
'js' => [
'example_2.js',
],
'css' => [
'example_2.css',
],
'php' => [
'example_2.php',
],
],
'variant callback' => '_libraries_test_return_installed',
'variant arguments' => [
TRUE,
],
],
],
],
'2' => [
'variants' => [
'example_variant_1' => [
'files' => [
'js' => [
'example_3.js',
],
'css' => [
'example_3.css',
],
'php' => [
'example_3.php',
],
],
'variant callback' => '_libraries_test_return_installed',
'variant arguments' => [
TRUE,
],
],
'example_variant_2' => [
'files' => [
'js' => [
'example_4.js',
],
'css' => [
'example_4.css',
],
'php' => [
'example_4.php',
],
],
'variant callback' => '_libraries_test_return_installed',
'variant arguments' => [
TRUE,
],
],
],
],
],
];
// Test dependency loading.
// We add one file to each library to be able to verify if it was loaded with
// libraries_load().
// This library acts as a dependency for the libraries below.
$libraries['example_dependency'] = [
'name' => 'Example dependency',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '1.1',
'files' => [
'js' => [
'example_1.js',
],
],
];
$libraries['example_dependency_missing'] = [
'name' => 'Example dependency missing',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '1',
'dependencies' => [
'example_missing',
],
'files' => [
'js' => [
'example_1.js',
],
],
];
$libraries['example_dependency_incompatible'] = [
'name' => 'Example dependency incompatible',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '1',
'dependencies' => [
'example_dependency (>1.1)',
],
'files' => [
'js' => [
'example_1.js',
],
],
];
$libraries['example_dependency_compatible'] = [
'name' => 'Example dependency compatible',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '1',
'dependencies' => [
'example_dependency (>=1.1)',
],
'files' => [
'js' => [
'example_1.js',
],
],
];
// Test the applying of callbacks.
$libraries['example_callback'] = [
'name' => 'Example callback',
'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
'version' => '1',
'versions' => [
'1' => [
'variants' => [
'example_variant' => [
// These keys are for testing purposes only.
'info callback' => 'not applied',
'pre-detect callback' => 'not applied',
'post-detect callback' => 'not applied',
'pre-load callback' => 'not applied',
'post-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',
'pre-load callback' => 'not applied',
'post-load callback' => 'not applied',
],
],
'variants' => [
'example_variant' => [
// These keys are for testing purposes only.
'info callback' => 'not applied',
'pre-detect callback' => 'not applied',
'post-detect callback' => 'not applied',
'pre-load callback' => 'not applied',
'post-load callback' => 'not applied',
],
],
'callbacks' => [
'info' => [
'_libraries_test_info_callback',
],
'pre-detect' => [
'_libraries_test_pre_detect_callback',
],
'post-detect' => [
'_libraries_test_post_detect_callback',
],
'pre-load' => [
'_libraries_test_pre_load_callback',
],
'post-load' => [
'_libraries_test_post_load_callback',
],
],
// These keys are for testing purposes only.
'info callback' => 'not applied',
'pre-detect callback' => 'not applied',
'post-detect callback' => 'not applied',
'pre-load callback' => 'not applied',
'post-load callback' => 'not applied',
];
return $libraries;
}