You are here

public function NestedArrayTest::testMergeOutOfSequenceKeys 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::testMergeOutOfSequenceKeys()

Tests that array keys values on the first array are ignored when merging.

Even if the initial ordering would place the data from the second array before those in the first one, they are still appended, and the keys on the first array are deleted and regenerated.

@covers ::mergeDeepArray

File

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

Class

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

Namespace

Drupal\Tests\Component\Utility

Code

public function testMergeOutOfSequenceKeys() {
  $a = array(
    'subkey' => array(
      10 => 'A',
      30 => 'B',
    ),
  );
  $b = array(
    'subkey' => array(
      20 => 'C',
      0 => '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() ignores numeric key order when merging.');
}