Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / link / tests / src / Functional / LinkFieldTest.php
index f32bf3c45b8282671688f50b935711dbf9831ce6..4df94dd6cf4f47845a6cf0ac03f7333b22f4f1f2 100644 (file)
@@ -59,7 +59,7 @@ class LinkFieldTest extends BrowserTestBase {
    * Tests link field URL validation.
    */
   public function testURLValidation() {
-    $field_name = Unicode::strtolower($this->randomMachineName());
+    $field_name = mb_strtolower($this->randomMachineName());
     // Create a field with settings to validate.
     $this->fieldStorage = FieldStorageConfig::create([
       'field_name' => $field_name,
@@ -121,6 +121,10 @@ class LinkFieldTest extends BrowserTestBase {
       '/?example=llama' => '<front>?example=llama',
       '/#example' => '<front>#example',
 
+      // Trailing spaces should be ignored.
+      '/ ' => '<front>',
+      '/path with spaces ' => '/path with spaces',
+
       // @todo '<front>' is valid input for BC reasons, may be removed by
       //   https://www.drupal.org/node/2421941
       '<front>' => '&lt;front&gt;',
@@ -200,7 +204,7 @@ class LinkFieldTest extends BrowserTestBase {
       preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
       $id = $match[1];
       $this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
-      $this->assertRaw($string);
+      $this->assertRaw('"' . $string . '"');
     }
   }
 
@@ -226,7 +230,7 @@ class LinkFieldTest extends BrowserTestBase {
    * Tests the link title settings of a link field.
    */
   public function testLinkTitle() {
-    $field_name = Unicode::strtolower($this->randomMachineName());
+    $field_name = mb_strtolower($this->randomMachineName());
     // Create a field with settings to validate.
     $this->fieldStorage = FieldStorageConfig::create([
       'field_name' => $field_name,
@@ -281,6 +285,14 @@ class LinkFieldTest extends BrowserTestBase {
         $this->assertRaw('placeholder="Enter the text for this link"');
 
         $this->assertFieldByName("{$field_name}[0][title]", '', 'Link text field found.');
+        if ($title_setting === DRUPAL_OPTIONAL) {
+          // Verify that the URL is required, if the link text is non-empty.
+          $edit = [
+            "{$field_name}[0][title]" => 'Example',
+          ];
+          $this->drupalPostForm(NULL, $edit, t('Save'));
+          $this->assertText(t('The URL field is required when the @title field is specified.', ['@title' => t('Link text')]));
+        }
         if ($title_setting === DRUPAL_REQUIRED) {
           // Verify that the link text is required, if the URL is non-empty.
           $edit = [
@@ -340,7 +352,7 @@ class LinkFieldTest extends BrowserTestBase {
    * Tests the default 'link' formatter.
    */
   public function testLinkFormatter() {
-    $field_name = Unicode::strtolower($this->randomMachineName());
+    $field_name = mb_strtolower($this->randomMachineName());
     // Create a field with settings to validate.
     $this->fieldStorage = FieldStorageConfig::create([
       'field_name' => $field_name,
@@ -495,7 +507,7 @@ class LinkFieldTest extends BrowserTestBase {
    * merged, since they involve different configuration and output.
    */
   public function testLinkSeparateFormatter() {
-    $field_name = Unicode::strtolower($this->randomMachineName());
+    $field_name = mb_strtolower($this->randomMachineName());
     // Create a field with settings to validate.
     $this->fieldStorage = FieldStorageConfig::create([
       'field_name' => $field_name,
@@ -622,7 +634,7 @@ class LinkFieldTest extends BrowserTestBase {
   public function testLinkTypeOnLinkWidget() {
 
     $link_type = LinkItemInterface::LINK_EXTERNAL;
-    $field_name = Unicode::strtolower($this->randomMachineName());
+    $field_name = mb_strtolower($this->randomMachineName());
 
     // Create a field with settings to validate.
     $this->fieldStorage = FieldStorageConfig::create([
@@ -654,7 +666,6 @@ class LinkFieldTest extends BrowserTestBase {
     $this->assertEqual($form[$field_name]['widget'][0]['uri']['#link_type'], $link_type);
   }
 
-
   /**
    * Tests editing a link to a non-node entity.
    */