You are here

function ArrayHelperTest::testNestedValue in Helper 7

File

tests/ArrayHelperTest.test, line 15

Class

ArrayHelperTest

Code

function testNestedValue() {
  $input = array(
    0 => array(
      'test' => 'foo',
      'keys' => array(
        'first',
        'a',
      ),
    ),
    1 => (object) array(
      'test' => 'bar',
      'keys' => array(
        'second',
        'b',
      ),
    ),
    2 => new ArrayHelperTestObject(array(
      'test' => 'foo',
      'keys' => array(
        'third',
        'c',
      ),
    )),
  );
  $this
    ->assertIdentical(ArrayHelper::filterByNestedValue($input, array(
    'test',
  ), 'foo'), array(
    0 => $input[0],
    2 => $input[2],
  ));
  $this
    ->assertIdentical(ArrayHelper::filterByNestedValue($input, array(
    'test',
  ), 'bar'), array(
    1 => $input[1],
  ));
  $this
    ->assertIdentical(ArrayHelper::filterByNestedValue($input, array(
    'test',
  ), 'ferzle'), array());
  $this
    ->assertIdentical(ArrayHelper::extractNestedValuesToArray($input, array(
    'test',
  )), array(
    0 => 'foo',
    1 => 'bar',
    2 => 'foo',
  ));
  $this
    ->assertIdentical(ArrayHelper::extractNestedValuesToArray($input, array(
    'test',
  ), array(
    'keys',
    0,
  )), array(
    'first' => 'foo',
    'second' => 'bar',
    'third' => 'foo',
  ));
  $this
    ->assertIdentical(ArrayHelper::extractNestedValuesToArray($input, array(
    'test',
  ), array(
    'keys',
    1,
  )), array(
    'a' => 'foo',
    'b' => 'bar',
    'c' => 'foo',
  ));
  $this
    ->assertIdentical(ArrayHelper::extractNestedValuesToArray($input, array(
    'invalid',
  )), array());
}