1 link.ui.test LinkUITest::testCRUDCreateFieldDefaults()

Creates a field with all the default values and check expected values.

File

core/modules/link/tests/link.ui.test, line 212
Testing CRUD API in the browser.

Class

LinkUITest
Testing that users can not input bad URLs or labels

Code

function testCRUDCreateFieldDefaults() {
  $name = strtolower($this->randomName());
  $edit = array(
    'fields[_add_new_field][label]' => $name,
    'fields[_add_new_field][field_name]' => $name,
    'fields[_add_new_field][type]' => 'link_field',
    'fields[_add_new_field][widget_type]' => 'link_field',
  );
  $this->backdropPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
  $this->backdropPost(NULL, array(), t('Save settings'));

  field_info_cache_clear();
  $instances = field_info_instances('node', 'page');

  $instance = $instances['field_' . $name];
  $this->assertFalse($instance['required'], 'Make sure field is not required.');
  $this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
  $this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
  $this->assertEqual($instance['settings']['type'], 'both', 'Link type should be "both" by default.');
  $this->assertFalse($instance['settings']['enable_tokens'], 'Enable Tokens should be off by default.');
  $this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
  $this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
  $this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
  $this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.');
  $this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
}