Commit bdaaa98b authored by Jakob P's avatar Jakob P
Browse files

Issue #3286075 by Lal_, nkoporec: Automated Drupal 10 compatibility fixes.

parent 562b997f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
name: Anonymous Login
type: module
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9.2 || ^10
description: Specify pages that when visited by anonymous users will be forced to login.
dependencies:
  - drupal:path_alias

composer.json

0 → 100644
+11 −0
Original line number Diff line number Diff line
{
    "name": "drupal/anonymous_login",
    "type": "drupal-module",
    "description": "Specify pages that when visited by anonymous users will be forced to login.",
    "license": "GPL-2.0-or-later",
    "extra": {
        "branch-alias": {
            "dev-8.x-2.x": "2.x-dev"
        }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\anonymous_login\EventSubscriber;

use Symfony\Component\HttpKernel\Event\RequestEvent;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\Path\CurrentPathStack;
@@ -15,7 +16,6 @@ use Drupal\path_alias\AliasManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

/**
 * Class AnonymousLoginSubscriber.
@@ -146,10 +146,10 @@ class AnonymousLoginSubscriber implements EventSubscriberInterface {
   * This method is called whenever the KernelEvents::REQUEST event is
   * dispatched.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
   * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
   *   The Event to process.
   */
  public function redirect(GetResponseEvent $event) {
  public function redirect(RequestEvent $event) {
    // Skip if maintenance mode is enabled.
    if ($this->state->get('system.maintenance_mode')) {
      return;
+2 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ class AnonymousLoginSettingsFormTest extends BrowserTestBase {
  /**
   * {@inheritdoc}
   */
  public static $modules = [
  protected static $modules = [
    'anonymous_login',
    'node',
  ];
@@ -29,7 +29,7 @@ class AnonymousLoginSettingsFormTest extends BrowserTestBase {
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
  protected function setUp(): void {
    parent::setUp();
    $this->moduleConfig = $this->config('anonymous_login.settings');
  }
+12 −27
Original line number Diff line number Diff line
@@ -2,11 +2,11 @@

namespace Drupal\Tests\anonymous_login\Unit;

use Symfony\Component\HttpKernel\Event\RequestEvent;
use Drupal\anonymous_login\EventSubscriber\AnonymousLoginSubscriber;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

/**
 * Tests the redirect logic.
@@ -66,31 +66,25 @@ class AnonymousLoginSubscriberTest extends UnitTestCase {
   * @param string $request_uri
   *   The URI of the request.
   *
   * @return \Symfony\Component\HttpKernel\Event\GetResponseEvent
   * @return \Symfony\Component\HttpKernel\Event\RequestEvent
   *   THe response event.
   */
  protected function callOnKernelRequestCheckRedirect($request_uri) {
    $event = $this->getGetResponseEventStub($request_uri);
    $request = $event->getRequest();

    $state = $this->getMockBuilder('Drupal\Core\State\StateInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $state = $this->createMock('Drupal\Core\State\StateInterface');
    $state->expects($this->any())
      ->method('get')
      ->with('system.maintenance_mode')
      ->will($this->returnValue(FALSE));

    $current_user = $this->getMockBuilder('Drupal\Core\Session\AccountProxyInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $current_user = $this->createMock('Drupal\Core\Session\AccountProxyInterface');
    $current_user->expects($this->any())
      ->method('isAnonymous')
      ->will($this->returnValue(TRUE));

    $alias_manager = $this->getMockBuilder('Drupal\path_alias\AliasManagerInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $alias_manager = $this->createMock('Drupal\path_alias\AliasManagerInterface');
    $alias_manager->expects($this->any())
      ->method('getPathByAlias')
      ->with($this->anything())
@@ -139,9 +133,7 @@ class AnonymousLoginSubscriberTest extends UnitTestCase {
        'sites/default/files/*',
      ],
    ];
    $path_matcher = $this->getMockBuilder('Drupal\Core\Path\PathMatcherInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $path_matcher = $this->createMock('Drupal\Core\Path\PathMatcherInterface');
    $path_matcher->expects($this->any())
      ->method('matchPath')
      ->with($this->anything(), $this->anything())
@@ -161,21 +153,15 @@ class AnonymousLoginSubscriberTest extends UnitTestCase {

          return (bool) preg_match($search, $path);
      }));
    $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandlerInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $module_handler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
    $module_handler->expects($this->any())
      ->method('alter')
      ->will($this->returnValue($paths));
    $path_validator = $this->getMockBuilder('Drupal\Core\Path\PathValidatorInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $path_validator = $this->createMock('Drupal\Core\Path\PathValidatorInterface');
    $path_validator->expects($this->any())
      ->method('getUrlIfValidWithoutAccessCheck')
      ->will($this->returnValue(FALSE));
    $current_path = $this->getMockBuilder('Drupal\Core\Path\CurrentPathStack')
      ->disableOriginalConstructor()
      ->getMock();
    $current_path = $this->createMock('Drupal\Core\Path\CurrentPathStack');
    $current_path->expects($this->any())
      ->method('getPath')
      ->with($request)
@@ -214,15 +200,14 @@ class AnonymousLoginSubscriberTest extends UnitTestCase {
   * @param string $request_uri
   *   The URI of the request.
   *
   * @return \Symfony\Component\HttpKernel\Event\GetResponseEvent
   * @return \Symfony\Component\HttpKernel\Event\RequestEvent
   *   The get response event object.
   */
  protected function getGetResponseEventStub($request_uri) {
    $request = Request::create($request_uri, 'GET', [], [], [], ['SCRIPT_NAME' => 'index.php']);

    $http_kernel = $this->getMockBuilder('\Symfony\Component\HttpKernel\HttpKernelInterface')
      ->getMock();
    return new GetResponseEvent($http_kernel, $request, 'test');
    $http_kernel = $this->createMock('\Symfony\Component\HttpKernel\HttpKernelInterface');
    return new RequestEvent($http_kernel, $request, 'test');
  }

}