function PasswordItemTest::testPreSaveExceptionExisting

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

@covers ::preSave

File

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

Class

PasswordItemTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Field%21Plugin%21Field%21FieldType%21PasswordItem.php/class/PasswordItem/10" title="Defines the &#039;password&#039; entity field type." class="local">\Drupal\Core\Field\Plugin\Field\FieldType\PasswordItem</a> @group Field

Namespace

Drupal\KernelTests\Core\Field\FieldType

Code

public function testPreSaveExceptionExisting() {
    $entity = EntityTest::create();
    $entity->test_field = 'will_be_hashed';
    $entity->save();
    $this->assertNotEquals('will_be_hashed', $entity->test_field->value);
    $this->expectException(EntityStorageException::class);
    $this->expectExceptionMessage('The entity does not have a password');
    $entity->test_field = str_repeat('a', PasswordInterface::PASSWORD_MAX_LENGTH + 1);
    $entity->save();
}

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