Guest User

Untitled

a guest
Feb 20th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. define('DRUPAL_ROOT', 'your/path/to/drupal');
  2. require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  3. $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  4.  
  5. // Bootstrap Drupal.
  6. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  7.  
  8. // Proceed with PHPUnit tests as usual from here.
  9. class MyTest extends PHPUnit_Framework_TestCase {
  10. ...
  11.  
  12. <?php
  13.  
  14. $path = CWD;
  15.  
  16. $site_dir = NULL;
  17. $dpl_dir = NULL;
  18.  
  19. while ($path != '/') {
  20. if (file_exists($path . '/settings.php')) {
  21. $site_dir = $path;
  22. }
  23. if (file_exists($path . '/index.php') && file_exists($path . '/includes/bootstrap.inc')) {
  24. $dpl_dir = $path;
  25. break;
  26. }
  27. $path = dirname($path);
  28. }
  29.  
  30. if (!$dpl_dir) {
  31. echo "No drupal directory found in or above current working directory. Aborting. n";
  32. exit(1);
  33. }
  34. if (!$site_dir) {
  35. $site_dir = $dpl_dir . '/sites/default';
  36. if (!file_exists($site_dir . '/settings.php')) {
  37. echo "No configured site found. Aborting.n";
  38. exit(1);
  39. }
  40. }
  41.  
  42. $_SERVER['HTTP_HOST'] = basename($site_dir);
  43. $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  44.  
  45. define('DRUPAL_ROOT', $dpl_dir);
  46. set_include_path($dpl_dir . PATH_SEPARATOR . get_include_path());
  47. require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  48. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  49.  
  50. #!/bin/bash
  51.  
  52. # get dirname of the script
  53. DIR="$(dirname $(readlink "$0"))"
  54.  
  55. # assume the boostrap script is stored in the same directory
  56. php "$DIR/drun-phpunit.php" "$(pwd)" --bootstrap "$DIR/bootstrap.inc.php" "$@"
  57.  
  58. <?php
  59. require_once 'PHP/CodeCoverage/Filter.php';
  60. PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'PHPUNIT');
  61.  
  62. if (extension_loaded('xdebug')) {
  63. xdebug_disable();
  64. }
  65.  
  66. if (strpos('/usr/bin/php', '@php_bin') === 0) {
  67. set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
  68. }
  69.  
  70. require_once 'PHPUnit/Autoload.php';
  71. define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main');
  72. define('CWD', $_SERVER['argv'][1]);
  73. unset($_SERVER['argv'][1]);
  74.  
  75. $command = new PHPUnit_TextUI_Command;
  76. $command->run($_SERVER['argv']);
  77.  
  78. <?xml version="1.0" encoding="UTF-8"?>
  79. <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  80. xsi:noNamespaceSchemaLocation="phpunit.xsd"
  81. bootstrap="drupal_phpunit_bootstrap.php"
  82. verbose="true">
  83.  
  84. </phpunit>
  85.  
  86. <?php
  87.  
  88. $_SERVER['HTTP_HOST'] = 'your.url';
  89. $_SERVER['SCRIPT_NAME'] = '/index.php';
  90. $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  91. $_SERVER['REQUEST_METHOD'] = 'GET';
  92. $_SERVER['SERVER_NAME'] = NULL;
  93. $_SERVER['SERVER_SOFTWARE'] = NULL;
  94. $_SERVER['HTTP_USER_AGENT'] = NULL;
  95. // Fix for behat drupal instantiation.
  96. define('DRUPAL_ROOT', dirname(realpath(__FILE__)));
  97. require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  98. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
Add Comment
Please, Sign In to add comment