You are here

public function ValidateSchemaTest::testSchemataAreValidJsonSchema in Schemata 8

Test the generated schemas are valid JSON Schema.

File

tests/src/Functional/ValidateSchemaTest.php, line 21

Class

ValidateSchemaTest
Tests that generated JSON Schemas are valid as JSON Schema.

Namespace

Drupal\Tests\schemata\Functional

Code

public function testSchemataAreValidJsonSchema() {
  foreach ([
    'json',
    'hal_json',
  ] as $described_format) {
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {
      try {

        // Retrieving the plugin is redundant, but if this succeeds without
        // throwing an error, it's a valid entity type for schema generation.
        $this->schemaFactory
          ->getSourceEntityPlugin($entity_type_id);
      } catch (\Exception $e) {

        // Skip schema validation testing of invalid entity types.
        // @todo add test coverage of skipped Config Entity schema generation
        // in https://www.drupal.org/node/2868562 or related follow-up.
        continue;
      }
      $this
        ->validateSchemaAsJsonSchema($described_format, $entity_type_id);
      if ($bundle_type = $entity_type
        ->getBundleEntityType()) {
        $bundles = $this->entityTypeManager
          ->getStorage($bundle_type)
          ->loadMultiple();
        foreach ($bundles as $bundle) {
          $this
            ->validateSchemaAsJsonSchema($described_format, $entity_type_id, $bundle
            ->id());
        }
      }
    }
  }
}