diff --git a/tests/libraries.test b/tests/libraries.test index 2a2e2cf..8c33541 100644 --- a/tests/libraries.test +++ b/tests/libraries.test @@ -297,24 +297,41 @@ class LibrariesTestCase extends DrupalWebTestCase { * array('js', 'css', 'php'). */ function assertLibraryFiles($name, $label = '', $extensions = array('js', 'css', 'php')) { - $names = drupal_map_assoc(array('example_1', 'example_2', 'example_3', 'example_4')); - unset($names[$name]); + // Test that the wrong files are not loaded... + $names = array( + 'example_1' => FALSE, + 'example_2' => FALSE, + 'example_3' => FALSE, + 'example_4' => FALSE, + ); + // ...and the correct ones are. + $names[$name] = TRUE; + + // Test for the specific HTML that the different file types appear as in the + // DOM. + $html = array( + 'js' => array(''), + 'css' => array('@import url("', '");'), + // PHP files do not get added to the DOM directly. + // @see _libraries_test_load() + 'php' => array('
  • ', '
  • '), + ); - // Test that the wrong files are not loaded. - foreach ($names as $filename) { + foreach ($names as $name => $found) { foreach ($extensions as $extension) { - $message = "$filename.$extension not found"; + $filepath = url(drupal_get_path('module', 'libraries_test') . "/example/$name.$extension"); + // JavaScript and CSS files appear as full URLs and with an appended + // query string. + if (in_array($extension, array('js', 'css'))) { + // Avoid a double forward slash through concatenation. + $filepath = url('', array('absolute' => TRUE)) . substr($filepath, 1) . '?' . variable_get('css_js_query_string'); + } + $raw = $html[$extension][0] . $filepath . $html[$extension][1]; + $message = ($found ? "$name.$extension found." : "$name.$extension not found."); $message = ($label !== '' ? "$label: $message" : $message); - $this->assertNoRaw("$filename.$extension", $message); + ($found ? $this->assertRaw($raw, $message) : $this->assertNoRaw($raw, $message)); } } - - // Test that the correct files are loaded. - foreach ($extensions as $extension) { - $message = "$name.$extension found"; - $message = ($label !== '' ? "$label: $message" : $message); - $this->assertRaw("$name.$extension", $message); - } } } diff --git a/tests/libraries_test.module b/tests/libraries_test.module index 4893b11..1f593b5 100644 --- a/tests/libraries_test.module +++ b/tests/libraries_test.module @@ -489,7 +489,7 @@ function _libraries_test_load($library, $variant = NULL) { $files = get_included_files(); foreach ($files as $file) { if (strpos($file, 'libraries/test') && !strpos($file, 'libraries_test.module')) { - $output .= '
  • ' . strstr($file, 'libraries/test') . '
  • '; + $output .= '
  • ' . str_replace(DRUPAL_ROOT, '', $file) . '
  • '; } } $output .= '';