function ComponentMetadataTest::testMetadataEnforceSchema

Same name in this branch
  1. 11.x core/modules/sdc/tests/src/Unit/ComponentMetadataTest.php \Drupal\Tests\sdc\Unit\ComponentMetadataTest::testMetadataEnforceSchema()
Same name and namespace in other branches
  1. 10 core/modules/sdc/tests/src/Unit/ComponentMetadataTest.php \Drupal\Tests\sdc\Unit\ComponentMetadataTest::testMetadataEnforceSchema()
  2. 10 core/tests/Drupal/Tests/Core/Theme/Component/ComponentMetadataTest.php \Drupal\Tests\Core\Theme\Component\ComponentMetadataTest::testMetadataEnforceSchema()

Tests the correct checks when enforcing schemas or not.

Attributes

#[DataProvider('dataProviderMetadata')]

File

core/tests/Drupal/Tests/Core/Theme/Component/ComponentMetadataTest.php, line 36

Class

ComponentMetadataTest
Unit tests for the component metadata class.

Namespace

Drupal\Tests\Core\Theme\Component

Code

public function testMetadataEnforceSchema(array $metadata_info, array $expectations, bool $missing_schema) : void {
  if ($missing_schema) {
    $this->expectException(InvalidComponentException::class);
    $this->expectExceptionMessage('The component "' . $metadata_info['id'] . '" does not provide schema information. Schema definitions are mandatory for components declared in modules. For components declared in themes, schema definitions are only mandatory if the "enforce_prop_schemas" key is set to "true" in the theme info file.');
    new ComponentMetadata($metadata_info, 'foo/', TRUE);
  }
  else {
    new ComponentMetadata($metadata_info, 'foo/', TRUE);
    $this->expectNotToPerformAssertions();
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.