ComponentRenderInvalidTest.php
Same filename in this branch
Same filename in other branches
Namespace
Drupal\KernelTests\ComponentsFile
-
core/
tests/ Drupal/ KernelTests/ Components/ ComponentRenderInvalidTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\KernelTests\Components;
use Drupal\Core\Render\Component\Exception\InvalidComponentException;
/**
* Tests invalid render options for components.
*
* @group sdc
*/
class ComponentRenderInvalidTest extends ComponentKernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'sdc_test_invalid',
];
/**
* {@inheritdoc}
*/
protected static $themes = [
'starterkit_theme',
];
/**
* Ensure that components in modules without schema fail validation.
*
* The module sdc_test_invalid contains the my-card-no-schema component. This
* component does not have schema definitions.
*/
public function testInvalidDefinitionModule() : void {
$this->expectException(InvalidComponentException::class);
$this->expectExceptionMessage('The component "sdc_test_invalid:my-card-no-schema" 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.');
$this->manager
->getDefinitions();
}
/**
* Ensure that components in modules without schema fail validation.
*
* The theme sdc_theme_test_enforce_schema_invalid is set as enforcing schemas
* but provides a component without schema.
*/
public function testInvalidDefinitionTheme() : void {
\Drupal::service('theme_installer')->install([
'sdc_theme_test_enforce_schema_invalid',
]);
$active_theme = \Drupal::service('theme.initialization')->initTheme('sdc_theme_test_enforce_schema_invalid');
\Drupal::service('theme.manager')->setActiveTheme($active_theme);
$this->expectException(InvalidComponentException::class);
$this->manager
->getDefinitions();
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
ComponentRenderInvalidTest | Tests invalid render options for components. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.