btmash

Drupal Web Test Modifications - only test class requirements

Sep 8th, 2011
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
  2. index b2a7bf1..1c8b45f 100644
  3. --- a/modules/simpletest/drupal_web_test_case.php
  4. +++ b/modules/simpletest/drupal_web_test_case.php
  5. @@ -84,6 +84,13 @@ abstract class DrupalTestCase {
  6.    }
  7.  
  8.    /**
  9. +   * Check for access to the test.
  10. +   */
  11. +  public function checkRequirements() {
  12. +    return TRUE;
  13. +  }
  14. +
  15. +  /**
  16.     * Internal helper: stores the assert.
  17.     *
  18.     * @param $status
  19. @@ -461,29 +468,43 @@ abstract class DrupalTestCase {
  20.      if ($methods) {
  21.        $class_methods = array_intersect($class_methods, $methods);
  22.      }
  23. -    foreach ($class_methods as $method) {
  24. -      // If the current method starts with "test", run it - it's a test.
  25. -      if (strtolower(substr($method, 0, 4)) == 'test') {
  26. -        // Insert a fail record. This will be deleted on completion to ensure
  27. -        // that testing completed.
  28. -        $method_info = new ReflectionMethod($class, $method);
  29. -        $caller = array(
  30. -          'file' => $method_info->getFileName(),
  31. -          'line' => $method_info->getStartLine(),
  32. -          'function' => $class . '->' . $method . '()',
  33. -        );
  34. -        $completion_check_id = DrupalTestCase::insertAssert($this->testId, $class, FALSE, t('The test did not complete due to a fatal error.'), 'Completion check', $caller);
  35. -        $this->setUp();
  36. -        try {
  37. -          $this->$method();
  38. -          // Finish up.
  39. -        }
  40. -        catch (Exception $e) {
  41. -          $this->exceptionHandler($e);
  42. +    $access = $this->checkRequirements();
  43. +    if ($access !== TRUE && isset($access['errors']) && count($access['errors']) > 0) {
  44. +      $error_object = new ReflectionObject($this);
  45. +      $caller = array(
  46. +        'file' => $error_object->getFileName(),
  47. +        'line' => 0,
  48. +        'function' => 'n/a',
  49. +      );
  50. +      foreach ($access['errors'] as $error) {
  51. +        DrupalTestCase::insertAssert($this->testId, $class, FALSE, $error, 'Requirements check', $caller);
  52. +      }
  53. +    }
  54. +    else {
  55. +      foreach ($class_methods as $method) {
  56. +        // If the current method starts with "test", run it - it's a test.
  57. +        if (strtolower(substr($method, 0, 4)) == 'test') {
  58. +          // Insert a fail record. This will be deleted on completion to ensure
  59. +          // that testing completed.
  60. +          $method_info = new ReflectionMethod($class, $method);
  61. +          $caller = array(
  62. +            'file' => $method_info->getFileName(),
  63. +            'line' => $method_info->getStartLine(),
  64. +            'function' => $class . '->' . $method . '()',
  65. +          );
  66. +          $completion_check_id = DrupalTestCase::insertAssert($this->testId, $class, FALSE, t('The test did not complete due to a fatal error.'), 'Completion check', $caller);
  67. +          $this->setUp();
  68. +          try {
  69. +            $this->$method();
  70. +            // Finish up.
  71. +          }
  72. +          catch (Exception $e) {
  73. +            $this->exceptionHandler($e);
  74. +          }
  75. +          $this->tearDown();
  76. +          // Remove the completion check record.
  77. +          DrupalTestCase::deleteAssert($completion_check_id);
  78.          }
  79. -        $this->tearDown();
  80. -        // Remove the completion check record.
  81. -        DrupalTestCase::deleteAssert($completion_check_id);
  82.        }
  83.      }
  84.      // Clear out the error messages and restore error handler.
RAW Paste Data