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 and namespace 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 78
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,
]);
$cta_with_invalid_slot_type = $valid_cta;
$cta_with_invalid_slot_type['slots'] = [
'valid_slot' => [
'title' => 'Valid slot',
'description' => 'Valid slot description',
],
'invalid_slot' => [
'title' => [
'hello' => 'Invalid slot',
'world' => 'Invalid slot',
],
'description' => 'Title must be string',
],
];
(yield 'invalid slot (type)' => [
$cta_with_invalid_slot_type,
]);
$cta_with_invalid_slot_name = $valid_cta;
$cta_with_invalid_slot_name['slots'] = [
'valid_slot' => [
'title' => 'Valid slot',
'description' => 'Valid slot description',
],
'invalid slot' => [
'title' => 'Invalid slot',
'description' => 'Slot name cannot have spaces',
],
];
(yield 'invalid slot (name with spaces)' => [
$cta_with_invalid_slot_name,
]);
$cta_with_invalid_variant_title_type = $valid_cta;
$cta_with_invalid_variant_title_type['variants'] = [
'valid_variant' => [
'title' => 'Valid variant',
'description' => 'Valid variant description',
],
'invalid_variant' => [
'title' => [
'hello' => 'Invalid variant',
'world' => 'Invalid variant',
],
'description' => 'Title must be string',
],
];
(yield 'invalid variant title (type)' => [
$cta_with_invalid_variant_title_type,
]);
$cta_with_missing_variant_title_type = $valid_cta;
$cta_with_missing_variant_title_type['variants'] = [
'valid_variant' => [
'title' => 'Valid variant',
'description' => 'Valid variant description',
],
'invalid_variant' => [
'description' => 'Title is required',
],
];
(yield 'invalid variant title (missing title)' => [
$cta_with_missing_variant_title_type,
]);
$cta_with_invalid_variant_description_type = $valid_cta;
$cta_with_invalid_variant_description_type['variants'] = [
'valid_variant' => [
'title' => 'Valid variant',
'description' => 'Valid variant description',
],
'invalid_variant' => [
'title' => 'Invalid variant',
'description' => [
'this' => 'Description must be',
'that' => 'a string',
],
],
];
(yield 'invalid variant description (type)' => [
$cta_with_invalid_variant_description_type,
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.