diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterConfigTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterConfigTest.php
new file mode 100644
index 0000000..4727a7f
--- /dev/null
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterConfigTest.php
@@ -0,0 +1,62 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\filter\Tests\FilterConfigTest.
+ */
+
+namespace Drupal\filter\Tests;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests config functionality for formats.
+ */
+class FilterConfigTest extends WebTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('config', 'filter_test');
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Filter config',
+      'description' => 'Tests config functionality for formats',
+      'group' => 'Filter',
+    );
+  }
+
+  protected function setUp() {
+    parent::setUp();
+
+    $this->drupalLogin($this->drupalCreateUser(array('synchronize configuration')));
+  }
+
+  /**
+   * Tests importing a new format.
+   */
+  public function testImportConfig() {
+    $staging = $this->container->get('config.storage.staging');
+
+    // Rename an existing format, disable it, and assign it to a role.
+    $config_data = config('filter.format.filter_test')->get();
+    $config_data['format'] = 'test';
+    $config_data['status'] = 0;
+    $config_data['roles'][] = 'anonymous';
+    $staging->write('filter.format.test', $config_data);
+
+    // Add an entry to the manifest.
+    $manifest = config('manifest.filter.format')->get();
+    $manifest += array('test' => array('name' => 'filter.format.test'));
+    $staging->write('manifest.filter.format', $manifest);
+
+    // Import the new format.
+    $this->drupalGet('admin/config/development/sync');
+    $this->drupalPost(NULL, array(), t('Import all'));
+    $this->assertText(t('There is no configuration to import.'));
+  }
+
+}
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 4500c9b..60aa7ff 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -1964,15 +1964,17 @@ function user_role_grant_permissions($rid, array $permissions = array()) {
   $modules = user_permission_get_modules();
   // Grant new permissions for the role.
   foreach ($permissions as $name) {
-    db_merge('role_permission')
-      ->key(array(
-        'rid' => $rid,
-        'permission' => $name,
-      ))
-      ->fields(array(
-        'module' => $modules[$name],
-      ))
-      ->execute();
+    if (isset($modules[$name])) {
+      db_merge('role_permission')
+        ->key(array(
+          'rid' => $rid,
+          'permission' => $name,
+        ))
+        ->fields(array(
+          'module' => $modules[$name],
+        ))
+        ->execute();
+    }
   }
 
   // Clear the user access cache.
