libraries.test 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <?php
  2. /**
  3. * @file
  4. * Tests for Libraries API.
  5. */
  6. /**
  7. * Tests basic Libraries API functions.
  8. */
  9. class LibrariesUnitTestCase extends DrupalUnitTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Libraries API unit tests',
  13. 'description' => 'Tests basic functions provided by Libraries API.',
  14. 'group' => 'Libraries API',
  15. );
  16. }
  17. function setUp() {
  18. drupal_load('module', 'libraries');
  19. parent::setUp();
  20. }
  21. /**
  22. * Tests libraries_get_path().
  23. */
  24. function testLibrariesGetPath() {
  25. // Note that, even though libraries_get_path() doesn't find the 'example'
  26. // library, we are able to make it 'installed' by specifying the 'library
  27. // path' up-front. This is only used for testing purposed and is strongly
  28. // discouraged as it defeats the purpose of Libraries API in the first
  29. // place.
  30. $this->assertEqual(libraries_get_path('example'), FALSE, 'libraries_get_path() returns FALSE for a missing library.');
  31. }
  32. /**
  33. * Tests libraries_prepare_files().
  34. */
  35. function testLibrariesPrepareFiles() {
  36. $expected = array(
  37. 'files' => array(
  38. 'js' => array('example.js' => array()),
  39. 'css' => array('example.css' => array()),
  40. 'php' => array('example.php' => array()),
  41. ),
  42. );
  43. $library = array(
  44. 'files' => array(
  45. 'js' => array('example.js'),
  46. 'css' => array('example.css'),
  47. 'php' => array('example.php'),
  48. ),
  49. );
  50. libraries_prepare_files($library, NULL, NULL);
  51. $this->assertEqual($expected, $library, 'libraries_prepare_files() works correctly.');
  52. }
  53. }
  54. /**
  55. * Tests basic detection and loading of libraries.
  56. */
  57. class LibrariesTestCase extends DrupalWebTestCase {
  58. protected $profile = 'testing';
  59. public static function getInfo() {
  60. return array(
  61. 'name' => 'Libraries detection and loading',
  62. 'description' => 'Tests detection and loading of libraries.',
  63. 'group' => 'Libraries API',
  64. );
  65. }
  66. function setUp() {
  67. parent::setUp('libraries', 'libraries_test');
  68. }
  69. /**
  70. * Tests libraries_detect_dependencies().
  71. */
  72. function testLibrariesDetectDependencies() {
  73. $library = array(
  74. 'name' => 'Example',
  75. 'dependencies' => array('example_missing'),
  76. );
  77. libraries_detect_dependencies($library);
  78. $this->assertEqual($library['error'], 'missing dependency', 'libraries_detect_dependencies() detects missing dependency');
  79. $error_message = t('The %dependency library, which the %library library depends on, is not installed.', array(
  80. '%dependency' => 'Example missing',
  81. '%library' => $library['name'],
  82. ));
  83. $this->verbose("Expected:<br>$error_message");
  84. $this->verbose('Actual:<br>' . $library['error message']);
  85. $this->assertEqual($library['error message'], $error_message, 'Correct error message for a missing dependency');
  86. // Test versioned dependencies.
  87. $version = '1.1';
  88. $compatible = array(
  89. '1.1',
  90. '<=1.1',
  91. '>=1.1',
  92. '<1.2',
  93. '<2.0',
  94. '>1.0',
  95. '>1.0-rc1',
  96. '>1.0-beta2',
  97. '>1.0-alpha3',
  98. '>0.1',
  99. '<1.2, >1.0',
  100. '>0.1, <=1.1',
  101. );
  102. $incompatible = array(
  103. '1.2',
  104. '2.0',
  105. '<1.1',
  106. '>1.1',
  107. '<=1.0',
  108. '<=1.0-rc1',
  109. '<=1.0-beta2',
  110. '<=1.0-alpha3',
  111. '>=1.2',
  112. '<1.1, >0.9',
  113. '>=0.1, <1.1',
  114. );
  115. $library = array(
  116. 'name' => 'Example',
  117. );
  118. foreach ($compatible as $version_string) {
  119. $library['dependencies'][0] = "example_dependency ($version_string)";
  120. // libraries_detect_dependencies() is a post-detect callback, so
  121. // 'installed' is already set, when it is called. It sets the value to
  122. // FALSE for missing or incompatible dependencies.
  123. $library['installed'] = TRUE;
  124. libraries_detect_dependencies($library);
  125. $this->assertTrue($library['installed'], "libraries_detect_dependencies() detects compatible version string: '$version_string' is compatible with '$version'");
  126. }
  127. foreach ($incompatible as $version_string) {
  128. $library['dependencies'][0] = "example_dependency ($version_string)";
  129. $library['installed'] = TRUE;
  130. unset($library['error'], $library['error message']);
  131. libraries_detect_dependencies($library);
  132. $this->assertEqual($library['error'], 'incompatible dependency', "libraries_detect_dependencies() detects incompatible version strings: '$version_string' is incompatible with '$version'");
  133. }
  134. // Instead of repeating this assertion for each version string, we just
  135. // re-use the $library variable from the foreach loop.
  136. $error_message = t('The version %dependency_version of the %dependency library is not compatible with the %library library.', array(
  137. '%dependency_version' => $version,
  138. '%dependency' => 'Example dependency',
  139. '%library' => $library['name'],
  140. ));
  141. $this->verbose("Expected:<br>$error_message");
  142. $this->verbose('Actual:<br>' . $library['error message']);
  143. $this->assertEqual($library['error message'], $error_message, 'Correct error message for an incompatible dependency');
  144. }
  145. /**
  146. * Tests libraries_scan_info_files().
  147. */
  148. function testLibrariesScanInfoFiles() {
  149. $expected = array('example_info_file' => (object) array(
  150. 'uri' => drupal_get_path('module', 'libraries') . '/tests/example/example_info_file.libraries.info',
  151. 'filename' => 'example_info_file.libraries.info',
  152. 'name' => 'example_info_file.libraries',
  153. ));
  154. $this->assertEqual(libraries_scan_info_files(), $expected, 'libraries_scan_info_files() correctly finds the example info file.');
  155. $this->verbose('<pre>' . var_export(libraries_scan_info_files(), TRUE) . '</pre>');
  156. }
  157. /**
  158. * Tests libraries_info().
  159. */
  160. function testLibrariesInfo() {
  161. // Test that library information is found correctly.
  162. $expected = array(
  163. 'name' => 'Example files',
  164. 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
  165. 'version' => '1',
  166. 'files' => array(
  167. 'js' => array('example_1.js' => array()),
  168. 'css' => array('example_1.css' => array()),
  169. 'php' => array('example_1.php' => array()),
  170. ),
  171. 'module' => 'libraries_test',
  172. );
  173. libraries_info_defaults($expected, 'example_files');
  174. $library = libraries_info('example_files');
  175. $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
  176. $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
  177. $this->assertEqual($library, $expected, 'Library information is correctly gathered.');
  178. // Test a library specified with an .info file gets detected.
  179. $expected = array(
  180. 'name' => 'Example info file',
  181. 'info file' => drupal_get_path('module', 'libraries_test') . '/example/example_info_file.libraries.info',
  182. );
  183. libraries_info_defaults($expected, 'example_info_file');
  184. $library = libraries_info('example_info_file');
  185. // If this module was downloaded from Drupal.org, the Drupal.org packaging
  186. // system has corrupted the test info file.
  187. // @see http://drupal.org/node/1606606
  188. unset($library['core'], $library['datestamp'], $library['project'], $library['version']);
  189. $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
  190. $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
  191. $this->assertEqual($library, $expected, 'Library specified with an .info file found');
  192. }
  193. /**
  194. * Tests libraries_detect().
  195. */
  196. function testLibrariesDetect() {
  197. // Test missing library.
  198. $library = libraries_detect('example_missing');
  199. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  200. $this->assertEqual($library['error'], 'not found', 'Missing library not found.');
  201. $error_message = t('The %library library could not be found.', array(
  202. '%library' => $library['name'],
  203. ));
  204. $this->assertEqual($library['error message'], $error_message, 'Correct error message for a missing library.');
  205. // Test unknown library version.
  206. $library = libraries_detect('example_undetected_version');
  207. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  208. $this->assertEqual($library['error'], 'not detected', 'Undetected version detected as such.');
  209. $error_message = t('The version of the %library library could not be detected.', array(
  210. '%library' => $library['name'],
  211. ));
  212. $this->assertEqual($library['error message'], $error_message, 'Correct error message for a library with an undetected version.');
  213. // Test unsupported library version.
  214. $library = libraries_detect('example_unsupported_version');
  215. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  216. $this->assertEqual($library['error'], 'not supported', 'Unsupported version detected as such.');
  217. $error_message = t('The installed version %version of the %library library is not supported.', array(
  218. '%version' => $library['version'],
  219. '%library' => $library['name'],
  220. ));
  221. $this->assertEqual($library['error message'], $error_message, 'Correct error message for a library with an unsupported version.');
  222. // Test supported library version.
  223. $library = libraries_detect('example_supported_version');
  224. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  225. $this->assertEqual($library['installed'], TRUE, 'Supported library version found.');
  226. // Test libraries_get_version().
  227. $library = libraries_detect('example_default_version_callback');
  228. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  229. $this->assertEqual($library['version'], '1', 'Expected version returned by default version callback.');
  230. // Test a multiple-parameter version callback.
  231. $library = libraries_detect('example_multiple_parameter_version_callback');
  232. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  233. $this->assertEqual($library['version'], '1', 'Expected version returned by multiple parameter version callback.');
  234. // Test a top-level files property.
  235. $library = libraries_detect('example_files');
  236. $files = array(
  237. 'js' => array('example_1.js' => array()),
  238. 'css' => array('example_1.css' => array()),
  239. 'php' => array('example_1.php' => array()),
  240. );
  241. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  242. $this->assertEqual($library['files'], $files, 'Top-level files property works.');
  243. // Test version-specific library files.
  244. $library = libraries_detect('example_versions');
  245. $files = array(
  246. 'js' => array('example_2.js' => array()),
  247. 'css' => array('example_2.css' => array()),
  248. 'php' => array('example_2.php' => array()),
  249. );
  250. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  251. $this->assertEqual($library['files'], $files, 'Version-specific library files found.');
  252. // Test missing variant.
  253. $library = libraries_detect('example_variant_missing');
  254. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  255. $this->assertEqual($library['variants']['example_variant']['error'], 'not found', 'Missing variant not found');
  256. $error_message = t('The %variant variant of the %library library could not be found.', array(
  257. '%variant' => 'example_variant',
  258. '%library' => 'Example variant missing',
  259. ));
  260. $this->assertEqual($library['variants']['example_variant']['error message'], $error_message, 'Correct error message for a missing variant.');
  261. // Test existing variant.
  262. $library = libraries_detect('example_variant');
  263. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  264. $this->assertEqual($library['variants']['example_variant']['installed'], TRUE, 'Existing variant found.');
  265. }
  266. /**
  267. * Tests libraries_load().
  268. */
  269. function testLibrariesLoad() {
  270. // Test dependencies.
  271. $library = libraries_load('example_dependency_missing');
  272. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  273. $this->assertFalse($library['loaded'], 'Library with missing dependency cannot be loaded');
  274. $library = libraries_load('example_dependency_incompatible');
  275. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  276. $this->assertFalse($library['loaded'], 'Library with incompatible dependency cannot be loaded');
  277. $library = libraries_load('example_dependency_compatible');
  278. $this->verbose('<pre>' . var_export($library, TRUE) . '</pre>');
  279. $this->assertEqual($library['loaded'], 1, 'Library with compatible dependency is loaded');
  280. $loaded = &drupal_static('libraries_load');
  281. $this->verbose('<pre>' . var_export($loaded, TRUE) . '</pre>');
  282. $this->assertEqual($loaded['example_dependency']['loaded'], 1, 'Dependency library is also loaded');
  283. }
  284. /**
  285. * Tests the applying of callbacks.
  286. */
  287. function testCallbacks() {
  288. $expected = array(
  289. 'name' => 'Example callback',
  290. 'library path' => drupal_get_path('module', 'libraries') . '/tests/example',
  291. 'version' => '1',
  292. 'versions' => array(
  293. '1' => array(
  294. 'variants' => array(
  295. 'example_variant' => array(
  296. 'info callback' => 'not applied',
  297. 'pre-detect callback' => 'not applied',
  298. 'post-detect callback' => 'not applied',
  299. 'pre-dependencies-load callback' => 'not applied',
  300. 'pre-load callback' => 'not applied',
  301. 'post-load callback' => 'not applied',
  302. ),
  303. ),
  304. 'info callback' => 'not applied',
  305. 'pre-detect callback' => 'not applied',
  306. 'post-detect callback' => 'not applied',
  307. 'pre-dependencies-load callback' => 'not applied',
  308. 'pre-load callback' => 'not applied',
  309. 'post-load callback' => 'not applied',
  310. ),
  311. ),
  312. 'variants' => array(
  313. 'example_variant' => array(
  314. 'info callback' => 'not applied',
  315. 'pre-detect callback' => 'not applied',
  316. 'post-detect callback' => 'not applied',
  317. 'pre-dependencies-load callback' => 'not applied',
  318. 'pre-load callback' => 'not applied',
  319. 'post-load callback' => 'not applied',
  320. ),
  321. ),
  322. 'callbacks' => array(
  323. 'info' => array('_libraries_test_info_callback'),
  324. 'pre-detect' => array('_libraries_test_pre_detect_callback'),
  325. 'post-detect' => array('_libraries_test_post_detect_callback'),
  326. 'pre-dependencies-load' => array('_libraries_test_pre_dependencies_load_callback'),
  327. 'pre-load' => array('_libraries_test_pre_load_callback'),
  328. 'post-load' => array('_libraries_test_post_load_callback'),
  329. ),
  330. 'info callback' => 'not applied',
  331. 'pre-detect callback' => 'not applied',
  332. 'post-detect callback' => 'not applied',
  333. 'pre-dependencies-load callback' => 'not applied',
  334. 'pre-load callback' => 'not applied',
  335. 'post-load callback' => 'not applied',
  336. 'module' => 'libraries_test',
  337. );
  338. libraries_info_defaults($expected, 'example_callback');
  339. // Test a callback in the 'info' group.
  340. $expected['info callback'] = 'applied (top-level)';
  341. $expected['versions']['1']['info callback'] = 'applied (version 1)';
  342. $expected['versions']['1']['variants']['example_variant']['info callback'] = 'applied (version 1, variant example_variant)';
  343. $expected['variants']['example_variant']['info callback'] = 'applied (variant example_variant)';
  344. $library = libraries_info('example_callback');
  345. $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
  346. $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
  347. $this->assertEqual($library, $expected, 'Prepare callback was applied correctly.');
  348. // Test a callback in the 'pre-detect' and 'post-detect' phases.
  349. // Successfully detected libraries should only contain version information
  350. // for the detected version and thus, be marked as installed.
  351. unset($expected['versions']);
  352. $expected['installed'] = TRUE;
  353. // Additionally, version-specific properties of the detected version are
  354. // supposed to override the corresponding top-level properties.
  355. $expected['info callback'] = 'applied (version 1)';
  356. $expected['variants']['example_variant']['installed'] = TRUE;
  357. $expected['variants']['example_variant']['info callback'] = 'applied (version 1, variant example_variant)';
  358. // Version-overloading takes place after the 'pre-detect' callbacks have
  359. // been applied.
  360. $expected['pre-detect callback'] = 'applied (version 1)';
  361. $expected['post-detect callback'] = 'applied (top-level)';
  362. $expected['variants']['example_variant']['pre-detect callback'] = 'applied (version 1, variant example_variant)';
  363. $expected['variants']['example_variant']['post-detect callback'] = 'applied (variant example_variant)';
  364. $library = libraries_detect('example_callback');
  365. $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
  366. $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
  367. $this->assertEqual($library, $expected, 'Detect callback was applied correctly.');
  368. // Test a callback in the 'pre-dependencies-load', 'pre-load' and
  369. // 'post-load' phases.
  370. // Successfully loaded libraries should only contain information about the
  371. // already loaded variant.
  372. unset($expected['variants']);
  373. $expected['loaded'] = 0;
  374. $expected['pre-dependencies-load callback'] = 'applied (top-level)';
  375. $expected['pre-load callback'] = 'applied (top-level)';
  376. $expected['post-load callback'] = 'applied (top-level)';
  377. $library = libraries_load('example_callback');
  378. $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
  379. $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
  380. $this->assertEqual($library, $expected, 'Pre-load and post-load callbacks were applied correctly.');
  381. // This is not recommended usually and is only used for testing purposes.
  382. drupal_static_reset('libraries_load');
  383. // Successfully loaded library variants are supposed to contain the specific
  384. // variant information only.
  385. $expected['info callback'] = 'applied (version 1, variant example_variant)';
  386. $expected['pre-detect callback'] = 'applied (version 1, variant example_variant)';
  387. $expected['post-detect callback'] = 'applied (variant example_variant)';
  388. $library = libraries_load('example_callback', 'example_variant');
  389. $this->verbose('Expected:<pre>' . var_export($expected, TRUE) . '</pre>');
  390. $this->verbose('Actual:<pre>' . var_export($library, TRUE) . '</pre>');
  391. $this->assertEqual($library, $expected, 'Pre-detect and post-detect callbacks were applied correctly to a variant.');
  392. }
  393. /**
  394. * Tests that library files are properly added to the page output.
  395. *
  396. * We check for JavaScript and CSS files directly in the DOM and add a list of
  397. * included PHP files manually to the page output.
  398. *
  399. * @see _libraries_test_load()
  400. */
  401. function testLibrariesOutput() {
  402. // Test loading of a simple library with a top-level files property.
  403. $this->drupalGet('libraries_test/files');
  404. $this->assertLibraryFiles('example_1', 'File loading');
  405. // Test loading of integration files.
  406. $this->drupalGet('libraries_test/integration_files');
  407. $this->assertRaw('libraries_test.js', 'Integration file loading: libraries_test.js found');
  408. $this->assertRaw('libraries_test.css', 'Integration file loading: libraries_test.css found');
  409. $this->assertRaw('libraries_test.inc', 'Integration file loading: libraries_test.inc found');
  410. // Test version overloading.
  411. $this->drupalGet('libraries_test/versions');
  412. $this->assertLibraryFiles('example_2', 'Version overloading');
  413. // Test variant loading.
  414. $this->drupalGet('libraries_test/variant');
  415. $this->assertLibraryFiles('example_3', 'Variant loading');
  416. // Test version overloading and variant loading.
  417. $this->drupalGet('libraries_test/versions_and_variants');
  418. $this->assertLibraryFiles('example_4', 'Concurrent version and variant overloading');
  419. // Test caching.
  420. variable_set('libraries_test_cache', TRUE);
  421. cache_clear_all('example_callback', 'cache_libraries');
  422. // When the library information is not cached, all callback groups should be
  423. // invoked.
  424. $this->drupalGet('libraries_test/cache');
  425. $this->assertRaw('The <em>info</em> callback group was invoked.', 'Info callback invoked for uncached libraries.');
  426. $this->assertRaw('The <em>pre-detect</em> callback group was invoked.', 'Pre-detect callback invoked for uncached libraries.');
  427. $this->assertRaw('The <em>post-detect</em> callback group was invoked.', 'Post-detect callback invoked for uncached libraries.');
  428. $this->assertRaw('The <em>pre-load</em> callback group was invoked.', 'Pre-load callback invoked for uncached libraries.');
  429. $this->assertRaw('The <em>post-load</em> callback group was invoked.', 'Post-load callback invoked for uncached libraries.');
  430. // When the library information is cached only the 'pre-load' and
  431. // 'post-load' callback groups should be invoked.
  432. $this->drupalGet('libraries_test/cache');
  433. $this->assertNoRaw('The <em>info</em> callback group was not invoked.', 'Info callback not invoked for cached libraries.');
  434. $this->assertNoRaw('The <em>pre-detect</em> callback group was not invoked.', 'Pre-detect callback not invoked for cached libraries.');
  435. $this->assertNoRaw('The <em>post-detect</em> callback group was not invoked.', 'Post-detect callback not invoked for cached libraries.');
  436. $this->assertRaw('The <em>pre-load</em> callback group was invoked.', 'Pre-load callback invoked for cached libraries.');
  437. $this->assertRaw('The <em>post-load</em> callback group was invoked.', 'Post-load callback invoked for cached libraries.');
  438. variable_set('libraries_test_cache', FALSE);
  439. }
  440. /**
  441. * Helper function to assert that a library was correctly loaded.
  442. *
  443. * Asserts that all the correct files were loaded and all the incorrect ones
  444. * were not.
  445. *
  446. * @param $name
  447. * The name of the files that should be loaded. The current testing system
  448. * knows of 'example_1', 'example_2', 'example_3' and 'example_4'. Each name
  449. * has an associated JavaScript, CSS and PHP file that will be asserted. All
  450. * other files will be asserted to not be loaded. See
  451. * tests/example/README.txt for more information on how the loading of the
  452. * files is tested.
  453. * @param $label
  454. * (optional) A label to prepend to the assertion messages, to make them
  455. * less ambiguous.
  456. * @param $extensions
  457. * (optional) The expected file extensions of $name. Defaults to
  458. * array('js', 'css', 'php').
  459. */
  460. function assertLibraryFiles($name, $label = '', $extensions = array('js', 'css', 'php')) {
  461. $label = ($label !== '' ? "$label: " : '');
  462. // Test that the wrong files are not loaded...
  463. $names = array(
  464. 'example_1' => FALSE,
  465. 'example_2' => FALSE,
  466. 'example_3' => FALSE,
  467. 'example_4' => FALSE,
  468. );
  469. // ...and the correct ones are.
  470. $names[$name] = TRUE;
  471. // Test for the specific HTML that the different file types appear as in the
  472. // DOM.
  473. $html = array(
  474. 'js' => array('<script type="text/javascript" src="', '"></script>'),
  475. 'css' => array('@import url("', '");'),
  476. // PHP files do not get added to the DOM directly.
  477. // @see _libraries_test_load()
  478. 'php' => array('<li>', '</li>'),
  479. );
  480. foreach ($names as $name => $expected) {
  481. foreach ($extensions as $extension) {
  482. $filepath = drupal_get_path('module', 'libraries_test') . "/example/$name.$extension";
  483. // JavaScript and CSS files appear as full URLs and with an appended
  484. // query string.
  485. if (in_array($extension, array('js', 'css'))) {
  486. $filepath = url('', array('absolute' => TRUE)) . $filepath . '?' . variable_get('css_js_query_string');
  487. }
  488. $raw = $html[$extension][0] . $filepath . $html[$extension][1];
  489. if ($expected) {
  490. $this->assertRaw($raw, "$label$name.$extension found.");
  491. }
  492. else {
  493. $this->assertNoRaw($raw, "$label$name.$extension not found.");
  494. }
  495. }
  496. }
  497. }
  498. }