class TextItemBaseTest in Drupal 10
Same name and namespace in other branches
- 9 core/modules/text/tests/src/Kernel/TextItemBaseTest.php \Drupal\Tests\text\Kernel\TextItemBaseTest
Tests TextItemBase.
@group text
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\Tests\text\Kernel\TextItemBaseTest
Expanded class hierarchy of TextItemBaseTest
File
- core/
modules/ text/ tests/ src/ Kernel/ TextItemBaseTest.php, line 14
Namespace
Drupal\Tests\text\KernelView source
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,
],
];
}
}