You are here

public function ArrayConfigTest::testMergeDefaults in Little helpers 7.2

Test various different kinds of config default configurations.

File

tests/ArrayConfigTest.php, line 15

Class

ArrayConfigTest
Unit-tests for the array config helper class.

Namespace

Drupal\little_helpers

Code

public function testMergeDefaults() {
  $config = [
    'top-level' => 1,
    'empty_assoc' => [],
    'empty_numeric' => [],
    'empty_select_config' => [],
    'assoc' => [
      'a' => 1,
    ],
    'numeric' => [
      1,
      2,
      3,
    ],
    'select_config' => [
      'a' => 'a',
      'b' => 0,
    ],
  ];
  $defaults = [
    'top-level' => 2,
    'empty_assoc' => [
      'foo' => 'bar',
    ],
    'empty_numeric' => [
      1,
      2,
      3,
    ],
    'empty_select_config' => [
      'a' => 'a',
      'b' => 0,
    ],
    'assoc' => [
      'b' => 2,
    ],
    'numeric' => [
      4,
      5,
      6,
    ],
    'select_config' => [
      'b' => 'b',
      'c' => 'c',
    ],
  ];
  ArrayConfig::mergeDefaults($config, $defaults);
  $this
    ->assertEquals([
    'top-level' => 1,
    'empty_assoc' => [
      'foo' => 'bar',
    ],
    'empty_numeric' => [],
    'empty_select_config' => [],
    'assoc' => [
      'a' => 1,
      'b' => 2,
    ],
    'numeric' => [
      1,
      2,
      3,
    ],
    'select_config' => [
      'a' => 'a',
      'b' => 0,
    ],
  ], $config);
}