Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
L
libraries
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
libraries
Commits
88e17104
Commit
88e17104
authored
Oct 15, 2010
by
Tobias Stoeckler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#864376
by tstoeckler, sun: Code-cleanup, allow hard-coded 'version'
parent
e0e885bf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
108 deletions
+79
-108
CHANGELOG.txt
CHANGELOG.txt
+2
-1
libraries.module
libraries.module
+25
-18
tests/example/libraries_example.info
tests/example/libraries_example.info
+1
-0
tests/libraries.test
tests/libraries.test
+12
-8
tests/libraries_test.module
tests/libraries_test.module
+39
-81
No files found.
CHANGELOG.txt
View file @
88e17104
...
...
@@ -6,7 +6,8 @@ Libraries x.x-x.x, xxxx-xx-xx
Libraries 7.x-1.x, xxxx-xx-xx
-----------------------------
#939174 by sun, tstoeckler: Rename example.info to libraries_example.info
#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.
...
...
libraries.module
View file @
88e17104
...
...
@@ -265,20 +265,22 @@ function libraries_detect_library(&$library) {
return
;
}
// Detect 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 %library could not be detected.'
,
array
(
'%library'
=>
$library
[
'title'
]));
return
;
// 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 %library could not be detected.'
,
array
(
'%library'
=>
$library
[
'title'
]));
return
;
}
}
// Determine to which supported version the installed version maps.
...
...
@@ -346,7 +348,11 @@ function libraries_detect_library(&$library) {
function
libraries_load
(
$library
,
$variant
=
NULL
)
{
$library
=
libraries_info
(
$library
);
libraries_detect_library
(
$library
);
libraries_load_files
(
$library
,
$variant
);
if
(
$library
[
'installed'
])
{
libraries_load_files
(
$library
,
$variant
);
return
TRUE
;
}
return
FALSE
;
}
/**
...
...
@@ -359,7 +365,7 @@ function libraries_load($library, $variant = NULL) {
*/
function
libraries_load_files
(
$library
,
$variant
=
NULL
)
{
// Construct the full path to the library for later use.
$path
=
!
empty
(
$library
[
'path'
])
?
$library
[
'library path'
]
.
'/'
.
$library
[
'path'
]
:
$library
[
'library path'
]
;
$path
=
(
!
empty
(
$library
[
'path'
])
?
$library
[
'library path'
]
.
'/'
.
$library
[
'path'
]
:
$library
[
'library path'
])
;
// If a variant was specified, override the top-level properties with the
// variant properties.
...
...
@@ -391,8 +397,9 @@ function libraries_load_files($library, $variant = NULL) {
$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.
// 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'
]);
...
...
tests/example/libraries_example.info
View file @
88e17104
...
...
@@ -3,6 +3,7 @@
; This is an example info file of a library used for testing purposes.
; Do not declare name manually. It is set automatically.
name = example_info_file
title = Example info file
; Because Drupal thinks this is a module's .info file, it is in the 'libraries'
; namespace, in order to not cause problems with other modules named 'example'.
...
...
tests/libraries.test
View file @
88e17104
...
...
@@ -49,27 +49,30 @@ class LibrariesTestCase extends DrupalWebTestCase {
// Test missing library.
$library
=
libraries_info
(
'example_missing'
);
libraries_detect_library
(
$library
);
$error
=
t
(
'%library could not be found.'
,
array
(
$this
->
assertEqual
(
$library
[
'error'
],
'not found'
,
'Non-existing library not found.'
);
$error_message
=
t
(
'%library could not be found.'
,
array
(
'%library'
=>
$library
[
'title'
],
));
$this
->
assertEqual
(
$library
[
'error message'
],
$error
,
'Non-existing library not found
.'
);
$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
);
$error
=
t
(
'The version of %library could not be detected.'
,
array
(
$this
->
assertEqual
(
$library
[
'error'
],
'not detected'
,
'Library version not found.'
);
$error_message
=
t
(
'The version of %library could not be detected.'
,
array
(
'%library'
=>
$library
[
'title'
],
));
$this
->
assertEqual
(
$library
[
'error message'
],
$error
,
'Library version not found
.'
);
$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
);
$error
=
t
(
'The installed version %version of %library is not supported.'
,
array
(
$this
->
assertEqual
(
$library
[
'error'
],
'not supported'
,
'Library version not supported.'
);
$error_message
=
t
(
'The installed version %version of %library is not supported.'
,
array
(
'%version'
=>
$library
[
'version'
],
'%library'
=>
$library
[
'title'
],
));
$this
->
assertEqual
(
$library
[
'error message'
],
$error
,
'Unsupported library version found
.'
);
$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'
);
...
...
@@ -112,11 +115,12 @@ class LibrariesTestCase extends DrupalWebTestCase {
$library
=
libraries_info
(
'example_variant_missing'
);
libraries_detect_library
(
$library
);
$variants
=
array_keys
(
$library
[
'variants'
]);
$error
=
t
(
'The %variant variant of %library could not be found.'
,
array
(
$this
->
assertEqual
(
$library
[
'variants'
][
'example_variant'
][
'error'
],
'not found'
,
'Missing variant not found'
);
$error_message
=
t
(
'The %variant variant of %library could not be found.'
,
array
(
'%variant'
=>
$variants
[
0
],
'%library'
=>
$library
[
'title'
],
));
$this
->
assertEqual
(
$library
[
'variants'
][
'example_variant'
][
'error message'
],
$error
,
'Missing variant not found
.'
);
$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'
);
...
...
tests/libraries_test.module
View file @
88e17104
...
...
@@ -12,18 +12,21 @@
function
libraries_test_libraries_info
()
{
// Test library detection.
$libraries
[
'example_missing'
]
=
array
(
'title'
=>
'Example missing'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests/missing'
,
'version callback'
=>
'_libraries_test_return_version'
,
'version arguments'
=>
array
(
'1'
),
);
$libraries
[
'example_undetected_version'
]
=
array
(
'title'
=>
'Example undetected version'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests'
,
'version callback'
=>
'_libraries_test_return_version'
,
'version arguments'
=>
array
(
FALSE
),
);
$libraries
[
'example_unsupported_version'
]
=
array
(
'title'
=>
'Example unsupported version'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests'
,
'version callback'
=>
'_libraries_test_return_version'
,
...
...
@@ -34,6 +37,7 @@ function libraries_test_libraries_info() {
);
$libraries
[
'example_supported_version'
]
=
array
(
'title'
=>
'Example supported version'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests'
,
'version callback'
=>
'_libraries_test_return_version'
,
...
...
@@ -45,6 +49,7 @@ function libraries_test_libraries_info() {
// Test the default version callback.
$libraries
[
'example_default_version_callback'
]
=
array
(
'title'
=>
'Example default version callback'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests/example'
,
'version arguments'
=>
array
(
...
...
@@ -57,6 +62,7 @@ function libraries_test_libraries_info() {
// Test a multiple-parameter version callback.
$libraries
[
'example_multiple_parameter_version_callback'
]
=
array
(
'title'
=>
'Example_multiple_parameter_version_callback'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests/example'
,
// Version 2
...
...
@@ -66,6 +72,7 @@ function libraries_test_libraries_info() {
// Test a top-level files property.
$libraries
[
'example_simple'
]
=
array
(
'title'
=>
'Example simple'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests/example'
,
'version callback'
=>
'_libraries_test_return_version'
,
...
...
@@ -87,27 +94,23 @@ function libraries_test_libraries_info() {
// 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
(
'title'
=>
'Example integration files'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests/example'
,
'version callback'
=>
'_libraries_test_return_version'
,
'version arguments'
=>
array
(
'2'
),
'integration files'
=>
array
(
'libraries_test'
=>
array
(
'js'
=>
array
(
'libraries_test.js'
,
),
'css'
=>
array
(
'libraries_test.css'
,
),
'php'
=>
array
(
'libraries_test.inc'
,
),
'js'
=>
array
(
'libraries_test.js'
),
'css'
=>
array
(
'libraries_test.css'
),
'php'
=>
array
(
'libraries_test.inc'
),
),
),
);
// Test version overloading.
$libraries
[
'example_versions'
]
=
array
(
'title'
=>
'Example versions'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests/example'
,
'version callback'
=>
'_libraries_test_return_version'
,
...
...
@@ -115,28 +118,16 @@ function libraries_test_libraries_info() {
'versions'
=>
array
(
'1'
=>
array
(
'files'
=>
array
(
'js'
=>
array
(
'example_1.js'
,
),
'css'
=>
array
(
'example_1.css'
,
),
'php'
=>
array
(
'example_1.php'
,
),
'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'
,
),
'js'
=>
array
(
'example_2.js'
),
'css'
=>
array
(
'example_2.css'
),
'php'
=>
array
(
'example_2.php'
),
),
),
),
...
...
@@ -144,6 +135,7 @@ function libraries_test_libraries_info() {
// Test variant detection.
$libraries
[
'example_variant_missing'
]
=
array
(
'title'
=>
'Example variant missing'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests/example'
,
'version callback'
=>
'_libraries_test_return_version'
,
...
...
@@ -151,15 +143,9 @@ function libraries_test_libraries_info() {
'variants'
=>
array
(
'example_variant'
=>
array
(
'files'
=>
array
(
'js'
=>
array
(
'example_3.js'
,
),
'css'
=>
array
(
'example_3.css'
,
),
'php'
=>
array
(
'example_3.php'
,
),
'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
),
...
...
@@ -168,6 +154,7 @@ function libraries_test_libraries_info() {
);
$libraries
[
'example_variant'
]
=
array
(
'title'
=>
'Example variant'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests/example'
,
'version callback'
=>
'_libraries_test_return_version'
,
...
...
@@ -175,15 +162,9 @@ function libraries_test_libraries_info() {
'variants'
=>
array
(
'example_variant'
=>
array
(
'files'
=>
array
(
'js'
=>
array
(
'example_3.js'
,
),
'css'
=>
array
(
'example_3.css'
,
),
'php'
=>
array
(
'example_3.php'
,
),
'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
),
...
...
@@ -193,6 +174,7 @@ function libraries_test_libraries_info() {
// Test correct behaviour with multiple versions and multiple variants.
$libraries
[
'example_versions_and_variants'
]
=
array
(
'title'
=>
'Example versions and variants'
,
// Never declare library path manually. It is detected automatically.
'library path'
=>
drupal_get_path
(
'module'
,
'libraries'
)
.
'/tests/example'
,
'version callback'
=>
'_libraries_test_return_version'
,
...
...
@@ -202,30 +184,18 @@ function libraries_test_libraries_info() {
'variants'
=>
array
(
'example_variant_1'
=>
array
(
'files'
=>
array
(
'js'
=>
array
(
'example_1.js'
,
),
'css'
=>
array
(
'example_1.css'
,
),
'php'
=>
array
(
'example_1.php'
,
),
'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'
,
),
'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
),
...
...
@@ -236,30 +206,18 @@ function libraries_test_libraries_info() {
'variants'
=>
array
(
'example_variant_1'
=>
array
(
'files'
=>
array
(
'js'
=>
array
(
'example_3.js'
,
),
'css'
=>
array
(
'example_3.css'
,
),
'php'
=>
array
(
'example_3.php'
,
),
'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'
,
),
'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
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment