class ViewValidationTest
Same name and namespace in other branches
- 11.x core/modules/views/tests/src/Kernel/Entity/ViewValidationTest.php \Drupal\Tests\views\Kernel\Entity\ViewValidationTest
Tests validation of view entities.
@group views @group #slow
Hierarchy
- class \Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase
- class \Drupal\Tests\views\Kernel\Entity\ViewValidationTest implements \Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase
Expanded class hierarchy of ViewValidationTest
File
-
core/
modules/ views/ tests/ src/ Kernel/ Entity/ ViewValidationTest.php, line 17
Namespace
Drupal\Tests\views\Kernel\EntityView source
class ViewValidationTest extends ConfigEntityValidationTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'views',
'views_test_config',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->entity = View::create([
'id' => 'test',
'label' => 'Test',
]);
$this->entity
->save();
}
/**
* @group legacy
*/
public function testLabelsAreRequired() : void {
$this->entity
->set('label', NULL);
$this->expectDeprecation('Saving a view without an explicit label is deprecated in drupal:10.2.0 and will raise an error in drupal:11.0.0. See https://www.drupal.org/node/3381669');
$this->assertSame($this->entity
->id(), $this->entity
->label());
}
/**
* Tests that the various plugin IDs making up a view display are validated.
*
* @param string ...$parents
* The array parents of the property of the view's default display which
* will be set to `non_existent`.
*
* @testWith ["display_plugin"]
* ["display_options", "pager", "type"]
* ["display_options", "exposed_form", "type"]
* ["display_options", "access", "type"]
* ["display_options", "style", "type"]
* ["display_options", "row", "type"]
* ["display_options", "query", "type"]
* ["display_options", "cache", "type"]
* ["display_options", "header", "non_existent", "plugin_id"]
* ["display_options", "footer", "non_existent", "plugin_id"]
* ["display_options", "empty", "non_existent", "plugin_id"]
* ["display_options", "arguments", "non_existent", "plugin_id"]
* ["display_options", "sorts", "non_existent", "plugin_id"]
* ["display_options", "fields", "non_existent", "plugin_id"]
* ["display_options", "filters", "non_existent", "plugin_id"]
* ["display_options", "relationships", "non_existent", "plugin_id"]
*/
public function testInvalidPluginId(string ...$parents) : void {
// Disable the `broken` handler plugin, which is used as a fallback for
// non-existent handler plugins. This ensures that when we use an
// invalid handler plugin ID, we will get the expected validation error.
// @todo Remove all this when fallback plugin IDs are not longer allowed by
// Views' config schema.
// @see views_test_config.module
$this->container
->get('state')
->set('views_test_config_disable_broken_handler', [
'area',
'argument',
'sort',
'field',
'filter',
'relationship',
]);
$this->container
->get('plugin.cache_clearer')
->clearCachedDefinitions();
$display =& $this->entity
->getDisplay('default');
NestedArray::setValue($display, $parents, 'non_existent');
$property_path = 'display.default.' . implode('.', $parents);
$this->assertValidationErrors([
$property_path => "The 'non_existent' plugin does not exist.",
]);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
ConfigEntityValidationTestBase::$entity | protected | property | The config entity being tested. | ||
ConfigEntityValidationTestBase::$hasLabel | protected | property | Whether a config entity of this type has a label. | 4 | |
ConfigEntityValidationTestBase::$propertiesWithOptionalValues | protected static | property | The config entity properties whose values are optional (set to NULL). | 4 | |
ConfigEntityValidationTestBase::$propertiesWithRequiredKeys | protected static | property | The config entity mapping properties with >=1 required keys. | 1 | |
ConfigEntityValidationTestBase::assertValidationErrors | protected | function | Asserts a set of validation errors is raised when the entity is validated. | ||
ConfigEntityValidationTestBase::getMachineNameConstraints | protected | function | Returns the validation constraints applied to the entity's ID. | ||
ConfigEntityValidationTestBase::getPropertiesWithOptionalValues | protected | function | Determines the config entity properties with optional values. | ||
ConfigEntityValidationTestBase::getRequiredPropertyKeys | protected | function | Determines the config entity mapping properties with required keys. | ||
ConfigEntityValidationTestBase::isFullyValidatable | protected | function | Whether the tested config entity type is fully validatable. | ||
ConfigEntityValidationTestBase::providerConfigDependenciesValidation | public static | function | Data provider for ::testConfigDependenciesValidation(). | ||
ConfigEntityValidationTestBase::providerInvalidMachineNameCharacters | public static | function | Data provider for ::testInvalidMachineNameCharacters(). | 5 | |
ConfigEntityValidationTestBase::setLabel | protected static | function | Sets the label of the given config entity. | 1 | |
ConfigEntityValidationTestBase::testConfigDependenciesValidation | public | function | Tests validation of config dependencies. | ||
ConfigEntityValidationTestBase::testEntityIsValid | public | function | Ensures that the entity created in ::setUp() has no validation errors. | ||
ConfigEntityValidationTestBase::testImmutableProperties | public | function | Tests that immutable properties cannot be changed. | 11 | |
ConfigEntityValidationTestBase::testInvalidMachineNameCharacters | public | function | Tests that the entity's ID is tested for invalid characters. | ||
ConfigEntityValidationTestBase::testLabelValidation | public | function | Tests validation of config entity's label. | 3 | |
ConfigEntityValidationTestBase::testLangcode | public | function | Tests that the config entity's langcode is validated. | ||
ConfigEntityValidationTestBase::testMachineNameLength | public | function | Tests that the entity ID's length is validated if it is a machine name. | ||
ConfigEntityValidationTestBase::testRequiredPropertyKeysMissing | public | function | A property that is required must have a value (i.e. not NULL). | 2 | |
ConfigEntityValidationTestBase::testRequiredPropertyValuesMissing | public | function | A property that is required must have a value (i.e. not NULL). | 2 | |
ViewValidationTest::$modules | protected static | property | Modules to install. | ||
ViewValidationTest::setUp | protected | function | Overrides ConfigEntityValidationTestBase::setUp | ||
ViewValidationTest::testInvalidPluginId | public | function | Tests that the various plugin IDs making up a view display are validated. | ||
ViewValidationTest::testLabelsAreRequired | public | function | @group legacy |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.