function FieldKernelTestBase::_generateTestFieldValues

Same name in other branches
  1. 8.9.x core/modules/field/tests/src/Kernel/FieldKernelTestBase.php \Drupal\Tests\field\Kernel\FieldKernelTestBase::_generateTestFieldValues()
  2. 10 core/modules/field/tests/src/Kernel/FieldKernelTestBase.php \Drupal\Tests\field\Kernel\FieldKernelTestBase::_generateTestFieldValues()
  3. 11.x core/modules/field/tests/src/Kernel/FieldKernelTestBase.php \Drupal\Tests\field\Kernel\FieldKernelTestBase::_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.

13 calls to FieldKernelTestBase::_generateTestFieldValues()
BulkDeleteTest::setUp in core/modules/field/tests/src/Kernel/BulkDeleteTest.php
Set the default field storage backend for fields created during tests.
BulkDeleteTest::testPurgeWithDeletedAndActiveField in core/modules/field/tests/src/Kernel/BulkDeleteTest.php
Tests that recreating a field with the name as a deleted field works.
DisplayApiTest::setUp in core/modules/field/tests/src/Kernel/DisplayApiTest.php
Set the default field storage backend for fields created during tests.
FieldAttachOtherTest::testEntityCache in core/modules/field/tests/src/Kernel/FieldAttachOtherTest.php
Tests entity cache.
FieldAttachOtherTest::testEntityDisplayBuild in core/modules/field/tests/src/Kernel/FieldAttachOtherTest.php
Tests rendering fields with EntityDisplay build().

... See full list

File

core/modules/field/tests/src/Kernel/FieldKernelTestBase.php, line 175

Class

FieldKernelTestBase
Parent class for Field API unit tests.

Namespace

Drupal\Tests\field\Kernel

Code

protected 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.