Advertisement
btmash

Drupal Web Test Modifications

Sep 7th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.77 KB | None | 0 0
  1. diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
  2. index 5c39cfc..6617ae4 100644
  3. --- a/modules/simpletest/drupal_web_test_case.php
  4. +++ b/modules/simpletest/drupal_web_test_case.php
  5. @@ -82,6 +82,29 @@ abstract class DrupalTestCase {
  6.    public function __construct($test_id = NULL) {
  7.      $this->testId = $test_id;
  8.    }
  9. +  
  10. +  /**
  11. +   * Check for access to the test.
  12. +   */
  13. +  public function checkRequirements() {
  14. +    $class = get_class($this);
  15. +    $errors = array();
  16. +    if (method_exists($class, 'getInfo')) {
  17. +      $info = call_user_func(array($class, 'getInfo'));
  18. +      // If this test class requires a non-existing module, skip it.
  19. +      if (!empty($info['dependencies'])) {
  20. +        foreach ($info['dependencies'] as $module) {
  21. +          if (!drupal_get_filename('module', $module)) {
  22. +            $errors[] = t('Missing dependency: '. $module);
  23. +          }
  24. +        }
  25. +      }
  26. +    }
  27. +    if (count($errors) > 0) {
  28. +      return array('errors' => $errors);
  29. +    }
  30. +    return TRUE;
  31. +  }
  32.  
  33.    /**
  34.     * Internal helper: stores the assert.
  35. @@ -461,29 +484,43 @@ abstract class DrupalTestCase {
  36.      if ($methods) {
  37.        $class_methods = array_intersect($class_methods, $methods);
  38.      }
  39. -    foreach ($class_methods as $method) {
  40. -      // If the current method starts with "test", run it - it's a test.
  41. -      if (strtolower(substr($method, 0, 4)) == 'test') {
  42. -        // Insert a fail record. This will be deleted on completion to ensure
  43. -        // that testing completed.
  44. -        $method_info = new ReflectionMethod($class, $method);
  45. -        $caller = array(
  46. -          'file' => $method_info->getFileName(),
  47. -          'line' => $method_info->getStartLine(),
  48. -          'function' => $class . '->' . $method . '()',
  49. -        );
  50. -        $completion_check_id = DrupalTestCase::insertAssert($this->testId, $class, FALSE, t('The test did not complete due to a fatal error.'), 'Completion check', $caller);
  51. -        $this->setUp();
  52. -        try {
  53. -          $this->$method();
  54. -          // Finish up.
  55. -        }
  56. -        catch (Exception $e) {
  57. -          $this->exceptionHandler($e);
  58. +    $access = $this->checkRequirements();
  59. +    if ($access !== TRUE && isset($access['errors']) && count($access['errors']) > 0) {
  60. +      $error_object = new ReflectionObject($this);
  61. +      $caller = array(
  62. +        'file' => $error_object->getFileName(),
  63. +        'line' => 0,
  64. +        'function' => 'n/a',
  65. +      );
  66. +      foreach ($access['errors'] as $error) {
  67. +        DrupalTestCase::insertAssert($this->testId, $class, FALSE, $error, 'Requirements check', $caller);
  68. +      }
  69. +    }
  70. +    else {
  71. +      foreach ($class_methods as $method) {
  72. +        // If the current method starts with "test", run it - it's a test.
  73. +        if (strtolower(substr($method, 0, 4)) == 'test') {
  74. +          // Insert a fail record. This will be deleted on completion to ensure
  75. +          // that testing completed.
  76. +          $method_info = new ReflectionMethod($class, $method);
  77. +          $caller = array(
  78. +            'file' => $method_info->getFileName(),
  79. +            'line' => $method_info->getStartLine(),
  80. +            'function' => $class . '->' . $method . '()',
  81. +          );
  82. +          $completion_check_id = DrupalTestCase::insertAssert($this->testId, $class, FALSE, t('The test did not complete due to a fatal error.'), 'Completion check', $caller);
  83. +          $this->setUp();
  84. +          try {
  85. +            $this->$method();
  86. +            // Finish up.
  87. +          }
  88. +          catch (Exception $e) {
  89. +            $this->exceptionHandler($e);
  90. +          }
  91. +          $this->tearDown();
  92. +          // Remove the completion check record.
  93. +          DrupalTestCase::deleteAssert($completion_check_id);
  94.          }
  95. -        $this->tearDown();
  96. -        // Remove the completion check record.
  97. -        DrupalTestCase::deleteAssert($completion_check_id);
  98.        }
  99.      }
  100.      // Clear out the error messages and restore error handler.
  101. diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module
  102. index ede9ac6..ce93ab4 100644
  103. --- a/modules/simpletest/simpletest.module
  104. +++ b/modules/simpletest/simpletest.module
  105. @@ -326,15 +326,6 @@ function simpletest_test_get_all() {
  106.          if (class_exists($class) && method_exists($class, 'getInfo')) {
  107.            $info = call_user_func(array($class, 'getInfo'));
  108.  
  109. -          // If this test class requires a non-existing module, skip it.
  110. -          if (!empty($info['dependencies'])) {
  111. -            foreach ($info['dependencies'] as $module) {
  112. -              if (!drupal_get_filename('module', $module)) {
  113. -                continue 2;
  114. -              }
  115. -            }
  116. -          }
  117. -
  118.            $groups[$info['group']][$class] = $info;
  119.          }
  120.        }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement