You are here

protected function DataTestCaseUI::randomValue in Data 6

Same name and namespace in other branches
  1. 7 data_ui/tests/data_ui.test \DataTestCaseUI::randomValue()

Get a random value from the given array.

Parameters

$array: Array to pick random value from.

$exclude: Values not to pick.

Return value

A random value from $array that does not exist in $exclude.

1 call to DataTestCaseUI::randomValue()
DataTestCaseUI::randomFields in data_ui/tests/data_ui.test
Generate N random fields. Will create at least 1 field.

File

data_ui/tests/data_ui.test, line 293

Class

DataTestCaseUI
Test basic Data API functionality.

Code

protected function randomValue($array, $exclude = array()) {
  $array = array_diff(array_values($array), $exclude);
  if (empty($array)) {
    $this
      ->error('Array for random value selection is empty.');
  }
  return $array[rand(0, count($array) - 1)];
}