Commit e2472883 authored by tstoeckler's avatar tstoeckler

Issue #1205854 by tstoeckler, sun: Test library caching.

parent 390ae67a
Libraries 7.x-2.x, xxxx-xx-xx
-----------------------------
#1205854 by tstoeckler, sun: Test library caching.
Libraries 7.x-2.0-ALPHA1, 2011-10-01
......
......@@ -360,6 +360,25 @@ class LibrariesTestCase extends DrupalWebTestCase {
// Test version overloading and variant loading.
$this->drupalGet('libraries_test/versions_and_variants');
$this->assertLibraryFiles('example_4', 'Concurrent version and variant overloading');
// Test caching.
variable_set('libraries_test_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/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>load</em> callback group was invoked.', 'Load callback invoked for uncached libraries.');
// When the library information is cached only the load callback group should
// be invoked.
$this->drupalGet('libraries_test/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>load</em> callback group was invoked.', 'Load callback invoked for cached libraries.');
variable_set('libraries_test_cache', FALSE);
}
/**
......
......@@ -438,41 +438,46 @@ function _libraries_test_callback(&$library, $version, $variant, $group) {
$string .= ' (top-level)';
}
$library["$group callback"] = $string;
// The following is used to test caching of library information.
// Only set the message for the top-level library to prevent confusing,
// duplicate messages.
if (!isset($version) && !isset($variant) && variable_get('libraries_test_cache', FALSE)) {
drupal_set_message("The <em>$group</em> callback group was invoked.");
}
}
/**
* Implements hook_menu().
*/
function libraries_test_menu() {
$items['libraries_test/files'] = array(
'title' => 'Test files',
$base = array(
'page callback' => '_libraries_test_load',
'page arguments' => array('example_files'),
'access callback' => TRUE,
);
$items['libraries_test/integration_files'] = array(
$items['libraries_test/files'] = $base + array(
'title' => 'Test files',
'page arguments' => array('example_files'),
);
$items['libraries_test/integration_files'] = $base + array(
'title' => 'Test integration files',
'page callback' => '_libraries_test_load',
'page arguments' => array('example_integration_files'),
'access callback' => TRUE,
);
$items['libraries_test/versions'] = array(
$items['libraries_test/versions'] = $base + array(
'title' => 'Test version loading',
'page callback' => '_libraries_test_load',
'page arguments' => array('example_versions'),
'access callback' => TRUE,
);
$items['libraries_test/variant'] = array(
$items['libraries_test/variant'] = $base + array(
'title' => 'Test variant loading',
'page callback' => '_libraries_test_load',
'page arguments' => array('example_variant', 'example_variant'),
'access callback' => TRUE,
);
$items['libraries_test/versions_and_variants'] = array(
$items['libraries_test/versions_and_variants'] = $base + array(
'title' => 'Test concurrent version and variant loading',
'page callback' => '_libraries_test_load',
'page arguments' => array('example_versions_and_variants', 'example_variant_2'),
'access callback' => TRUE,
);
$items['libraries_test/cache'] = $base + array(
'title' => 'Test caching of library information',
'page arguments' => array('example_callback'),
);
return $items;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment