You are here

public function TextItemBaseTest::testTextFieldSampleValue in Drupal 9

Tests creation of sample values.

@covers ::generateSampleValue @dataProvider providerTextFieldSampleValue

File

core/modules/text/tests/src/Kernel/TextItemBaseTest.php, line 27

Class

TextItemBaseTest
Tests TextItemBase.

Namespace

Drupal\Tests\text\Kernel

Code

public function testTextFieldSampleValue($max_length) {

  // Create a text field.
  $field_definition = BaseFieldDefinition::create('text')
    ->setTargetEntityTypeId('foo');

  // Ensure testing of max_lengths from 1 to 3 because generateSampleValue
  // creates a sentence with a maximum number of words set to 1/3 of the
  // max_length of the field.
  $field_definition
    ->setSetting('max_length', $max_length);
  $sample_value = TextItemBase::generateSampleValue($field_definition);
  $this
    ->assertEquals($max_length, strlen($sample_value['value']));
}