change and add tests

This commit is contained in:
Daniel Seifert 2019-08-11 00:33:59 +02:00
parent 2ffb5a4d73
commit c77f6fa9e2
13 changed files with 323 additions and 59 deletions

View File

@ -166,6 +166,6 @@ class d3user_totp extends AdminDetailsController
public function getAvailableBackupCodeCount() public function getAvailableBackupCodeCount()
{ {
$oBackupCodeList = $this->getBackupcodeListObject(); $oBackupCodeList = $this->getBackupcodeListObject();
return $oBackupCodeList->getAvailableCodeCount($this->getUser()->getId()); return $oBackupCodeList->getAvailableCodeCount($this->getEditObjectId());
} }
} }

View File

@ -51,7 +51,6 @@ class d3totp extends BaseModel
/** /**
* @param $userId * @param $userId
* @return bool
* @throws DBALException * @throws DBALException
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
*/ */
@ -66,10 +65,8 @@ class d3totp extends BaseModel
->where("oxuserid = " . $oQB->createNamedParameter($userId)) ->where("oxuserid = " . $oQB->createNamedParameter($userId))
->setMaxResults(1); ->setMaxResults(1);
return $this->load(DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC)->getOne($oQB->getSQL(), $oQB->getParameters())); $this->load(DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC)->getOne($oQB->getSQL(), $oQB->getParameters()));
} }
return false;
} }
/** /**

View File

@ -1,6 +1,8 @@
[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}] [{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]
[{assign var="totp" value=$edit->d3GetTotp()}] [{assign var="totp" value=$edit->d3GetTotp()}]
[{assign var="userid" value=$edit->getId()}]
[{$totp->loadByUserId($userid)}]
[{if $readonly}] [{if $readonly}]
[{assign var="readonly" value="readonly disabled"}] [{assign var="readonly" value="readonly disabled"}]

View File

@ -3,6 +3,8 @@
<h1 class="page-header">[{oxmultilang ident="D3_TOTP_ACCOUNT"}]</h1> <h1 class="page-header">[{oxmultilang ident="D3_TOTP_ACCOUNT"}]</h1>
[{assign var="totp" value=$user->d3GetTotp()}] [{assign var="totp" value=$user->d3GetTotp()}]
[{assign var="userid" value=$user->getId()}]
[{$totp->loadByUserId($userid)}]
<style type="text/css"> <style type="text/css">
.registerNew { .registerNew {

View File

@ -39,10 +39,7 @@ class d3_totp_user extends d3_totp_user_parent
*/ */
public function d3getTotp() public function d3getTotp()
{ {
$oTotp = oxNew(d3totp::class); return oxNew(d3totp::class);
$oTotp->loadByUserId($this->getId());
return $oTotp;
} }
/** /**

View File

@ -15,7 +15,7 @@
* @link http://www.oxidmodule.com * @link http://www.oxidmodule.com
*/ */
namespace D3\Totp\tests\unit\Application\Controller; namespace D3\Totp\tests\unit\Application\Controller\Admin;
use D3\Totp\Application\Controller\Admin\d3user_totp; use D3\Totp\Application\Controller\Admin\d3user_totp;
use D3\Totp\Application\Model\d3backupcodelist; use D3\Totp\Application\Model\d3backupcodelist;
@ -104,6 +104,49 @@ class d3user_totpTest extends d3TotpUnitTestCase
$this->assertSame($oxid, 'foobar'); $this->assertSame($oxid, 'foobar');
} }
/**
* @test
* @throws ReflectionException
*/
public function canRenderUnloadableUser()
{
/** @var User|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oUserMock = $this->getMock(User::class, array(
'getId',
'load',
));
$oUserMock->expects($this->never())->method('getId');
$oUserMock->expects($this->atLeast(1))->method('load')->willReturn(false);
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array(
'getEditObjectId',
'getUserObject',
'addTplParam'
));
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
$oControllerMock->expects($this->once())->method('getUserObject')->willReturn($oUserMock);
$oControllerMock->expects($this->exactly(3))->method('addTplParam')->with(
$this->logicalOr(
$this->stringContains('sSaveError'),
$this->stringContains('oxid'),
$this->stringContains('edit')
)
);
$this->_oController = $oControllerMock;
$this->setValue($this->_oController, '_sSaveError', 'foo');
$sTpl = $this->callMethod($this->_oController, 'render');
$tplUser = $this->callMethod($this->_oController, 'getViewDataElement', array('edit'));
$oxid = $this->callMethod($this->_oController, 'getViewDataElement', array('oxid'));
$this->assertSame('d3user_totp.tpl', $sTpl);
$this->assertNull($tplUser);
$this->assertSame($oxid, 'foobar');
}
/** /**
* @test * @test
* @throws ReflectionException * @throws ReflectionException
@ -155,7 +198,7 @@ class d3user_totpTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'save', 'save',
)); ), array(), '', false);
$oTotpMock->expects($this->never())->method('save')->willReturn(true); $oTotpMock->expects($this->never())->method('save')->willReturn(true);
/** @var User|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var User|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
@ -202,7 +245,7 @@ class d3user_totpTest extends d3TotpUnitTestCase
'verify', 'verify',
'saveSecret', 'saveSecret',
'assign' 'assign'
)); ), array(), '', false);
$oTotpMock->method('load')->willReturn(true); $oTotpMock->method('load')->willReturn(true);
$oTotpMock->expects($this->never())->method('save')->willReturn(true); $oTotpMock->expects($this->never())->method('save')->willReturn(true);
$oTotpMock->expects($this->once())->method('verify')->willThrowException(new Exception()); $oTotpMock->expects($this->once())->method('verify')->willThrowException(new Exception());
@ -255,8 +298,8 @@ class d3user_totpTest extends d3TotpUnitTestCase
'verify', 'verify',
'saveSecret', 'saveSecret',
'assign' 'assign'
)); ), array(), '', false);
$oTotpMock->method('load')->willReturn(true); $oTotpMock->expects($this->never())->method('load')->willReturn(true);
$oTotpMock->expects($this->once())->method('save')->willReturn(true); $oTotpMock->expects($this->once())->method('save')->willReturn(true);
$oTotpMock->expects($this->once())->method('verify')->willReturn(true); $oTotpMock->expects($this->once())->method('verify')->willReturn(true);
$oTotpMock->method('saveSecret')->willReturn(true); $oTotpMock->method('saveSecret')->willReturn(true);
@ -287,6 +330,64 @@ class d3user_totpTest extends d3TotpUnitTestCase
$this->callMethod($this->_oController, 'save'); $this->callMethod($this->_oController, 'save');
} }
/**
* @test
* @throws ReflectionException
*/
public function canSaveWithKnownOXID()
{
$aEditval = [
'd3totp__oxid' => 'foo'
];
$_GET['editval'] = $aEditval;
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
'save',
'generateBackupCodes'
));
$oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true);
$oBackupCodeListMock->method('generateBackupCodes')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oTotpMock = $this->getMock(d3totp::class, array(
'load',
'save',
'verify',
'saveSecret',
'assign'
), array(), '', false);
$oTotpMock->expects($this->once())->method('load')->willReturn(true);
$oTotpMock->expects($this->once())->method('save')->willReturn(true);
$oTotpMock->expects($this->never())->method('verify')->willReturn(true);
$oTotpMock->method('saveSecret')->willReturn(true);
$oTotpMock->method('assign')->willReturn(true);
/** @var User|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oUserMock = $this->getMock(User::class, array(
'load',
'isSamePassword',
));
$oUserMock->expects($this->atLeast(1))->method('load')->willReturn(true);
$oUserMock->expects($this->atLeast(1))->method('isSamePassword')->willReturn(true);
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array(
'getEditObjectId',
'getUserObject',
'getTotpObject',
'getBackupcodeListObject'
));
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
$oControllerMock->expects($this->once())->method('getUserObject')->willReturn($oUserMock);
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
$this->_oController = $oControllerMock;
$this->callMethod($this->_oController, 'save');
}
/** /**
* @test * @test
* @throws ReflectionException * @throws ReflectionException
@ -317,7 +418,7 @@ class d3user_totpTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'delete' 'delete'
)); ), array(), '', false);
$oTotpMock->expects($this->never())->method('delete'); $oTotpMock->expects($this->never())->method('delete');
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
@ -344,9 +445,11 @@ class d3user_totpTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'delete' 'delete',
)); 'load'
), array(), '', false);
$oTotpMock->expects($this->once())->method('delete')->willReturn(true); $oTotpMock->expects($this->once())->method('delete')->willReturn(true);
$oTotpMock->method('load')->willReturn(true);
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMock(d3user_totp::class, array(

View File

@ -202,7 +202,7 @@ class d3_account_totpTest extends d3TotpUnitTestCase
'assign', 'assign',
'verify', 'verify',
'save' 'save'
)); ), array(), '', false);
$oTotpMock->method('saveSecret')->willReturn(true); $oTotpMock->method('saveSecret')->willReturn(true);
$oTotpMock->method('assign')->willReturn(true); $oTotpMock->method('assign')->willReturn(true);
$oTotpMock->expects($this->once())->method('verify')->willThrowException(new Exception('foo')); $oTotpMock->expects($this->once())->method('verify')->willThrowException(new Exception('foo'));
@ -250,7 +250,7 @@ class d3_account_totpTest extends d3TotpUnitTestCase
'verify', 'verify',
'save', 'save',
'setId', 'setId',
)); ), array(), '', false);
$oTotpMock->method('saveSecret')->willReturn(true); $oTotpMock->method('saveSecret')->willReturn(true);
$oTotpMock->method('assign')->willReturn(true); $oTotpMock->method('assign')->willReturn(true);
$oTotpMock->method('verify')->willReturn(true); $oTotpMock->method('verify')->willReturn(true);
@ -305,7 +305,7 @@ class d3_account_totpTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'delete' 'delete'
)); ), array(), '', false);
$oTotpMock->expects($this->never())->method('delete'); $oTotpMock->expects($this->never())->method('delete');
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
@ -331,9 +331,11 @@ class d3_account_totpTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'delete' 'delete',
)); 'loadByUserId'
), array(), '', false);
$oTotpMock->expects($this->once())->method('delete')->willReturn(true); $oTotpMock->expects($this->once())->method('delete')->willReturn(true);
$oTotpMock->method('loadByUserId')->willReturn(true);
$oUser = oxNew(User::class); $oUser = oxNew(User::class);
$oUser->setId('foo'); $oUser->setId('foo');
@ -350,4 +352,16 @@ class d3_account_totpTest extends d3TotpUnitTestCase
$this->callMethod($this->_oController, 'delete'); $this->callMethod($this->_oController, 'delete');
} }
/**
* @test
* @throws ReflectionException
*/
public function getTotpObjectReturnsRightObject()
{
$this->assertInstanceOf(
d3totp::class,
$this->callMethod($this->_oController, 'getTotpObject')
);
}
} }

