You are here

public function NestedArrayTest::testMergeDeepArray in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeDeepArray()
  2. 10 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeDeepArray()

Tests NestedArray::mergeDeepArray().

@covers ::mergeDeep @covers ::mergeDeepArray

File

core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php, line 146

Class

NestedArrayTest
@coversDefaultClass \Drupal\Component\Utility\NestedArray @group Utility

Namespace

Drupal\Tests\Component\Utility

Code

public function testMergeDeepArray() {
  $link_options_1 = [
    'fragment' => 'x',
    'attributes' => [
      'title' => 'X',
      'class' => [
        'a',
        'b',
      ],
    ],
    'language' => 'en',
  ];
  $link_options_2 = [
    'fragment' => 'y',
    'attributes' => [
      'title' => 'Y',
      'class' => [
        'c',
        'd',
      ],
    ],
    'absolute' => TRUE,
  ];
  $expected = [
    'fragment' => 'y',
    'attributes' => [
      'title' => 'Y',
      'class' => [
        'a',
        'b',
        'c',
        'd',
      ],
    ],
    'language' => 'en',
    'absolute' => TRUE,
  ];
  $this
    ->assertSame($expected, NestedArray::mergeDeepArray([
    $link_options_1,
    $link_options_2,
  ]), 'NestedArray::mergeDeepArray() returned a properly merged array.');

  // Test wrapper function, NestedArray::mergeDeep().
  $this
    ->assertSame($expected, NestedArray::mergeDeep($link_options_1, $link_options_2), 'NestedArray::mergeDeep() returned a properly merged array.');
}