TextItemBaseTest.php

Same filename and directory in other branches
  1. 10 core/modules/text/tests/src/Kernel/TextItemBaseTest.php
  2. 11.x core/modules/text/tests/src/Kernel/TextItemBaseTest.php

Namespace

Drupal\Tests\text\Kernel

File

core/modules/text/tests/src/Kernel/TextItemBaseTest.php

View source
<?php

namespace Drupal\Tests\text\Kernel;

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\KernelTests\KernelTestBase;
use Drupal\text\Plugin\Field\FieldType\TextItemBase;

/**
 * Tests TextItemBase.
 *
 * @group text
 */
class TextItemBaseTest extends KernelTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'filter',
    'text',
  ];
  
  /**
   * Tests creation of sample values.
   *
   * @covers ::generateSampleValue
   * @dataProvider providerTextFieldSampleValue
   */
  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']));
  }
  
  /**
   * Data provider for testTextFieldSampleValue.
   */
  public function providerTextFieldSampleValue() {
    return [
      [
        1,
      ],
      [
        2,
      ],
      [
        3,
      ],
      [
        4,
      ],
    ];
  }

}

Classes

Title Deprecated Summary
TextItemBaseTest Tests TextItemBase.

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