From 708fc9b1c1e7ca079507f9a2d5da7a8e9f457b02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"J.=20Rene=CC=81e=20Beach"?= <splendidnoise@gmail.com>
Date: Fri, 15 Feb 2013 15:10:46 -0500
Subject: [PATCH] Issue #1874354
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: J. Renée Beach <splendidnoise@gmail.com>
---
 .../link/lib/Drupal/link/Tests/LinkFieldTest.php   |  103 ++++++++++++--------
 1 file changed, 61 insertions(+), 42 deletions(-)

diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php
index a608873..bd0fa08 100644
--- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php
+++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php
@@ -59,7 +59,7 @@ function testURLValidation() {
       'widget' => array(
         'type' => 'link_default',
         'settings' => array(
-          'placeholder_url' => 'http://example.com',
+          'placeholder_url' => 'http://example1.com',
         ),
       ),
     );
@@ -75,10 +75,10 @@ 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->assertRaw('placeholder="http://example.com"');
+    $this->assertRaw('placeholder="http://example1.com"');
 
     // Verify that a valid URL can be submitted.
-    $value = 'http://www.example.com/';
+    $value = 'http://www.example1.com/';
     $edit = array(
       "{$this->field['field_name']}[$langcode][0][url]" => $value,
     );
@@ -108,7 +108,7 @@ function testURLValidation() {
   }
 
   /**
-   * Tests the title settings of a link field.
+   * Tests the anchor text settings of a link field.
    */
   function testLinkTitle() {
     // Create a field with settings to validate.
@@ -122,13 +122,15 @@ function testLinkTitle() {
       'entity_type' => 'test_entity',
       'bundle' => 'test_bundle',
       'settings' => array(
-        'title' => DRUPAL_OPTIONAL,
+        'anchor_text' => DRUPAL_OPTIONAL,
+#        'title' => DRUPAL_OPTIONAL,
       ),
       'widget' => array(
         'type' => 'link_default',
         'settings' => array(
-          'placeholder_url' => 'http://example.com',
-          'placeholder_title' => 'Enter a title for this link',
+          'placeholder_url' => 'http://example2.com',
+          'placeholder_anchor_text' => 'Enter anchor text for this link',
+#          'placeholder_title' => 'Enter title attribute for this link',
         ),
       ),
     );
@@ -142,57 +144,63 @@ function testLinkTitle() {
 
     $langcode = LANGUAGE_NOT_SPECIFIED;
 
-    // Verify that the title field works according to the field setting.
-    foreach (array(DRUPAL_DISABLED, DRUPAL_REQUIRED, DRUPAL_OPTIONAL) as $title_setting) {
-      // Update the title field setting.
-      $this->instance['settings']['title'] = $title_setting;
+    // Verify that the anchor text field works according to the field setting.
+    foreach (array(DRUPAL_DISABLED, DRUPAL_REQUIRED, DRUPAL_OPTIONAL) as $anchor_text_setting) {
+      // Update the anchor text field setting.
+      $this->instance['settings']['anchor_text'] = $anchor_text_setting;
       field_update_instance($this->instance);
 
       // Display creation form.
       $this->drupalGet('test-entity/add/test_bundle');
       $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][url]", '', 'URL field found.');
-      $this->assertRaw('placeholder="http://example.com"');
+      $this->assertRaw('placeholder="http://example2.com"');
 
-      if ($title_setting === DRUPAL_DISABLED) {
-        $this->assertNoFieldByName("{$this->field['field_name']}[$langcode][0][title]", '', 'Title field not found.');
-        $this->assertNoRaw('placeholder="Enter a title for this link"');
+      if ($anchor_text_setting === DRUPAL_DISABLED) {
+        $this->assertNoFieldByName("{$this->field['field_name']}[$langcode][0][anchor_text]", '', 'Anchor text field not found.');
+#        $this->assertNoRaw('placeholder="Enter a title for this link"');
+        $this->assertRaw('placeholder="Enter anchor text for this link"');
+#        $this->assertNoRaw('placeholder="Enter anchor text attribute for this link"');
       }
       else {
-        $this->assertRaw('placeholder="Enter a title for this link"');
-
-        $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][title]", '', 'Title field found.');
-        if ($title_setting === DRUPAL_REQUIRED) {
+#        $this->assertRaw('placeholder="Enter a title for this link"');
+        $this->assertRaw('placeholder="Enter anchor text for this link"');
+#        $this->assertRaw('placeholder="Enter title attribute for this link"');
+        $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][anchor_text]", '', 'Anchor text field found.');
+        if ($anchor_text_setting === DRUPAL_REQUIRED) {
           // Verify that the title is required, if the URL is non-empty.
           $edit = array(
-            "{$this->field['field_name']}[$langcode][0][url]" => 'http://www.example.com',
+            "{$this->field['field_name']}[$langcode][0][url]" => 'http://www.example3.com',
           );
           $this->drupalPost(NULL, $edit, t('Save'));
-          $this->assertText(t('!name field is required.', array('!name' => t('Title'))));
+          $this->assertText(t('!name field is required.', array('!name' => t('Anchor text'))));
 
-          // Verify that the title is not required, if the URL is empty.
+          // Verify that the anchor text is not required, if the URL is empty.
           $edit = array(
             "{$this->field['field_name']}[$langcode][0][url]" => '',
           );
           $this->drupalPost(NULL, $edit, t('Save'));
-          $this->assertNoText(t('!name field is required.', array('!name' => t('Title'))));
+          $this->assertNoText(t('!name field is required.', array('!name' => t('Anchor text'))));
 
-          // Verify that a URL and title meets requirements.
+          // Verify that a URL and anchor 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['field_name']}[$langcode][0][url]" => 'http://www.example3.com',
+            "{$this->field['field_name']}[$langcode][0][anchor_text]" => 'Example',
           );
           $this->drupalPost(NULL, $edit, t('Save'));
-          $this->assertNoText(t('!name field is required.', array('!name' => t('Title'))));
+          $this->assertNoText(t('!name field is required.', array('!name' => t('Anchor text'))));
         }
       }
     }
 
-    // Verify that a link without title is rendered using the URL as link text.
-    $value = 'http://www.example.com/';
+    // Verify that a link without anchor text is rendered using the URL as link text.
+    $value = 'http://www.example3.com/';
+    $link_attributes['#options']['attributes']['title'] = 'Example title';
+
     $edit = array(
       "{$this->field['field_name']}[$langcode][0][url]" => $value,
-      "{$this->field['field_name']}[$langcode][0][title]" => '',
+      "{$this->field['field_name']}[$langcode][0][anchor_text]" => $value,
+#      "{$this->field['field_name']}[$langcode][0][title]" => $link_attributes,
     );
     $this->drupalPost(NULL, $edit, t('Save'));
     preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match);
