function EntityResourceHalTestCoverageTest::testEntityTypeHalTestCoverage
Tests that all core content/config entity types have HAL test coverage.
File
-
core/
modules/ hal/ tests/ src/ Kernel/ EntityResource/ EntityResourceHalTestCoverageTest.php, line 68
Class
- EntityResourceHalTestCoverageTest
- Checks that all core content/config entity types have HAL test coverage.
Namespace
Drupal\Tests\hal\Kernel\EntityResourceCode
public function testEntityTypeHalTestCoverage() {
$tests = [
// Test coverage for formats provided by the 'hal' module.
'hal' => [
'path' => '\\Drupal\\Tests\\hal\\Functional\\PROVIDER\\CLASS',
'class suffix' => [
'HalJsonAnonTest',
'HalJsonBasicAuthTest',
'HalJsonCookieTest',
],
],
];
$problems = [];
foreach ($this->definitions as $entity_type_id => $info) {
$class_name_full = $info->getClass();
$parts = explode('\\', $class_name_full);
$class_name = end($parts);
$module_name = $parts[1];
foreach ($tests as $module => $info) {
$path = $info['path'];
$missing_tests = [];
foreach ($info['class suffix'] as $postfix) {
$class = str_replace([
'PROVIDER',
'CLASS',
], [
$module_name,
$class_name,
], $path . $postfix);
if (class_exists($class)) {
continue;
}
$missing_tests[] = $postfix;
}
if (!empty($missing_tests)) {
$missing_tests_list = implode(', ', array_map(function ($missing_test) use ($class_name) {
return $class_name . $missing_test;
}, $missing_tests));
$which_normalization = $module === 'serialization' ? 'default' : $module;
$problems[] = "{$entity_type_id}: {$class_name} ({$class_name_full}), {$which_normalization} normalization (expected tests: {$missing_tests_list})";
}
}
$config_entity = is_subclass_of($class_name_full, ConfigEntityInterface::class);
$config_test = is_subclass_of($class, ConfigEntityResourceTestBase::class);
if ($config_entity && !$config_test) {
$problems[] = "{$entity_type_id}: {$class_name} is a config entity, but the test is for content entities.";
}
elseif (!$config_entity && $config_test) {
$problems[] = "{$entity_type_id}: {$class_name} is a content entity, but the test is for config entities.";
}
}
$this->assertSame([], $problems);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.