<?php
namespace Drupal\edit\Tests;
use Drupal\simpletest\DrupalUnitTestBase;
class EditTestBase extends DrupalUnitTestBase {
public static $modules = array(
'system',
'entity',
'entity_test',
'field',
'field_sql_storage',
'field_test',
'number',
'text',
'edit',
);
function setUp() {
parent::setUp();
$this
->installSchema('system', 'variable');
$this
->installSchema('entity_test', array(
'entity_test',
'entity_test_rev',
));
$this
->installConfig(array(
'field',
));
}
function createFieldWithInstance($field_name, $type, $cardinality, $label, $instance_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings) {
$field = $field_name . '_field';
$this->field = array(
'field_name' => $field_name,
'type' => $type,
'cardinality' => $cardinality,
);
$this->{$field} = field_create_field($this->field);
$instance = $field_name . '_instance';
$this->{$instance} = array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'label' => $label,
'description' => $label,
'weight' => mt_rand(0, 127),
'settings' => $instance_settings,
);
field_create_instance($this->{$instance});
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
'type' => $widget_type,
'label' => $label,
'settings' => $widget_settings,
))
->save();
entity_get_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
'label' => 'above',
'type' => $formatter_type,
'settings' => $formatter_settings,
))
->save();
}
}