.../EntityResourceRestTestCoverageTest.php | 57 ++++++++++++++++------ 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php index f82f9a4..9e5ed54 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php @@ -59,16 +59,28 @@ protected function setUp() { * Tests that all core content/config entity types have REST test coverage. */ public function testEntityTypeRestTestCoverage() { - $tests = [ - '\Drupal\Tests\rest\Functional\EntityResource' => [ - 'JsonAnonTest', - 'JsonBasicAuthTest', - 'JsonCookieTest', + $default_test_locations = [ + // Test coverage for formats provided by the 'serialization' module. + 'serialization' => [ + 'possible paths' => [ + '\Drupal\Tests\rest\Functional\EntityResource\CLASS\CLASS', + ], + 'class suffix' => [ + 'JsonAnonTest', + 'JsonBasicAuthTest', + 'JsonCookieTest', + ], ], - '\Drupal\Tests\hal\Functional\EntityResource' => [ - 'HalJsonAnonTest', - 'HalJsonBasicAuthTest', - 'HalJsonCookieTest', + // Test coverage for formats provided by the 'hal' module. + 'hal' => [ + 'possible paths' => [ + '\Drupal\Tests\hal\Functional\EntityResource\CLASS\CLASS', + ], + 'class suffix' => [ + 'HalJsonAnonTest', + 'HalJsonBasicAuthTest', + 'HalJsonCookieTest', + ], ], ]; @@ -77,13 +89,26 @@ public function testEntityTypeRestTestCoverage() { $class_name_full = $info->getClass(); $parts = explode('\\', $class_name_full); $class_name = end($parts); - foreach ($tests as $path => $postfixes) { - foreach ($postfixes as $postfix) { - $class = $path . '\\' . $class_name . '\\' . $class_name . $postfix; - if (!class_exists($class)) { - $problems[] = "$class_name ($class_name_full)"; - break 2; - } + $module_name = $parts[1]; + + // The test class can live either in the REST/HAL module, or in the module + // providing the entity type. + $tests = $default_test_locations; + $tests['serialization']['possible paths'][] = '\Drupal\Tests\\' . $module_name . '\Functional\Rest\CLASS'; + $tests['hal']['possible paths'][] = '\Drupal\Tests\\' . $module_name . '\Functional\Hal\CLASS'; + + foreach ($tests as $module => $info) { + $possible_paths = $info['possible paths']; + foreach ($info['class suffix'] as $postfix) { + do { + $path = array_shift($possible_paths); + $class = str_replace('CLASS', $class_name, $path . $postfix); + if (class_exists($class)) { + continue 3; + } + } while (!empty($possible_paths)); + $problems[] = "$class_name ($class_name_full)"; + break 2; } } }