Projet

Général

Profil

Révision 7c856df4

Ajouté par Assos Assos il y a environ 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/libraries/CHANGELOG.txt
1 1

  
2
Libraries 7.x-2.3, 2016-05-12
3
-----------------------------
4
#1884246 by BR0kEN, tstoeckler et al: Allow downloading libraries via Drush.
5
by tstoeckler: Allow detecting all libraries by calling libraries_detect().
6
by tstoeckler: Prevent LibrariesWebTestBase from being displayed in the UI.
7
#819610 by tstoeckler: Add tests for the Libraries UI.
8
#1884246 by BR0kEN, tstoeckler: Show the provider in drush libraries-list
9
#819610 by Pol, tstoeckler: Show the provider in the UI.
10
#2634732 by Rob Holmes, tstoeckler: Sort libraries by title in the UI.
11
#2585395 by robinsonsarah01: Allow object methods as version callbacks.
12
#819610 by tstoeckler, Pol: Provide a status report for library information.
13
#2352251 by netw3rker: Fix incorrect hook name in libraries.api.php.
14
#2352237 by netw3rker, tstoeckler: Allow clearing the libraries cache from Drush.
15
#2193969 by tstoeckler: Avoid warnings for stale library caches.
16
#2287529 by drupalshrek, tstoeckler: Update installation link in README.txt.
17

  
2 18
Libraries 7.x-2.2, 2014-02-09
3 19
-----------------------------
4 20
#2046919 by tstoeckler: Clarify 'version' docs.
drupal7/sites/all/modules/libraries/README.txt
16 16

  
17 17
-- INSTALLATION --
18 18

  
19
* Install as usual, see http://drupal.org/node/70151 for further information.
20
  Note that installing external libraries is separate from installing this
21
  module and should happen in the sites/all/libraries directory. See
22
  http://drupal.org/node/1440066 for more information.
19
* Install as usual, see
20
  https://www.drupal.org/documentation/install/modules-themes/modules-7 for
21
  further information. Note that installing external libraries is separate from
22
  installing this module and should happen in the sites/all/libraries directory.
23
  See http://drupal.org/node/1440066 for more information.
23 24

  
24 25

  
25 26
-- CONTACT --
drupal7/sites/all/modules/libraries/libraries.admin.inc
1
<?php
2

  
3
/**
4
 * @file
5
 * Provides administrative page and form callbacks for Libraries module.
6
 */
7

  
8
/**
9
 * Form generation callback for the libraries overview table.
10
 *
11
 * This is a form instead of a page to allow easier extending in contributed
12
 * modules.
13
 *
14
 * @param array $form
15
 *   An associative array containing the structure of the form.
16
 * @param array $form_state
17
 *   A keyed array containing the current state of the form.
18
 *
19
 * @return array
20
 *   The form array for the overview form.
21
 */
22
function libraries_admin_overview(array $form, array &$form_state) {
23
  $header = array(t('Name'), t('Status'), t('Installed version'), t('Provider'), t('Links'));
24
  $rows = array();
25

  
26
  $libraries = libraries_detect();
27
  uasort($libraries, 'libraries_admin_sort_title');
28

  
29
  foreach ($libraries as $machine_name => $library) {
30
    $actions = array();
31

  
32
    if ($library['vendor url']) {
33
      $actions[] = l('Homepage', $library['vendor url']);
34
    }
35
    if ($library['download url']) {
36
      $actions[] = l('Download', $library['download url']);
37
    }
38

  
39
    $rows[] = array(
40
      'data' => array(
41
        l($library['name'], 'admin/reports/libraries/' . $machine_name),
42
        ($library['installed'] ? t('OK') : drupal_ucfirst($library['error'])),
43
        (isset($library['version']) ? $library['version'] : ''),
44
        libraries_admin_get_provider_with_type($library),
45
        implode(' | ', $actions),
46
      ),
47
      'class' => ($library['installed'] ? array('ok') : array('error')),
48
    );
49
  }
50

  
51
  $form['libraries']['list'] = array(
52
    '#theme' => 'table',
53
    '#header' => $header,
54
    '#rows' => $rows,
55
    '#empty' => t('There are currently no libraries installed'),
56
  );
57

  
58
  return $form;
59
}
60

  
61
/**
62
 * Form generation callback for the status overview for a single library.
63
 *
64
 * This is a form instead of a page to allow easier extending in contributed
65
 * modules.
66
 *
67
 * @param array $form
68
 *   An associative array containing the structure of the form.
69
 * @param array $form_state
70
 *   A keyed array containing the current state of the form.
71
 * @param array $library
72
 *   A library information array.
73
 *
74
 * @return array|null
75
 *   The form array for the status form or NULL if the library was not found.
76
 *
77
 * @todo Add some var_export($library)-style output
78
 */
79
function libraries_admin_library_status_form(array $form, array &$form_state, $library) {
80
  drupal_set_title(t('Status report for library %library', array('%library' => $library['name'])), PASS_THROUGH);
81

  
82
  if ($library['installed']) {
83
    drupal_set_message(t('The %name library is installed correctly.', array('%name' => $library['name'])));
84
    $form['status'] = libraries_admin_status_table($library);
85
  }
86
  else {
87
    drupal_set_message($library['error message'], 'error');
88
    switch ($library['error']) {
89
      case 'not found':
90
        $form['instructions'] = libraries_admin_instructions_missing($library);
91
        break;
92

  
93
      case 'not detected':
94
        $form['instructions'] = libraries_admin_instructions_undetected($library);;
95
        break;
96

  
97
      case 'not supported':
98
        $form['instructions'] = libraries_admin_instructions_unsupported($library);
99
        break;
100

  
101
      case 'missing dependency':
102
        $form['instructions']['instruction']['#markup'] = t('There a missing dependency in your configuration that prevent this library to work properly.') . '<br>';
103
        break;
104

  
105
      case 'incompatible dependency':
106
        $form['instructions']['instruction']['#markup'] = t('There an incompatible dependency in your configuration that prevent this library to work properly.') . '<br>';
107
        break;
108
    }
109
  }
110

  
111
  return $form;
112
}
113

  
114

  
115
/**
116
 * Displays a table of status information about a library.
117
 *
118
 * @param array $library
119
 *   A library information array.
120
 *
121
 * @return array
122
 *   A renderable array containing a table with status information.
123
 */