@@ -200,19 +208,27 @@ function testLinkTitle() {
     $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)));
 
     $this->renderTestEntity($id);
-    $expected_link = l($value, $value);
+    $expected_link = l($value, $value, $link_attributes);
     $this->assertRaw($expected_link);
 
-    // Verify that a link with title is rendered using the title as link text.
+    // Verify that a link with anchor text is rendered using the title as link text.
+    $anchor_text = $this->randomName();
     $title = $this->randomName();
+
     $edit = array(
-      "{$this->field['field_name']}[$langcode][0][title]" => $title,
+      "{$this->field['field_name']}[$langcode][0][anchor_text]" => $anchor_text,
+#      "{$this->field['field_name']}[$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)));
 
+    $link_attributes['#options']['attributes']['title'] = $title;
+// print_r($link_attributes);
+// Array ( [options] => Array ( [title] => aA3scJST
+// $element[$delta]['#options']['attributes']['title'] = $item['title'];
+
     $this->renderTestEntity($id);
-    $expected_link = l($title, $value);
+    $expected_link = l($anchor_text, $value, $link_attributes);
     $this->assertRaw($expected_link);
   }
 
@@ -263,9 +279,9 @@ function testLinkFormatter() {
     $edit = array(
       "{$this->field['field_name']}[$langcode][0][url]" => $url1,
       // Note that $title1 is not submitted.
-      "{$this->field['field_name']}[$langcode][0][title]" => '',
+      "{$this->field['field_name']}[$langcode][0][anchor_text]" => '',
       "{$this->field['field_name']}[$langcode][1][url]" => $url2,
-      "{$this->field['field_name']}[$langcode][1][title]" => $title2,
+      "{$this->field['field_name']}[$langcode][1][anchor_text]" => $title2,
     );
     $this->drupalPost(NULL, $edit, t('Save'));
     preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match);
