diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index 046d3c0..4dcdb17 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -238,4 +238,5 @@ function assertFileIsPermanent($file, $message = NULL) { $message = isset($message) ? $message : t('File %file is permanent.', array('%file' => $file->uri)); $this->assertTrue($file->status == FILE_STATUS_PERMANENT, $message); } + } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php index 5d340e8..3b9be9f 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php @@ -128,4 +128,5 @@ function uploadNodeImage($image, $field_name, $type) { preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches); return isset($matches[1]) ? $matches[1] : FALSE; } + } diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php index 28946b4..8849ccd 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php @@ -22,6 +22,27 @@ class LinkFieldTest extends WebTestBase { */ public static $modules = array('entity_test', 'link'); + /** + * A field to use in this test class. + * + * @var \Drupal\field\Plugin\Core\Entity\Field + */ + protected $field; + + /** + * The instance used in this test class. + * + * @var \Drupal\field\Plugin\Core\Entity\FieldInstance + */ + protected $instance; + + /** + * A user with permission to view and manage test entities. + * + * @var object + */ + protected $web_user; + public static function getInfo() { return array( 'name' => 'Link field', @@ -44,6 +65,7 @@ function setUp() { * Tests link field URL validation. */ function testURLValidation() { + $field_name = $this->field->id(); // Create a field with settings to validate. $this->field = entity_create('field_entity', array( 'field_name' => drupal_strtolower($this->randomName()), @@ -51,7 +73,7 @@ function testURLValidation() { )); $this->field->save(); entity_create('field_instance', array( - 'field_name' => $this->field->id(), + 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'settings' => array( @@ -59,7 +81,7 @@ function testURLValidation() { ), ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field->id(), array( + ->setComponent($field_name, array( 'type' => 'link_default', 'settings' => array( 'placeholder_url' => 'http://example.com', @@ -67,7 +89,7 @@ function testURLValidation() { )) ->save(); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($this->field->id(), array( + ->setComponent($field_name, array( 'type' => 'link', )) ->save(); @@ -76,7 +98,7 @@ function testURLValidation() { // Display creation form. $this->drupalGet('entity_test/add'); - $this->assertFieldByName("{$this->field->id()}[$langcode][0][url]", '', 'Link URL field is displayed'); + $this->assertFieldByName("{$field_name}[$langcode][0][url]", '', 'Link URL field is displayed'); $this->assertRaw('placeholder="http://example.com"'); // Verify that a valid URL can be submitted. @@ -84,7 +106,7 @@ function testURLValidation() { $edit = array( 'user_id' => 1, 'name' => $this->randomName(), - "{$this->field->id()}[$langcode][0][url]" => $value, + "{$field_name}[$langcode][0][url]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); @@ -106,7 +128,7 @@ function testURLValidation() { $edit = array( 'user_id' => 1, 'name' => $this->randomName(), - "{$this->field->id()}[$langcode][0][url]" => $invalid_value, + "{$field_name}[$langcode][0][url]" => $invalid_value, ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertText(t('The URL @url is not valid.', array('@url' => $invalid_value))); @@ -117,6 +139,7 @@ function testURLValidation() { * Tests the link title settings of a link field. */ function testLinkTitle() { + $field_name = $this->field->id(); // Create a field with settings to validate. $this->field = entity_create('field_entity', array( 'field_name' => drupal_strtolower($this->randomName()), @@ -124,7 +147,7 @@ function testLinkTitle() { )); $this->field->save(); $this->instance = entity_create('field_instance', array( - 'field_name' => $this->field->id(), + 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => 'Read more about this entity', @@ -134,7 +157,7 @@ function testLinkTitle() { )); $this->instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field->id(), array( + ->setComponent($field_name, array( 'type' => 'link_default', 'settings' => array( 'placeholder_url' => 'http://example.com', @@ -143,7 +166,7 @@ function testLinkTitle() { )) ->save(); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($this->field->id(), array( + ->setComponent($field_name, array( 'type' => 'link', 'label' => 'hidden', )) @@ -161,28 +184,28 @@ function testLinkTitle() { $this->drupalGet('entity_test/add'); // Assert label is shown. $this->assertText('Read more about this entity'); - $this->assertFieldByName("{$this->field->id()]}[$langcode][0][url]", '', 'URL field found.'); + $this->assertFieldByName("{$field_name}[$langcode][0][url]", '', 'URL field found.'); $this->assertRaw('placeholder="http://example.com"'); if ($title_setting === DRUPAL_DISABLED) { - $this->assertNoFieldByName("{$this->field->id()}[$langcode][0][title]", '', 'Link text field not found.'); + $this->assertNoFieldByName("{$field_name}[$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->id()}[$langcode][0][title]", '', 'Link text field found.'); + $this->assertFieldByName("{$field_name}[$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->id()}[$langcode][0][url]" => 'http://www.example.com', + "{$field_name}[$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->id()}[$langcode][0][url]" => '', + "{$field_name}[$langcode][0][url]" => '', ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertNoText(t('!name field is required.', array('!name' => t('Link text')))); @@ -190,8 +213,8 @@ function testLinkTitle() { // Verify that a URL and link text meets requirements. $this->drupalGet('entity_test/add'); $edit = array( - "{$this->field->id()}[$langcode][0][url]" => 'http://www.example.com', - "{$this->field->id()}[$langcode][0][title]" => 'Example', + "{$field_name}[$langcode][0][url]" => 'http://www.example.com', + "{$field_name}[$langcode][0][title]" => 'Example', ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertNoText(t('!name field is required.', array('!name' => t('Link text')))); @@ -204,8 +227,8 @@ function testLinkTitle() { $edit = array( 'user_id' => 1, 'name' => $this->randomName(), - "{$this->field->id()}[$langcode][0][url]" => $value, - "{$this->field->id()}[$langcode][0][title]" => '', + "{$field_name}[$langcode][0][url]" => $value, + "{$field_name}[$langcode][0][title]" => '', ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); @@ -221,7 +244,7 @@ function testLinkTitle() { $edit = array( 'user_id' => 1, 'name' => $this->randomName(), - "{$this->field->id()}[$langcode][0][title]" => $title, + "{$field_name}[$langcode][0][title]" => $title, ); $this->drupalPost("entity_test/manage/$id/edit", $edit, t('Save')); $this->assertText(t('entity_test @id has been updated.', array('@id' => $id))); @@ -235,6 +258,7 @@ function testLinkTitle() { * Tests the default 'link' formatter. */ function testLinkFormatter() { + $field_name = $this->field->id(); // Create a field with settings to validate. $this->field = entity_create('field_entity', array( 'field_name' => drupal_strtolower($this->randomName()), @@ -243,7 +267,7 @@ function testLinkFormatter() { )); $this->field->save(); entity_create('field_instance', array( - 'field_name' => $this->field->id(), + 'field_name' => $field_name, 'entity_type' => 'entity_test', 'label' => 'Read more about this entity', 'bundle' => 'entity_test', @@ -252,7 +276,7 @@ function testLinkFormatter() { ), ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field->id(), array( + ->setComponent($field_name, array( 'type' => 'link_default', )) ->save(); @@ -261,7 +285,7 @@ function testLinkFormatter() { 'label' => 'hidden', ); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($this->field->id(), $display_options) + ->setComponent($field_name, $display_options) ->save(); $langcode = Language::LANGCODE_NOT_SPECIFIED; @@ -280,11 +304,11 @@ function testLinkFormatter() { $edit = array( 'user_id' => 1, 'name' => $this->randomName(), - "{$this->field->id()}[$langcode][0][url]" => $url1, + "{$field_name}[$langcode][0][url]" => $url1, // Note that $title1 is not submitted. - "{$this->field->id()}[$langcode][0][title]" => '', - "{$this->field->id()}[$langcode][1][url]" => $url2, - "{$this->field->id()}[$langcode][1][title]" => $title2, + "{$field_name}[$langcode][0][title]" => '', + "{$field_name}[$langcode][1][url]" => $url2, + "{$field_name}[$langcode][1][title]" => $title2, ); // Assert label is shown. $this->assertText('Read more about this entity'); @@ -319,7 +343,7 @@ function testLinkFormatter() { $display_options['settings'] = $new_value; } entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($this->field->id(), $display_options) + ->setComponent($field_name, $display_options) ->save(); $this->renderTestEntity($id); @@ -377,6 +401,7 @@ function testLinkFormatter() { * merged, since they involve different configuration and output. */ function testLinkSeparateFormatter() { + $field_name = $this->field->id(); // Create a field with settings to validate. $this->field = entity_create('field_entity', array( 'field_name' => drupal_strtolower($this->randomName()), @@ -385,7 +410,7 @@ function testLinkSeparateFormatter() { )); $this->field->save(); entity_create('field_instance', array( - 'field_name' => $this->field->id()], + 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'settings' => array( @@ -397,12 +422,12 @@ function testLinkSeparateFormatter() { 'label' => 'hidden', ); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field->id(), array( + ->setComponent($field_name, array( 'type' => 'link_default', )) ->save(); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($this->field->id(), $display_options) + ->setComponent($field_name, $display_options) ->save(); $langcode = Language::LANGCODE_NOT_SPECIFIED; @@ -420,9 +445,9 @@ function testLinkSeparateFormatter() { $edit = array( 'user_id' => 1, 'name' => $this->randomName(), - "{$this->field->id()}[$langcode][0][url]" => $url1, - "{$this->field->id()}[$langcode][1][url]" => $url2, - "{$this->field->id()}[$langcode][1][title]" => $title2, + "{$field_name}[$langcode][0][url]" => $url1, + "{$field_name}[$langcode][1][url]" => $url2, + "{$field_name}[$langcode][1][title]" => $title2, ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); @@ -503,4 +528,5 @@ protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) { $this->drupalSetContent($output); $this->verbose($output); } + }