From a7464d581b971342942019c4a8b1de3a7a3118b1 Mon Sep 17 00:00:00 2001
From: Christoph Burschka <christoph@burschka.de>
Date: Mon, 7 Dec 2015 10:31:10 +0100
Subject: [PATCH] Issue #2629292: Test format-specific settings.

Create a second text format, set it to override the global
settings, rename tags and check the tips for both tag names.
---
 src/Tests/XBBCodeAdminTest.php | 58 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/src/Tests/XBBCodeAdminTest.php b/src/Tests/XBBCodeAdminTest.php
index 1c5d299..8f8e9be 100644
--- a/src/Tests/XBBCodeAdminTest.php
+++ b/src/Tests/XBBCodeAdminTest.php
@@ -274,4 +274,62 @@ class XBBCodeAdminTest extends WebTestBase {
     $this->assertRaw('<abbr title="Test Plugin Description">[' . $new_name . ']</abbr>');
   }
 
+  /**
+   * Tests the format-specific settings.
+   */
+  public function testFormatSettings() {
+    // Set up a BBCode filter format.
+    $xbbcode_format = entity_create('filter_format', [
+      'format' => 'xbbcode_test',
+      'name' => 'XBBCode Test',
+      'filters' => [
+        'xbbcode' => [
+          'status' => 1,
+          'settings' => [
+            'tags' => [],
+            'override' => FALSE,
+            'linebreaks' => FALSE,
+          ],
+        ],
+      ],
+    ]);
+    $xbbcode_format->save();
+    $xbbcode_format->getPermissionName();
+    user_role_grant_permissions('authenticated', [$xbbcode_format->getPermissionName()]);
+    user_role_grant_permissions('anonymous', [$xbbcode_format->getPermissionName()]);
+
+    // Rename the tag globally.
+    $name1 = Unicode::strtolower($this->randomMachineName());
+    $edit = [
+      'tags[xbbcode_tag:test_tag_id][status]' => 1,
+      'tags[xbbcode_tag:test_tag_id][name]' => $name1,
+    ];
+    $this->drupalPostForm('admin/config/content/xbbcode/settings', $edit, t('Save configuration'));
+
+    // The validator must be called in this form too:
+    $name = $this->randomMachineName() . 'A';
+    $invalid_edit = [
+      'filters[xbbcode][settings][tags][xbbcode_tag:test_tag_id][name]' => $name,
+    ];
+    $this->drupalPostForm('admin/config/content/formats/manage/xbbcode_test', $invalid_edit, t('Save configuration'));
+    $this->assertRaw(format_string('The name [%name] must consist of lower-case letters, numbers and underscores.', [
+      '%name' => $name,
+    ]));
+
+    // Rename the tag in the second format.
+    $name2 = Unicode::strtolower($this->randomMachineName());
+    $edit = [
+      'filters[xbbcode][settings][override]' => TRUE,
+      'filters[xbbcode][settings][tags][xbbcode_tag:test_tag_id][status]' => TRUE,
+      'filters[xbbcode][settings][tags][xbbcode_tag:test_tag_id][name]' => $name,
+    ];
+    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
+
+    $this->drupalGet('filter/tips');
+
+    // Ensure that both names are shown in the filter tips.
+    $this->assertRaw("<strong>[$name1]</strong>");
+    $this->assertRaw("<strong>[$name2]</strong>");
+  }
+
 }
-- 
1.9.1

