function FieldTestBase::_generateTestFieldValues

Same name in other branches
  1. 9 core/modules/field/tests/src/Functional/FieldTestBase.php \Drupal\Tests\field\Functional\FieldTestBase::_generateTestFieldValues()
  2. 8.9.x core/modules/field/src/Tests/FieldTestBase.php \Drupal\field\Tests\FieldTestBase::_generateTestFieldValues()
  3. 8.9.x core/modules/field/tests/src/Functional/FieldTestBase.php \Drupal\Tests\field\Functional\FieldTestBase::_generateTestFieldValues()
  4. 11.x core/modules/field/tests/src/Functional/FieldTestBase.php \Drupal\Tests\field\Functional\FieldTestBase::_generateTestFieldValues()

Generate random values for a field_test field.

Parameters

$cardinality: Number of values to generate.

Return value

array An array of random values, in the format expected for field values.

File

core/modules/field/tests/src/Functional/FieldTestBase.php, line 25

Class

FieldTestBase
Parent class for Field API tests.

Namespace

Drupal\Tests\field\Functional

Code

public function _generateTestFieldValues($cardinality) {
    $values = [];
    for ($i = 0; $i < $cardinality; $i++) {
        // field_test fields treat 0 as 'empty value'.
        $values[$i]['value'] = mt_rand(1, 127);
    }
    return $values;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.