diff options
author | Alex Pott <alex.a.pott@googlemail.com> | 2021-07-06 15:45:43 +0100 |
---|---|---|
committer | Alex Pott <alex.a.pott@googlemail.com> | 2021-07-06 15:45:43 +0100 |
commit | 12aec14a9141ffdf880ecc4ab52734fcab0b5b5e (patch) | |
tree | 5cdd0c6163456d2e0943154cd5bd97f3b6fb7c63 /core/modules/text/tests | |
parent | f0a97d0cdd7ff02aff79760cbb2063dffb0ac3e4 (diff) | |
download | drupal-12aec14a9141ffdf880ecc4ab52734fcab0b5b5e.tar.gz drupal-12aec14a9141ffdf880ecc4ab52734fcab0b5b5e.zip |
Issue #2750925 by quietone, vakulrai, pavnish, Neslee Canil Pinto, ankithashetty, Meenakshi_j, nikitagupta, Suresh Prabhu Parkala, JvE, Gauravmahlawat, larowlan, Kristen Pol, paulocs, acbramley, catch: Text item sample generation fails if max length < 3
Diffstat (limited to 'core/modules/text/tests')
-rw-r--r-- | core/modules/text/tests/src/Kernel/TextItemBaseTest.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/core/modules/text/tests/src/Kernel/TextItemBaseTest.php b/core/modules/text/tests/src/Kernel/TextItemBaseTest.php new file mode 100644 index 00000000000..50abbc26128 --- /dev/null +++ b/core/modules/text/tests/src/Kernel/TextItemBaseTest.php @@ -0,0 +1,60 @@ +<?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, + ], + ]; + } + +} |