function UserNameItemTest::testGenerateSampleValue
Same name in other branches
- 10 core/modules/user/tests/src/Unit/UserNameItemTest.php \Drupal\Tests\user\Unit\UserNameItemTest::testGenerateSampleValue()
Tests generating sample values.
@covers ::generateSampleValue @dataProvider providerMaxLength
Parameters
int $max_length: Maximum field length.
File
-
core/
modules/ user/ tests/ src/ Unit/ UserNameItemTest.php, line 28
Class
- UserNameItemTest
- Defines a test for the UserNameItem field-type.
Namespace
Drupal\Tests\user\UnitCode
public function testGenerateSampleValue(int $max_length) : void {
$definition = $this->prophesize(FieldDefinitionInterface::class);
$definition->getSetting('max_length')
->willReturn($max_length);
for ($i = 0; $i < 1000; $i++) {
$sample_value = UserNameItem::generateSampleValue($definition->reveal());
$this->assertLessThanOrEqual($max_length, mb_strlen($sample_value['value']));
$this->assertEquals(trim($sample_value['value'], ' '), $sample_value['value']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.