From 6c2a4bc2a1973c0c70cb09009dc2954b81d6ba57 Mon Sep 17 00:00:00 2001 From: Rik Willems <> Date: Mon, 9 Oct 2023 21:44:15 +0200 Subject: [PATCH 1/4] Add module enabled check to plugin --- Plugin/AfterLoginPlugin.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Plugin/AfterLoginPlugin.php b/Plugin/AfterLoginPlugin.php index 61303a4..3eb9af1 100644 --- a/Plugin/AfterLoginPlugin.php +++ b/Plugin/AfterLoginPlugin.php @@ -11,6 +11,7 @@ namespace BitExpert\ForceCustomerLogin\Plugin; +use BitExpert\ForceCustomerLogin\Controller\ModuleCheck; use BitExpert\ForceCustomerLogin\Model\Session; use Magento\Customer\Controller\Account\LoginPost; use Magento\Framework\App\Config\ScopeConfigInterface; @@ -37,14 +38,18 @@ class AfterLoginPlugin * @var Session */ private $session; - /** - * @var string - */ - private $defaultTargetUrl; /** * @var ScopeConfigInterface */ private $scopeConfig; + /** + * @var ModuleCheck + */ + private $moduleCheck; + /** + * @var string + */ + private $defaultTargetUrl; /** * AfterLoginPlugin constructor. @@ -56,10 +61,12 @@ class AfterLoginPlugin public function __construct( Session $session, ScopeConfigInterface $scopeConfig, + ModuleCheck $moduleCheck, $defaultTargetUrl ) { $this->session = $session; $this->scopeConfig = $scopeConfig; + $this->moduleCheck = $moduleCheck; $this->defaultTargetUrl = $defaultTargetUrl; } @@ -72,6 +79,10 @@ public function __construct( */ public function afterExecute(LoginPost $customerAccountLoginController, ResultInterface $resultRedirect) { + if ($this->moduleCheck->isModuleEnabled() === false) { + return $resultRedirect; + } + if (self::REDIRECT_DASHBOARD_ENABLED === $this->scopeConfig->getValue(self::REDIRECT_DASHBOARD_CONFIG)) { return $resultRedirect; From 97e34005426a5bad9d41a2e8f6945bc70b4365d8 Mon Sep 17 00:00:00 2001 From: Rik Willems <> Date: Tue, 10 Oct 2023 09:19:56 +0200 Subject: [PATCH 2/4] Fix tests & add test --- Test/Unit/Plugin/AfterLoginPluginUnitTest.php | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/Test/Unit/Plugin/AfterLoginPluginUnitTest.php b/Test/Unit/Plugin/AfterLoginPluginUnitTest.php index 65d5ffc..76d8347 100644 --- a/Test/Unit/Plugin/AfterLoginPluginUnitTest.php +++ b/Test/Unit/Plugin/AfterLoginPluginUnitTest.php @@ -11,6 +11,7 @@ namespace BitExpert\ForceCustomerLogin\Test\Unit\Plugin; +use BitExpert\ForceCustomerLogin\Controller\ModuleCheck; use BitExpert\ForceCustomerLogin\Model\Session; use BitExpert\ForceCustomerLogin\Plugin\AfterLoginPlugin; use Magento\Customer\Controller\Account\LoginPost; @@ -41,9 +42,15 @@ public function runAfterExecuteWithRedirectDashboardOptionEnabled() ->with(AfterLoginPlugin::REDIRECT_DASHBOARD_CONFIG) ->willReturn(AfterLoginPlugin::REDIRECT_DASHBOARD_ENABLED); + $moduleCheck = $this->getModuleCheck(); + $moduleCheck->expects($this->once()) + ->method('isModuleEnabled') + ->willReturn(true); + $plugin = new AfterLoginPlugin( $session, $scopeConfig, + $moduleCheck, 'default-target-url' ); @@ -70,9 +77,15 @@ public function runAfterExecuteWithSpecificTargetUrl() ->with(AfterLoginPlugin::REDIRECT_DASHBOARD_CONFIG) ->willReturn(AfterLoginPlugin::REDIRECT_DASHBOARD_DISABLED); + $moduleCheck = $this->getModuleCheck(); + $moduleCheck->expects($this->once()) + ->method('isModuleEnabled') + ->willReturn(true); + $plugin = new AfterLoginPlugin( $session, $scopeConfig, + $moduleCheck, 'default-target-url' ); @@ -101,9 +114,15 @@ public function runAfterExecuteWithDefaultTargetUrl() ->with(AfterLoginPlugin::REDIRECT_DASHBOARD_CONFIG) ->willReturn(AfterLoginPlugin::REDIRECT_DASHBOARD_DISABLED); + $moduleCheck = $this->getModuleCheck(); + $moduleCheck->expects($this->once()) + ->method('isModuleEnabled') + ->willReturn(true); + $plugin = new AfterLoginPlugin( $session, $scopeConfig, + $moduleCheck, 'default-target-url' ); @@ -116,6 +135,39 @@ public function runAfterExecuteWithDefaultTargetUrl() $this->assertEquals($redirect, $plugin->afterExecute($loginPost, $redirect)); } + /** + * @test + */ + public function runAfterExecuteWithModuleDisabled() + { + $session = $this->getSession(); + $session->expects($this->never()) + ->method('getAfterLoginReferer'); + + $scopeConfig = $this->getScopeConfig(); + $scopeConfig->expects($this->never()) + ->method('getValue'); + + $moduleCheck = $this->getModuleCheck(); + $moduleCheck->expects($this->once()) + ->method('isModuleEnabled') + ->willReturn(false); + + $plugin = new AfterLoginPlugin( + $session, + $scopeConfig, + $moduleCheck, + 'default-target-url' + ); + + $loginPost = $this->getLoginPost(); + $redirect = $this->getRedirect(); + $redirect->expects($this->never()) + ->method('setUrl'); + + $this->assertEquals($redirect, $plugin->afterExecute($loginPost, $redirect)); + } + /** * @return MockObject|Session */ @@ -139,6 +191,16 @@ private function getScopeConfig() ->getMock(); } + /** + * @return MockObject|ModuleCheck + */ + private function getModuleCheck() + { + return $this->getMockBuilder(ModuleCheck::class) + ->disableOriginalConstructor() + ->getMock(); + } + /** * @return MockObject|LoginPost */ From 91cbf29d3c57cfa0d9175ed59813c1edc637ca39 Mon Sep 17 00:00:00 2001 From: Rik Willems <> Date: Mon, 16 Oct 2023 16:42:02 +0200 Subject: [PATCH 3/4] Update `phpstan/phpstan` & `bitexpert/phpstan-magento` versions --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b1d4424..c2b1824 100644 --- a/composer.json +++ b/composer.json @@ -30,8 +30,8 @@ "captainhook/captainhook": "^5.10.8", "captainhook/plugin-composer": "^5.3.3", "phpstan/extension-installer": "^1.1.0", - "phpstan/phpstan": "^1.7.2", - "bitexpert/phpstan-magento": "^0.23.0", + "phpstan/phpstan": "^1.10.0", + "bitexpert/phpstan-magento": "^0.30.0", "magento/magento-coding-standard": "^15" }, "autoload": { From 48da86b6524796a8b497e06d8f0f2e8214573c73 Mon Sep 17 00:00:00 2001 From: Rik Willems <> Date: Mon, 16 Oct 2023 16:42:29 +0200 Subject: [PATCH 4/4] Remove ignored error --- phpstan.neon | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 5d5ecb2..4ba490c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -18,7 +18,7 @@ parameters: - Validator - view magento: - checkServiceContracts: false + checkServiceContracts: false ignoreErrors: - message: '~Parameter #1 \$modelId of method Magento\\Framework\\Model\\AbstractModel::load\(\) expects int, string given~' @@ -29,6 +29,3 @@ parameters: - message: '~Call to an undefined method Magento\\Framework\\App\\RequestInterface::isPost\(\)~' path: Controller/LoginCheck.php - - - message: '~Parameter #3 \$data of method~' - path: Block/Adminhtml/Manage/Create.php