You are here

public function LibrariesLoadWebTest::testLibrariesOutput in Libraries API 7.2

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/LibrariesLoadWebTest.test, line 427
Contains LibrariesLoadWebTest.

Class

LibrariesLoadWebTest
Tests basic detection and loading of libraries.

Code

public 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 loading of post-load integration files.
  $this
    ->drupalGet('libraries-test-module/module-integration-files-post-load');

  // If the files were not loaded correctly, a fatal error occurs.
  $this
    ->assertResponse(200, 'Post-load integration files are loaded correctly.');

  // 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);
}