You are here

protected function ConfigTest::assertOverriddenKeys in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest::assertOverriddenKeys()
  2. 9 core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest::assertOverriddenKeys()

Asserts that the correct keys are overridden.

@internal

Parameters

array $data: The original data.

array $overridden_data: The overridden data.

1 call to ConfigTest::assertOverriddenKeys()
ConfigTest::testOverrideData in core/tests/Drupal/Tests/Core/Config/ConfigTest.php
@covers ::setModuleOverride @covers ::setSettingsOverride @covers ::getOriginal @covers ::hasOverrides @dataProvider overrideDataProvider

File

core/tests/Drupal/Tests/Core/Config/ConfigTest.php, line 637

Class

ConfigTest
Tests the Config.

Namespace

Drupal\Tests\Core\Config

Code

protected function assertOverriddenKeys(array $data, array $overridden_data) : void {
  if (empty($overridden_data)) {
    $this
      ->assertFalse($this->config
      ->hasOverrides());
  }
  else {
    $this
      ->assertTrue($this->config
      ->hasOverrides());
    foreach ($overridden_data as $key => $value) {

      // If there are nested overrides test a keys at every level.
      if (is_array($value)) {
        $nested_key = $key;
        $nested_value = $overridden_data[$key];
        while (is_array($nested_value)) {
          $nested_key .= '.' . key($nested_value);
          $this
            ->assertTrue($this->config
            ->hasOverrides($nested_key));
          $nested_value = array_pop($nested_value);
        }
      }
      $this
        ->assertTrue($this->config
        ->hasOverrides($key));
    }
  }
  $non_overridden_keys = array_diff(array_keys($data), array_keys($overridden_data));
  foreach ($non_overridden_keys as $non_overridden_key) {
    $this
      ->assertFalse($this->config
      ->hasOverrides($non_overridden_key));

    // If there are nested overrides test keys at every level.
    if (is_array($data[$non_overridden_key])) {
      $nested_key = $non_overridden_key;
      $nested_value = $data[$non_overridden_key];
      while (is_array($nested_value)) {
        $nested_key .= '.' . key($nested_value);
        $this
          ->assertFalse($this->config
          ->hasOverrides($nested_key));
        $nested_value = array_pop($nested_value);
      }
    }
  }
}