You are here

public function ConfigCRUDTest::testValueValidation in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php \Drupal\KernelTests\Core\Config\ConfigCRUDTest::testValueValidation()

Tests the validation of configuration object values.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php, line 245

Class

ConfigCRUDTest
Tests CRUD operations on configuration objects.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testValueValidation() {

  // Verify that setData() will catch dotted keys.
  try {
    $this
      ->config('namespace.object')
      ->setData([
      'key.value' => 12,
    ])
      ->save();
    $this
      ->fail('Expected ConfigValueException was thrown from setData() for value with dotted keys.');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf(ConfigValueException::class, $e);
  }

  // Verify that set() will catch dotted keys.
  try {
    $this
      ->config('namespace.object')
      ->set('foo', [
      'key.value' => 12,
    ])
      ->save();
    $this
      ->fail('Expected ConfigValueException was thrown from set() for value with dotted keys.');
  } catch (\Exception $e) {
    $this
      ->assertInstanceOf(ConfigValueException::class, $e);
  }
}