class SchemaCheckTraitTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Config/SchemaCheckTraitTest.php \Drupal\KernelTests\Core\Config\SchemaCheckTraitTest
- 10 core/tests/Drupal/KernelTests/Core/Config/SchemaCheckTraitTest.php \Drupal\KernelTests\Core\Config\SchemaCheckTraitTest
- 8.9.x core/tests/Drupal/KernelTests/Core/Config/SchemaCheckTraitTest.php \Drupal\KernelTests\Core\Config\SchemaCheckTraitTest
Tests the functionality of SchemaCheckTrait.
@group config
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Config\SchemaCheckTraitTest uses \Drupal\Core\Config\Schema\SchemaCheckTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of SchemaCheckTraitTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ SchemaCheckTraitTest.php, line 13
Namespace
Drupal\KernelTests\Core\ConfigView source
class SchemaCheckTraitTest extends KernelTestBase {
use SchemaCheckTrait;
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfig;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'config_test',
'config_schema_test',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installConfig([
'config_test',
'config_schema_test',
]);
$this->typedConfig = \Drupal::service('config.typed');
}
/**
* Tests \Drupal\Core\Config\Schema\SchemaCheckTrait.
*/
public function testTrait() {
// Test a non existing schema.
$ret = $this->checkConfigSchema($this->typedConfig, 'config_schema_test.noschema', $this->config('config_schema_test.noschema')
->get());
$this->assertFalse($ret);
// Test an existing schema with valid data.
$config_data = $this->config('config_test.types')
->get();
$ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data);
$this->assertTrue($ret);
// Add a new key, a new array and overwrite boolean with array to test the
// error messages.
$config_data = [
'new_key' => 'new_value',
'new_array' => [],
] + $config_data;
$config_data['boolean'] = [];
$ret = $this->checkConfigSchema($this->typedConfig, 'config_test.types', $config_data);
$expected = [
'config_test.types:new_key' => 'missing schema',
'config_test.types:new_array' => 'missing schema',
'config_test.types:boolean' => 'non-scalar value but not defined as an array (such as mapping or sequence)',
];
$this->assertEquals($expected, $ret);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.