You are here

public function LibrariesLoadWebTest::testLibrariesInfo in Libraries API 7.2

Tests libraries_info().

File

tests/LibrariesLoadWebTest.test, line 131
Contains LibrariesLoadWebTest.

Class

LibrariesLoadWebTest
Tests basic detection and loading of libraries.

Code

public function testLibrariesInfo() {

  // Test that modules can provide and alter library information.
  $info = libraries_info();
  $this
    ->assertTrue(isset($info['example_module']));
  $this
    ->verbose('Library:<pre>' . var_export($info['example_module'], TRUE) . '</pre>');
  $this
    ->assertEqual($info['example_module']['info type'], 'module');
  $this
    ->assertEqual($info['example_module']['module'], 'libraries_test_module');
  $this
    ->assertTrue($info['example_module']['module_altered']);

  // Test that themes can provide and alter library information.
  $this
    ->assertTrue(isset($info['example_theme']));
  $this
    ->verbose('Library:<pre>' . var_export($info['example_theme'], TRUE) . '</pre>');
  $this
    ->assertEqual($info['example_theme']['info type'], 'theme');
  $this
    ->assertEqual($info['example_theme']['theme'], 'libraries_test_theme');
  $this
    ->assertTrue($info['example_theme']['theme_altered']);

  // Test that library information is found correctly.
  $expected = array(
    'name' => 'Example files',
    'library path' => drupal_get_path('module', 'libraries') . '/tests/libraries/example',
    'version' => '1',
    'files' => array(
      'js' => array(
        'example_1.js' => array(),
      ),
      'css' => array(
        'example_1.css' => array(),
      ),
      'php' => array(
        'example_1.php' => array(),
      ),
    ),
    'info type' => 'module',
    'module' => 'libraries_test_module',
  );
  libraries_info_defaults($expected, 'example_files');
  $library = libraries_info('example_files');
  $this
    ->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
  $this
    ->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
  $this
    ->assertEqual($library, $expected, 'Library information is correctly gathered.');

  // Test a library specified with an .info file gets detected.
  $expected = array(
    'name' => 'Example info file',
    'info type' => 'info file',
    'info file' => drupal_get_path('module', 'libraries') . '/tests/libraries/example_info_file.libraries.info',
  );
  libraries_info_defaults($expected, 'example_info_file');
  $library = libraries_info('example_info_file');

  // If this module was downloaded from Drupal.org, the Drupal.org packaging
  // system has corrupted the test info file.
  // @see http://drupal.org/node/1606606
  unset($library['core'], $library['datestamp'], $library['project'], $library['version']);
  $this
    ->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
  $this
    ->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
  $this
    ->assertEqual($library, $expected, 'Library specified with an .info file found');
}