You are here

function ManageFieldsTest::testFieldPrefix in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field_ui/src/Tests/ManageFieldsTest.php \Drupal\field_ui\Tests\ManageFieldsTest::testFieldPrefix()

Tests that the 'field_prefix' setting works on Field UI.

File

core/modules/field_ui/src/Tests/ManageFieldsTest.php, line 346
Contains \Drupal\field_ui\Tests\ManageFieldsTest.

Class

ManageFieldsTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\field_ui\Tests

Code

function testFieldPrefix() {

  // Change default field prefix.
  $field_prefix = strtolower($this
    ->randomMachineName(10));
  $this
    ->config('field_ui.settings')
    ->set('field_prefix', $field_prefix)
    ->save();

  // Create a field input and label exceeding the new maxlength, which is 22.
  $field_exceed_max_length_label = $this
    ->randomString(23);
  $field_exceed_max_length_input = $this
    ->randomMachineName(23);

  // Try to create the field.
  $edit = array(
    'label' => $field_exceed_max_length_label,
    'field_name' => $field_exceed_max_length_input,
  );
  $this
    ->drupalPostForm('admin/structure/types/manage/' . $this->contentType . '/fields/add-field', $edit, t('Save and continue'));
  $this
    ->assertText('Machine-readable name cannot be longer than 22 characters but is currently 23 characters long.');

  // Create a valid field.
  $this
    ->fieldUIAddNewField('admin/structure/types/manage/' . $this->contentType, $this->fieldNameInput, $this->fieldLabel);
  $this
    ->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_prefix . $this->fieldNameInput);
  $this
    ->assertText(format_string('@label settings for @type', array(
    '@label' => $this->fieldLabel,
    '@type' => $this->contentType,
  )));
}