You are here

public function ArrayHelperTest::testSpliceAssociativeValues in Helper 7

File

tests/ArrayHelperTest.test, line 83

Class

ArrayHelperTest

Code

public function testSpliceAssociativeValues() {
  $input = array(
    0 => 'value1',
    'key1' => 'value2',
    1 => 'value3',
    'key2' => 'value4',
  );
  $result = ArrayHelper::spliceAssociativeValues($input, array(
    'newkey' => 'newvalue',
  ), 2);
  $this
    ->assertIdentical($result, array(
    0 => 'value1',
    'key1' => 'value2',
    'newkey' => 'newvalue',
    1 => 'value3',
    'key2' => 'value4',
  ));
  $result = ArrayHelper::spliceAssociativeValues($input, array(
    'newkey' => 'newvalue',
  ), 1, 1);
  $this
    ->assertIdentical($result, array(
    0 => 'value1',
    'newkey' => 'newvalue',
    1 => 'value3',
    'key2' => 'value4',
  ));
  $result = ArrayHelper::spliceAssociativeValues($input, array(
    'newkey' => 'newvalue',
  ), 2, 1);
  $this
    ->assertIdentical($result, array(
    0 => 'value1',
    'key1' => 'value2',
    'newkey' => 'newvalue',
    'key2' => 'value4',
  ));
}