View source
<?php
namespace Drupal\icon_field;
use Drupal\icon_field\Tests\IconTestBase;
class IconFieldWebTestBase extends ExamplesTestBase {
protected $contentTypeName;
protected $administratorAccount;
protected $authorAccount;
protected $fieldName;
public static $modules = array(
'block',
'node',
'field_ui',
'icon',
);
protected function setUp() {
parent::setUp();
$permissions = array(
'administer content types',
'administer node fields',
'administer node form display',
'administer node display',
);
$this->administratorAccount = $this
->drupalCreateUser($permissions);
parent::drupalLogin($this->administratorAccount);
$this->contentTypeName = strtolower($this
->randomMachineName(10));
$this
->drupalGet('admin/structure/types/add');
$edit = array(
'name' => $this->contentTypeName,
'type' => $this->contentTypeName,
);
$this
->drupalPostForm(NULL, $edit, t('Save and manage fields'));
$this
->assertText(t('The content type @name has been added.', array(
'@name' => $this->contentTypeName,
)));
$create_permission = 'create ' . $this->contentTypeName . ' content';
$this
->checkPermissions(array(
$create_permission,
), TRUE);
$this->authorAccount = $this
->drupalCreateUser(array(
$create_permission,
));
}
protected function createField($type = 'icon', $widget_type = 'icon_default_widget', $cardinality = '1', $fieldFormatter = 'icon_default_widget_formatter') {
$this
->drupalGet('admin/structure/types/manage/' . $this->contentTypeName . '/fields');
$this
->clickLink('Add field');
$field_name = strtolower($this
->randomMachineName(10));
$edit = array(
'new_storage_type' => $type,
'field_name' => $field_name,
'label' => $field_name,
);
$this
->drupalPostForm(NULL, $edit, t('Save and continue'));
$edit = array(
'cardinality' => 'number',
'cardinality_number' => (string) $cardinality,
);
if (-1 == $cardinality) {
$edit = array(
'cardinality' => '-1',
'cardinality_number' => '1',
);
}
$this
->drupalPostForm(NULL, $edit, t('Save field settings'));
debug(t('Saved settings for field %field_name with widget %widget_type and cardinality %cardinality', array(
'%field_name' => $field_name,
'%widget_type' => $widget_type,
'%cardinality' => $cardinality,
)));
$this
->assertText(t('Updated field @name field settings.', array(
'@name' => $field_name,
)));
$this
->drupalGet('admin/structure/types/manage/' . $this->contentTypeName . '/form-display');
$edit = array(
'fields[field_' . $field_name . '][type]' => $widget_type,
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->drupalGet('admin/structure/types/manage/' . $this->contentTypeName . '/display');
$edit1 = array(
'fields[field_' . $field_name . '][type]' => $fieldFormatter,
);
$this
->drupalPostForm(NULL, $edit1, t('Save'));
return $field_name;
}
}