function LibrariesTestCase::testLibrariesDetect in Libraries API 7.3
Tests libraries_detect().
File
- tests/
libraries.test, line 229 - Tests for Libraries API.
Class
- LibrariesTestCase
- Tests basic detection and loading of libraries.
Code
function testLibrariesDetect() {
// 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.');
}