Commit a4bfb01a authored by alexpott's avatar alexpott

Issue #1981334 by pcambra, aspilicious, swentel, andypost: Drop procedural...

Issue #1981334 by pcambra, aspilicious, swentel, andypost: Drop procedural usage of fields in [n-r] modules.
parent 72bd779d
......@@ -16,10 +16,11 @@
class MultiStepNodeFormBasicOptionsTest extends NodeTestBase {
/**
* Modules to enable.
* The field name to create.
*
* @var array
* @var string
*/
protected $field_name;
public static function getInfo() {
return array(
......@@ -39,15 +40,14 @@ function testMultiStepNodeFormBasicOptions() {
// Create an unlimited cardinality field.
$this->field_name = drupal_strtolower($this->randomName());
$this->field = array(
'field_name' => drupal_strtolower($this->field_name),
entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => 'text',
'cardinality' => -1,
);
field_create_field($this->field);
))->save();
// Attach an instance of the field to the page content type.
$this->instance = array(
entity_create('field_instance', array(
'field_name' => $this->field_name,
'entity_type' => 'node',
'bundle' => 'page',
......@@ -55,8 +55,7 @@ function testMultiStepNodeFormBasicOptions() {
'settings' => array(
'text_processing' => TRUE,
),
);
field_create_instance($this->instance);
))->save();
entity_get_form_display('node', 'page', 'default')
->setComponent($this->field_name, array(
'type' => 'text_textfield',
......@@ -69,10 +68,11 @@ function testMultiStepNodeFormBasicOptions() {
'title' => 'a',
'promote' => FALSE,
'sticky' => 1,
"$this->field_name[$langcode][0][value]" => $this->randomString(32),
"{$this->field_name}[$langcode][0][value]" => $this->randomString(32),
);
$this->drupalPost('node/add/page', $edit, t('Add another item'));
$this->assertNoFieldChecked('edit-promote', 'promote stayed unchecked');
$this->assertFieldChecked('edit-sticky', 'sticky stayed checked');
}
}
......@@ -21,6 +21,27 @@ class NodeAccessFieldTest extends NodeTestBase {
*/
public static $modules = array('node_access_test', 'field_ui');
/**
* A user with permission to bypass access content.
*
* @var \Drupal\user\UserInterface
*/
protected $admin_user;
/**
* A user with permission to manage content types and fields.
*
* @var \Drupal\user\UserInterface
*/
protected $content_admin_user;
/**
* The name of the created field.
*
* @var string
*/
protected $field_name;
public static function getInfo() {
return array(
'name' => 'Node access and fields',
......@@ -40,13 +61,15 @@ public function setUp() {
// Add a custom field to the page content type.
$this->field_name = drupal_strtolower($this->randomName() . '_field_name');
$this->field = field_create_field(array('field_name' => $this->field_name, 'type' => 'text'));
$instance = array(
entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => 'text'
))->save();
entity_create('field_instance', array(
'field_name' => $this->field_name,
'entity_type' => 'node',
'bundle' => 'page',
);
$this->instance = field_create_instance($instance);
))->save();
entity_get_display('node', 'page', 'default')
->setComponent($this->field_name)
->save();
......
......@@ -31,10 +31,17 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
/**
* A normal authenticated user.
*
* @var \Drupal\user\Plugin\Core\Entity\User.
* @var \Drupal\user\Plugin\Core\Entity\UserInterface.
*/
protected $web_user;
/**
* User 1.
*
* @var \Drupal\user\Plugin\Core\Entity\UserInterface.
*/
protected $admin_user;
public static function getInfo() {
return array(
'name' => 'Node access language-aware combination',
......
......@@ -60,8 +60,8 @@ function setUp() {
// Make node body translatable.
$field = field_info_field('body');
$field['translatable'] = TRUE;
field_update_field($field);
$field->translatable = TRUE;
$field->save();
}
/**
......
......@@ -169,7 +169,7 @@ function testFieldTranslationForm() {
$this->assertRaw('Not translated');
// Delete the only translatable field.
field_delete_field('field_test_et_ui_test');
field_info_field('field_test_et_ui_test')->delete();
// Visit translation page.
$this->drupalGet('node/' . $article->nid . '/translations');
......
......@@ -21,6 +21,13 @@ class PagePreviewTest extends NodeTestBase {
*/
public static $modules = array('node', 'taxonomy');
/**
* The name of the created field.
*
* @var string
*/
protected $field_name;
public static function getInfo() {
return array(
'name' => 'Node preview',
......@@ -60,7 +67,7 @@ function setUp() {
// Set up 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,30 +79,27 @@ function setUp() {
),
),
'cardinality' => '-1',
);
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();
entity_get_form_display('node', 'page', 'default')
->setComponent($this->field['field_name'], array(
->setComponent($this->field_name, array(
'type' => 'taxonomy_autocomplete',
))
->save();
// Show on default display and teaser.
entity_get_display('node', 'page', 'default')
->setComponent($this->field['field_name'], array(
->setComponent($this->field_name, array(
'type' => 'taxonomy_term_reference_link',
))
->save();
entity_get_display('node', 'page', 'teaser')
->setComponent($this->field['field_name'], array(
->setComponent($this->field_name, array(
'type' => 'taxonomy_term_reference_link',
))
->save();
......@@ -206,4 +210,5 @@ function testPagePreviewWithRevisions() {
// Check that the log field has the correct value.
$this->assertFieldByName('log', $edit['log'], 'Log field displayed.');
}
}
......@@ -530,39 +530,39 @@ function node_add_body_field($type, $label = 'Body') {
$field = field_info_field('body');
$instance = field_info_instance('node', 'body', $type->type);
if (empty($field)) {
$field = array(
$field = entity_create('field_entity', array(
'field_name' => 'body',
'type' => 'text_with_summary',
'entity_types' => array('node'),
);
$field = field_create_field($field);
));
$field->save();
}
if (empty($instance)) {
$instance = array(
$instance = entity_create('field_instance', array(
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => $type->type,
'label' => $label,
'settings' => array('display_summary' => TRUE),
);
$instance = field_create_instance($instance);
));
$instance->save();
// Assign widget settings for the 'default' form mode.
entity_get_form_display('node', $type->type, 'default')
->setComponent($field['field_name'], array(
->setComponent($field->id(), array(
'type' => 'text_textarea_with_summary',
))
->save();
// Assign display settings for the 'default' and 'teaser' view modes.
entity_get_display('node', $type->type, 'default')
->setComponent($field['field_name'], array(
->setComponent($field->id(), array(
'label' => 'hidden',
'type' => 'text_default',
))
->save();
entity_get_display('node', $type->type, 'teaser')
->setComponent($field['field_name'], array(
->setComponent($field->id(), array(
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
))
......
......@@ -49,7 +49,7 @@ function node_access_test_language_node_access_records(EntityInterface $node) {
* (restricted access) in a given translation.
*/
function node_access_test_language_enable() {
$field_private = array(
$field_private = entity_create('field_entity', array(
'field_name' => 'field_private',
'type' => 'list_boolean',
'cardinality' => 1,
......@@ -57,23 +57,22 @@ function node_access_test_language_enable() {
'settings' => array(
'allowed_values' => array(0 => 'Not private', 1 => 'Private'),
),
);
$field_private = field_create_field($field_private);
));
$field_private->save();
$instance = array(
'field_name' => $field_private['field_name'],
entity_create('field_instance', array(
'field_name' => $field_private->id(),
'entity_type' => 'node',
'bundle' => 'page',
'widget' => array(
'type' => 'options_buttons',
),
);
$instance = field_create_instance($instance);
))->save();
}
/**
* Implements hook_disable().
*/
function node_access_test_language_disable() {
field_delete_instance(field_read_instance('node', 'field_private', 'page'));
field_read_instance('node', 'field_private', 'page')->delete();
}
......@@ -22,8 +22,25 @@ class NumberFieldTest extends WebTestBase {
*/
public static $modules = array('node', 'entity_test', 'number', 'field_ui');
/**
* A field to use in this class.
*
* @var \Drupal\field\Plugin\Core\Entity\Field
*/
protected $field;
/**
* A field instance to use in this test class.
*
* @var \Drupal\field\Plugin\Core\Entity\FieldInstance
*/
protected $instance;
/**
* A user with permission to view and manage entities and content types.
*
* @var \Drupal\user\UserInterface
*/
protected $web_user;
public static function getInfo() {
......@@ -46,23 +63,22 @@ function setUp() {
*/
function testNumberDecimalField() {
// Create a field with settings to validate.
$this->field = array(
$this->field = entity_create('field_entity', array(
'field_name' => drupal_strtolower($this->randomName()),
'type' => 'number_decimal',
'settings' => array(
'precision' => 8, 'scale' => 4, 'decimal_separator' => '.',
)
);
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field['field_name'],
));
$this->field->save();
entity_create('field_instance', array(
'field_name' => $this->field->id(),
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
field_create_instance($this->instance);
))->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($this->field['field_name'], array(
->setComponent($this->field->id(), array(
'type' => 'number',
'settings' => array(
'placeholder' => '0.00'
......@@ -70,7 +86,7 @@ function testNumberDecimalField() {
))
->save();
entity_get_display('entity_test', 'entity_test', 'default')
->setComponent($this->field['field_name'], array(
->setComponent($this->field->id(), array(
'type' => 'number_decimal',
))
->save();
......
......@@ -36,17 +36,15 @@ public function setUp() {
// Create number fields and instances for validation.
foreach (array('integer', 'float', 'decimal') as $type) {
$this->field[$type] = array(
entity_create('field_entity', array(
'field_name' => 'field_' . $type,
'type' => 'number_' . $type,
);
field_create_field($this->field[$type]);
$this->instance[$type] = array(
))->save();
entity_create('field_instance', array(
'entity_type' => 'entity_test',
'field_name' => 'field_' . $type,
'bundle' => 'entity_test',
);
field_create_instance($this->instance[$type]);
))->save();
}
}
......
......@@ -32,23 +32,20 @@ function setUp() {
parent::setUp();
$this->field_name = 'test_options';
$this->field = array(
entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => 'list_text',
'cardinality' => 1,
'settings' => array(
'allowed_values_function' => 'options_test_dynamic_values_callback',
),
);
$this->field = field_create_field($this->field);
$this->instance = array(
))->save();
$this->instance = entity_create('field_instance', array(
'field_name' => $this->field_name,
'entity_type' => 'entity_test_rev',
'bundle' => 'entity_test_rev',
'required' => TRUE,
);
$this->instance = field_create_instance($this->instance);
))->save();
entity_get_form_display('entity_test_rev', 'entity_test_rev', 'default')
->setComponent($this->field_name, array(
'type' => 'options_select',
......
......@@ -48,9 +48,9 @@ function testUpdateAllowedValues() {
$entity = entity_create('entity_test', array());
$entity->{$this->fieldName}->value = 1;
$entity->save();
$this->field['settings']['allowed_values'] = array(2 => 'Two');
$this->field->settings['allowed_values'] = array(2 => 'Two');
try {
field_update_field($this->field);
$this->field->save();
$this->fail(t('Cannot update a list field to not include keys with existing data.'));
}
catch (FieldException $e) {
......@@ -61,8 +61,8 @@ function testUpdateAllowedValues() {
$entity->save();
// Removed options do not appear.
$this->field['settings']['allowed_values'] = array(2 => 'Two');
field_update_field($this->field);
$this->field->settings['allowed_values'] = array(2 => 'Two');
$this->field->save();
$entity = entity_create('entity_test', array());
$form = \Drupal::entityManager()->getForm($entity);
$this->assertTrue(empty($form[$this->fieldName][$langcode][1]), 'Option 1 does not exist');
......@@ -71,7 +71,7 @@ function testUpdateAllowedValues() {
// Completely new options appear.
$this->field['settings']['allowed_values'] = array(10 => 'Update', 20 => 'Twenty');
field_update_field($this->field);
$this->field->save();
$form = \Drupal::entityManager()->getForm($entity);
$this->assertTrue(empty($form[$this->fieldName][$langcode][1]), 'Option 1 does not exist');
$this->assertTrue(empty($form[$this->fieldName][$langcode][2]), 'Option 2 does not exist');
......@@ -80,15 +80,13 @@ function testUpdateAllowedValues() {
$this->assertTrue(!empty($form[$this->fieldName][$langcode][20]), 'Option 20 exists');
// Options are reset when a new field with the same name is created.
field_delete_field($this->fieldName);
unset($this->field['id']);
field_create_field($this->fieldDefinition);
$this->instance = array(
$this->field->delete();
entity_create('field_entity', $this->fieldDefinition)->save();
entity_create('field_instance', array(
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
field_create_instance($this->instance);
))->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($this->fieldName, array(
'type' => 'options_buttons',
......
......@@ -78,7 +78,7 @@ function testOptionsAllowedValuesInteger() {
// Create a node with actual data for the field.
$settings = array(
'type' => $this->type,
$this->field_name =>array(array('value' => 1)),
$this->field_name => array(array('value' => 1)),
);
$node = $this->drupalCreateNode($settings);
......@@ -258,17 +258,15 @@ function testOptionsTrimmedValuesText() {
*/
protected function createOptionsField($type) {
// Create a test field and instance.
$field = array(
entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => $type,
);
field_create_field($field);
$instance = array(
))->save();
entity_create('field_instance', array(
'field_name' => $this->field_name,
'entity_type' => 'node',
'bundle' => $this->type,
);
field_create_instance($instance);
))->save();
entity_get_form_display('node', $this->type, 'default')->setComponent($this->field_name)->save();
......
......@@ -107,17 +107,15 @@ function testAttributesInMarkupFile() {
$bundle_name = "article";
$field_name = 'file_test';
$field = array(
entity_create('field_entity', array(
'field_name' => $field_name,
'type' => 'file',
);
field_create_field($field);
$instance = array(
))->save();
entity_create('field_instance', array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => $bundle_name,
);
field_create_instance($instance);
))->save();
entity_get_form_display('node', $bundle_name, 'default')
->setComponent($field_name, array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment