Skip to content
Snippets Groups Projects
Commit 4c4321a4 authored by Tobias Zimmermann's avatar Tobias Zimmermann
Browse files

Issue #1167496 by tstoeckler, benshell: Port to Drupal 8.

parent e563e65b
No related branches found
No related tags found
No related merge requests found
Libraries 8.x-3.x, xxxx-xx-xx
-----------------------------
#1167496 by tstoeckler, benshell: Port to Drupal 8.
Libraries 7.x-3.x, xxxx-xx-xx
-----------------------------
#1775668 by tstoeckler: Fix bogus assertion message in assertLibraryFiles().
......
<?php
/**
* @file
* Definition of \Drupal\libraries\Tests\LibrariesUnitTest.
*/
namespace Drupal\libraries\Tests;
use \Drupal\simpletest\UnitTestBase;
/**
* Tests basic Libraries API functions.
*/
class LibrariesUnitTest extends UnitTestBase {
public static function getInfo() {
return array(
'name' => 'Libraries API unit tests',
'description' => 'Tests basic functions provided by Libraries API.',
'group' => 'Libraries API',
);
}
function setUp() {
drupal_load('module', 'libraries');
parent::setUp();
}
/**
* Tests libraries_get_path().
*/
function testLibrariesGetPath() {
// Note that, even though libraries_get_path() doesn't find the 'example'
// library, we are able to make it 'installed' by specifying the 'library
// path' up-front. This is only used for testing purposed and is strongly
// discouraged as it defeats the purpose of Libraries API in the first
// place.
$this->assertEqual(libraries_get_path('example'), FALSE, 'libraries_get_path() returns FALSE for a missing library.');
}
/**
* Tests libraries_prepare_files().
*/
function testLibrariesPrepareFiles() {
$expected = array(
'files' => array(
'js' => array('example.js' => array()),
'css' => array('example.css' => array()),
'php' => array('example.php' => array()),
),
);
$library = array(
'files' => array(
'js' => array('example.js'),
'css' => array('example.css'),
'php' => array('example.php'),
),
);
libraries_prepare_files($library, NULL, NULL);
$this->assertEqual($expected, $library, 'libraries_prepare_files() works correctly.');
}
}
This diff is collapsed.
name = Libraries
description = Allows version-dependent and shared usage of external libraries.
core = 7.x
files[] = tests/libraries.test
core = 8.x
......@@ -13,15 +13,3 @@ function libraries_schema() {
$schema['cache_libraries']['description'] = 'Cache table to store library information.';
return $schema;
}
/**
* Create the 'cache_libraries' table.
*/
function libraries_update_7200() {
// Note that previous versions of this function created the table with a
// different table comment.
if (!db_table_exists('cache_libraries')) {
$specs = libraries_schema();
db_create_table('cache_libraries', $specs['cache_libraries']);
}
}
......@@ -9,12 +9,7 @@
* Implements hook_flush_caches().
*/
function libraries_flush_caches() {
// @todo When upgrading from 1.x, update.php attempts to flush caches before
// the cache table has been created.
// @see http://drupal.org/node/1477932
if (db_table_exists('cache_libraries')) {
return array('cache_libraries');
}
return array('cache_libraries');
}
/**
......@@ -69,19 +64,19 @@ function libraries_get_libraries() {
$profile = drupal_get_path('profile', drupal_get_profile());
$config = conf_path();
// Similar to 'modules' and 'themes' directories in the root directory,
// certain distributions may want to place libraries into a 'libraries'
// directory in Drupal's root directory.
$searchdir[] = 'libraries';
// @todo core/libraries
// Similar to 'modules' and 'themes' directories inside an installation
// profile, installation profiles may want to place libraries into a
// 'libraries' directory.
$searchdir[] = "$profile/libraries";
// Always search sites/all/libraries.
// Search sites/all/libraries for backwards-compatibility.
$searchdir[] = 'sites/all/libraries';
// Always search the root 'libraries' directory.
$searchdir[] = 'libraries';
// Also search sites/<domain>/*.
$searchdir[] = "$config/libraries";
......@@ -124,9 +119,9 @@ function libraries_scan_info_files() {
// Build a list of directories.
$directories = module_invoke_all('libraries_info_file_paths');
$directories[] = 'libraries';
$directories[] = "$profile/libraries";
$directories[] = 'sites/all/libraries';
$directories[] = 'libraries';
$directories[] = "$config/libraries";
// Scan for info files.
......@@ -590,15 +585,14 @@ function libraries_load($name, $variant = NULL) {
$loaded = &drupal_static(__FUNCTION__, array());
if (!isset($loaded[$name])) {
$library = cache_get($name, 'cache_libraries');
$library = cache('libraries')->get($name);
if ($library) {
$library = $library->data;
}
else {
$library = libraries_detect($name);
cache_set($name, $library, 'cache_libraries');
cache('libraries')->set($name, $library);
}
// If a variant was specified, override the top-level properties with the
// variant properties.
if (isset($variant)) {
......
name = Libraries test module
description = Tests library detection and loading.
core = 7.x
core = 8.x
dependencies[] = libraries
hidden = TRUE
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment