diff --git a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php index 7697423..65e3aec 100644 --- a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php @@ -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'); } + } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php index 4b3dc88..e1a33aa 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php @@ -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(); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php index 6b60907..6688530 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php @@ -35,6 +35,13 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase { */ protected $web_user; + /** + * User 1. + * + * @var \Drupal\user\Plugin\Core\Entity\User. + */ + protected $admin_user; + public static function getInfo() { return array( 'name' => 'Node access language-aware combination', diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php index 18c879f..e9447ec 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php @@ -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(); } /** diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php index ac024bb..9344355 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php @@ -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'); diff --git a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php index d46c24e..ae7529b 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php @@ -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.'); } + } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 3245f24..981d94c 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -532,39 +532,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', )) diff --git a/core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module b/core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module index 3d67454..1baa48e 100644 --- a/core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module +++ b/core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module @@ -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(); } diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php index f9a817f..2514b6d 100644 --- a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php +++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php @@ -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 a and manage entities and content types. + * + * @var object + */ 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(); diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php index fa7e0fa..a0cc904 100644 --- a/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php +++ b/core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php @@ -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(); } } diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php index df3ac66..c270e4a 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php @@ -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', diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php index 984a205..2422971 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php @@ -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 = entity_get_form($entity); $this->assertTrue(empty($form[$this->fieldName][$langcode][1]), 'Option 1 does not exist'); @@ -70,8 +70,8 @@ function testUpdateAllowedValues() { $this->assertTrue(empty($form[$this->fieldName][$langcode][3]), 'Option 3 does not exist'); // Completely new options appear. - $this->field['settings']['allowed_values'] = array(10 => 'Update', 20 => 'Twenty'); - field_update_field($this->field); + $this->field->settings['allowed_values'] = array(10 => 'Update', 20 => 'Twenty'); + $this->field->save(); $form = entity_get_form($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', diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php index f28fb7c..d34f178 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php @@ -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(); diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php index f206d0e..8d335c3 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php @@ -22,6 +22,35 @@ class OptionsWidgetsTest extends FieldTestBase { */ public static $modules = array('options', 'entity_test', 'options_test', 'taxonomy', 'field_ui'); + /** + * A field with cardinality 1 to use in this test class. + * + * @var \Drupal\field\Plugin\Core\Entity\Field + */ + protected $card_1; + + /** + * A field with cardinality 2 to use in this test class. + * + * @var \Drupal\field\Plugin\Core\Entity\Field + */ + protected $card_2; + + /** + * A boolean field to use in this test class. + * + * @var \Drupal\field\Plugin\Core\Entity\Field + */ + protected $bool; + + /** + * A user with permission to view and manage entities. + * + * @var \Drupal\user\UserInterface + */ + protected $web_user; + + public static function getInfo() { return array( 'name' => 'Options widgets', @@ -34,7 +63,7 @@ function setUp() { parent::setUp(); // Field with cardinality 1. - $this->card_1 = array( + $this->card_1 = entity_create('field_entity', array( 'field_name' => 'card_1', 'type' => 'list_integer', 'cardinality' => 1, @@ -42,11 +71,11 @@ function setUp() { // Make sure that 0 works as an option. 'allowed_values' => array(0 => 'Zero', 1 => 'One', 2 => 'Some & unescaped markup'), ), - ); - $this->card_1 = field_create_field($this->card_1); + )); + $this->card_1->save(); // Field with cardinality 2. - $this->card_2 = array( + $this->card_2 = entity_create('field_entity', array( 'field_name' => 'card_2', 'type' => 'list_integer', 'cardinality' => 2, @@ -54,19 +83,19 @@ function setUp() { // Make sure that 0 works as an option. 'allowed_values' => array(0 => 'Zero', 1 => 'One', 2 => 'Some & unescaped markup'), ), - ); - $this->card_2 = field_create_field($this->card_2); + )); + $this->card_2->save(); // Boolean field. - $this->bool = array( + $this->bool = entity_create('field_entity', array( 'field_name' => 'bool', 'type' => 'list_boolean', 'cardinality' => 1, 'settings' => array( 'allowed_values' => array(0 => 'Zero', 1 => 'Some & unescaped markup'), ), - ); - $this->bool = field_create_field($this->bool); + )); + $this->bool->save(); // Create a web user. $this->web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content')); @@ -78,14 +107,14 @@ function setUp() { */ function testRadioButtons() { // Create an instance of the 'single value' field. - $instance = array( - 'field_name' => $this->card_1['field_name'], + $instance = entity_create('field_instance', array( + 'field_name' => $this->card_1->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', - ); - $instance = field_create_instance($instance); + )); + $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_1['field_name'], array( + ->setComponent($this->card_1->id(), array( 'type' => 'options_buttons', )) ->save(); @@ -124,10 +153,10 @@ function testRadioButtons() { $this->assertFieldValues($entity_init, 'card_1', $langcode, array()); // Check that required radios with one option is auto-selected. - $this->card_1['settings']['allowed_values'] = array(99 => 'Only allowed value'); - field_update_field($this->card_1); - $instance['required'] = TRUE; - field_update_instance($instance); + $this->card_1->settings['allowed_values'] = array(99 => 'Only allowed value'); + $this->card_1->save(); + $instance->required = TRUE; + $instance->save(); $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertFieldChecked("edit-card-1-$langcode-99"); } @@ -137,14 +166,14 @@ function testRadioButtons() { */ function testCheckBoxes() { // Create an instance of the 'multiple values' field. - $instance = array( - 'field_name' => $this->card_2['field_name'], + $instance = entity_create('field_instance', array( + 'field_name' => $this->card_2->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', - ); - $instance = field_create_instance($instance); + )); + $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_2['field_name'], array( + ->setComponent($this->card_2->id(), array( 'type' => 'options_buttons', )) ->save(); @@ -216,10 +245,10 @@ function testCheckBoxes() { $this->assertFieldValues($entity_init, 'card_2', $langcode, array()); // Required checkbox with one option is auto-selected. - $this->card_2['settings']['allowed_values'] = array(99 => 'Only allowed value'); - field_update_field($this->card_2); - $instance['required'] = TRUE; - field_update_instance($instance); + $this->card_2->settings['allowed_values'] = array(99 => 'Only allowed value'); + $this->card_2->save(); + $instance->required = TRUE; + $instance->save(); $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertFieldChecked("edit-card-2-$langcode-99"); } @@ -229,15 +258,15 @@ function testCheckBoxes() { */ function testSelectListSingle() { // Create an instance of the 'single value' field. - $instance = array( - 'field_name' => $this->card_1['field_name'], + $instance = entity_create('field_instance', array( + 'field_name' => $this->card_1->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'required' => TRUE, - ); - $instance = field_create_instance($instance); + )); + $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_1['field_name'], array( + ->setComponent($this->card_1->id(), array( 'type' => 'options_select', )) ->save(); @@ -283,8 +312,8 @@ function testSelectListSingle() { $this->assertNoOptionSelected("edit-card-1-$langcode", 2); // Make the field non required. - $instance['required'] = FALSE; - field_update_instance($instance); + $instance->required = FALSE; + $instance->save(); // Display form. $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); @@ -299,7 +328,7 @@ function testSelectListSingle() { $this->card_1['settings']['allowed_values'] = array(); $this->card_1['settings']['allowed_values_function'] = 'options_test_allowed_values_callback'; - field_update_field($this->card_1); + $this->card_1->save(); // Display form: with no field data, nothing is selected $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); @@ -331,14 +360,14 @@ function testSelectListSingle() { */ function testSelectListMultiple() { // Create an instance of the 'multiple values' field. - $instance = array( - 'field_name' => $this->card_2['field_name'], + $instance = entity_create('field_instance', array( + 'field_name' => $this->card_2->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', - ); - $instance = field_create_instance($instance); + )); + $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_2['field_name'], array( + ->setComponent($this->card_2->id(), array( 'type' => 'options_select', )) ->save(); @@ -406,8 +435,8 @@ function testSelectListMultiple() { $this->assertFieldValues($entity_init, 'card_2', $langcode, array()); // A required select list does not have an empty key. - $instance['required'] = TRUE; - field_update_instance($instance); + $instance->required = TRUE; + $instance->save(); $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertFalse($this->xpath('//select[@id=:id]//option[@value=""]', array(':id' => 'edit-card-2-' . $langcode)), 'A required select list does not have an empty key.'); @@ -417,11 +446,11 @@ function testSelectListMultiple() { // Test optgroups. // Use a callback function defining optgroups. - $this->card_2['settings']['allowed_values'] = array(); - $this->card_2['settings']['allowed_values_function'] = 'options_test_allowed_values_callback'; - field_update_field($this->card_2); - $instance['required'] = FALSE; - field_update_instance($instance); + $this->card_2->settings['allowed_values'] = array(); + $this->card_2->settings['allowed_values_function'] = 'options_test_allowed_values_callback'; + $this->card_2->save(); + $instance->required = FALSE; + $instance->save(); // Display form: with no field data, nothing is selected. $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); @@ -453,14 +482,13 @@ function testSelectListMultiple() { */ function testOnOffCheckbox() { // Create an instance of the 'boolean' field. - $instance = array( - 'field_name' => $this->bool['field_name'], + entity_create('field_instance', array( + 'field_name' => $this->bool->id(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', - ); - $instance = field_create_instance($instance); + ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->bool['field_name'], array( + ->setComponent($this->bool->id(), array( 'type' => 'options_onoff', )) ->save(); @@ -508,13 +536,12 @@ function testOnOffCheckbox() { // Create a test field instance. $fieldUpdate = $this->bool; $fieldUpdate['settings']['allowed_values'] = array(0 => 0, 1 => 'MyOnValue'); - field_update_field($fieldUpdate); - $instance = array( + $fieldUpdate->save(); + entity_create('field_instance', array( 'field_name' => $this->bool['field_name'], 'entity_type' => 'node', 'bundle' => 'page', - ); - field_create_instance($instance); + ))->save(); entity_get_form_display('node', 'page', 'default') ->setComponent($this->bool['field_name'], array( diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php index 320126c..82eb211 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php @@ -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(