function TextFieldTest::_testTextfieldWidgets

Helper function for testTextfieldWidgets().

1 call to TextFieldTest::_testTextfieldWidgets()
TextFieldTest::testTextfieldWidgets in drupal/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php
Test widgets.

File

drupal/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php, line 95
Definition of Drupal\text\TextFieldTest.

Class

TextFieldTest
Tests the creation of text fields.

Namespace

Drupal\text\Tests

Code

function _testTextfieldWidgets($field_type, $widget_type) {

  // Setup a field and instance
  $entity_type = 'entity_test';
  $this->field_name = drupal_strtolower($this
    ->randomName());
  $this->field = array(
    'field_name' => $this->field_name,
    'type' => $field_type,
  );
  field_create_field($this->field);
  $this->instance = array(
    'field_name' => $this->field_name,
    'entity_type' => 'entity_test',
    'bundle' => 'entity_test',
    'label' => $this
      ->randomName() . '_label',
    'settings' => array(
      'text_processing' => TRUE,
    ),
  );
  field_create_instance($this->instance);
  entity_get_form_display('entity_test', 'entity_test', 'default')
    ->setComponent($this->field_name, array(
    'type' => $widget_type,
    'settings' => array(
      'placeholder' => 'A placeholder on ' . $widget_type,
    ),
  ))
    ->save();
  entity_get_display('entity_test', 'entity_test', 'full')
    ->setComponent($this->field_name)
    ->save();
  $langcode = Language::LANGCODE_NOT_SPECIFIED;

  // Display creation form.
  $this
    ->drupalGet('entity_test/add');
  $this
    ->assertFieldByName("{$this->field_name}[{$langcode}][0][value]", '', 'Widget is displayed');
  $this
    ->assertNoFieldByName("{$this->field_name}[{$langcode}][0][format]", '1', 'Format selector is not displayed');
  $this
    ->assertRaw(format_string('placeholder="A placeholder on !widget_type"', array(
    '!widget_type' => $widget_type,
  )));

  // Submit with some value.
  $value = $this
    ->randomName();
  $edit = array(
    'user_id' => 1,
    'name' => $this
      ->randomName(),
    "{$this->field_name}[{$langcode}][0][value]" => $value,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  preg_match('|entity_test/manage/(\\d+)/edit|', $this->url, $match);
  $id = $match[1];
  $this
    ->assertText(t('entity_test @id has been created.', array(
    '@id' => $id,
  )), 'Entity was created');

  // Display the entity.
  $entity = entity_load('entity_test', $id);
  $display = entity_get_display($entity
    ->entityType(), $entity
    ->bundle(), 'full');
  $entity->content = field_attach_view($entity, $display);
  $this
    ->drupalSetContent(drupal_render($entity->content));
  $this
    ->assertText($value, 'Filtered tags are not displayed');
}