function NestedArrayTest::testMergeDeepArray

Same name and namespace in other branches
  1. 8.9.x 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()
  3. 11.x 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 <a href="/api/drupal/core%21lib%21Drupal%21Component%21Utility%21NestedArray.php/class/NestedArray/9" title="Provides helpers to perform operations on nested arrays and array keys of variable depth." class="local">\Drupal\Component\Utility\NestedArray</a> @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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.