function PasswordItemTest::testPreSaveNewEmptyString

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Field/FieldType/PasswordItemTest.php \Drupal\KernelTests\Core\Field\FieldType\PasswordItemTest::testPreSaveNewEmptyString()
  2. 11.x core/tests/Drupal/KernelTests/Core/Field/FieldType/PasswordItemTest.php \Drupal\KernelTests\Core\Field\FieldType\PasswordItemTest::testPreSaveNewEmptyString()

@covers ::preSave

File

core/tests/Drupal/KernelTests/Core/Field/FieldType/PasswordItemTest.php, line 84

Class

PasswordItemTest
@coversDefaultClass \Drupal\Core\Field\Plugin\Field\FieldType\PasswordItem @group Field

Namespace

Drupal\KernelTests\Core\Field\FieldType

Code

public function testPreSaveNewEmptyString() {
    $entity = EntityTest::create([
        'name' => $this->randomString(),
    ]);
    $entity->test_field = '';
    $entity->save();
    // The string starts with the portable password string and is a hash of an
    // empty string.
    $this->assertStringStartsWith('$S$', $entity->test_field->value);
    $this->assertTrue($this->container
        ->get('password')
        ->check('', $entity->test_field->value));
}

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