124
function libraries_admin_status_table(array $library) {
125
  $header = array(array(
126
    // @todo The title implies that other type of information is displayed, as
127
    //   well, but this is currently not the case.
128
    // @todo Use CSS instead of a <strong> element.
129
    'data' => '<strong>' . t('General information') . '</strong>',
130
    'colspan' => 2,
131
    'class' => 'table-heading',
132
    'no_striping' => TRUE,
133
  ));
134

  
135
  $rows = array();
136
  // @todo Use CSS instead of <strong> elements.
137
  $rows['name'] = array('<strong>' . t('Name') . '</strong>', check_plain($library['name']));
138
  $rows['machine_name'] = array('<strong>' . t('Machine name') . '</strong>', check_plain($library['machine name']));
139
  if ($library['vendor url']) {
140
    $rows['vendor_url'] = array('<strong>' . t('Vendor URL') . '</strong>', l($library['vendor url'], $library['vendor url']));
141
  }
142
  if ($library['download url']) {
143
    $rows['download_url'] = array('<strong>' . t('Download URL') . '</strong>', l($library['download url'], $library['download url']));
144
  }
145
  $rows['provider'] = array('<strong>' . t('Provider') . '</strong>', libraries_admin_get_provider_with_type($library));
146
  $rows['library_path'] = array('<strong>' . t('Library path') . '</strong>', $library['library path']);
147
  $rows['version'] = array('<strong>' . t('Version') . '</strong>', $library['version']);
148
  if (!empty($library['variants'])) {
149
    $rows['variants'] = array('<strong>' . t('Variants') . '</strong>', implode(', ', array_keys($library['variants'])));
150
  }
151

  
152
  return array(
153
    '#theme' => 'table',
154
    '#header' => $header,
155
    '#rows' => $rows,
156
  );
157
}
158

  
159
/**
160
 * Returns instructions for dealing with a missing library.
161
 *
162
 * @param array $library
163
 *   A library information array.
164
 *
165
 * @return array
166
 *   A renderable array containing the instructions.
167
 */
168
function libraries_admin_instructions_missing(array $library) {
169
  $build = array();
170

  
171
  $build['instruction']['#markup'] = t('Follow these steps to install the library:');
172

  
173
  $items = array();
174
  // 1. Download the library.
175
  // If no supported versions are specified, the latest version is
176
  // recommended.
177
  if (empty($library['versions'])) {
178
    $items[] = t('Download the latest version of the library <a href="@download-url">here</a>.', array(
179
      '@download-url' => $library['download url'],
180
    ));
181
  }
182
  // Otherwise, the latest supported version is recommended.
183
  else {
184
    $versions = array_keys($library['versions']);
185
    usort($versions, 'version_compare');
186
    $versions = array_reverse($versions);
187
    $version = $versions[0];
188
    $items[] = t('Download version %version of the library <a href="@download-url">here</a>.', array(
189
      '%version' => $version,
190
      '@download-url' => $library['download url'],
191
    ));
192
  }
193
  // 2. Unpack it.
194
  $items[] = t('If the library is an archive, i.e. if the file ending is for example <em>.tar.gz</em> or <em>.zip</em>, unpack it.');
195
  // 3. Create the libraries folder.
196
  $items[] = t('In the %library-directory directory of your Drupal installation create a %library directory.', array(
197
    '%library-directory' => 'sites/all/libraries',
198
    '%library' => $library['machine name'],
199
  ));
200
  // 4. Upload it.
201
  // If the library has variant-independent files, give the user the
202
  // location of an example file to check his filesystem against.
203
  if ($directory_layout = libraries_admin_directory_layout($library)) {
204
    $items[] = t('Upload the whole library (which can consist of multiple directories) into the newly created %library-path directory. The following files and directories should be contained in that directory: !directory-layout', array(
205
      '%library-path' => 'sites/all/libraries/' . $library['machine name'],
206
      '!directory-layout' => drupal_render($directory_layout),
207
    ));
208
  }
209
  else {
210
    $items[] = t('Upload the whole library (which can consist of multiple directories) into the newly created %library-path directory.', array(
211
      '%library-path' => 'sites/all/libraries/' . $library['machine name'],
212
    ));
213
  }
214
  // 5. Reload.
215
  $items[] = t('<a href="">Reload</a> the page. If successful, you should see status information about this library.');
216

  
217
  $build['steps'] = array(
218
    '#theme' => 'item_list',
219
    '#items' => $items,
220
    '#type' => 'ol'
221
  );
222

  
223
  return $build;
224
}
225

  
226

  
227
/**
228
 * Returns instructions for dealing with an undetected library.
229
 *
230
 * @param array $library
231
 *   A library information array.
232
 *
233
 * @return array
234
 *   A renderable array containing the instructions.
235
 */
236
function libraries_admin_instructions_undetected($library) {
237
  $build = array();
238
  // Re-check location.
239
  // @todo Avoid usage of <br> elements.
240
  $build['instruction']['#markup'] = t('Check that the whole library is located at %library-path.', array(
241
      '%library-path' => $library['library path'],
242
    )) . '<br>';
243
  // If the library has variant-independent files, give the user the
244
  // exact location of the files to check against.
245
  // @todo It should be possible to display even variant-specific files
246
  //   in case the variant is installed, but libraries_detect() does not
247
  //   detect variants if the library version cannot be detected.
248
  if ($directory_layout = libraries_admin_directory_layout($library)) {
249
    $build['directory_layout'] = $directory_layout;
250
    $build['directory_layout']['#prefix'] = t('The following files and directories should be contained in that directory:');
251
  }
252

  
253
  // If the library is placed correctly the library information is
254
  // incorrect.
255
  // This switch could be avoided by using $library['info type'], but that would
256
  // hinder properly translating these strings.
257
  $build['reload']['#markup'] = t('If you have moved any files, <a href="">reload</a> the page. If successful, you should see status information about this library.') . '<br>';
258
  $build['notice']['#markup'] = t('If the files are placed correctly and the version can still not be detected, the library information is incorrect.') . '<br>';
259

  
260
  $provider = libraries_admin_get_provider($library);
261
  switch ($library['info type']) {
262
    case 'module':
263
      $build['contact']['#markup'] = t('Contact the maintainer of the %module module to correct this.', array(
264
          '%module' => $provider,
265
        )) . '<br>';
266
      break;
267

  
268
    case 'theme':
269
      $build['contact']['#markup'] = t('Contact the maintainer of the %theme theme to correct this.', array(
270
          '%theme' => $provider,
271
        )) . '<br>';
272
      break;
273

  
274
    case 'info file':
275
      $build['contact']['#markup'] = t('Contact the maintainer of the %info-file info file to correct this.', array(
276
          '%info-file' => $provider,
277
        )) . '<br>';
278
      break;
279
  }
280
  return $build;
281
}
282

  
283

  
284
/**
285
 * Returns instructions for dealing with an unsupported library.
286
 *
287
 * @param array $library
288
 *   A library information array.
289
 *
290
 * @return array
291
 *   A renderable array containing the instructions.
292
 */
