qunit.module 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Implements hook_permission().
  4. */
  5. function qunit_permission() {
  6. if (module_exists('simpletest')) {
  7. return array();
  8. }
  9. else {
  10. return array(
  11. 'administer unit tests' => array(
  12. 'title' => t('Administer unit tests'),
  13. 'description' => t('Manage and run automated testing. %warning', array('%warning' => t('Warning: Give to trusted roles only; this permission has security implications.'))),
  14. ),
  15. );
  16. }
  17. }
  18. /**
  19. * Implements hook_menu().
  20. */
  21. function qunit_menu() {
  22. $items['admin/config/development/qunit'] = array(
  23. 'title' => 'JavaScript testing',
  24. 'description' => "Run the tests for Drupal's JavaScript code, which will make sure that the JavaScript works properly your browser.",
  25. 'page callback' => 'qunit_run_tests',
  26. 'access arguments' => array('administer unit tests'),
  27. );
  28. return $items;
  29. }
  30. /**
  31. * Implements hook_library().
  32. */
  33. function qunit_library() {
  34. $libraries['qunit'] = array(
  35. 'title' => 'QUnit',
  36. 'website' => 'http://docs.jquery.com/QUnit',
  37. 'version' => '20110420',
  38. 'js' => array(
  39. // The QUnit JavaScript library.
  40. drupal_get_path('module', 'qunit') . '/qunit/qunit/qunit.js' => array('weight' => JS_LIBRARY),
  41. // The QUnit Drupal behavior.
  42. drupal_get_path('module', 'qunit') . '/qunit.admin.js' => array(),
  43. ),
  44. 'css' => array(
  45. // The QUnit library CSS framework.
  46. drupal_get_path('module', 'qunit') . '/qunit/qunit/qunit.css' => array(),
  47. // CSS fixes to make QUnit look nicer when in Drupal.
  48. drupal_get_path('module', 'qunit') . '/qunit.admin.css' => array(),
  49. ),
  50. );
  51. return $libraries;
  52. }
  53. /**
  54. * Implements hook_library_alter().
  55. */
  56. function qunit_library_alter(&$libraries, $module) {
  57. // Add available JavaScript tests and dependencies.
  58. if ($module == 'qunit') {
  59. $libraries['qunit']['js'][drupal_get_path('module', 'qunit') . '/tests/drupal.test.js'] = array();
  60. $libraries['qunit']['js'][drupal_get_path('module', 'qunit') . '/tests/jquery.once.test.js'] = array();
  61. }
  62. }
  63. /**
  64. * Menu callback; Page to run all the JavaScript tests.
  65. */
  66. function qunit_run_tests() {
  67. drupal_add_library('qunit', 'qunit');
  68. $output = '<div id="qunit-wrapper"><h1 id="qunit-header">QUnit Test Suite</h1><h2 id="qunit-banner"></h2><div id="qunit-testrunner-toolbar"></div><h2 id="qunit-userAgent"></h2><ol id="qunit-tests"></ol><div id="qunit-fixture">test markup</div></div>';
  69. return $output;
  70. }