function UriItemTest::testGenerateSampleValue

Same name in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Field/UriItemTest.php \Drupal\Tests\Core\Field\UriItemTest::testGenerateSampleValue()

Tests generating sample values.

@covers ::generateSampleValue @dataProvider providerMaxLength

Parameters

int $max_length: Maximum field length.

File

core/tests/Drupal/Tests/Core/Field/UriItemTest.php, line 28

Class

UriItemTest
Defines a test for the UriItem field-type.

Namespace

Drupal\Tests\Core\Field

Code

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 = UriItem::generateSampleValue($definition->reveal());
        $this->assertLessThanOrEqual($max_length, mb_strlen($sample_value['value']));
        $this->assertStringNotContainsString(' ', $sample_value['value']);
    }
}

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