Issue #1981342 by aspilicious, andypost, swentel: Drop procedural usage of fields in [s-u-v] modules.
parent
fc35679d72
commit
72bd779d56
|
@ -49,8 +49,8 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
// Make the body field translatable.
|
||||
// The parent class has already created the article and page content types.
|
||||
$field = field_info_field('body');
|
||||
$field['translatable'] = TRUE;
|
||||
field_update_field($field);
|
||||
$field->translatable = TRUE;
|
||||
$field->save();
|
||||
|
||||
// Create a few page nodes with multilingual body values.
|
||||
$default_format = filter_default_format();
|
||||
|
|
|
@ -34,22 +34,20 @@ class EntityResolverTest extends NormalizerTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create the test field.
|
||||
$field = array(
|
||||
entity_create('field_entity', array(
|
||||
'settings' => array(
|
||||
'target_type' => 'entity_test_mulrev',
|
||||
),
|
||||
'field_name' => 'field_test_entity_reference',
|
||||
'type' => 'entity_reference',
|
||||
);
|
||||
field_create_field($field);
|
||||
))->save();
|
||||
|
||||
// Create the test field instance.
|
||||
$instance = array(
|
||||
entity_create('field_instance', array(
|
||||
'entity_type' => 'entity_test_mulrev',
|
||||
'field_name' => 'field_test_entity_reference',
|
||||
'bundle' => 'entity_test_mulrev',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,13 +26,13 @@ abstract class NormalizerTestBase extends DrupalUnitTestBase {
|
|||
$this->installConfig(array('field'));
|
||||
|
||||
// Auto-create a field for testing.
|
||||
field_create_field(array(
|
||||
entity_create('field_entity', array(
|
||||
'field_name' => 'field_test_text',
|
||||
'type' => 'text',
|
||||
'cardinality' => 1,
|
||||
'translatable' => FALSE,
|
||||
));
|
||||
$instance = array(
|
||||
))->save();
|
||||
entity_create('field_instance', array(
|
||||
'entity_type' => 'entity_test_mulrev',
|
||||
'field_name' => 'field_test_text',
|
||||
'bundle' => 'entity_test_mulrev',
|
||||
|
@ -41,7 +41,7 @@ abstract class NormalizerTestBase extends DrupalUnitTestBase {
|
|||
'type' => 'text_textfield',
|
||||
'weight' => 0,
|
||||
),
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -231,17 +231,16 @@ class DrupalUnitTestBaseTest extends DrupalUnitTestBase {
|
|||
'bundle' => 'entity_test',
|
||||
'mode' => 'default',
|
||||
));
|
||||
$field = array(
|
||||
$field = entity_create('field_entity', array(
|
||||
'field_name' => 'test_field',
|
||||
'type' => 'test_field'
|
||||
);
|
||||
field_create_field($field);
|
||||
$instance = array(
|
||||
'field_name' => $field['field_name'],
|
||||
));
|
||||
$field->save();
|
||||
entity_create('field_instance', array(
|
||||
'field_name' => $field->id(),
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,18 +34,16 @@ class MultiFormTest extends AjaxTestBase {
|
|||
|
||||
// Create a multi-valued field for 'page' nodes to use for Ajax testing.
|
||||
$field_name = 'field_ajax_test';
|
||||
$field = array(
|
||||
entity_create('field_entity', array(
|
||||
'field_name' => $field_name,
|
||||
'type' => 'text',
|
||||
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
|
||||
);
|
||||
field_create_field($field);
|
||||
$instance = array(
|
||||
))->save();
|
||||
entity_create('field_instance', array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
entity_get_form_display('node', 'page', 'default')
|
||||
->setComponent($field_name, array('type' => 'text_default'))
|
||||
->save();
|
||||
|
|
|
@ -598,8 +598,8 @@ class EntityFieldTest extends EntityUnitTestBase {
|
|||
protected function assertComputedProperties($entity_type) {
|
||||
// Make the test text field processed.
|
||||
$instance = field_info_instance($entity_type, 'field_test_text', $entity_type);
|
||||
$instance['settings']['text_processing'] = 1;
|
||||
field_update_instance($instance);
|
||||
$instance->settings['text_processing'] = 1;
|
||||
$instance->save();
|
||||
|
||||
$entity = $this->createTestEntity($entity_type);
|
||||
$entity->field_test_text->value = "The <strong>text</strong> text to filter.";
|
||||
|
|
|
@ -60,18 +60,17 @@ class EntityQueryAggregateTest extends EntityUnitTestBase {
|
|||
|
||||
// Add some fieldapi fields to be used in the test.
|
||||
for ($i = 1; $i <= 2; $i++) {
|
||||
$field = array(
|
||||
'field_name' => 'field_test_' . $i,
|
||||
$field_name = 'field_test_' . $i;
|
||||
entity_create('field_entity', array(
|
||||
'field_name' => $field_name,
|
||||
'type' => 'number_integer',
|
||||
'cardinality' => 2,
|
||||
);
|
||||
field_create_field($field);
|
||||
$instance = array(
|
||||
'field_name' => $field['field_name'],
|
||||
))->save();
|
||||
entity_create('field_instance', array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
}
|
||||
|
||||
$entity = $this->entityStorageController->create(array(
|
||||
|
|
|
@ -85,14 +85,13 @@ class EntityQueryRelationshipTest extends EntityUnitTestBase {
|
|||
'type' => 'taxonomy_term_reference',
|
||||
);
|
||||
$field['settings']['allowed_values']['vocabulary'] = $vocabulary->id();
|
||||
field_create_field($field);
|
||||
entity_create('field_entity', $field)->save();
|
||||
// Third, create the instance.
|
||||
$instance = array(
|
||||
entity_create('field_instance', array(
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => $this->fieldName,
|
||||
'bundle' => 'entity_test',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
// Create two terms and also two accounts.
|
||||
for ($i = 0; $i <= 1; $i++) {
|
||||
$term = entity_create('taxonomy_term', array(
|
||||
|
|
|
@ -61,13 +61,14 @@ class EntityQueryTest extends EntityUnitTestBase {
|
|||
$figures = drupal_strtolower($this->randomName());
|
||||
$greetings = drupal_strtolower($this->randomName());
|
||||
foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) {
|
||||
$field = array(
|
||||
$field = entity_create('field_entity', array(
|
||||
'field_name' => $field_name,
|
||||
'type' => $field_type,
|
||||
'cardinality' => 2,
|
||||
'translatable' => TRUE,
|
||||
);
|
||||
$fields[] = field_create_field($field);
|
||||
));
|
||||
$field->save();
|
||||
$fields[] = $field;
|
||||
}
|
||||
$bundles = array();
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
|
@ -78,12 +79,11 @@ class EntityQueryTest extends EntityUnitTestBase {
|
|||
} while ($bundles && strtolower($bundles[0]) >= strtolower($bundle));
|
||||
entity_test_create_bundle($bundle);
|
||||
foreach ($fields as $field) {
|
||||
$instance = array(
|
||||
'field_name' => $field['field_name'],
|
||||
entity_create('field_instance', array(
|
||||
'field_name' => $field->id(),
|
||||
'entity_type' => 'entity_test_mulrev',
|
||||
'bundle' => $bundle,
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
}
|
||||
$bundles[] = $bundle;
|
||||
}
|
||||
|
@ -410,12 +410,11 @@ class EntityQueryTest extends EntityUnitTestBase {
|
|||
// can test whether cross entity type fields produce the correct query.
|
||||
$field_name = $this->figures;
|
||||
$bundle = $this->randomName();
|
||||
$instance = array(
|
||||
entity_create('field_instance', array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => $bundle,
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
|
||||
$entity = entity_create('entity_test', array(
|
||||
'id' => 1,
|
||||
|
|
|
@ -105,8 +105,8 @@ class EntityTranslationFormTest extends WebTestBase {
|
|||
|
||||
// Make body translatable.
|
||||
$field = field_info_field('body');
|
||||
$field['translatable'] = TRUE;
|
||||
field_update_field($field);
|
||||
$field->translatable = TRUE;
|
||||
$field->save();
|
||||
$field = field_info_field('body');
|
||||
$this->assertTrue($field['translatable'], 'Field body is translatable.');
|
||||
|
||||
|
|
|
@ -50,23 +50,21 @@ class EntityTranslationTest extends EntityUnitTestBase {
|
|||
|
||||
// Create a translatable test field.
|
||||
$this->field_name = drupal_strtolower($this->randomName() . '_field_name');
|
||||
$field = array(
|
||||
entity_create('field_entity', array(
|
||||
'field_name' => $this->field_name,
|
||||
'type' => 'text',
|
||||
'cardinality' => 4,
|
||||
'translatable' => TRUE,
|
||||
);
|
||||
field_create_field($field);
|
||||
))->save();
|
||||
$this->field = field_read_field($this->field_name);
|
||||
|
||||
// Create instance in all entity variations.
|
||||
foreach (entity_test_entity_types() as $entity_type) {
|
||||
$instance = array(
|
||||
entity_create('field_instance', array(
|
||||
'field_name' => $this->field_name,
|
||||
'entity_type' => $entity_type,
|
||||
'bundle' => $entity_type,
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
$this->instance[$entity_type] = field_read_instance($entity_type, $this->field_name, $entity_type);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,15 +33,13 @@ class ArbitraryRebuildTest extends WebTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Auto-create a field for testing.
|
||||
$field = array(
|
||||
entity_create('field_entity', array(
|
||||
'field_name' => 'test_multiple',
|
||||
'type' => 'text',
|
||||
'cardinality' => -1,
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
field_create_field($field);
|
||||
|
||||
$instance = array(
|
||||
))->save();
|
||||
entity_create('field_instance', array(
|
||||
'entity_type' => 'user',
|
||||
'field_name' => 'test_multiple',
|
||||
'bundle' => 'user',
|
||||
|
@ -49,8 +47,7 @@ class ArbitraryRebuildTest extends WebTestBase {
|
|||
'settings' => array(
|
||||
'user_register_form' => TRUE,
|
||||
),
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
entity_get_form_display('user', 'user', 'default')
|
||||
->setComponent('test_multiple', array(
|
||||
'type' => 'text_textfield',
|
||||
|
|
|
@ -76,13 +76,13 @@ class RebuildTest extends WebTestBase {
|
|||
'type' => 'text',
|
||||
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
|
||||
);
|
||||
field_create_field($field);
|
||||
entity_create('field_entity', $field)->save();
|
||||
$instance = array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
entity_create('field_instance', $instance)->save();
|
||||
entity_get_form_display('node', 'page', 'default')
|
||||
->setComponent($field_name, array('type' => 'text_test'))
|
||||
->save();
|
||||
|
|
|
@ -10,13 +10,12 @@
|
|||
*/
|
||||
function entity_test_install() {
|
||||
// Auto-create a field for testing.
|
||||
$field = array(
|
||||
entity_create('field_entity', array(
|
||||
'field_name' => 'field_test_text',
|
||||
'type' => 'text',
|
||||
'cardinality' => 1,
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
field_create_field($field);
|
||||
))->save();
|
||||
|
||||
$entity_types = array(
|
||||
'entity_test',
|
||||
|
@ -25,13 +24,12 @@ function entity_test_install() {
|
|||
'entity_test_mulrev',
|
||||
);
|
||||
foreach ($entity_types as $entity_type) {
|
||||
$instance = array(
|
||||
entity_create('field_instance', array(
|
||||
'entity_type' => $entity_type,
|
||||
'field_name' => 'field_test_text',
|
||||
'bundle' => $entity_type,
|
||||
'label' => 'Test text-field',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
))->save();
|
||||
|
||||
entity_get_form_display($entity_type, $entity_type, 'default')
|
||||
->setComponent('field_test_text', array('type' => 'text_text'))
|
||||
|
|
|
@ -195,34 +195,34 @@ class UserRegistrationTest extends WebTestBase {
|
|||
*/
|
||||
function testRegistrationWithUserFields() {
|
||||
// Create a field, and an instance on 'user' entity type.
|
||||
$field = array(
|
||||
$field = entity_create('field_entity', array(
|
||||
'type' => 'test_field',
|
||||
'field_name' => 'test_user_field',
|
||||
'cardinality' => 1,
|
||||
);
|
||||
field_create_field($field);
|
||||
$instance = array(
|
||||
));
|
||||
$field->save();
|
||||
$instance = entity_create('field_instance', array(
|
||||
'field_name' => 'test_user_field',
|
||||
'entity_type' => 'user',
|
||||
'label' => 'Some user field',
|
||||
'bundle' => 'user',
|
||||
'required' => TRUE,
|
||||
'settings' => array('user_register_form' => FALSE),
|
||||
);
|
||||
field_create_instance($instance);
|
||||
));
|
||||
$instance->save();
|
||||
entity_get_form_display('user', 'user', 'default')
|
||||
->setComponent('test_user_field', array('type' => 'test_field_widget'))
|
||||
->save();
|
||||
|
||||
// Check that the field does not appear on the registration form.
|
||||
$this->drupalGet('user/register');
|
||||
$this->assertNoText($instance['label'], 'The field does not appear on user registration form');
|
||||
$this->assertNoText($instance->label(), 'The field does not appear on user registration form');
|
||||
|
||||
// Have the field appear on the registration form.
|
||||
$instance['settings']['user_register_form'] = TRUE;
|
||||
field_update_instance($instance);
|
||||
$instance->settings['user_register_form'] = TRUE;
|
||||
$instance->save();
|
||||
$this->drupalGet('user/register');
|
||||
$this->assertText($instance['label'], 'The field appears on user registration form');
|
||||
$this->assertText($instance->label(), 'The field appears on user registration form');
|
||||
|
||||
// Check that validation errors are correctly reported.
|
||||
$edit = array();
|
||||
|
@ -231,11 +231,11 @@ class UserRegistrationTest extends WebTestBase {
|
|||
// Missing input in required field.
|
||||
$edit['test_user_field[und][0][value]'] = '';
|
||||
$this->drupalPost(NULL, $edit, t('Create new account'));
|
||||
$this->assertRaw(t('@name field is required.', array('@name' => $instance['label'])), 'Field validation error was correctly reported.');
|
||||
$this->assertRaw(t('@name field is required.', array('@name' => $instance->label())), 'Field validation error was correctly reported.');
|
||||
// Invalid input.
|
||||
$edit['test_user_field[und][0][value]'] = '-1';
|
||||
$this->drupalPost(NULL, $edit, t('Create new account'));
|
||||
$this->assertRaw(t('%name does not accept the value -1.', array('%name' => $instance['label'])), 'Field validation error was correctly reported.');
|
||||
$this->assertRaw(t('%name does not accept the value -1.', array('%name' => $instance->label())), 'Field validation error was correctly reported.');
|
||||
|
||||
// Submit with valid data.
|
||||
$value = rand(1, 255);
|
||||
|
@ -247,8 +247,8 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->assertEqual($new_user->test_user_field->value, $value, 'The field value was correclty saved.');
|
||||
|
||||
// Check that the 'add more' button works.
|
||||
$field['cardinality'] = FIELD_CARDINALITY_UNLIMITED;
|
||||
field_update_field($field);
|
||||
$field->cardinality = FIELD_CARDINALITY_UNLIMITED;
|
||||
$field->save();
|
||||
foreach (array('js', 'nojs') as $js) {
|
||||
$this->drupalGet('user/register');
|
||||
// Add two inputs.
|
||||
|
|
|
@ -315,7 +315,7 @@ function user_install_picture_field() {
|
|||
'default_image' => FALSE,
|
||||
),
|
||||
);
|
||||
$field = field_create_field($field);
|
||||
entity_create('field_entity', $field)->save();
|
||||
|
||||
$instance = array(
|
||||
'field_name' => 'user_picture',
|
||||
|
@ -335,7 +335,7 @@ function user_install_picture_field() {
|
|||
'default_image' => 0,
|
||||
),
|
||||
);
|
||||
field_create_instance($instance);
|
||||
entity_create('field_instance', $instance)->save();
|
||||
|
||||
// Assign form display settings for the 'default' view mode.
|
||||
entity_get_form_display('user', 'user', 'default')
|
||||
|
|
|
@ -61,7 +61,7 @@ class DefaultViewsTest extends ViewTestBase {
|
|||
|
||||
// Setup a field and instance.
|
||||
$this->field_name = drupal_strtolower($this->randomName());
|
||||
$this->field = array(
|
||||
entity_create('field_entity', array(
|
||||
'field_name' => $this->field_name,
|
||||
'type' => 'taxonomy_term_reference',
|
||||
'settings' => array(
|
||||
|
@ -72,14 +72,12 @@ class DefaultViewsTest extends ViewTestBase {
|
|||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
field_create_field($this->field);
|
||||
$this->instance = array(
|
||||
))->save();
|
||||
entity_create('field_instance', array(
|
||||
'field_name' => $this->field_name,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
);
|
||||
field_create_instance($this->instance);
|
||||
))->save();
|
||||
|
||||
// Create a time in the past for the archive.
|
||||
$time = REQUEST_TIME - 3600;
|
||||
|
|
|
@ -55,7 +55,7 @@ class TaggedWithTest extends WizardTestBase {
|
|||
$this->tag_vocabulary->save();
|
||||
|
||||
// Create the tag field itself.
|
||||
$this->tag_field = array(
|
||||
$this->tag_field = entity_create('field_entity', array(
|
||||
'field_name' => 'field_views_testing_tags',
|
||||
'type' => 'taxonomy_term_reference',
|
||||
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
|
||||
|
@ -67,8 +67,8 @@ class TaggedWithTest extends WizardTestBase {
|
|||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
field_create_field($this->tag_field);
|
||||
));
|
||||
$this->tag_field->save();
|
||||
|
||||
// Create an instance of the tag field on one of the content types, and
|
||||
// configure it to display an autocomplete widget.
|
||||
|
@ -77,7 +77,7 @@ class TaggedWithTest extends WizardTestBase {
|
|||
'entity_type' => 'node',
|
||||
'bundle' => $this->node_type_with_tags->type,
|
||||
);
|
||||
field_create_instance($this->tag_instance);
|
||||
entity_create('field_instance', $this->tag_instance)->save();
|
||||
|
||||
entity_get_form_display('node', $this->node_type_with_tags->type, 'default')
|
||||
->setComponent('field_views_testing_tags', array(
|
||||
|
@ -108,7 +108,7 @@ class TaggedWithTest extends WizardTestBase {
|
|||
$node_add_path = 'node/add/' . $this->node_type_with_tags->type;
|
||||
|
||||
// Create three nodes, with different tags.
|
||||
$tag_field = $this->tag_field['field_name'] . '[' . Language::LANGCODE_NOT_SPECIFIED . ']';
|
||||
$tag_field = $this->tag_field->id() . '[' . Language::LANGCODE_NOT_SPECIFIED . ']';
|
||||
$edit = array();
|
||||
$edit['title'] = $node_tag1_title = $this->randomName();
|
||||
$edit[$tag_field] = 'tag1';
|
||||
|
@ -189,7 +189,7 @@ class TaggedWithTest extends WizardTestBase {
|
|||
// "tagged with" form element should not appear for it too.
|
||||
$instance = $this->tag_instance;
|
||||
$instance['bundle'] = $this->node_type_without_tags->type;
|
||||
field_create_instance($instance);
|
||||
entity_create('field_instance', $instance)->save();
|
||||
entity_get_form_display('node', $this->node_type_without_tags->type, 'default')
|
||||
->setComponent('field_views_testing_tags', array(
|
||||
'type' => 'taxonomy_autocomplete',
|
||||
|
|
|
@ -93,7 +93,7 @@ for ($i = 0; $i < 24; $i++) {
|
|||
),
|
||||
),
|
||||
);
|
||||
field_create_field($field);
|
||||
entity_create('field_entity', $field)->save();
|
||||
$node_types = $i > 11 ? array('page') : array_keys(node_type_get_types());
|
||||
foreach ($node_types as $bundle) {
|
||||
$instance = array(
|
||||
|
@ -132,7 +132,7 @@ for ($i = 0; $i < 24; $i++) {
|
|||
'settings' => array(),
|
||||
);
|
||||
}
|
||||
field_create_instance($instance);
|
||||
entity_create('field_instance', $instance)->save();
|
||||
}
|
||||
$parents = array();
|
||||
// Vocabularies without hierarchy get one term, single parent vocabularies get
|
||||
|
|
Loading…
Reference in New Issue