diff -u b/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module --- b/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -820,20 +820,10 @@ if (!$contents) { return; } - $xml = new SimpleXMLElement($contents); $records = array(); - foreach ($xml->testsuite as $testsuite) { - foreach ($testsuite as $suite) { - // The file element won't be on testcase objects created with - // @dataProvider, so just use the one from the test suite at this level - // because it should be the same. - $file = (string) $suite->attributes()->file; - - $testcases = simpletest_phpunit_find_testcases($suite); - foreach ($testcases as $testcase) { - $records[] = simpletest_phpunit_testcase_to_row($test_id, $testcase, $file); - } - } + $testcases = simpletest_phpunit_find_testcases(new SimpleXMLElement($contents)); + foreach ($testcases as $testcase) { + $records[] = simpletest_phpunit_testcase_to_row($test_id, $testcase); } return $records; } @@ -841,27 +831,38 @@ /** * Finds all test cases recursively from a test suite list. * - * @param \SimpleXMLElement[] $suite - * The list of test cases contained in the PHPUnit XML. + * @param \SimpleXMLElement $element + * The PHPUnit xml to search for test cases. + * @param \SimpleXMLElement $suite + * (Optional) The parent of the current element. Defaults to NULL. * * @return array * A list of all test cases. */ -function simpletest_phpunit_find_testcases($suite) { +function simpletest_phpunit_find_testcases(\SimpleXMLElement $element, \SimpleXMLElement $parent = NULL) { $testcases = array(); - foreach ($suite as $testcase) { - // Beside from being 'testcases', it could be also a group of testcases. - // This happens if you use a data provider in the PHPUnit tests. - if ($testcase->getName() === 'testcase') { - $testcases[] = $testcase; + if (!isset($parent)) { + $parent = $element; + } + + if ($element->getName() === 'testcase' && (int) $parent->attributes()->tests > 0) { + // Add the class attribute if the testcase does not have one. This is the + // case for tests using a data provider. The name of the parent testsuite + // will be in the format class::method. + if (!$element->attributes()->class) { + $name = explode('::', $parent->attributes()->name, 2); + $element->addAttribute('class', $name[0]); } - elseif (isset($testcase->testcase) && ((int) $testcase->attributes()->tests) > 0) { - foreach ($testcase->testcase as $childtestcase) { - // Add the class attribute since the child test case will not have it. - $childtestcase->addAttribute('class', $suite->attributes()->name); - $testcases[] = $childtestcase; + $testcases[] = $element; + } + else { + foreach ($element as $child) { + $file = (string) $parent->attributes()->file; + if ($file && !$child->attributes()->file) { + $child->addAttribute('file', $file); } + $testcases = array_merge($testcases, simpletest_phpunit_find_testcases($child, $element)); } } return $testcases; @@ -874,13 +875,11 @@ * The current test ID. * @param \SimpleXMLElement $testcase * The PHPUnit test case represented as XML element. - * @param string $file - * The path to test file, which was executed. * * @return array * An array containing the {simpletest} result row. */ -function simpletest_phpunit_testcase_to_row($test_id, \SimpleXMLElement $testcase, $file) { +function simpletest_phpunit_testcase_to_row($test_id, \SimpleXMLElement $testcase) { $message = ''; $pass = TRUE; if ($testcase->failure) { @@ -904,7 +903,7 @@ 'message_group' => 'Other', 'function' => $attributes->class . '->' . $attributes->name . '()', 'line' => $attributes->line ?: 0, - 'file' => $file, + 'file' => $attributes->file, ); return $record; }