Skip to content

Commit

Permalink
Fix tests & add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rik Willems committed Oct 10, 2023
1 parent 6c2a4bc commit 97e3400
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Test/Unit/Plugin/AfterLoginPluginUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'
);

Expand All @@ -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'
);

Expand Down Expand Up @@ -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'
);

Expand All @@ -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
*/
Expand All @@ -139,6 +191,16 @@ private function getScopeConfig()
->getMock();
}

/**
* @return MockObject|ModuleCheck
*/
private function getModuleCheck()
{
return $this->getMockBuilder(ModuleCheck::class)
->disableOriginalConstructor()
->getMock();
}

/**
* @return MockObject|LoginPost
*/
Expand Down

0 comments on commit 97e3400

Please sign in to comment.