improve code
This commit is contained in:
parent
a3c75df635
commit
7a2648fe7b
@ -54,5 +54,8 @@
|
||||
"psr-4": {
|
||||
"D3\\Totp\\": "../../../source/modules/d3/totp"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"totp_phpstan": "./vendor/bin/phpstan -c./vendor/d3/oxtotp/phpstan.neon"
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,10 @@ parameters:
|
||||
paths:
|
||||
- src
|
||||
level: 5
|
||||
phpVersion: 70300
|
||||
phpVersion: 70300
|
||||
ignoreErrors:
|
||||
- '#Call to method getFieldData\(\) on an unknown class oxShop.#'
|
||||
- '#Return type \(array\) of method D3\\Totp\\Application\\Controller\\d3totplogin::getBreadCrumb\(\) should be compatible with return type \(null\) of method OxidEsales\\EshopCommunity\\Application\\Controller\\FrontendController::getBreadCrumb\(\)#'
|
||||
- '#Parameter \#\d+ \$value of method OxidEsales\\EshopCommunity\\Core\\Config::setConfigParam\(\) expects string, (true|false) given.#'
|
||||
parallel:
|
||||
processTimeout: 900.0
|
@ -56,6 +56,7 @@ class d3totpadminlogin extends AdminController
|
||||
*/
|
||||
protected function isTotpIsNotRequired(): bool
|
||||
{
|
||||
/** @var d3_totp_user $user */
|
||||
$user = $this->d3TotpGetUserObject();
|
||||
$userId = $user->d3TotpGetCurrentUser();
|
||||
|
||||
@ -131,15 +132,16 @@ class d3totpadminlogin extends AdminController
|
||||
*/
|
||||
public function d3CancelLogin(): string
|
||||
{
|
||||
/** @var d3_totp_user $oUser */
|
||||
$oUser = $this->d3TotpGetUserObject();
|
||||
$oUser->logout();
|
||||
return "login";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3_totp_user
|
||||
* @return User
|
||||
*/
|
||||
public function d3TotpGetUserObject(): d3_totp_user
|
||||
public function d3TotpGetUserObject(): User
|
||||
{
|
||||
return oxNew(User::class);
|
||||
}
|
||||
@ -156,7 +158,7 @@ class d3totpadminlogin extends AdminController
|
||||
$userId = $user->d3TotpGetCurrentUser();
|
||||
|
||||
try {
|
||||
$sTotp = implode('', Registry::getRequest()->getRequestEscapedParameter('d3totp', []));
|
||||
$sTotp = implode('', Registry::getRequest()->getRequestEscapedParameter('d3totp') ?: []);
|
||||
|
||||
$totp = $this->d3TotpGetTotpObject();
|
||||
$totp->loadByUserId($userId);
|
||||
@ -223,7 +225,7 @@ class d3totpadminlogin extends AdminController
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3_totp_LoginController
|
||||
* @return LoginController
|
||||
*/
|
||||
public function d3GetLoginController(): LoginController
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ class d3_account_totp extends AccountController
|
||||
$oTotp->save();
|
||||
$oTotpBackupCodes->save();
|
||||
} catch (Exception $oExcp) {
|
||||
Registry::get(UtilsView::class)->addErrorToDisplay($oExcp);
|
||||
Registry::get(UtilsView::class)->addErrorToDisplay($oExcp->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ class d3totplogin extends FrontendController
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBreadCrumb(): array
|
||||
public function getBreadCrumb()
|
||||
{
|
||||
$aPaths = [];
|
||||
$aPath = [];
|
||||
|
@ -268,7 +268,7 @@ class d3totp extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $oxid
|
||||
* @param null|string $oxid
|
||||
* @return bool
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
|
@ -84,7 +84,7 @@ class d3_totp_UserComponent extends d3_totp_UserComponent_parent
|
||||
*/
|
||||
public function d3TotpCheckTotpLogin()
|
||||
{
|
||||
$sTotp = implode('', Registry::getRequest()->getRequestEscapedParameter('d3totp', []));
|
||||
$sTotp = implode('', Registry::getRequest()->getRequestEscapedParameter('d3totp') ?: []);
|
||||
|
||||
/** @var d3_totp_user $oUser */
|
||||
$oUser = oxNew(User::class);
|
||||
@ -99,7 +99,7 @@ class d3_totp_UserComponent extends d3_totp_UserComponent_parent
|
||||
// relogin, don't extract from this try block
|
||||
$this->d3TotpGetSession()->setVariable(d3totp_conf::SESSION_AUTH, $oUser->getId());
|
||||
$this->d3TotpGetSession()->setVariable(d3totp_conf::OXID_FRONTEND_AUTH, $oUser->getId());
|
||||
$this->setUser(null);
|
||||
$this->setUser(oxNew(User::class));
|
||||
$this->setLoginStatus(USER_LOGIN_SUCCESS);
|
||||
$this->_afterLogin($oUser);
|
||||
|
||||
|
@ -21,8 +21,10 @@ use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
||||
use OxidEsales\Eshop\Core\Language;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\UtilsServer;
|
||||
|
||||
class d3_totp_LoginController extends d3_totp_LoginController_parent
|
||||
{
|
||||
@ -31,7 +33,7 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
|
||||
/**
|
||||
* @return d3totp
|
||||
*/
|
||||
public function d3GetTotpObject()
|
||||
public function d3GetTotpObject(): d3totp
|
||||
{
|
||||
return oxNew(d3totp::class);
|
||||
}
|
||||
@ -39,7 +41,7 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
public function d3TotpGetSession()
|
||||
public function d3TotpGetSession(): Session
|
||||
{
|
||||
return Registry::getSession();
|
||||
}
|
||||
@ -111,25 +113,17 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3_totp_user
|
||||
* @return UtilsServer
|
||||
*/
|
||||
protected function d3TotpGetUserObject(): d3_totp_user
|
||||
{
|
||||
return oxNew( User::class );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object|\OxidEsales\Eshop\Core\UtilsServer
|
||||
*/
|
||||
protected function d3TotpGetUtilsServer()
|
||||
protected function d3TotpGetUtilsServer(): UtilsServer
|
||||
{
|
||||
return Registry::getUtilsServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object|\OxidEsales\Eshop\Core\Language
|
||||
* @return Language
|
||||
*/
|
||||
protected function d3TotpGetLangObject()
|
||||
protected function d3TotpGetLangObject(): Language
|
||||
{
|
||||
return Registry::getLang();
|
||||
}
|
||||
|
@ -91,10 +91,10 @@ class totpSystemEventHandler extends totpSystemEventHandler_parent
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3_totp_user
|
||||
* @return User
|
||||
*/
|
||||
protected function d3TotpGetUserObject(): d3_totp_user
|
||||
protected function d3TotpGetUserObject(): User
|
||||
{
|
||||
return oxNew( User::class );
|
||||
return oxNew(User::class);
|
||||
}
|
||||
}
|
@ -84,7 +84,7 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canRenderSelectedUser()
|
||||
{
|
||||
/** @var User|MockObject $oControllerMock */
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'getId',
|
||||
@ -123,7 +123,7 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canRenderUnloadableUser()
|
||||
{
|
||||
/** @var User|MockObject $oControllerMock */
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'getId',
|
||||
@ -219,13 +219,13 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function cantSaveBecauseOfNotVerifiable()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['save'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->never())->method('save')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oControllerMock */
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'load',
|
||||
@ -269,13 +269,13 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function cantSaveBecauseExistingRegistration()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['save'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->never())->method('save')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oControllerMock */
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
@ -319,7 +319,7 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canSave()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'save',
|
||||
@ -329,7 +329,7 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
$oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true);
|
||||
$oBackupCodeListMock->method('generateBackupCodes')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oControllerMock */
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'load',
|
||||
@ -378,7 +378,7 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
];
|
||||
$_GET['editval'] = $aEditval;
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'save',
|
||||
@ -388,7 +388,7 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
$oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true);
|
||||
$oBackupCodeListMock->method('generateBackupCodes')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oControllerMock */
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'load',
|
||||
@ -514,7 +514,7 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canGetAvailableBackupCodeCount()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
|
@ -148,7 +148,7 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canGetAvailableBackupCodeCount()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
|
@ -57,7 +57,7 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function generateBackupCodes()
|
||||
{
|
||||
/** @var FrontendController|MockObject $oConfigMock */
|
||||
/** @var FrontendController|MockObject $oViewMock */
|
||||
$oViewMock = $this->getMockBuilder(FrontendController::class)
|
||||
->addMethods(['setBackupCodes'])
|
||||
->getMock();
|
||||
|
@ -36,28 +36,6 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3_totp_UserComponent */
|
||||
protected $_oController;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(UserComponent::class);
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, false);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oController);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
@ -99,11 +77,9 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3TotpGetUtils')->willReturn($oUtilsMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->expectException( InvalidArgumentException::class);
|
||||
|
||||
$this->callMethod($this->_oController, '_afterLogin', [$oUser]);
|
||||
$this->callMethod($oControllerMock, '_afterLogin', [$oUser]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,9 +136,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3TotpGetUtils')->willReturn($oUtilsMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, '_afterLogin', [$oUserMock]);
|
||||
$this->callMethod($oControllerMock, '_afterLogin', [$oUserMock]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -238,9 +212,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3TotpGetUtils')->willReturn($oUtilsMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, '_afterLogin', [$oUserMock]);
|
||||
$this->callMethod($oControllerMock, '_afterLogin', [$oUserMock]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -250,9 +222,12 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3GetTotpObjectReturnsRightInstance()
|
||||
{
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod($this->_oController, 'd3GetTotpObject')
|
||||
$this->callMethod($oController, 'd3GetTotpObject')
|
||||
);
|
||||
}
|
||||
|
||||
@ -290,11 +265,9 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
'd3totplogin',
|
||||
$this->callMethod($this->_oController, 'd3TotpCheckTotpLogin')
|
||||
$this->callMethod($oControllerMock, 'd3TotpCheckTotpLogin')
|
||||
);
|
||||
}
|
||||
|
||||
@ -318,7 +291,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->never())->method('setVariable');
|
||||
|
||||
/** @var d3totp_wrongOtpException|MockObject $oUtilsViewMock */
|
||||
/** @var d3totp_wrongOtpException|MockObject $oTotpExceptionMock */
|
||||
$oTotpExceptionMock = $this->getMockBuilder(d3totp_wrongOtpException::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@ -345,11 +318,9 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
'd3totplogin',
|
||||
$this->callMethod($this->_oController, 'd3TotpCheckTotpLogin')
|
||||
$this->callMethod($oControllerMock, 'd3TotpCheckTotpLogin')
|
||||
);
|
||||
}
|
||||
|
||||
@ -399,10 +370,8 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
$this->identicalTo(USER_LOGIN_SUCCESS)
|
||||
);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oController, 'd3TotpCheckTotpLogin')
|
||||
$this->callMethod($oControllerMock, 'd3TotpCheckTotpLogin')
|
||||
);
|
||||
}
|
||||
|
||||
@ -413,9 +382,12 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3GetUtilsViewReturnsRightInstance()
|
||||
{
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
UtilsView::class,
|
||||
$this->callMethod($this->_oController, 'd3TotpGetUtilsView')
|
||||
$this->callMethod($oController, 'd3TotpGetUtilsView')
|
||||
);
|
||||
}
|
||||
|
||||
@ -426,9 +398,12 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3GetUtilsReturnsRightInstance()
|
||||
{
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Utils::class,
|
||||
$this->callMethod($this->_oController, 'd3TotpGetUtils')
|
||||
$this->callMethod($oController, 'd3TotpGetUtils')
|
||||
);
|
||||
}
|
||||
|
||||
@ -445,9 +420,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3TotpClearSessionVariables')->willReturn(false);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'd3TotpCancelTotpLogin');
|
||||
$this->callMethod($oControllerMock, 'd3TotpCancelTotpLogin');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -466,8 +439,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
|
||||
$this->callMethod($oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
@ -487,8 +463,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
|
||||
$this->callMethod($oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
@ -508,8 +487,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
|
||||
$this->callMethod($oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
@ -529,8 +511,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
$this->callMethod($oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
@ -550,8 +535,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
$this->callMethod($oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
@ -571,8 +559,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willThrowException(oxNew(d3totp_wrongOtpException::class));
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->expectException(d3totp_wrongOtpException::class);
|
||||
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', [null, $oTotpMock]);
|
||||
$this->callMethod($oController, 'd3TotpHasValidTotp', [null, $oTotpMock]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -591,8 +582,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
$this->callMethod($oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
@ -615,9 +609,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'd3TotpClearSessionVariables');
|
||||
$this->callMethod($oControllerMock, 'd3TotpClearSessionVariables');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -627,9 +619,12 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3GetSessionReturnsRightInstance()
|
||||
{
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod($this->_oController, 'd3TotpGetSession')
|
||||
$this->callMethod($oController, 'd3TotpGetSession')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -24,25 +24,5 @@ class d3_totp_OrderControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use d3_totp_getUserTestTrait;
|
||||
|
||||
/** @var d3_totp_OrderController|MockObject */
|
||||
protected $_oController;
|
||||
|
||||
protected $sControllerClass = d3_totp_OrderController::class;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(OrderController::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oController);
|
||||
}
|
||||
protected $sControllerClass = OrderController::class;
|
||||
}
|
||||
|
@ -23,25 +23,5 @@ class d3_totp_PaymentControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use d3_totp_getUserTestTrait;
|
||||
|
||||
/** @var d3_totp_PaymentController */
|
||||
protected $_oController;
|
||||
|
||||
protected $sControllerClass = d3_totp_PaymentController::class;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(PaymentController::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oController);
|
||||
}
|
||||
protected $sControllerClass = PaymentController::class;
|
||||
}
|
||||
|
@ -23,25 +23,5 @@ class d3_totp_UserControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use d3_totp_getUserTestTrait;
|
||||
|
||||
/** @var d3_totp_UserController */
|
||||
protected $_oController;
|
||||
|
||||
protected $sControllerClass = d3_totp_UserController::class;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(UserController::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oController);
|
||||
}
|
||||
protected $sControllerClass = UserController::class;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ namespace D3\Totp\tests\unit\Modules\Application\Controller;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController;
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_PaymentController;
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_UserController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
@ -36,16 +38,14 @@ trait d3_totp_getUserTestTrait
|
||||
*/
|
||||
public function getUserHasNoUser()
|
||||
{
|
||||
/** @var d3_totp_orderController|MockObject $oControllerMock */
|
||||
/** @var d3_totp_orderController|d3_totp_UserController|d3_totp_PaymentController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods(['d3GetTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->never())->method('d3GetTotpObject');
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oController, 'getUser')
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ trait d3_totp_getUserTestTrait
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_orderController|MockObject $oControllerMock */
|
||||
/** @var d3_totp_orderController|d3_totp_UserController|d3_totp_PaymentController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
@ -93,11 +93,9 @@ trait d3_totp_getUserTestTrait
|
||||
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3CallMockableParent')->willReturn($oUserMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
$oUserMock,
|
||||
$this->callMethod($this->_oController, 'getUser')
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
}
|
||||
|
||||
@ -132,7 +130,7 @@ trait d3_totp_getUserTestTrait
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_orderController|MockObject $oControllerMock */
|
||||
/** @var d3_totp_orderController|d3_totp_UserController|d3_totp_PaymentController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
@ -144,11 +142,9 @@ trait d3_totp_getUserTestTrait
|
||||
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3CallMockableParent')->willReturn($oUserMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
$oUserMock,
|
||||
$this->callMethod($this->_oController, 'getUser')
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
}
|
||||
|
||||
@ -184,7 +180,7 @@ trait d3_totp_getUserTestTrait
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_orderController|MockObject $oControllerMock */
|
||||
/** @var d3_totp_orderController|d3_totp_UserController|d3_totp_PaymentController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
@ -196,10 +192,8 @@ trait d3_totp_getUserTestTrait
|
||||
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3CallMockableParent')->willReturn($oUserMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oController, 'getUser')
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
}
|
||||
|
||||
@ -212,9 +206,12 @@ trait d3_totp_getUserTestTrait
|
||||
*/
|
||||
public function d3GetTotpObjectReturnsRightObject()
|
||||
{
|
||||
/** @var d3_totp_UserController|d3_totp_PaymentController|d3_totp_OrderController $oController */
|
||||
$oController = oxNew($this->sControllerClass);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod($this->_oController, 'd3GetTotpObject')
|
||||
$this->callMethod($oController, 'd3GetTotpObject')
|
||||
);
|
||||
}
|
||||
|
||||
@ -227,24 +224,15 @@ trait d3_totp_getUserTestTrait
|
||||
*/
|
||||
public function d3GetSessionObjectReturnsRightObject()
|
||||
{
|
||||
/** @var d3_totp_UserController|d3_totp_PaymentController|d3_totp_OrderController $oController */
|
||||
$oController = oxNew($this->sControllerClass);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
$oController,
|
||||
'd3TotpGetSessionObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @te__st
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_OrderController::d3CallMockableParent
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_PaymentController::d3CallMockableParent
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_UserController::d3CallMockableParent
|
||||
*/
|
||||
public function d3callMockableParentTest()
|
||||
{
|
||||
$this->callMockableParentTest($this->_oController);
|
||||
}
|
||||
}
|
||||
|
@ -29,26 +29,6 @@ class d3_totp_userTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3_totp_user */
|
||||
protected $_oModel;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(User::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
@ -68,11 +48,11 @@ class d3_totp_userTest extends d3TotpUnitTestCase
|
||||
->getMock();
|
||||
$oModelMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
$sut = $oModelMock;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
$sut,
|
||||
'logout'
|
||||
)
|
||||
);
|
||||
@ -85,9 +65,14 @@ class d3_totp_userTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3getTotpReturnsRightInstance()
|
||||
{
|
||||
$sut = oxNew(User::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod($this->_oModel, 'd3getTotp')
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3getTotp'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -98,9 +83,14 @@ class d3_totp_userTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3GetSessionReturnsRightInstance()
|
||||
{
|
||||
$sut = oxNew(User::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod($this->_oModel, 'd3TotpGetSession')
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3TotpGetSession'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -138,12 +128,12 @@ class d3_totp_userTest extends d3TotpUnitTestCase
|
||||
$oModelMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oModelMock->method('isAdmin')->willReturn($isAdmin);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
$sut = $oModelMock;
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
$sut,
|
||||
'd3TotpGetCurrentUser'
|
||||
)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user