diff --git a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php index 674553c..d7616c1 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php @@ -44,18 +44,16 @@ public function setUp() { $this->installSchema('file', 'file_managed'); $this->installSchema('file', 'file_usage'); - $field = array( + entity_create('field_entity', array( 'field_name' => 'file_test', 'type' => 'file', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, - ); - entity_create('field_entity', $field)->save(); - $instance = array( + ))->save(); + entity_create('field_instance', array( 'entity_type' => 'entity_test', 'field_name' => 'file_test', 'bundle' => 'entity_test', - ); - entity_create('field_instance', $instance)->save(); + ))->save(); file_put_contents('public://example.txt', $this->randomName()); $this->file = entity_create('file', array( 'uri' => 'public://example.txt', diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 37c4248..f90b966 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -53,7 +53,7 @@ function forum_enable() { // is being enabled at the same time as taxonomy after both modules have been // enabled, the field might exist but still be marked inactive. if (!field_read_field('taxonomy_forums', array('include_inactive' => TRUE))) { - $field = array( + entity_create('field_entity', array( 'field_name' => 'taxonomy_forums', 'type' => 'taxonomy_term_reference', 'settings' => array( @@ -64,8 +64,7 @@ function forum_enable() { ), ), ), - ); - entity_create('field_entity', $field)->save(); + ))->save(); // Create a default forum so forum posts can be created. $term = entity_create('taxonomy_term', array( @@ -78,14 +77,13 @@ function forum_enable() { $term->save(); // Create the instance on the bundle. - $instance = array( + entity_create('field_instance', array( 'field_name' => 'taxonomy_forums', 'entity_type' => 'node', 'label' => $vocabulary->name, 'bundle' => 'forum', 'required' => TRUE, - ); - entity_create('field_instance', $instance)->save(); + ))->save(); // Assign form display settings for the 'default' form mode. entity_get_form_display('node', 'forum', 'default') diff --git a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php index 990e33e..ae7e582 100644 --- a/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php +++ b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php @@ -78,49 +78,43 @@ function setUp() { language_save($german); // Create the test text field. - $field = array( + entity_create('field_entity', array( 'field_name' => 'field_test_text', 'type' => 'text', 'translatable' => FALSE, - ); - entity_create('field_entity', $field)->save(); - $instance = array( + ))->save(); + entity_create('field_instance', array( 'entity_type' => 'entity_test', 'field_name' => 'field_test_text', 'bundle' => 'entity_test', - ); - entity_create('field_instance', $instance)->save(); + ))->save(); // Create the test translatable field. - $field = array( + entity_create('field_entity', array( 'field_name' => 'field_test_translatable_text', 'type' => 'text', 'translatable' => TRUE, - ); - entity_create('field_entity', $field)->save(); - $instance = array( + ))->save(); + entity_create('field_instance', array( 'entity_type' => 'entity_test', 'field_name' => 'field_test_translatable_text', 'bundle' => 'entity_test', - ); - entity_create('field_instance', $instance)->save(); + ))->save(); // Create the test entity reference field. - $field = array( + entity_create('field_entity', array( 'translatable' => TRUE, 'settings' => array( 'target_type' => 'entity_test', ), 'field_name' => 'field_test_entity_reference', 'type' => 'entity_reference', - ); - entity_create('field_entity', $field)->save(); - $instance = array( + ))->save(); + entity_create('field_instance', array( 'entity_type' => 'entity_test', 'field_name' => 'field_test_entity_reference', 'bundle' => 'entity_test', - ); - entity_create('field_instance', $instance)->save(); + ))->save(); // Set up the mock serializer. $normalizers = array( diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php index 6ebfde1..4db47eb 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php @@ -56,11 +56,11 @@ function testDefaultImages() { // Add another instance with another default image to the page content type. $instance2 = entity_create('field_instance', array( - 'field_name' => $field['field_name'], + 'field_name' => $field->id(), 'entity_type' => 'node', 'bundle' => 'page', - 'label' => $instance['label'], - 'required' => $instance['required'], + 'label' => $instance->id(), + 'required' => $instance->required, 'settings' => array( 'default_image' => $default_images['instance2']->fid, ), @@ -69,10 +69,10 @@ function testDefaultImages() { $widget_settings = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')->getComponent($field['field_name']); entity_get_form_display('node', 'page', 'default') - ->setComponent($field['field_name'], $widget_settings) + ->setComponent($field->id(), $widget_settings) ->save(); entity_get_display('node', 'page', 'default') - ->setComponent($field['field_name']) + ->setComponent($field->id()) ->save(); // Confirm the defaults are present on the article field settings form. diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php index 8ba2521..7744e0b 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php @@ -43,18 +43,16 @@ public function setUp() { $this->installSchema('file', array('file_managed', 'file_usage')); - $field = array( + entity_create('field_entity', array( 'field_name' => 'image_test', 'type' => 'image', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, - ); - entity_create('field_entity', $field)->save(); - $instance = array( + ))->save(); + entity_create('field_instance', array( 'entity_type' => 'entity_test', 'field_name' => 'image_test', 'bundle' => 'entity_test', - ); - entity_create('field_instance', $instance)->save(); + ))->save(); file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg'); $this->image = entity_create('file', array( 'uri' => 'public://example.jpg', diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php index e7cc631..bf1a656 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php @@ -45,22 +45,20 @@ function setUp() { */ function testURLValidation() { // Create a field with settings to validate. - $this->field = array( + $this->field = entity_create('field_entity', array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'link', - ); - entity_create('field_entity', $this->field)->save(); - $this->instance = array( - 'field_name' => $this->field['field_name'], + ))->save(); + $this->instance = entity_create('field_instance', array( + 'field_name' => $this->field->id(), 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'settings' => array( 'title' => DRUPAL_DISABLED, ), - ); - entity_create('field_instance', $this->instance)->save(); + ))->save(); entity_get_form_display('test_entity', 'test_bundle', 'default') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->id(), array( 'type' => 'link_default', 'settings' => array( 'placeholder_url' => 'http://example.com', @@ -68,7 +66,7 @@ function testURLValidation() { )) ->save(); entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->id(), array( 'type' => 'link', )) ->save(); @@ -77,13 +75,13 @@ function testURLValidation() { // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); - $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][url]", '', 'Link URL field is displayed'); + $this->assertFieldByName("{$this->field->id()}[$langcode][0][url]", '', 'Link URL field is displayed'); $this->assertRaw('placeholder="http://example.com"'); // Verify that a valid URL can be submitted. $value = 'http://www.example.com/'; $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => $value, + "{$this->field->id()}[$langcode][0][url]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); @@ -103,7 +101,7 @@ function testURLValidation() { $this->drupalGet('test-entity/add/test_bundle'); foreach ($wrong_entries as $invalid_value) { $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => $invalid_value, + "{$this->field->id()}[$langcode][0][url]" => $invalid_value, ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertText(t('The URL @url is not valid.', array('@url' => $invalid_value))); @@ -115,13 +113,13 @@ function testURLValidation() { */ function testLinkTitle() { // Create a field with settings to validate. - $this->field = array( + $this->field = entity_create('field_entity',array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'link', - ); - entity_create('field_entity', $this->field)->save(); + )); + $this->field->save(); $this->instance = entity_create('field_instance', array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->id(), 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'label' => 'Read more about this entity', @@ -131,7 +129,7 @@ function testLinkTitle() { )); $this->instance->save(); entity_get_form_display('test_entity', 'test_bundle', 'default') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->id(), array( 'type' => 'link_default', 'settings' => array( 'placeholder_url' => 'http://example.com', @@ -140,7 +138,7 @@ function testLinkTitle() { )) ->save(); entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->id(), array( 'type' => 'link', 'label' => 'hidden', )) @@ -158,28 +156,28 @@ function testLinkTitle() { $this->drupalGet('test-entity/add/test_bundle'); // Assert label is shown. $this->assertText('Read more about this entity'); - $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][url]", '', 'URL field found.'); + $this->assertFieldByName("{$this->field_>id()}[$langcode][0][url]", '', 'URL field found.'); $this->assertRaw('placeholder="http://example.com"'); if ($title_setting === DRUPAL_DISABLED) { - $this->assertNoFieldByName("{$this->field['field_name']}[$langcode][0][title]", '', 'Link text field not found.'); + $this->assertNoFieldByName("{$this->field->id()}[$langcode][0][title]", '', 'Link text field not found.'); $this->assertNoRaw('placeholder="Enter the text for this link"'); } else { $this->assertRaw('placeholder="Enter the text for this link"'); - $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][title]", '', 'Link text field found.'); + $this->assertFieldByName("{$this->field->id()}[$langcode][0][title]", '', 'Link text field found.'); if ($title_setting === DRUPAL_REQUIRED) { // Verify that the link text is required, if the URL is non-empty. $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => 'http://www.example.com', + "{$this->field->id()}[$langcode][0][url]" => 'http://www.example.com', ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertText(t('!name field is required.', array('!name' => t('Link text')))); // Verify that the link text is not required, if the URL is empty. $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => '', + "{$this->field->id()}[$langcode][0][url]" => '', ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertNoText(t('!name field is required.', array('!name' => t('Link text')))); @@ -187,8 +185,8 @@ function testLinkTitle() { // Verify that a URL and link text meets requirements. $this->drupalGet('test-entity/add/test_bundle'); $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => 'http://www.example.com', - "{$this->field['field_name']}[$langcode][0][title]" => 'Example', + "{$this->field->id()}[$langcode][0][url]" => 'http://www.example.com', + "{$this->field->id()}[$langcode][0][title]" => 'Example', ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertNoText(t('!name field is required.', array('!name' => t('Link text')))); @@ -199,8 +197,8 @@ function testLinkTitle() { // Verify that a link without link text is rendered using the URL as text. $value = 'http://www.example.com/'; $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => $value, - "{$this->field['field_name']}[$langcode][0][title]" => '', + "{$this->field->id()}[$langcode][0][url]" => $value, + "{$this->field->id()}[$langcode][0][title]" => '', ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); @@ -214,7 +212,7 @@ function testLinkTitle() { // Verify that a link with text is rendered using the link text. $title = $this->randomName(); $edit = array( - "{$this->field['field_name']}[$langcode][0][title]" => $title, + "{$this->field->id()}[$langcode][0][title]" => $title, ); $this->drupalPost("test-entity/manage/$id/edit", $edit, t('Save')); $this->assertRaw(t('test_entity @id has been updated.', array('@id' => $id))); @@ -229,33 +227,31 @@ function testLinkTitle() { */ function testLinkFormatter() { // Create a field with settings to validate. - $this->field = array( + $this->field = entity_create('field_entity', array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'link', 'cardinality' => 2, - ); - entity_create('field_entity', $this->field)->save(); - $this->instance = array( - 'field_name' => $this->field['field_name'], + ))->save(); + $this->instance = entity_create('field_instance', array( + 'field_name' => $this->field->id(), 'entity_type' => 'test_entity', 'label' => 'Read more about this entity', 'bundle' => 'test_bundle', 'settings' => array( 'title' => DRUPAL_OPTIONAL, ), - ); - $display_options = array( - 'type' => 'link', - 'label' => 'hidden', - ); - entity_create('field_instance', $this->instance)->save(); + ))->save(); entity_get_form_display('test_entity', 'test_bundle', 'default') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->id(), array( 'type' => 'link_default', )) ->save(); + $display_options = array( + 'type' => 'link', + 'label' => 'hidden', + ); entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], $display_options) + ->setComponent($this->field->id(), $display_options) ->save(); $langcode = Language::LANGCODE_NOT_SPECIFIED; @@ -272,11 +268,11 @@ function testLinkFormatter() { // Intentionally contains an ampersand that needs sanitization on output. $title2 = 'A very long & strange example title that could break the nice layout of the site'; $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => $url1, + "{$this->field->id()}[$langcode][0][url]" => $url1, // Note that $title1 is not submitted. - "{$this->field['field_name']}[$langcode][0][title]" => '', - "{$this->field['field_name']}[$langcode][1][url]" => $url2, - "{$this->field['field_name']}[$langcode][1][title]" => $title2, + "{$this->field->id()}[$langcode][0][title]" => '', + "{$this->field->id()}[$langcode][1][url]" => $url2, + "{$this->field->id()}[$langcode][1][title]" => $title2, ); // Assert label is shown. $this->assertText('Read more about this entity'); @@ -311,7 +307,7 @@ function testLinkFormatter() { $display_options['settings'] = $new_value; } entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], $display_options) + ->setComponent($this->field->id(), $display_options) ->save(); $this->renderTestEntity($id); @@ -369,33 +365,31 @@ function testLinkFormatter() { * merged, since they involve different configuration and output. */ function testLinkSeparateFormatter() { - // Create a field with settings to validate. - $this->field = array( + // Create a field with settings to validate.; + $this->field = entity_create('field_entity', array( 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'link', 'cardinality' => 2, - ); - entity_create('field_entity', $this->field)->save(); - $this->instance = array( - 'field_name' => $this->field['field_name'], + ))->save(); + $this->instance = entity_create('field_instance', array( + 'field_name' => $this->field->id(), 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'settings' => array( 'title' => DRUPAL_OPTIONAL, ), - ); - $display_options = array( - 'type' => 'link_separate', - 'label' => 'hidden', - ); - entity_create('field_instance', $this->instance)->save(); + ))->save(); entity_get_form_display('test_entity', 'test_bundle', 'default') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->id(), array( 'type' => 'link_default', )) ->save(); + $display_options = array( + 'type' => 'link_separate', + 'label' => 'hidden', + ); entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], $display_options) + ->setComponent($this->field->id(), $display_options) ->save(); $langcode = Language::LANGCODE_NOT_SPECIFIED; @@ -411,9 +405,9 @@ function testLinkSeparateFormatter() { // Intentionally contains an ampersand that needs sanitization on output. $title2 = 'A very long & strange example title that could break the nice layout of the site'; $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => $url1, - "{$this->field['field_name']}[$langcode][1][url]" => $url2, - "{$this->field['field_name']}[$langcode][1][title]" => $title2, + "{$this->field->id()}[$langcode][0][url]" => $url1, + "{$this->field->id()}[$langcode][1][url]" => $url2, + "{$this->field->id()}[$langcode][1][title]" => $title2, ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); @@ -431,7 +425,7 @@ function testLinkSeparateFormatter() { // Update the field formatter settings. $display_options['settings'] = array($setting => $new_value); entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], $display_options) + ->setComponent($this->field->id(), $display_options) ->save(); $this->renderTestEntity($id); diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php index ea94a6b..2cd88bc 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php @@ -35,17 +35,15 @@ public function setUp() { parent::setUp(); // Create an link field and instance for validation. - $this->field = entity_create('field_entity', array( + entity_create('field_entity', array( 'field_name' => 'field_test', 'type' => 'link', - )); - $this->field->save(); - $this->instance = entity_create('field_instance', array( + ))->save(); + entity_create('field_instance', array( 'entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test', - )); - $this->instance->save(); + ))->save(); } /**