Loading anonymous_login.info.yml +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 Loading 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" } } } src/EventSubscriber/AnonymousLoginSubscriber.php +3 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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. Loading Loading @@ -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; Loading tests/src/Functional/AnonymousLoginSettingsFormTest.php +2 −2 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ class AnonymousLoginSettingsFormTest extends BrowserTestBase { /** * {@inheritdoc} */ public static $modules = [ protected static $modules = [ 'anonymous_login', 'node', ]; Loading @@ -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'); } Loading tests/src/Unit/AnonymousLoginSubscriberTest.php +12 −27 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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()) Loading Loading @@ -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()) Loading @@ -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) Loading Loading @@ -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'); } } Loading
anonymous_login.info.yml +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 Loading
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" } } }
src/EventSubscriber/AnonymousLoginSubscriber.php +3 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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. Loading Loading @@ -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; Loading
tests/src/Functional/AnonymousLoginSettingsFormTest.php +2 −2 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ class AnonymousLoginSettingsFormTest extends BrowserTestBase { /** * {@inheritdoc} */ public static $modules = [ protected static $modules = [ 'anonymous_login', 'node', ]; Loading @@ -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'); } Loading
tests/src/Unit/AnonymousLoginSubscriberTest.php +12 −27 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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()) Loading Loading @@ -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()) Loading @@ -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) Loading Loading @@ -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'); } }