293
function libraries_admin_instructions_unsupported($library) {
294
  $build = array();
295
  $items = array();
296

  
297
  // Either download a different version of the library...
298
  $versions = array_keys($library['versions']);
299
  usort($versions, 'version_compare');
300
  $versions = array_reverse($versions);
301
  $version = $versions[0];
302
  $build['instruction']['#markup'] = t('Please install version %version of the library by following the following steps:',
303
    array(
304
      '%version' => $version,
305
    ));
306
  // 1. Delete the old library.
307
  $items[] = t('Delete the entire contents of the %library-path directory.',
308
    array(
309
      '%library-path' => $library['library path'],
310
    ));
311
  // 2. Download the new library.
312
  $items[] = t('Download version %version of the library <a href="@download-url">here</a>.',
313
    array(
314
      '%version' => $version,
315
      '@download-url' => $library['download url'],
316
    ));
317
  // 3. Unpack it.
318
  $items[] = t('If the library is an archive, i.e. if the file ending is for example <em>.tar.gz</em> or <em>.zip</em>, unpack it.');
319
  // 4. Upload the new library.
320
  // If the library has variant-independent files, give the user the
321
  // location of an example file to check his filesystem against.
322
  if ($directory_layout = libraries_admin_directory_layout($library)) {
323
    $items[] = t('Upload the new files into the %library-path directory. The following files and directories should be contained in that directory: !directory-layout',
324
      array(
325
        '%library-path' => $library['library path'],
326
        '!directory-layout' => drupal_render($directory_layout),
327
      ));
328
  }
329
  else {
330
    $items[] = t('Upload the new files into the %library-path directory.',
331
      array(
332
        '%library-path' => $library['library path'],
333
      ));
334
  }
335
  // 5. Reload.
336
  $items[] = t('<a href="">Reload</a> the page. If successful, you should see status information about this library.');
337
  $build['steps'] = array(
338
    '#theme' => 'item_list',
339
    '#items' => $items,
340
    '#type' => 'ol',
341
  );
342
  // ...or contact the maintainer of the library information.
343
  $provider = libraries_admin_get_provider($library);
344
  switch ($library['info type']) {
345
    case 'module':
346
      $build['contact']['#markup'] = t('If you are bound to version @version of the library, ask the maintainer of the %module module to provide support for it.', array(
347
          '@version' => $library['version'],
348
          '%module' => $provider,
349
        )) . '<br>';
350
      break;
351

  
352
    case 'theme':
353
      $build['contact']['#markup'] = t('If you are bound to version @version of the library, ask the maintainer of the %theme theme to provide support for it.', array(
354
          '@version' => $library['version'],
355
          '%theme' => $provider,
356
        )) . '<br>';
357
      break;
358

  
359
    case 'info file':
360
      $build['contact']['#markup'] = t('If you are bound to version @version of the library, ask the maintainer of the %info-file info file to provide support for it.', array(
361
          '@version' => $library['version'],
362
          '%info-file' => $provider,
363
        )) . '<br>';
364
      break;
365
  }
366
  return $build;
367
}
368

  
369
/**
370
 * Returns the directory layout of the library, if possible.
371
 *
372
 * The result of this function can help users to verify that they have uploaded
373
 * the library to the correct location.
374
 *
375
 * @param array $library
376
 *   A library information array.
377
 *
378
 * @return array|false
379
 *   A renderable array containing the directory layout of the library or FALSE
380
 *   if a directory layout could not be generated.
381
 */
382
function libraries_admin_directory_layout(array $library) {
383
  $build = array(
384
    '#theme' => 'item_list',
385
    '#type' => 'ul',
386
    '#items' => array(),
387
  );
388

  
389
  $items = &$build['#items'];
390
  if ($library['path']) {
391
    $items = &libraries_admin_path_to_tree($items, $library['path']);
392
  }
393
  foreach (array('js', 'css', 'php') as $type) {
394
    if (!empty($library['files'][$type])) {
395
      $files = array_keys($library['files'][$type]);
396
      foreach ($files as $file) {
397
        // Skip JavaScript settings.
398
        if (is_int($file)) {
399
          continue;
400
        }
401

  
402
        $children = &$items;
403
        libraries_admin_path_to_tree($children, $file);
404
      }
405
    }
406
  }
407
  return $build['#items'] ? $build : FALSE;
408
}
409

  
410
/**
411
 * Converts a file path into a tree structure for use in an item list.
412
 *
413
 * For example, the path 'foo/bar/baz' will be converted into the tree structure
414
 * represented by the following list:
415
 * - foo
416
 *   - bar
417
 *     - baz
418
 *
419
 * The $items array that is modified by reference or returned (see below) can
420
 * be used as the 'items' variable for theme_item_list().
421
 *
422
 * This function modifies passed-in $items array, so that multiple paths can
423
 * be placed into the same tree structure easily.
424
 *
425
 * @code
426
 *   $items = array();
427
 *   foreach ($paths as $path) {
428
 *     libraries_admin_path_to_tree($items, $path);
429
 *   }
430
 * @endcode
431
 *
432
 * It also returns the last item by reference, so that it can also be used to
433
 * traverse into a sub-structure and add further children there.
434
 *
435
 * @code
436
 *   $items = array();
437
 *   $children = &libraries_admin_path_to_tree($items, $path);
438
 *   foreach ($sub_paths as $sub_path) {
439
 *     libraries_admin_path_to_tree($children, $sub_path);
440
 *   }
441
 * @endcode
442
 *
443
 * @param array $items
444
 * @param string $path
445
 *
446
 * @return array
447
 */
448
function &libraries_admin_path_to_tree(array &$items, $path) {
449
  $part = strtok($path, '/');
450
  while ($part) {
451
    if (!isset($items[$part])) {
452
      $items[$part] = array(
453
        'data' => $part,
454
        'children' => array(),
455
      );
456
    }
457
    $items = &$items[$part]['children'];
458
    $part = strtok('/');
459
  }
460

  
461
  return $items;
462
}
463

  
464
/**
465
 * Sorts libraries by name.
466
 *
467
 * This function can be used as a callback for usort() or uasort().
468
 *
469
 * @param array $a
470
 *   The first library information array.
471
 * @param array $b
472
 *   The second library information array.
473
 *
474
 * @return int
475
 *   Returns -1 if $a is considered smaller than $b, 1 if $a considered greater
476
 *   than $b and 0 if $a and $b are considered equal.
477
 *
478
 * @see strnatcasecmp()
479
 * @see usort()
480
 * @see uasort()
481
 */
482
function libraries_admin_sort_title(array $a, array $b) {
483
  return strnatcasecmp($a['name'], $b['name']);
484
}
485

  
486
/**
487
 * Returns the library's provider.
488
 *
489
 * The provider can be a module, a theme, or an info file.
490
 *
491
 * @param array $library
492
 *   A library information array.
493
 *
494
 * @return string
495
 *   The provider.
496
 */
497
function libraries_admin_get_provider($library) {
498
  $provider = '';
499

  
500
  switch ($library['info type']) {
501
    case 'module':
502
    case 'theme':
503
      $info = system_get_info($library['info type'], $library[$library['info type']]);
504
      $provider = $info['name'];
505
      break;
506

  
507
    case 'info file':
508
      $provider = basename($library['info file']);
509
      break;
510
  }
511

  
512
  return $provider;
513
}
514

  
515
/**
516
 * Returns the library's provider and provider type.
517
 *
518
 * The provider type is either 'module', 'theme', or 'info file'.
519
 *
520
 * @param array $library
521
 *   A library information array.
522
 *
523
 * @return string
524
 *   The provider and provider type.
525
 */
