From 5d29f324494007c0a190163b090ce312fdc5f744 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Sun, 4 May 2014 00:32:35 -0700
Subject: [PATCH] Issue #2256317 by sun: Remove static caching from
 WebTestBase::checkPermissions().

---
 .../lib/Drupal/block/Tests/BlockTestBase.php  |  1 -
 .../Tests/CommentTranslationUITest.php        |  2 --
 .../filter/Tests/FilterDefaultFormatTest.php  |  1 -
 .../filter/Tests/FilterFormatAccessTest.php   |  1 -
 .../Tests/FilterHtmlImageSecureTest.php       |  1 -
 .../lib/Drupal/rest/Tests/RESTTestBase.php    |  3 ---
 .../lib/Drupal/simpletest/WebTestBase.php     | 26 +++++--------------
 .../Tests/VocabularyPermissionsTest.php       |  3 ---
 .../lib/Drupal/text/Tests/TextFieldTest.php   |  1 -
 .../Drupal/user/Tests/UserSignatureTest.php   |  1 -
 .../lib/Drupal/views/Tests/ViewTestBase.php   |  1 -
 11 files changed, 7 insertions(+), 34 deletions(-)

diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTestBase.php b/core/modules/block/lib/Drupal/block/Tests/BlockTestBase.php
index 88073c36d19f..3ee504f1aa8e 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockTestBase.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockTestBase.php
@@ -47,7 +47,6 @@ function setUp() {
       'name' => 'Full HTML',
     ));
     $full_html_format->save();
-    $this->checkPermissions(array(), TRUE);
 
     // Create and log in an administrative user having access to the Full HTML
     // text format.
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php
index 5e5b4de70264..0fa07a3a5d1e 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php
@@ -61,8 +61,6 @@ function setupBundle() {
     content_translation_set_config('comment', 'node__comment_article', 'enabled', TRUE);
     // Refresh entity info.
     entity_info_cache_clear();
-    // Flush the permissions after adding the translatable comment bundle.
-    $this->checkPermissions(array(), TRUE);
   }
 
   /**
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php
index b9b6b7114565..bff71aa5ec0f 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php
@@ -83,6 +83,5 @@ function testDefaultTextFormats() {
    */
   protected function resetFilterCaches() {
     filter_formats_reset();
-    $this->checkPermissions(array(), TRUE);
   }
 }
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php
index 6550ffdbea6d..c0aeb26ef947 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php
@@ -330,6 +330,5 @@ function testFormatWidgetPermissions() {
    */
   protected function resetFilterCaches() {
     filter_formats_reset();
-    $this->checkPermissions(array(), TRUE);
   }
 }
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php
index bc6d8bb0ba09..c5b5e0d60766 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php
@@ -55,7 +55,6 @@ function setUp() {
     $filtered_html_format->save();
 
     // Setup users.
-    $this->checkPermissions(array(), TRUE);
     $this->web_user = $this->drupalCreateUser(array(
       'access content',
       'access comments',
diff --git a/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php b/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php
index fdf56d942cbc..1e19be2d5dc6 100644
--- a/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php
+++ b/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php
@@ -247,9 +247,6 @@ protected function enableService($resource_type, $method = 'GET', $format = NULL
   protected function rebuildCache() {
     // Rebuild routing cache, so that the REST API paths are available.
     $this->container->get('router.builder')->rebuild();
-    // Reset the Simpletest permission cache, so that the new resource
-    // permissions get picked up.
-    drupal_static_reset('checkPermissions');
   }
 
   /**
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 12c54e529e54..b91aeb627c73 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -335,10 +335,6 @@ protected function drupalCreateContentType(array $values = array()) {
 
     $this->assertEqual($status, SAVED_NEW, String::format('Created content type %type.', array('%type' => $type->id())));
 
-    // Reset permissions so that permissions for this content type are
-    // available.
-    $this->checkPermissions(array(), TRUE);
-
     return $type;
   }
 
@@ -663,23 +659,16 @@ protected function drupalCreateRole(array $permissions, $rid = NULL, $name = NUL
   }
 
   /**
-   * Check to make sure that the array of permissions are valid.
+   * Checks whether a given list of permission names is valid.
    *
-   * @param $permissions
-   *   Permissions to check.
-   * @param $reset
-   *   Reset cached available permissions.
+   * @param array $permissions
+   *   The permission names to check.
    *
-   * @return
-   *   TRUE or FALSE depending on whether the permissions are valid.
+   * @return bool
+   *   TRUE if the permissions are valid, FALSE otherwise.
    */
-  protected function checkPermissions(array $permissions, $reset = FALSE) {
-    $available = &drupal_static(__FUNCTION__);
-
-    if (!isset($available) || $reset) {
-      $available = array_keys(\Drupal::moduleHandler()->invokeAll('permission'));
-    }
-
+  protected function checkPermissions(array $permissions) {
+    $available = array_keys(\Drupal::moduleHandler()->invokeAll('permission'));
     $valid = TRUE;
     foreach ($permissions as $permission) {
       if (!in_array($permission, $available)) {
@@ -1132,7 +1121,6 @@ protected function resetAll() {
 
     // Reset static variables and reload permissions.
     $this->refreshVariables();
-    $this->checkPermissions(array(), TRUE);
   }
 
   /**
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php
index 7b898020f7f6..6ed3e093690f 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php
@@ -27,9 +27,6 @@ function testVocabularyPermissionsTaxonomyTerm() {
     // Vocabulary used for creating, removing and editing terms.
     $vocabulary = $this->createVocabulary();
 
-    // Reset to permission static cache to get proper permissions.
-    $this->checkPermissions(array(), TRUE);
-
     // Test as admin user.
     $user = $this->drupalCreateUser(array('administer taxonomy'));
     $this->drupalLogin($user);
diff --git a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php
index aecf2574f183..62a2ed4ca9b3 100644
--- a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php
+++ b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php
@@ -226,7 +226,6 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
     );
     $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
     filter_formats_reset();
-    $this->checkPermissions(array(), TRUE);
     $format = entity_load('filter_format', $edit['format']);
     $format_id = $format->format;
     $permission = $format->getPermissionName();
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php
index 74a17122d2e8..83f597367191 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php
@@ -64,7 +64,6 @@ function setUp() {
     $this->full_html_format->save();
 
     user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array($this->filtered_html_format->getPermissionName()));
-    $this->checkPermissions(array(), TRUE);
 
     // Create regular and administrative users.
     $this->web_user = $this->drupalCreateUser(array('post comments'));
diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php b/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php
index 4ed9064f9e16..9b677ee4b06c 100644
--- a/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php
+++ b/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php
@@ -64,7 +64,6 @@ protected function enableViewsTestModule() {
       $query->values($record);
     }
     $query->execute();
-    $this->checkPermissions(array(), TRUE);
   }
 
   /**
-- 
GitLab