You are here

public function UniqueFieldAjaxTest::testUniqueFieldCustomMessage in Unique field ajax 2.x

Tests unique field custom message.

Throws

\Drupal\Core\Entity\EntityStorageException

\Behat\Mink\Exception\ResponseTextException

File

tests/src/Functional/UniqueFieldAjaxTest.php, line 123

Class

UniqueFieldAjaxTest
Test the field permissions report page.

Namespace

Drupal\Tests\unique_field_ajax\Functional

Code

public function testUniqueFieldCustomMessage() {
  foreach ($this->fieldTypes as $field_type) {
    $this
      ->createField($field_type['type'], $field_type['widget'], $field_type['settings']);
    $field_name = $this->fieldStorage
      ->getName();

    // Create a random sentence.
    $msg = $this
      ->createRandomData('sentence');

    // With a custom message this is presented if errors.
    $this
      ->updateThirdPartyFieldSetting('unique', TRUE);
    $this
      ->updateThirdPartyFieldSetting('message', $msg);
    $edit = $this
      ->createUpdateFieldData($field_name, $field_type['value'], $field_type['effect']);
    $this
      ->itCanSaveField($edit);
    $this
      ->itCannotSaveField($edit, $msg);

    // Not adding a custom message falls back to default.
    $this
      ->updateThirdPartyFieldSetting('unique', TRUE);
    $this
      ->updateThirdPartyFieldSetting('message', '');
    $edit = $this
      ->createUpdateFieldData($field_name, $field_type['value'], $field_type['effect']);
    $this
      ->itCanSaveField($edit);
    $this
      ->itCannotSaveField($edit);
  }
}