You are here

public function NestedArrayTest::testMergeExplicitKeys in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testMergeExplicitKeys()

Tests that even with explicit keys, values are appended, not merged.

@covers ::mergeDeepArray

File

core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php, line 199
Contains \Drupal\Tests\Component\Utility\NestedArrayTest.

Class

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

Namespace

Drupal\Tests\Component\Utility

Code

public function testMergeExplicitKeys() {
  $a = array(
    'subkey' => array(
      0 => 'A',
      1 => 'B',
    ),
  );
  $b = array(
    'subkey' => array(
      0 => 'C',
      1 => 'D',
    ),
  );

  // Drupal core behavior.
  $expected = array(
    'subkey' => array(
      0 => 'A',
      1 => 'B',
      2 => 'C',
      3 => 'D',
    ),
  );
  $actual = NestedArray::mergeDeepArray(array(
    $a,
    $b,
  ));
  $this
    ->assertSame($expected, $actual, 'drupal_array_merge_deep() creates new numeric keys in the explicit sequence.');
}