You are here

public function WebformArrayHelperTest::testGetKey in Webform 8.5

Same name and namespace in other branches
  1. 6.x tests/src/Unit/Utility/WebformArrayHelperTest.php \Drupal\Tests\webform\Unit\Utility\WebformArrayHelperTest::testGetKey()

Tests navigating an associative array's keys.

See also

WebformArrayHelper::getFirstKey()

WebformArrayHelper::getLastKey()

WebformArrayHelper::getPreviousKey()

WebformArrayHelper::getNextKey()

File

tests/src/Unit/Utility/WebformArrayHelperTest.php, line 125

Class

WebformArrayHelperTest
Tests webform array utility.

Namespace

Drupal\Tests\webform\Unit\Utility

Code

public function testGetKey() {
  $array = [
    'one' => 'One',
    'two' => 'Two',
    'three' => 'Three',
    'four' => 'Four',
    'five' => 'Five',
  ];
  $this
    ->assertEquals(WebformArrayHelper::getFirstKey($array), 'one');
  $this
    ->assertEquals(WebformArrayHelper::getFirstKey([]), NULL);
  $this
    ->assertEquals(WebformArrayHelper::getLastKey($array), 'five');
  $this
    ->assertEquals(WebformArrayHelper::getLastKey([]), NULL);
  $this
    ->assertEquals(WebformArrayHelper::getNextKey($array, 'one'), 'two');
  $this
    ->assertEquals(WebformArrayHelper::getNextKey($array, 'five'), NULL);
  $this
    ->assertEquals(WebformArrayHelper::getNextKey($array, 'six'), NULL);
  $this
    ->assertEquals(WebformArrayHelper::getPreviousKey($array, 'five'), 'four');
  $this
    ->assertEquals(WebformArrayHelper::getPreviousKey($array, 'one'), NULL);
  $this
    ->assertEquals(WebformArrayHelper::getNextKey($array, 'six'), NULL);
}