@@ -305,12 +321,12 @@ function testLinkFormatter() {
         switch ($setting) {
           case 'trim_length':
             $url = $url1;
-            $title = isset($new_value) ? truncate_utf8($title1, $new_value, FALSE, TRUE) : $title1;
-            $this->assertRaw('<a href="' . check_plain($url) . '">' . check_plain($title) . '</a>');
+            $anchor_text = isset($new_value) ? truncate_utf8($title1, $new_value, FALSE, TRUE) : $title1;
+            $this->assertRaw('<a href="' . check_plain($url) . '">' . check_plain($anchor_text) . '</a>');
 
             $url = $url2;
-            $title = isset($new_value) ? truncate_utf8($title2, $new_value, FALSE, TRUE) : $title2;
-            $this->assertRaw('<a href="' . check_plain($url) . '">' . check_plain($title) . '</a>');
+            $anchor_text = isset($new_value) ? truncate_utf8($title2, $new_value, FALSE, TRUE) : $title2;
+            $this->assertRaw('<a href="' . check_plain($url) . '">' . check_plain($anchor_text) . '</a>');
             break;
 
           case 'rel':
@@ -368,6 +384,7 @@ function testLinkSeparateFormatter() {
       'entity_type' => 'test_entity',
       'bundle' => 'test_bundle',
       'settings' => array(
+        'anchor_text' => DRUPAL_OPTIONAL,
         'title' => DRUPAL_OPTIONAL,
       ),
       'widget' => array(
@@ -398,6 +415,8 @@ function testLinkSeparateFormatter() {
     $edit = array(
       "{$this->field['field_name']}[$langcode][0][url]" => $url1,
       "{$this->field['field_name']}[$langcode][1][url]" => $url2,
+      "{$this->field['field_name']}[$langcode][0][anchor_text]" => $url1,
+      "{$this->field['field_name']}[$langcode][1][anchor_text]" => $title2,
       "{$this->field['field_name']}[$langcode][1][title]" => $title2,
     );
     $this->drupalPost(NULL, $edit, t('Save'));
@@ -431,9 +450,9 @@ function testLinkSeparateFormatter() {
 
             $url = $url2;
             $url_title = isset($new_value) ? truncate_utf8($url, $new_value, FALSE, TRUE) : $url;
-            $title = isset($new_value) ? truncate_utf8($title2, $new_value, FALSE, TRUE) : $title2;
+            $anchor_text = isset($new_value) ? truncate_utf8($title2, $new_value, FALSE, TRUE) : $title2;
             $expected = '<div class="link-item">';
-            $expected .= '<div class="link-title">' . check_plain($title) . '</div>';
+            $expected .= '<div class="link-title">' . check_plain($anchor_text) . '</div>';
             $expected .= '<div class="link-url"><a href="' . check_plain($url) . '">' . check_plain($url_title) . '</a></div>';
             $expected .= '</div>';
             $this->assertRaw($expected);
-- 
1.7.10.4