View File

@ -0,0 +1,58 @@
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
*
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
*
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\Totp\tests\unit\Application\Model\Exceptions;
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
use D3\Totp\tests\unit\d3TotpUnitTestCase;
use ReflectionException;
class d3totp_wrongOtpExceptionTest extends d3TotpUnitTestCase
{
/** @var d3totp_wrongOtpException */
protected $_oModel;
/**
* setup basic requirements
*/
public function setUp()
{
parent::setUp();
$this->_oModel = oxNew(d3totp_wrongOtpException::class);
}
public function tearDown()
{
parent::tearDown();
unset($this->_oModel);
}
/**
* @test
* @throws ReflectionException
*/
public function constructorHasRightDefaultMessage()
{
$this->_oModel = oxNew(d3totp_wrongOtpException::class);
$this->assertSame(
'D3_TOTP_ERROR_UNVALID',
$this->callMethod($this->_oModel, 'getMessage')
);
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
*
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
*
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\Totp\tests\unit\Application\Model;
use D3\Totp\Application\Model\d3RandomGenerator;
use D3\Totp\tests\unit\d3TotpUnitTestCase;
use ReflectionException;
class d3RandomGeneratorTest extends d3TotpUnitTestCase
{
/** @var d3RandomGenerator */
protected $_oModel;
/**
* setup basic requirements
*/
public function setUp()
{
parent::setUp();
$this->_oModel = oxNew(d3RandomGenerator::class);
}
public function tearDown()
{
parent::tearDown();
unset($this->_oModel);
}
/**
* @test
* @throws ReflectionException
*/
public function getRandomTotpBackupCodeReturnsRightCode()
{
$this->assertRegExp(
'@[0-9]{6}@',
$this->callMethod($this->_oModel, 'getRandomTotpBackupCode')
);
}
}

View File

@ -71,7 +71,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
)); ), array(), '', false);
$oTotpMock->expects($this->never())->method('isActive')->willReturn(false); $oTotpMock->expects($this->never())->method('isActive')->willReturn(false);
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
@ -112,8 +112,10 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
)); 'loadByUserId'
), array(), '', false);
$oTotpMock->expects($this->once())->method('isActive')->willReturn(false); $oTotpMock->expects($this->once())->method('isActive')->willReturn(false);
$oTotpMock->method('loadByUserId')->willReturn(true);
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMock(UserComponent::class, array(
@ -153,8 +155,10 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
)); 'loadByUserId'
), array(), '', false);
$oTotpMock->expects($this->once())->method('isActive')->willReturn(true); $oTotpMock->expects($this->once())->method('isActive')->willReturn(true);
$oTotpMock->method('loadByUserId')->willReturn(true);
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMock(UserComponent::class, array(
@ -192,15 +196,23 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function checkTotploginNoTotpLogin() public function checkTotploginNoTotpLogin()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array(
'loadByUserId'
), array(), '', false);
$oTotpMock->method('loadByUserId')->willReturn(true);
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMock(UserComponent::class, array(
'isNoTotpOrNoLogin', 'isNoTotpOrNoLogin',
'hasValidTotp', 'hasValidTotp',
'd3TotpRelogin' 'd3TotpRelogin',
'd3GetTotpObject'
)); ));
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(true); $oControllerMock->method('isNoTotpOrNoLogin')->willReturn(true);
$oControllerMock->expects($this->never())->method('hasValidTotp')->willReturn(false); $oControllerMock->expects($this->never())->method('hasValidTotp')->willReturn(false);
$oControllerMock->expects($this->never())->method('d3TotpRelogin')->willReturn(false); $oControllerMock->expects($this->never())->method('d3TotpRelogin')->willReturn(false);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -216,6 +228,15 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function checkTotploginUnvalidTotp() public function checkTotploginUnvalidTotp()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array(
'loadByUserId'
), array(), '', false);
$oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3totp_wrongOtpException|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */
$oTotpExceptionMock = $this->getMock(d3totp_wrongOtpException::class, array(), array(), '', false);
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */ /** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */
$oUtilsViewMock = $this->getMock(UtilsView::class, array( $oUtilsViewMock = $this->getMock(UtilsView::class, array(
'addErrorToDisplay', 'addErrorToDisplay',
@ -227,12 +248,14 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
'isNoTotpOrNoLogin', 'isNoTotpOrNoLogin',
'hasValidTotp', 'hasValidTotp',
'd3TotpRelogin', 'd3TotpRelogin',
'd3GetUtilsView' 'd3GetUtilsView',
'd3GetTotpObject'
)); ));
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false); $oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false);
$oControllerMock->expects($this->once())->method('hasValidTotp')->willThrowException(oxNew(d3totp_wrongOtpException::class)); $oControllerMock->expects($this->once())->method('hasValidTotp')->willThrowException($oTotpExceptionMock);
$oControllerMock->expects($this->never())->method('d3TotpRelogin')->willReturn(false); $oControllerMock->expects($this->never())->method('d3TotpRelogin')->willReturn(false);
$oControllerMock->method('d3GetUtilsView')->willReturn($oUtilsViewMock); $oControllerMock->method('d3GetUtilsView')->willReturn($oUtilsViewMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -248,6 +271,12 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function checkTotploginValidTotp() public function checkTotploginValidTotp()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array(
'loadByUserId'
), array(), '', false);
$oTotpMock->method('loadByUserId')->willReturn(true);
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */ /** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */
$oUtilsViewMock = $this->getMock(UtilsView::class, array( $oUtilsViewMock = $this->getMock(UtilsView::class, array(
'addErrorToDisplay', 'addErrorToDisplay',
@ -259,12 +288,14 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
'isNoTotpOrNoLogin', 'isNoTotpOrNoLogin',
'hasValidTotp', 'hasValidTotp',
'd3TotpRelogin', 'd3TotpRelogin',
'd3GetUtilsView' 'd3GetUtilsView',
'd3GetTotpObject'
)); ));
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false); $oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false);
$oControllerMock->expects($this->once())->method('hasValidTotp')->willReturn(true); $oControllerMock->expects($this->once())->method('hasValidTotp')->willReturn(true);
$oControllerMock->expects($this->once())->method('d3TotpRelogin')->willReturn(true); $oControllerMock->expects($this->once())->method('d3TotpRelogin')->willReturn(true);
$oControllerMock->method('d3GetUtilsView')->willReturn($oUtilsViewMock); $oControllerMock->method('d3GetUtilsView')->willReturn($oUtilsViewMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -313,7 +344,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
)); ), array(), '', false);
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
$this->assertTrue( $this->assertTrue(
@ -332,7 +363,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
)); ), array(), '', false);
$oTotpMock->method('isActive')->willReturn(false); $oTotpMock->method('isActive')->willReturn(false);
$this->assertTrue( $this->assertTrue(
@ -351,7 +382,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
)); ), array(), '', false);
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
$this->assertFalse( $this->assertFalse(
@ -370,7 +401,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'verify', 'verify',
)); ), array(), '', false);
$oTotpMock->method('verify')->willReturn(false); $oTotpMock->method('verify')->willReturn(false);
$this->assertTrue( $this->assertTrue(
@ -389,7 +420,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'verify', 'verify',
)); ), array(), '', false);
$oTotpMock->method('verify')->willReturn(true); $oTotpMock->method('verify')->willReturn(true);
$this->assertTrue( $this->assertTrue(
@ -408,7 +439,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'verify', 'verify',
)); ), array(), '', false);
$oTotpMock->method('verify')->willReturn(true); $oTotpMock->method('verify')->willReturn(true);
$this->assertFalse( $this->assertFalse(
@ -427,7 +458,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'verify', 'verify',
)); ), array(), '', false);
$oTotpMock->method('verify')->willReturn(false); $oTotpMock->method('verify')->willReturn(false);
$this->assertFalse( $this->assertFalse(

View File

@ -61,7 +61,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
'loadByUserId' 'loadByUserId'
)); ), array(), '', false);
$oTotpMock->expects($this->never())->method('isActive')->willReturn(false); $oTotpMock->expects($this->never())->method('isActive')->willReturn(false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
@ -97,7 +97,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
'loadByUserId' 'loadByUserId'
)); ), array(), '', false);
$oTotpMock->expects($this->once())->method('isActive')->willReturn(false); $oTotpMock->expects($this->once())->method('isActive')->willReturn(false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
@ -133,7 +133,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
'loadByUserId' 'loadByUserId'
)); ), array(), '', false);
$oTotpMock->expects($this->once())->method('isActive')->willReturn(false); $oTotpMock->expects($this->once())->method('isActive')->willReturn(false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
@ -169,7 +169,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
'loadByUserId' 'loadByUserId'
)); ), array(), '', false);
$oTotpMock->expects($this->once())->method('isActive')->willReturn(true); $oTotpMock->expects($this->once())->method('isActive')->willReturn(true);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
@ -252,7 +252,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'loadByUserId' 'loadByUserId'
)); ), array(), '', false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
@ -276,6 +276,9 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function checkloginUnvalidTotp() public function checkloginUnvalidTotp()
{ {
/** @var d3totp_wrongOtpException|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */
$oTotpExceptionMock = $this->getMock(d3totp_wrongOtpException::class, array(), array(), '', false);
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $utilsViewMock */ /** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $utilsViewMock */
$utilsViewMock = $this->getMock(UtilsView::class, array( $utilsViewMock = $this->getMock(UtilsView::class, array(
'addErrorToDisplay', 'addErrorToDisplay',
@ -285,7 +288,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'loadByUserId' 'loadByUserId'
)); ), array(), '', false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
@ -297,7 +300,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
)); ));
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false); $oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false);
$oControllerMock->method('hasValidTotp')->willThrowException(oxNew(d3totp_wrongOtpException::class)); $oControllerMock->method('hasValidTotp')->willThrowException($oTotpExceptionMock);
$oControllerMock->method('d3GetUtilsView')->willReturn($utilsViewMock); $oControllerMock->method('d3GetUtilsView')->willReturn($utilsViewMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -320,7 +323,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'loadByUserId' 'loadByUserId'
)); ), array(), '', false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
@ -411,7 +414,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive' 'isActive'
)); ), array(), '', false);
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
@ -442,7 +445,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive' 'isActive'
)); ), array(), '', false);
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
@ -473,7 +476,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive' 'isActive'
)); ), array(), '', false);
$oTotpMock->method('isActive')->willReturn(false); $oTotpMock->method('isActive')->willReturn(false);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
@ -506,7 +509,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'verify', 'verify',
)); ), array(), '', false);
$oTotpMock->method('verify')->willReturn(false); $oTotpMock->method('verify')->willReturn(false);
$this->assertTrue( $this->assertTrue(
@ -525,7 +528,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'verify', 'verify',
)); ), array(), '', false);
$oTotpMock->method('verify')->willReturn(true); $oTotpMock->method('verify')->willReturn(true);
$this->assertTrue( $this->assertTrue(
@ -544,7 +547,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'verify', 'verify',
)); ), array(), '', false);
$oTotpMock->method('verify')->willReturn(true); $oTotpMock->method('verify')->willReturn(true);
$this->assertFalse( $this->assertFalse(
@ -563,7 +566,7 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'verify', 'verify',
)); ), array(), '', false);
$oTotpMock->method('verify')->willReturn(false); $oTotpMock->method('verify')->willReturn(false);
$this->assertFalse( $this->assertFalse(

View File

@ -64,7 +64,7 @@ trait d3_totp_getUserTestTrait
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
'loadByUserId' 'loadByUserId'
)); ), array(), '', false);
$oTotpMock->method('isActive')->willReturn(false); $oTotpMock->method('isActive')->willReturn(false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
@ -107,7 +107,7 @@ trait d3_totp_getUserTestTrait
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
'loadByUserId' 'loadByUserId'
)); ), array(), '', false);
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
@ -150,7 +150,7 @@ trait d3_totp_getUserTestTrait
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'isActive', 'isActive',
'loadByUserId' 'loadByUserId'
)); ), array(), '', false);
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);

View File

@ -60,7 +60,7 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'loadByUserId', 'loadByUserId',
'isActive', 'isActive',
)); ), array(), '', false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
$oTotpMock->method('isActive')->willReturn(false); $oTotpMock->method('isActive')->willReturn(false);
@ -91,7 +91,7 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'loadByUserId', 'loadByUserId',
'isActive', 'isActive',
)); ), array(), '', false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
$oTotpMock->method('isActive')->willReturn(false); $oTotpMock->method('isActive')->willReturn(false);
@ -130,7 +130,7 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'loadByUserId', 'loadByUserId',
'isActive', 'isActive',
)); ), array(), '', false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
@ -177,7 +177,7 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMock(d3totp::class, array(
'loadByUserId', 'loadByUserId',
'isActive', 'isActive',
)); ), array(), '', false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);