You are here

function LibrariesTestCase::testLibrariesOutput in Libraries API 7.3

Tests that library files are properly added to the page output.

We check for JavaScript and CSS files directly in the DOM and add a list of included PHP files manually to the page output.

See also

_libraries_test_module_load()

File

tests/libraries.test, line 456
Tests for Libraries API.

Class

LibrariesTestCase
Tests basic detection and loading of libraries.

Code

function testLibrariesOutput() {

  // Test loading of a simple library with a top-level files property.
  $this
    ->drupalGet('libraries-test-module/files');
  $this
    ->assertLibraryFiles('example_1', 'File loading');

  // Test loading of integration files.
  $this
    ->drupalGet('libraries-test-module/module-integration-files');
  $this
    ->assertRaw('libraries_test_module.js', 'Integration file loading: libraries_test_module.js found');
  $this
    ->assertRaw('libraries_test_module.css', 'Integration file loading: libraries_test_module.css found');
  $this
    ->assertRaw('libraries_test_module.inc', 'Integration file loading: libraries_test_module.inc found');
  $this
    ->drupalGet('libraries-test-module/theme-integration-files');
  $this
    ->assertRaw('libraries_test_theme.js', 'Integration file loading: libraries_test_theme.js found');
  $this
    ->assertRaw('libraries_test_theme.css', 'Integration file loading: libraries_test_theme.css found');
  $this
    ->assertRaw('libraries_test_theme.inc', 'Integration file loading: libraries_test_theme.inc found');

  // Test version overloading.
  $this
    ->drupalGet('libraries-test-module/versions');
  $this
    ->assertLibraryFiles('example_2', 'Version overloading');

  // Test variant loading.
  $this
    ->drupalGet('libraries-test-module/variant');
  $this
    ->assertLibraryFiles('example_3', 'Variant loading');

  // Test version overloading and variant loading.
  $this
    ->drupalGet('libraries-test-module/versions-and-variants');
  $this
    ->assertLibraryFiles('example_4', 'Concurrent version and variant overloading');

  // Test caching.
  variable_set('libraries_test_module_cache', TRUE);
  cache_clear_all('example_callback', 'cache_libraries');

  // When the library information is not cached, all callback groups should be
  // invoked.
  $this
    ->drupalGet('libraries-test-module/cache');
  $this
    ->assertRaw('The <em>info</em> callback group was invoked.', 'Info callback invoked for uncached libraries.');
  $this
    ->assertRaw('The <em>pre-detect</em> callback group was invoked.', 'Pre-detect callback invoked for uncached libraries.');
  $this
    ->assertRaw('The <em>post-detect</em> callback group was invoked.', 'Post-detect callback invoked for uncached libraries.');
  $this
    ->assertRaw('The <em>pre-load</em> callback group was invoked.', 'Pre-load callback invoked for uncached libraries.');
  $this
    ->assertRaw('The <em>post-load</em> callback group was invoked.', 'Post-load callback invoked for uncached libraries.');

  // When the library information is cached only the 'pre-load' and
  // 'post-load' callback groups should be invoked.
  $this
    ->drupalGet('libraries-test-module/cache');
  $this
    ->assertNoRaw('The <em>info</em> callback group was not invoked.', 'Info callback not invoked for cached libraries.');
  $this
    ->assertNoRaw('The <em>pre-detect</em> callback group was not invoked.', 'Pre-detect callback not invoked for cached libraries.');
  $this
    ->assertNoRaw('The <em>post-detect</em> callback group was not invoked.', 'Post-detect callback not invoked for cached libraries.');
  $this
    ->assertRaw('The <em>pre-load</em> callback group was invoked.', 'Pre-load callback invoked for cached libraries.');
  $this
    ->assertRaw('The <em>post-load</em> callback group was invoked.', 'Post-load callback invoked for cached libraries.');
  variable_set('libraries_test_module_cache', FALSE);
}