function ComponentValidatorTest::dataProviderValidateDefinitionInvalid
Same name in this branch
- 11.x core/modules/sdc/tests/src/Unit/ComponentValidatorTest.php \Drupal\Tests\sdc\Unit\ComponentValidatorTest::dataProviderValidateDefinitionInvalid()
Same name in other branches
- 10 core/modules/sdc/tests/src/Unit/ComponentValidatorTest.php \Drupal\Tests\sdc\Unit\ComponentValidatorTest::dataProviderValidateDefinitionInvalid()
- 10 core/tests/Drupal/Tests/Core/Theme/Component/ComponentValidatorTest.php \Drupal\Tests\Core\Theme\Component\ComponentValidatorTest::dataProviderValidateDefinitionInvalid()
Data provider with invalid component definitions.
Return value
\Generator Returns the generator with the invalid definitions.
File
-
core/
tests/ Drupal/ Tests/ Core/ Theme/ Component/ ComponentValidatorTest.php, line 71
Class
- ComponentValidatorTest
- Unit tests for the component validation.
Namespace
Drupal\Tests\Core\Theme\ComponentCode
public static function dataProviderValidateDefinitionInvalid() : \Generator {
$valid_cta = static::loadComponentDefinitionFromFs('my-cta');
$cta_with_missing_required = $valid_cta;
unset($cta_with_missing_required['path']);
(yield 'missing required' => [
$cta_with_missing_required,
]);
$cta_with_invalid_class = $valid_cta;
$cta_with_invalid_class['props']['properties']['attributes']['type'] = 'Drupal\\Foo\\Invalid';
(yield 'invalid class' => [
$cta_with_invalid_class,
]);
$cta_with_invalid_enum = array_merge($valid_cta, [
'extension_type' => 'invalid',
]);
(yield 'invalid enum' => [
$cta_with_invalid_enum,
]);
// A list of property types that are not strings, but can be provided via
// YAML.
$non_string_types = [
NULL,
123,
123.45,
TRUE,
];
foreach ($non_string_types as $non_string_type) {
$cta_with_non_string_prop_type = $valid_cta;
$cta_with_non_string_prop_type['props']['properties']['text']['type'] = $non_string_type;
(yield "non string type ({$non_string_type})" => [
$cta_with_non_string_prop_type,
]);
// Same, but as a part of the list of allowed types.
$cta_with_non_string_prop_type['props']['properties']['text']['type'] = [
'string',
$non_string_type,
];
(yield "non string type ({$non_string_type}) in a list of types" => [
$cta_with_non_string_prop_type,
]);
}
// The array is a valid value for the 'type' parameter, but it is not
// allowed as the allowed type.
$cta_with_non_string_prop_type['props']['properties']['text']['type'] = [
'string',
[],
];
(yield 'non string type (Array)' => [
$cta_with_non_string_prop_type,
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.