function TextFieldTest::_testTextfieldWidgets

Helper function for testTextfieldWidgets().

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

File

drupal/core/modules/field/modules/text/lib/Drupal/text/Tests/TextFieldTest.php, line 101
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 = 'test_entity';
  $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' => 'test_entity',
    'bundle' => 'test_bundle',
    'label' => $this
      ->randomName() . '_label',
    'settings' => array(
      'text_processing' => TRUE,
    ),
    'widget' => array(
      'type' => $widget_type,
      'settings' => array(
        'placeholder' => 'A placeholder on ' . $widget_type,
      ),
    ),
    'display' => array(
      'full' => array(
        'type' => 'text_default',
      ),
    ),
  );
  field_create_instance($this->instance);
  $langcode = LANGUAGE_NOT_SPECIFIED;

  // Display creation form.
  $this
    ->drupalGet('test-entity/add/test_bundle');
  $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(
    "{$this->field_name}[{$langcode}][0][value]" => $value,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  preg_match('|test-entity/manage/(\\d+)/edit|', $this->url, $match);
  $id = $match[1];
  $this
    ->assertRaw(t('test_entity @id has been created.', array(
    '@id' => $id,
  )), 'Entity was created');

  // Display the entity.
  $entity = field_test_entity_test_load($id);
  $entity->content = field_attach_view($entity_type, $entity, 'full');
  $this->content = drupal_render($entity->content);
  $this
    ->assertText($value, 'Filtered tags are not displayed');
}