function NestedArrayTest::testMergeDeepArray

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeDeepArray()
  2. 8.9.x core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeDeepArray()
  3. 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 152

Class

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

Namespace

Drupal\Tests\Component\Utility

Code

public function testMergeDeepArray() : void {
    $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.