Commit 9ee03ffe authored by sun's avatar sun

Preparing new release.

parent dbb7c2d4
......@@ -2,31 +2,11 @@
Libraries 7.x-1.x, xxxx-xx-xx
-----------------------------
#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().
#743522 by sun: Ported to D7.
Libraries 6.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
......
This diff is collapsed.
<?php
// $Id$
/**
* @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 = libraries_detect(libraries_info());
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');
}
}
......@@ -2,4 +2,3 @@
name = Libraries
description = Allows version dependent and shared usage of external libraries.
core = 7.x
files[] = tests/libraries.test
This diff is collapsed.
; $Id$
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).
/* $Id$ */
/**
* @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;
}
// $Id$
/**
* @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);
<?php
// $Id$
/**
* @file
* Test PHP file for Libraries loading.
*/
/**
* Dummy function to see if this file was loaded.
*/
function _libraries_test_example_1() {
}
/* $Id$ */
/**
* @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;
}
// $Id$
/**
* @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);
<?php
// $Id$
/**
* @file
* Test PHP file for Libraries loading.
*/
/**
* Dummy function to see if this file was loaded.
*/
function _libraries_test_example_2() {
}
/* $Id$ */
/**
* @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;
}
// $Id$
/**
* @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);
<?php
// $Id$
/**
* @file
* Test PHP file for Libraries loading.
*/
/**
* Dummy function to see if this file was loaded.
*/
function _libraries_test_example_3() {
}
/* $Id$ */
/**
* @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;
}
// $Id$
/**
* @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);
<?php
// $Id$
/**
* @file
* Test PHP file for Libraries loading.
*/
/**
* Dummy function to see if this file was loaded.
*/
function _libraries_test_example_4() {
}
; $Id$
; This is an example info file of a library used for testing purposes.
name = Example info file
<?php
// $Id$
/**
* @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 that library information is found correctly.
$expected = array_merge(libraries_info('example_empty'), array(
'machine name' => 'example_files',
'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'),
),
));
$library = libraries_info('example_files');
$this->verbose(var_export($expected, TRUE));
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library, $expected, 'Library information is correctly gathered.');
// Test a library specified with an .info file gets detected.
$expected = array_merge(libraries_info('example_empty'), array(
'machine name' => 'example_info_file',
'name' => 'Example info file',
'info file' => drupal_get_path('module', 'libraries_test') . '/example/example_info_file.libraries.info',
));
unset($expected['module']);
$library = libraries_info('example_info_file');
$this->verbose(var_export($expected, TRUE));
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library, $expected, 'Library specified with an .info file found');
// Test missing library.
$library = libraries_info('example_missing');
libraries_detect_library($library);
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['error'], 'not found', 'Missing library not found.');
$error_message = t('The %library library could not be found.', array(
'%library' => $library['name'],
));
$this->assertEqual($library['error message'], $error_message, 'Correct error message for a missing library.');
// Test unknown library version.
$library = libraries_info('example_undetected_version');
libraries_detect_library($library);
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['error'], 'not detected', 'Undetected version detected as such.');
$error_message = t('The version of the %library library could not be detected.', array(
'%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_info('example_unsupported_version');
libraries_detect_library($library);
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['error'], 'not supported', 'Unsupported version detected as such.');
$error_message = t('The installed version %version of the %library library is not supported.', array(
'%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_info('example_supported_version');
libraries_detect_library($library);
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['installed'], TRUE, 'Supported library version found.');
// Test libraries_get_version().
$library = libraries_info('example_default_version_callback');
libraries_detect_library($library);
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['version'], '1', 'Expected version returned by default version callback.');
// Test a multiple-parameter version callback.
$library = libraries_info('example_multiple_parameter_version_callback');
libraries_detect_library($library);
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['version'], '1', 'Expected version returned by multiple parameter version callback.');
// Test a top-level files property.
$library = libraries_info('example_files');
libraries_detect_library($library);
$files = array(
'js' => array('example_1.js'),
'css' => array('example_1.css'),
'php' => array('example_1.php'),
);
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['files'], $files, 'Top-level files property works.');
// Test version-specific library files.
$library = libraries_info('example_versions');
libraries_detect_library($library);
$files = array(
'js' => array('example_2.js'),
'css' => array('example_2.css'),
'php' => array('example_2.php'),
);
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['files'], $files, 'Version-specific library files found.');
// Test missing variant.
$library = libraries_info('example_variant_missing');
libraries_detect_library($library);
$variants = array_keys($library['variants']);
$this->verbose(var_export($library, TRUE));
$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' => $variants[0],
'%library' => $library['name'],
));
$this->assertEqual($library['variants']['example_variant']['error message'], $error_message, 'Correct error message for a missing variant.');
// Test existing variant.
$library = libraries_info('example_variant');
libraries_detect_library($library);
$this->verbose(var_export($library, TRUE));
$this->assertEqual($library['variants']['example_variant']['installed'], TRUE, 'Existing variant found.');
// 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);
}
}
}
/* $Id$ */
/**
* @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;
}
<?php
// $Id$
/**
* @file
* Test PHP file for Libraries loading.
/**
* Dummy function to see if this file was loaded.
*/
function _libraries_test_integration_file() {
}
; $Id$
name = Libraries test module
description = Tests library detection and loading.
core = 7.x
dependencies[] = libraries
hidden = TRUE
// $Id$
/**
* @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);
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment