From 684602eaccb55b8142f9394a39593e219e390040 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Thu, 21 May 2015 14:19:05 +0100
Subject: [PATCH] Issue #2491915 by Berdir, miro_dietiker: Test @group
 detection fails for test classes with non-standard indendation

---
 core/modules/simpletest/src/TestDiscovery.php |  8 +++-
 .../tests/src/Unit/TestInfoParsingTest.php    | 39 +++++++++++++++++++
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php
index 6a9407ebf303..144580214839 100644
--- a/core/modules/simpletest/src/TestDiscovery.php
+++ b/core/modules/simpletest/src/TestDiscovery.php
@@ -312,7 +312,9 @@ public static function getTestInfo($classname, $doc_comment = NULL) {
       'name' => $classname,
     );
     $annotations = array();
-    preg_match_all('/^ \* \@([^\s]*) (.*$)/m', $doc_comment, $matches);
+    // Look for annotations, allow an arbitrary amount of spaces before the
+    // * but nothing else.
+    preg_match_all('/^[ ]*\* \@([^\s]*) (.*$)/m', $doc_comment, $matches);
     if (isset($matches[1])) {
       foreach ($matches[1] as $key => $annotation) {
         if (!empty($annotations[$annotation])) {
@@ -369,8 +371,10 @@ public static function parseTestClassSummary($doc_comment) {
 
     $lines = explode("\n", $doc_comment);
     $summary = [];
+    // Add every line to the summary until the first empty line or annotation
+    // is found.
     foreach ($lines as $line) {
-      if ($line == ' *' || preg_match('/^ \* \@/', $line)) {
+      if (preg_match('/^[ ]*\*$/', $line) || preg_match('/^[ ]*\* \@/', $line)) {
         break;
       }
       $summary[] = trim($line, ' *');
diff --git a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php
index 4df976f3e8f8..6ac777e51da2 100644
--- a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php
+++ b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php
@@ -76,6 +76,45 @@ public function infoParserProvider() {
  ",
     ];
 
+    // Test with a different amount of leading spaces.
+    $tests[] = [
+      // Expected result.
+      [
+        'name' => 'Drupal\field\Tests\BulkDeleteTest',
+        'group' => 'field',
+        'description' => 'Bulk delete storages and fields, and clean up afterwards.',
+      ],
+      // Classname.
+      'Drupal\field\Tests\BulkDeleteTest',
+      // Doc block.
+      "/**
+   * Bulk delete storages and fields, and clean up afterwards.
+   *
+   * @group field
+   */
+ ",
+    ];
+
+    // Make sure that a "* @" inside a string does not get parsed as an
+    // annotation.
+    $tests[] = [
+      // Expected result.
+      [
+        'name' => 'Drupal\field\Tests\BulkDeleteTest',
+        'group' => 'field',
+        'description' => 'Bulk delete storages and fields, and clean up afterwards. * @',
+      ],
+      // Classname.
+      'Drupal\field\Tests\BulkDeleteTest',
+      // Doc block.
+      "/**
+   * Bulk delete storages and fields, and clean up afterwards. * @
+   *
+   * @group field
+   */
+ ",
+    ];
+
     // Multiple @group annotations.
     $tests[] = [
       // Expected result.
-- 
GitLab