526
function libraries_admin_get_provider_with_type($library) {
527
  $provider = libraries_admin_get_provider($library);
528
  $provider_with_type = '';
529

  
530
  // This switch could be avoided by using $library['info type'], but that would
531
  // hinder properly translating these strings.
532
  switch ($library['info type']) {
533
    case 'module':
534
      $provider_with_type = t('%module module', array('%module' => $provider));
535
      break;
536

  
537
    case 'theme':
538
      $provider_with_type = t('%theme theme', array('%theme' => $provider));
539
      break;
540

  
541
    case 'info file':
542
      $provider_with_type = t('%info-file info file', array('%info-file' => $provider));
543
      break;
544
  }
545

  
546
  return $provider_with_type;
547
}
drupal7/sites/all/modules/libraries/libraries.api.php
16 16
 *   - name: The official, human-readable name of the library.
17 17
 *   - vendor url: The URL of the homepage of the library.
18 18
 *   - download url: The URL of a web page on which the library can be obtained.
19
 *   - download file url: (optional) The URL where the latest version of the
20
 *     library can be downloaded. In case such a static URL exists the library
21
 *     can be downloaded automatically via Drush. Run
22
 *     'drush help libraries-download' in the command-line for more information.
19 23
 *   - path: (optional) A relative path from the directory of the library to the
20 24
 *     actual library. Only required if the extracted download package contains
21 25
 *     the actual library files in a sub-directory.
......
211 215
    'name' => 'Example library',
212 216
    'vendor url' => 'http://example.com',
213 217
    'download url' => 'http://example.com/download',
218
    // It is important that this URL does not include the actual version to
219
    // download. Not all libraries provide such a static URL.
220
    'download file url' => 'http://example.com/latest.tar.gz',
214 221
    // Optional: If, after extraction, the actual library files are contained in
215 222
    // 'sites/all/libraries/example/lib', specify the relative path here.
216 223
    'path' => 'lib',
......
343 350
    'name' => 'Simple library',
344 351
    'vendor url' => 'http://example.com/simple',
345 352
    'download url' => 'http://example.com/simple',
353
    // The download file URL can also point to a single file (instead of an
354
    // archive).
355
    'download file url' => 'http://example.com/latest/simple.js',
346 356
    'version arguments' => array(
347 357
      'file' => 'readme.txt',
348 358
      // Best practice: Document the actual version strings for later reference.
......
467 477
 * @return
468 478
 *   An array of paths.
469 479
 */
470
function hook_libraries_paths() {
480
function hook_libraries_info_file_paths() {
471 481
  // Taken from the Libraries test module, which needs to specify the path to
472 482
  // the test library.
473 483
  return array(drupal_get_path('module', 'libraries_test') . '/example');
drupal7/sites/all/modules/libraries/libraries.drush.inc
1 1
<?php
2

  
3 2
/**
4 3
 * @file
5 4
 * Drush integration for Libraries API.
......
9 8
 * Implements hook_drush_command().
10 9
 */
11 10
function libraries_drush_command() {
11
  $items = array();
12

  
12 13
  $items['libraries-list'] = array(
13
    'callback' => 'libraries_drush_list',
14
    'description' => dt('Lists registered library information.'),
14
    'description' => dt('Show a list of registered libraries.'),
15 15
    'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
16
    'aliases' => array('lls', 'lib-list'),
16 17
  );
17
  /**$items['libraries-download'] = array(
18
    'callback' => 'libraries_drush_download',
19
    'description' => dt('Downloads a registered library into the libraries directory for the active site.'),
18

  
19
  $items['libraries-download'] = array(
20
    'description' => dt('Download library files of registered libraries.'),
21
    'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
22
    'aliases' => array('ldl', 'lib-download'),
20 23
    'arguments' => array(
21
      'name' => dt('The internal name of the registered library.'),
24
      'libraries' => 'A comma delimited list of library machine names.',
22 25
    ),
23
  );*/
26
    'required-arguments' => TRUE,
27
  );
28

  
24 29
  return $items;
25 30
}
26 31

  
27 32
/**
28
 * Implements hook_drush_help().
33
 * Implements hook_drush_cache_clear().
34
 *
35
 * @see drush_cache_clear_types()
29 36
 */
30
function libraries_drush_help($section) {
31
  switch ($section) {
32
    case 'drush:libraries-list':
33
      return dt('Lists registered library information.');
34

  
35
    case 'drush:libraries-download':
36
      return dt('Downloads a registered library into the libraries directory for the active site.
37
function libraries_drush_cache_clear(array &$types) {
38
  $types['libraries'] = 'libraries_drush_invalidate_cache';
39
}
37 40

  
38
See libraries-list for a list of registered libraries.');
41
/**
42
 * Clears the library cache.
43
 */
44
function libraries_drush_invalidate_cache() {
45
  // @see drupal_flush_all_caches()
46
  foreach (libraries_flush_caches() as $table) {
47
    cache_clear_all('*', $table, TRUE);
39 48
  }
40 49
}
41 50

  
42 51
/**
43
 * Lists registered library information.
52
 * Command callback. Show a list of registered libraries.
44 53
 */
45
function libraries_drush_list() {
46
  $libraries = array();
47
  foreach (libraries_info() as $name => $info) {
48
    $libraries[$name] = libraries_detect($name);
49
  }
54
function drush_libraries_list() {
55
  $libraries = libraries_detect();
50 56
  ksort($libraries);
51 57

  
52 58
  if (empty($libraries)) {
53 59
    drush_print('There are no registered libraries.');
54 60
  }
55

  
56 61
  else {
62
    module_load_include('inc', 'libraries', 'libraries.admin');
63

  
57 64
    $rows = array();
58 65
    // drush_print_table() automatically treats the first row as the header, if
59 66
    // $header is TRUE.
60
    $rows[] = array(dt('Name'), dt('Status'), dt('Version'), dt('Variants'), dt('Dependencies'));
67
    $rows[] = array(
68
      dt('Name'),
69
      dt('Status'),
70
      dt('Version'),
71
      dt('Variants'),
72
      dt('Dependencies'),
73
      dt('Provider'),
74
    );
61 75
    foreach ($libraries as $name => $library) {
62
      $status = ($library['installed'] ? dt('OK') : drupal_ucfirst($library['error']));
63
      $version = (($library['installed'] && !empty($library['version'])) ? $library['version'] : '-');
64

  
65 76
      // Only list installed variants.
66 77
      $variants = array();
67 78
      foreach ($library['variants'] as $variant_name => $variant) {
......
69 80
          $variants[] = $variant_name;
70 81
        }
71 82
      }
72
      $variants = (empty($variants) ? '-' : implode(', ', $variants));
73 83

  
74
      $dependencies = (!empty($library['dependencies']) ? implode(', ', $library['dependencies']) : '-');
75

  
76
      $rows[] = array($name, $status, $version, $variants, $dependencies);
84
      $rows[] = array(
85
        $name,
86
        $library['installed'] ? dt('OK') : drupal_ucfirst($library['error']),
87
        ($library['installed'] && $library['version']) ? '-' : $library['version'],
88
        $variants ? implode(', ', $variants) : '-',
89
        $library['dependencies'] ? implode(', ', $library['dependencies']) : '-',
90
        libraries_admin_get_provider($library),
91
      );
77 92
    }
93

  
78 94
    // Make the possible values for the 'Status' column and the 'Version' header
79 95
    // wrap nicely.
80
    $widths = array(0, 12, 7, 0, 0);
96
    $widths = array(0, 12, 7, 0, 0, 0);
81 97
    drush_print_table($rows, TRUE, $widths);
82 98
  }
83 99
}
84 100

  
85 101
/**
86
 * Downloads a library.
102
 * Command callback. Downloads a library.
103
 *
104
 * Only libraries that provide a download file URL can be downloaded.
87 105
 *
88
 * @param $name
89
 *   The internal name of the library to download.
106
 * @see hook_libraries_info()
107
 * @see drush_pm_download()
90 108
 */
91
function libraries_drush_download($name) {
92
  return;
109
function drush_libraries_download() {
110
  drush_command_include('pm-download');
111

  
112
  $libraries = libraries_info();
113

  
114
  // @todo Consider supporting downloading all downloadable libraries.
115
  // @todo Consider offering a selection if no library is specified.
116
  foreach (pm_parse_arguments(func_get_args(), FALSE) as $machine_name) {
117
    if (!isset($libraries[$machine_name])) {
118
      $message = dt("The !library library is not registered with Libraries API.\n", array('!library' => $machine_name));
119
      $message .= dt("Provide an info file for it or implement hook_libraries_info().\n");
120
      $message .= dt("See hook_libraries_info() for more information.\n");
121
      drush_set_error('DRUSH_LIBRARY_UKNOWN', $message);
122
      continue;
123
    }
124
    $library = $libraries[$machine_name];
125

  
126
    if (empty($library['download file url'])) {
127
      $message = dt("The !library library cannot be downloaded.\n", array('!library' => $machine_name));
128
      $message .= dt("Libraries need to specify a download file URL to support being downloaded via Drush.\n");
129
      $message .= dt("See hook_libraries_info() for more information.\n");
130
      drush_set_error('DRUSH_LIBRARY_NOT_DOWNLOADABLE', $message);
131
      continue;
132
    }
133
    $download_url = $library['download file url'];
134

  
135
    drush_log(dt('Downloading library !name ...', array('!name' => $machine_name)));
136

  
137
    // @see package_handler_download_project() in wget.inc
138
    // It cannot be used directly because it will always try to extract the
139
    // archive which fails when downloading a single file.
140
    // @todo Modify upstream to be able to use
141
    //   package_handler_download_project() directly.
142
    // Prepare download path. On Windows file name cannot contain '?'.
143
    // See http://drupal.org/node/1782444
144
    $filename = str_replace('?', '_', basename($download_url));
145
    $download_path = drush_tempdir() . '/' . $filename;
146

  
147
    // Download the tarball.
148
    // Never cache the downloaded file. The downloading relies on the fact that
149
    // different versions of the library are available under the same URL as new
150
    // versions are released.
151
    $download_path = drush_download_file($download_url, $download_path, 0);
152
    if ($download_path || drush_get_context('DRUSH_SIMULATE')) {
153
      drush_log(dt('Downloading !filename was successful.', array('!filename' => $filename)));
154
    }
155
    else {
156
      drush_set_error('DRUSH_PM_DOWNLOAD_FAILED', dt('Unable to download !project to !path from !url.', array('!project' => $machine_name, '!path' => $download_path, '!url' => $download_url)));
157
      drush_log(dt('Error downloading !name', array('!name' => $machine_name)), 'error');
158
      continue;
159
    }
93 160

  
94
  // @todo Looks wonky?
95
  if (!drush_shell_exec('type unzip')) {
96
    return drush_set_error(dt('Missing dependency: unzip. Install it before using this command.'));
97
  }
161
    // @todo Suport MD5 file hashing.
98 162

  
99
  // @todo Simply use current drush site.
100
  $args = func_get_args();
101
  if ($args[0]) {
102
    $path = $args[0];
103
  }
104
  else {
105
    $path = 'sites/all/libraries';
106
  }
163
    // Extract the tarball in place and return the full path to the untarred directory.
164
    $download_base = dirname($download_path);
165
    if (drush_file_is_tarball($download_path)) {
166
      if (!$tar_file_list = drush_tarball_extract($download_path, $download_base, TRUE)) {
167
        // An error has been logged.
168
        return FALSE;
169
      }
170
      $tar_directory = drush_trim_path($tar_file_list[0]);
171
      $download_path = $download_base . '/' . $tar_directory;
172
    }
173
    else {
174
      $download_path = $download_base;
175
    }
107 176

  
108
  // Create the path if it does not exist.
109
  if (!is_dir($path)) {
110
    drush_op('mkdir', $path);
111
    drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
112
  }
177
    // Determine the install location for the project.  User provided
178
    // --destination has preference.
179
    $destination = drush_get_option('destination');
180
    if (!empty($destination)) {
181
      if (!file_exists($destination)) {
182
        drush_mkdir($destination);
183
      }
184
      $install_location = realpath($destination);
185
    }
186
    else {
187
      /** @see _pm_download_destination_lookup() */
188
      // _pm_download_destination_lookup() pluralizes the passed type by
189
      // appending an s.
190
      // This relies on the fact that there is no library named 'contrib'.
191
      // @todo Request that this be turned into a proper API upstream.
192
      $install_location = _pm_download_destination('librarie');
193
    }
113 194

  
114
  // Set the directory to the download location.
115
  $olddir = getcwd();
116
  chdir($path);
195
    // @todo Consider invoking a hook similar to
196
    //   hook_drush_pm_download_destination_alter().
117 197

  
118
  $filename = basename(COLORBOX_DOWNLOAD_URI);
119
  $dirname = basename(COLORBOX_DOWNLOAD_URI, '.zip');
198
    // @todo Consider adding version-control support similar to pm-download.
120 199

  
121
  // Remove any existing Colorbox plugin directory
122
  if (is_dir($dirname)) {
123
    drush_log(dt('A existing Colorbox plugin was overwritten at @path', array('@path' => $path)), 'notice');
124
  }
125
  // Remove any existing Colorbox plugin zip archive
126
  if (is_file($filename)) {
127
    drush_op('unlink', $filename);
128
  }
200
    $install_location .= '/' . $machine_name;
129 201

  
130
  // Download the zip archive
131
  if (!drush_shell_exec('wget '. COLORBOX_DOWNLOAD_URI)) {
132
    drush_shell_exec('curl -O '. COLORBOX_DOWNLOAD_URI);
133
  }
202
    // Check if install location already exists.
203
    if (is_dir($install_location)) {
204
      if (drush_confirm(dt('Install location !location already exists. Do you want to overwrite it?', array('!location' => $install_location)))) {
205
        drush_delete_dir($install_location, TRUE);
206
      }
207
      else {
208
        drush_log(dt("Skip installation of !project to !dest.", array('!project' => $library['machine name'], '!dest' => $install_location)), 'warning');
209
        continue;
210
      }
211
    }
134 212

  
135
  if (is_file($filename)) {
136
    // Decompress the zip archive
137
    drush_shell_exec('unzip -qq -o '. $filename);
138
    // Remove the zip archive
139
    drush_op('unlink', $filename);
140
  }
213
    // Copy the project to the install location.
214
    if (drush_op('_drush_recursive_copy', $download_path, $install_location)) {
215
      drush_log(dt("Library !project downloaded to !dest.", array('!project' => $machine_name, '!dest' => $install_location)), 'success');
141 216

  
142
  // Set working directory back to the previous working directory.
143
  chdir($olddir);
217
      // @todo Consider invoking a hook similar to
218
      //   hook_drush_pm_post_download().
144 219

  
145
  if (is_dir($path .'/'. $dirname)) {
146
    drush_log(dt('Colorbox plugin has been downloaded to @path', array('@path' => $path)), 'success');
147
  }
148
  else {
149
    drush_log(dt('Drush was unable to download the Colorbox plugin to @path', array('@path' => $path)), 'error');
220
      // @todo Support printing release notes.
221
    }
222
    else {
223
      // We don't `return` here in order to proceed with downloading additional projects.
224
      drush_set_error('DRUSH_PM_DOWNLOAD_FAILED', dt("Project !project could not be downloaded to !dest.", array('!project' => $machine_name, '!dest' => $install_location)));
225
    }
226

  
227
    // @todo Consider adding notify support.
150 228
  }
151 229
}
drupal7/sites/all/modules/libraries/libraries.info
3 3
core = 7.x
4 4
; We use hook_system_theme_info() which was added in Drupal 7.11
5 5
dependencies[] = system (>=7.11)
6
files[] = tests/libraries.test
6
files[] = tests/LibrariesAdminWebTest.test
7
files[] = tests/LibrariesLoadWebTest.test
8
files[] = tests/LibrariesUnitTest.test
9
files[] = tests/LibrariesWebTestBase.test
7 10

  
8
; Information added by Drupal.org packaging script on 2014-02-09
9
version = "7.x-2.2"
11
; Information added by Drupal.org packaging script on 2016-05-12
12
version = "7.x-2.3"
10 13
core = "7.x"
11 14
project = "libraries"
12
datestamp = "1391965716"
15
datestamp = "1463077450"
13 16

  
drupal7/sites/all/modules/libraries/libraries.install
25 25
    db_create_table('cache_libraries', $specs['cache_libraries']);
26 26
  }
27 27
}
28

  
29
/**
30
 * Rebuild the class registry.
31
 */
32
function libraries_update_7201() {
33
  // The tests were split from a single libraries.test file into multiple files
34
  // during the 7.x-2.x cycle.
35
  registry_rebuild();
36
}
drupal7/sites/all/modules/libraries/libraries.module
33 33
 * @param $base_path
34 34
 *   Whether to prefix the resulting path with base_path().
35 35
 *
36
 * @return
36
 * @return string
37 37
 *   The path to the specified library or FALSE if the library wasn't found.
38 38
 *
39 39
 * @ingroup libraries
......
67 67
 * in both the site-wide directory and site-specific directory, only the
68 68
 * site-specific version will be listed.
69 69
 *
70
 * @return
70
 * @return array
71 71
 *   A list of library directories.
72 72
 *
73 73
 * @ingroup libraries
......
122 122
 * - sites/$sitename/libraries
123 123
 * - any directories specified via hook_libraries_info_file_paths()
124 124
 *
125
 * @return
125
 * @return array
126 126
 *   An array of info files, keyed by library name. The values are the paths of
127 127
 *   the files.
128 128
 */
......
429 429
/**
430 430
 * Applies default properties to a library definition.
431 431
 *
432
 * @library
432
 * @param array $library
433 433
 *   An array of library information, passed by reference.
434
 * @name
434
 * @param string $name
435 435
 *   The machine name of the passed-in library.
436
 *
437
 * @return array
438
 *   The library information array with defaults populated.
436 439
 */
437
function libraries_info_defaults(&$library, $name) {
440
function libraries_info_defaults(array &$library, $name) {
438 441
  $library += array(
439 442
    'machine name' => $name,
440 443
    'name' => $name,
441 444
    'vendor url' => '',
442 445
    'download url' => '',
446
    'download file url' => '',
443 447
    'path' => '',
444 448
    'library path' => NULL,
445 449
    'version callback' => 'libraries_get_version',
......
472 476
/**
473 477
 * Tries to detect a library and its installed version.
474 478
 *
475
 * @param $name
476
 *   The machine name of a library to return registered information for.
479
 * @param string $name
480
 *   (optional) The machine name of a library to detect and return registered
481
 *   information for. If omitted, information about all registered libraries is
482
 *   returned.
477 483
 *
478 484
 * @return array|false
479
 *   An associative array containing registered information for the library
480
 *   specified by $name, or FALSE if the library $name is not registered.
485
 *   An associative array containing registered information for all libraries,
486
 *   the registered information for the library specified by $name, or FALSE if
487
 *   the library $name is not registered.
481 488
 *   In addition to the keys returned by libraries_info(), the following keys
482 489
 *   are contained:
483 490
 *   - installed: A boolean indicating whether the library is installed. Note
......
491 498
 *
492 499
 * @see libraries_info()
493 500
 */
494
function libraries_detect($name) {
501
function libraries_detect($name = NULL) {
502
  if (!isset($name)) {
503
    $libraries = &libraries_info();
504
    foreach ($libraries as $name => $library) {
505
      libraries_detect($name);
506
    }
507
    return $libraries;
508
  }
509

  
495 510
  // Re-use the statically cached value of libraries_info() to save memory.
496 511
  $library = &libraries_info($name);
497 512

  
......
531 546
      $library['version'] = call_user_func_array($library['version callback'], array_merge(array($library), $library['version arguments']));
532 547
    }
533 548
    else {
534
      $library['version'] = $library['version callback']($library, $library['version arguments']);
549
      $library['version'] = call_user_func($library['version callback'], $library, $library['version arguments']);
535 550
    }
536 551
    if (empty($library['version'])) {
537 552
      $library['error'] = 'not detected';
......
693 708
 *   The number of loaded files.
694 709
 */
695 710
function libraries_load_files($library) {
711
  // As this key was added after 7.x-2.1 cached library structures might not
712
  // have it.
713
  $library += array('post-load integration files' => FALSE);
714

  
696 715
  // Load integration files.
697 716
  if (!$library['post-load integration files'] && !empty($library['integration files'])) {
698 717
    $enabled_themes = array();
......
867 886
  }
868 887
  fclose($file);
869 888
}
889

  
890
/**
891
 * Implements hook_help().
892
 */
893
function libraries_help($path, $arg) {
894
  switch ($path) {
895
    case 'admin/reports/libraries':
896
      return t('Click on a library for a status report or detailed installation instructions in case the library is not installed correctly.');
897
  }
898
}
899

  
900
/**
901
 * Implements hook_menu().
902
 */
903
function libraries_menu() {
904
  $items = array();
905
  $items['admin/reports/libraries'] = array(
906
    'title' => 'Libraries',
907
    'description' => 'An overview of libraries installed on this site.',
908
    'page callback' => 'drupal_get_form',
909
    'page arguments' => array('libraries_admin_overview'),
910
    'access arguments' => array('access site reports'),
911
    'file' => 'libraries.admin.inc'
912
  );
913
  $items['admin/reports/libraries/%libraries_ui'] = array(
914
    'title' => 'Library status report',
915
    'description' => 'Status overview for a single library',
916
    'page callback' => 'drupal_get_form',
917
    'page arguments' => array('libraries_admin_library_status_form', 3),
918
    'access arguments' => array('access site reports'),
919
    'file' => 'libraries.admin.inc'
920
  );
921
  return $items;
922
}
923

  
924
/**
925
 * Loads library information for display in the user interface.
926
 *
927
 * This can be used as a menu loader function by specifying a '%libraries_ui'
928
 * parameter in a path.
929
 *
930
 * We do not use libraries_load() (and, thus, a '%libraries' parameter) directly
931
 * for displaying library information in the user interface as we do not want
932
 * the library files to be loaded.
933
 *
934
 * @param string $name
935
 *   The machine name of a library to return registered information for.
936
 *
937
 * @return array|false
938
 *   An associative array containing registered information for the library
939
 *   specified by $name, or FALSE if the library $name is not registered.
940
 *
941
 * @see libraries_detect()
942
 * @see libraries_menu()
943
 */
944
function libraries_ui_load($name) {
945
  return libraries_detect($name);
946
}
drupal7/sites/all/modules/libraries/tests/LibrariesAdminWebTest.test
1
<?php
2

  
3
/**
4
 * @file
5
 * Contains LibrariesAdminWebTest.
6
 *
7
 * Simpletest automatically discovers test files using PSR-4. We cannot,
8
 * however, declare a namespace for this class, as that would require PHP 5.3.
9
 * To prepare the PHP 5.3 requirement and the usage of PSR-4 in 7.x-3.x, we
10
 * split each test class into its own file and use the correct base name, but
11
 * for now use the 'test' extension and register them explicitly in
12
 * libraries.info.
13
 *
14
 * @see simpletest_test_get_all()
15
 */
16

  
17
/**
18
 * Tests the administrative interface for libraries.
19
 */
20
class LibrariesAdminWebTest extends LibrariesWebTestBase {
21

  
22
  /**
23
   * Provides metadata about this test.
24
   *
25
   * @return array
26
   *   An array of test metadata with the following keys:
27
   *   - name: The name of the test.
28
   *   - description: The description of the test.
29
   *   - group: The group of the test.
30
   */
31
  public static function getInfo() {
32
    return array(
33
      'name' => 'Libraries administration',
34
      'description' => 'Tests the administrative interface for libraries.',
35
      'group' => 'Libraries API',
36
    );
37
  }
38

  
39
  /**
40
   * Tests the libraries report at /admin/reports/libraries.
41
   */
42
  public function testLibrariesReportOverview() {
43
    $this->getWithPermissions(array('access site reports'), 'admin/reports/libraries');
44
    $this->assertRaw('Libraries');
45

  
46
    // Make sure that all the libraries are listed.
47
    $libraries = libraries_info();
48
    $this->assertTrue($libraries);
49
    foreach ($libraries as $library) {
50
      $this->assertText($library['name']);
51
      $this->assertLinkByHref('admin/reports/libraries/' . $library['machine name']);
52
    }
53

  
54
    // Make sure that all possible statuses are displayed.
55
    $this->assertText('OK');
56
    $this->assertText('Not found');
57
    $this->assertText('Not detected');
58
    $this->assertText('Not supported');
59
    $this->assertText('Missing dependency');
60
    $this->assertText('Incompatible dependency');
61

  
62
    // Make sure that the providers are displayed.
63
    $this->assertRaw('<em class="placeholder">Libraries test module</em> module');
64
    $this->assertRaw('<em class="placeholder">Libraries test theme</em> theme');
65
    $this->assertRaw('<em class="placeholder">example_info_file.libraries.info</em> info file');
66

  
67
    // Make sure that homepage and download links are displayed.
68
    $this->assertLinkByHref('http://example.com');
69
    $this->assertLinkByHref('http://example.com/download');
70
  }
71

  
72
  /**
73
   * Tests the libraries report for an installed library.
74
   */
75
  public function testLibrariesReportInstalled() {
76
    $this->getWithPermissions(array('access site reports'), 'admin/reports/libraries/example_files');
77
    $this->assertRaw('Status report for library <em class="placeholder">Example files</em>');
78
    $this->assertRaw('The <em class="placeholder">Example files</em> library is installed correctly.');
79
    // Check that the information in the status report is displayed.
80
    $this->assertText('Example files');
81
    $this->assertText('example_files');
82
    $this->assertRaw('<em class="placeholder">Libraries test module</em> module');
83
    $this->assertText(drupal_get_path('module', 'libraries') . '/tests/libraries/example');
84
    $this->assertText('1');
85
  }
86

  
87
  /**
88
   * Tests the libraries report for a missing library.
89
   */
90
  public function testLibrariesReportMissing() {
91
    $this->getWithPermissions(array('access site reports'), 'admin/reports/libraries/example_missing');
92
    $this->assertRaw('Status report for library <em class="placeholder">Example missing</em>');
93
    $this->assertRaw('The <em class="placeholder">Example missing</em> library could not be found.');
94
    // Check that the download link is being displayed.
95
    $this->assertLinkByHref('http://example.com/download');
96
  }
97

  
98

  
99
  /**
100
   * Tests the libraries report for a missing library.
101
   */
102
  public function testLibrariesReportNotDetected() {
103
    $this->getWithPermissions(array('access site reports'), 'admin/reports/libraries/example_undetected_version');
104
    $this->assertRaw('Status report for library <em class="placeholder">Example undetected version</em>');
105
    $this->assertRaw('The version of the <em class="placeholder">Example undetected version</em> library could not be detected.');
106
  }
107

  
108
  /**
109
   * Tests the libraries report for a missing library.
110
   */
111
  public function testLibrariesReportNotSupported() {
112
    $this->getWithPermissions(array('access site reports'), 'admin/reports/libraries/example_unsupported_version');
113
    $this->assertRaw('Status report for library <em class="placeholder">Example unsupported version</em>');
114
    $this->assertRaw('The installed version <em class="placeholder">1</em> of the <em class="placeholder">Example unsupported version</em> library is not supported.');
115
    // Check that the download link is being displayed.
116
    $this->assertLinkByHref('http://example.com/download');
117
  }
118

  
119
}
drupal7/sites/all/modules/libraries/tests/LibrariesLoadWebTest.test
2 2

  
3 3
/**
4 4
 * @file
5
 * Tests for Libraries API.
5
 * Contains LibrariesLoadWebTest.
6
 *
7
 * Simpletest automatically discovers test files using PSR-4. We cannot,
8
 * however, declare a namespace for this class, as that would require PHP 5.3.
9
 * To prepare the PHP 5.3 requirement and the usage of PSR-4 in 7.x-3.x, we
10
 * place the test files in the correct directory already, but for now register
11
 * them explicitly in libraries.info
6 12
 */
7 13

  
8 14
/**
9
 * Tests basic Libraries API functions.
15
 * Tests basic detection and loading of libraries.
10 16
 */
11
class LibrariesUnitTestCase extends DrupalUnitTestCase {
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'Libraries API unit tests',
15
      'description' => 'Tests basic functions provided by Libraries API.',
16
      'group' => 'Libraries API',
17
    );
18
  }
19

  
20
  function setUp() {
21
    drupal_load('module', 'libraries');
22
    parent::setUp();
23
  }
24

  
25
  /**
26
   * Tests libraries_get_path().
27
   */
28
  function testLibrariesGetPath() {
29
    // Note that, even though libraries_get_path() doesn't find the 'example'
30
    // library, we are able to make it 'installed' by specifying the 'library
31
    // path' up-front. This is only used for testing purposed and is strongly
32
    // discouraged as it defeats the purpose of Libraries API in the first
33
    // place.
34
    $this->assertEqual(libraries_get_path('example'), FALSE, 'libraries_get_path() returns FALSE for a missing library.');
35
  }
17
class LibrariesLoadWebTest extends LibrariesWebTestBase {
36 18

  
37 19
  /**
38
   * Tests libraries_prepare_files().
20
   * Provides metadata about this test.
21
   *
22
   * @return array
23
   *   An array of test metadata with the following keys:
24
   *   - name: The name of the test.
25
   *   - description: The description of the test.
26
   *   - group: The group of the test.
39 27
   */
40
  function testLibrariesPrepareFiles() {
41
    $expected = array(
42
      'files' => array(
43
        'js' => array('example.js' => array()),
44
        'css' => array('example.css' => array()),
45
        'php' => array('example.php' => array()),
46
      ),
47
    );
48
    $library = array(
49
      'files' => array(
50
        'js' => array('example.js'),
51
        'css' => array('example.css'),
52
        'php' => array('example.php'),
53
      ),
54
    );
55
    libraries_prepare_files($library, NULL, NULL);
56
    $this->assertEqual($expected, $library, 'libraries_prepare_files() works correctly.');
57
  }
58
}
59

  
60
/**
61
 * Tests basic detection and loading of libraries.
62
 */
63
class LibrariesTestCase extends DrupalWebTestCase {
64
  protected $profile = 'testing';
65

  
66 28
  public static function getInfo() {
67 29
    return array(
68 30
      'name' => 'Libraries detection and loading',
......
71 33
    );
72 34
  }
73 35

  
74
  function setUp() {
75
    parent::setUp('libraries', 'libraries_test_module');
76
    theme_enable(array('libraries_test_theme'));
77
  }
78

  
79 36
  /**
80 37
   * Tests libraries_detect_dependencies().
81 38
   */
82
  function testLibrariesDetectDependencies() {
39
  public function testLibrariesDetectDependencies() {
83 40
    $library = array(
84 41
      'name' => 'Example',
85 42
      'dependencies' => array('example_missing'),
......
158 115
  /**
159 116
   * Tests libraries_scan_info_files().
160 117
   */
161
  function testLibrariesScanInfoFiles() {
118
  public function testLibrariesScanInfoFiles() {
162 119
    $expected = array('example_info_file' => (object) array(
163 120
      'uri' => drupal_get_path('module', 'libraries') . '/tests/libraries/example_info_file.libraries.info',
164 121
      'filename' => 'example_info_file.libraries.info',
......
171 128
  /**
172 129
   * Tests libraries_info().
173 130
   */
174
  function testLibrariesInfo() {
131
  public function testLibrariesInfo() {
175 132
    // Test that modules can provide and alter library information.
176 133
    $info = libraries_info();
177 134
    $this->assertTrue(isset($info['example_module']));
......
226 183
  /**
227 184
   * Tests libraries_detect().
228 185
   */
229
  function testLibrariesDetect() {
186
  public function testLibrariesDetect() {
230 187
    // Test missing library.
231 188
    $library = libraries_detect('example_missing');
232 189
    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
......
306 263
    $this->assertEqual($library['variants']['example_variant']['installed'], TRUE, 'Existing variant found.');
307 264
  }
308 265

  
266
  /**
267
   * Tests libraries_detect() without a $name parameter.
268
   */
269
  public function testLibrariesDetectAll() {
270
    // Test that an array with all library information is returned and that the
271
    // libraries are properly detected.
272
    $libraries = libraries_detect();
273
    $this->verbose('<pre>' . var_export($libraries, TRUE) . '</pre>');
274
    $this->assertEqual($libraries['example_missing']['error'], 'not found');
275
    $this->assertEqual($libraries['example_undetected_version']['error'], 'not detected');
276
    $this->assertEqual($libraries['example_unsupported_version']['error'], 'not supported');
277
    $this->assertEqual($libraries['example_supported_version']['installed'], TRUE);
278
  }
279

  
309 280
  /**
310 281
   * Tests libraries_load().
311 282
   */
312
  function testLibrariesLoad() {
283
  public function testLibrariesLoad() {
313 284
    // Test dependencies.
314 285
    $library = libraries_load('example_dependency_missing');
315 286
    $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
......
334 305
  /**
335 306
   * Tests the applying of callbacks.
336 307
   */
337
  function testCallbacks() {
308
  public function testCallbacks() {
338 309
    $expected = array(
339 310
      'name' => 'Example callback',
340 311
      'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
......
453 424
   *
454 425
   * @see _libraries_test_module_load()
455 426
   */
456
  function testLibrariesOutput() {
427
  public function testLibrariesOutput() {
457 428
    // Test loading of a simple library with a top-level files property.
458 429
    $this->drupalGet('libraries-test-module/files');
459 430
    $this->assertLibraryFiles('example_1', 'File loading');
......
527 498
   *   (optional) The expected file extensions of $name. Defaults to
528 499
   *   array('js', 'css', 'php').
529 500
   */
530
  function assertLibraryFiles($name, $label = '', $extensions = array('js', 'css', 'php')) {
501
  public function assertLibraryFiles($name, $label = '', $extensions = array('js', 'css', 'php')) {
531 502
    $label = ($label !== '' ? "$label: " : '');
532 503

  
533 504
    // Test that the wrong files are not loaded...
......
570 541
  }
571 542

  
572 543
}
573

  
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff