Commit f1bd4c55 authored by catch's avatar catch
Browse files

Issue #3196245 by prudloff, longwave, smustgrave, berdir, catch:...

Issue #3196245 by prudloff, longwave, smustgrave, berdir, catch: UserPermissionsForm should not use overridden permissions

(cherry picked from commit 02513abe)
parent 32732bcb
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ public function getFormId() {
   *   An array of role objects.
   */
  protected function getRoles() {
    return $this->roleStorage->loadMultiple();
    return $this->roleStorage->loadMultipleOverrideFree();
  }

  /**
+49 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\user_config_override_test;

use Drupal\Core\Config\StorableConfigBase;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;

/**
 * Tests overridden permissions.
 */
class ConfigOverrider implements ConfigFactoryOverrideInterface {

  /**
   * {@inheritdoc}
   */
  public function loadOverrides($names): array {
    return [
      'user.role.anonymous' => [
        'permissions' => [9999 => 'access content'],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheSuffix(): string {
    return 'user_config_override_test';
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata($name): CacheableMetadata {
    return new CacheableMetadata();
  }

  /**
   * {@inheritdoc}
   */
  public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION): StorableConfigBase|null {
    return NULL;
  }

}
+4 −0
Original line number Diff line number Diff line
name: 'Permission config overrider'
type: module
package: Testing
version: VERSION
+5 −0
Original line number Diff line number Diff line
services:
  user_config_override_test.overrider:
    class: Drupal\user_config_override_test\ConfigOverrider
    tags:
      - { name: config.factory.override }
+19 −0
Original line number Diff line number Diff line
@@ -37,6 +37,13 @@ class UserPermissionsTest extends BrowserTestBase {
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'user_config_override_test',
  ];

  /**
   * {@inheritdoc}
   */
@@ -331,4 +338,16 @@ public function testBundlePermissionError(): void {
    $assert_session->pageTextNotContains("Entity view display 'node.article.default': Component");
  }

  /**
   * Verify that the permission form does not use overridden config.
   *
   * @see \Drupal\user_config_override_test\ConfigOverrider
   */
  public function testOverriddenPermission(): void {
    $this->drupalLogin($this->adminUser);

    $this->drupalGet('admin/people/permissions');
    $this->assertSession()->checkboxNotChecked('anonymous[access content]');
  }

}