diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php new file mode 100644 index 0000000..0f19839 --- /dev/null +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceRestTestCoverageTest.php @@ -0,0 +1,112 @@ +origin !== 'core' || !empty($module->info['hidden']) || $module->status == TRUE || $module->info['package'] == 'Testing') { + return FALSE; + } + return TRUE; + }); + + \Drupal::service('module_installer')->install(array_keys($all_modules)); + + $this->definitions = \Drupal::entityTypeManager()->getDefinitions(); + } + + /** + * Tests that all core content/config entity types have REST test coverage. + */ + public function testEntityTypeRestTestCoverage() { + $tests = [ + 'Drupal\Tests\rest\Functional\EntityResource' => [ + 'JsonAnonTest', + 'JsonBasicAuthTest', + 'JsonCookieTest', + ], + 'Drupal\Tests\hal\Functional\EntityResource' => [ + 'HalJsonAnonTest', + 'HalJsonBasicAuthTest', + 'HalJsonCookieTest', + ], + ]; + + $problems = []; + foreach ($this->definitions as $info) { + $class_name_full = $info->getClass(); + $class_name = basename($class_name_full); + 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; + } + } + } + } + $all = count($this->definitions); + $bad = count($problems); + $this->assertSame([], $problems, $this->getLlamaMessage($bad, $all)); + } + + /** + * Message from Llama. + * + * @param int $b + * A count of entities without test coverage. + * @param int $a + * A count of all entities. + * + * @return string + * An information about progress of REST test coverage. + */ + protected function getLlamaMessage($b, $a) { + + if ($b < 10) { + $b = "0$b"; + } + + $message = " + ________________________ + / Hi! \\ + | What about a few of cool | + | REST tests? | + | | + | Progress: $b/$a. | + | ________________________/ + |/ +// o +l'> +ll +llama +|| || +'' '' +"; + return $message; + } + +}