refactor tests

This commit is contained in:
Daniel Seifert 2022-09-28 00:08:36 +02:00
parent 7be2c32cf5
commit 9c4e7cfcc3
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
43 changed files with 1579 additions and 1201 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
src/tests/.phpunit.result.cache
src/tests/reports/

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Application\Controller\Admin; namespace D3\Totp\Application\Controller\Admin;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
@ -93,12 +95,10 @@ class d3user_totp extends AdminDetailsController
$aParams = Registry::getRequest()->getRequestEscapedParameter("editval"); $aParams = Registry::getRequest()->getRequestEscapedParameter("editval");
try { try {
/** @var d3totp $oTotp */
$oTotp = $this->getTotpObject(); $oTotp = $this->getTotpObject();
if ($oTotp->checkIfAlreadyExist($this->getEditObjectId())) { if ($oTotp->checkIfAlreadyExist($this->getEditObjectId())) {
$oException = oxNew(StandardException::class, 'D3_TOTP_ALREADY_EXIST'); throw oxNew(StandardException::class, 'D3_TOTP_ALREADY_EXIST');
throw $oException; }
};
$oTotpBackupCodes = $this->getBackupcodeListObject(); $oTotpBackupCodes = $this->getBackupcodeListObject();
if ($aParams['d3totp__oxid']) { if ($aParams['d3totp__oxid']) {

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Application\Controller; namespace D3\Totp\Application\Controller;
use D3\Totp\Application\Model\d3backupcodelist; use D3\Totp\Application\Model\d3backupcodelist;
@ -45,7 +47,7 @@ class d3_account_totp extends AccountController
} }
/** /**
* @param $aCodes * @param array $aCodes
*/ */
public function setBackupCodes(array $aCodes) public function setBackupCodes(array $aCodes)
{ {
@ -119,7 +121,6 @@ class d3_account_totp extends AccountController
/** /**
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws DBALException
*/ */
public function delete() public function delete()
{ {

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Application\Controller; namespace D3\Totp\Application\Controller;
use D3\Totp\Application\Model\d3backupcodelist; use D3\Totp\Application\Model\d3backupcodelist;
@ -29,7 +31,7 @@ class d3totplogin extends FrontendController
if (Registry::getSession()->hasVariable(d3totp::TOTP_SESSION_VARNAME) || if (Registry::getSession()->hasVariable(d3totp::TOTP_SESSION_VARNAME) ||
false == Registry::getSession()->hasVariable(d3totp::TOTP_SESSION_CURRENTUSER) false == Registry::getSession()->hasVariable(d3totp::TOTP_SESSION_CURRENTUSER)
) { ) {
$this->getUtils()->redirect('index.php?cl=start', true, 302); $this->getUtils()->redirect('index.php?cl=start');
if (false == defined('OXID_PHP_UNIT')) { if (false == defined('OXID_PHP_UNIT')) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
exit; exit;
@ -64,9 +66,7 @@ class d3totplogin extends FrontendController
Registry::getLang()->translateString('D3_TOTP_AVAILBACKUPCODECOUNT', null, true), Registry::getLang()->translateString('D3_TOTP_AVAILBACKUPCODECOUNT', null, true),
$iCount $iCount
); );
}; }
return;
} }
/** /**
@ -86,7 +86,7 @@ class d3totplogin extends FrontendController
{ {
$sClassKey = Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS); $sClassKey = Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS);
$resolvedClass = Registry::getControllerClassNameResolver()->getClassNameById($sClassKey); $resolvedClass = Registry::getControllerClassNameResolver()->getClassNameById($sClassKey);
$resolvedClass = $resolvedClass ? $resolvedClass : 'start'; $resolvedClass = $resolvedClass ?: 'start';
/** @var FrontendController $oController */ /** @var FrontendController $oController */
$oController = oxNew($resolvedClass); $oController = oxNew($resolvedClass);

View File

@ -22,12 +22,10 @@ class BaconQrCodeFactory
private static function v200($size) private static function v200($size)
{ {
$renderer = oxNew( return oxNew(
ImageRenderer::class, ImageRenderer::class,
oxNew(RendererStyle::class, $size), oxNew(RendererStyle::class, $size),
oxNew(SvgImageBackEnd::class), oxNew(SvgImageBackEnd::class),
); );
return $renderer;
} }
} }

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Application\Model\Exceptions; namespace D3\Totp\Application\Model\Exceptions;
use Exception; use Exception;

View File

@ -1,20 +1,25 @@
<?php <?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Totp\Application\Model; namespace D3\Totp\Application\Model;
use Laminas\Math\Rand; use Laminas\Math\Rand;
class d3RandomGenerator extends Rand class d3RandomGenerator extends Rand
{ {
const CHAR_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const CHAR_LOWER = 'abcdefghijklmnopqrstuvwxyz';
const CHAR_DIGITS = '0123456789'; const CHAR_DIGITS = '0123456789';
const CHAR_UPPER_HEX = 'ABCDEF';
const CHAR_LOWER_HEX = 'abcdef';
const CHAR_BASE64 = '+/';
const CHAR_SYMBOLS = '!"#$%&\'()* +,-./:;<=>?@[\]^_`{|}~';
const CHAR_BRACKETS = '()[]{}<>';
const CHAR_PUNCT = ',.;:';
/** /**
* @return string * @return string

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Application\Model; namespace D3\Totp\Application\Model;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
@ -48,6 +50,7 @@ class d3backupcode extends BaseModel
/** /**
* @param $code * @param $code
* @param $sUserId
* @return false|string * @return false|string
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
*/ */

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Application\Model; namespace D3\Totp\Application\Model;
use D3\Totp\Application\Controller\Admin\d3user_totp; use D3\Totp\Application\Controller\Admin\d3user_totp;
@ -46,7 +48,7 @@ class d3backupcodelist extends ListModel
for ($i = 1; $i <= 10; $i++) { for ($i = 1; $i <= 10; $i++) {
$oBackupCode = $this->getD3BackupCodeObject(); $oBackupCode = $this->getD3BackupCodeObject();
$this->_backupCodes[] = $oBackupCode->generateCode($sUserId); $this->_backupCodes[] = $oBackupCode->generateCode($sUserId);
$this->offsetSet(md5(rand()), $oBackupCode); $this->offsetSet(md5((string) rand()), $oBackupCode);
} }
/** @var d3user_totp $oActView */ /** @var d3user_totp $oActView */

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Application\Model; namespace D3\Totp\Application\Model;
use BaconQrCode\Renderer\RendererInterface; use BaconQrCode\Renderer\RendererInterface;
@ -201,22 +203,20 @@ class d3totp extends BaseModel
*/ */
public function verify($totp, $seed = null) public function verify($totp, $seed = null)
{ {
$blVerify = $this->getTotp($seed)->verify($totp, null, $this->timeWindow); $blNotVerified = $this->getTotp($seed)->verify($totp, null, $this->timeWindow) == false;
if (false == $blVerify && null == $seed) { if ($blNotVerified && null == $seed) {
$oBC = $this->d3GetBackupCodeListObject(); $oBC = $this->d3GetBackupCodeListObject();
$blVerify = $oBC->verify($totp); $blNotVerified = $oBC->verify($totp) == false;
if (false == $blVerify) { if ($blNotVerified) {
$oException = oxNew(d3totp_wrongOtpException::class); throw oxNew(d3totp_wrongOtpException::class);
throw $oException;
} }
} elseif (false == $blVerify && $seed) { } elseif ($blNotVerified && $seed) {
$oException = oxNew(d3totp_wrongOtpException::class); throw oxNew(d3totp_wrongOtpException::class);
throw $oException;
} }
return $blVerify; return !$blNotVerified;
} }
/** /**
@ -282,8 +282,6 @@ class d3totp extends BaseModel
$oBackupCodeList = $this->d3GetBackupCodeListObject(); $oBackupCodeList = $this->d3GetBackupCodeListObject();
$oBackupCodeList->deleteAllFromUser($this->getFieldData('oxuserid')); $oBackupCodeList->deleteAllFromUser($this->getFieldData('oxuserid'));
$blDelete = parent::delete(); return parent::delete();
return $blDelete;
} }
} }

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
$sLangName = "Deutsch"; $sLangName = "Deutsch";
$aLang = [ $aLang = [

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
$sLangName = "English"; $sLangName = "English";
$aLang = [ $aLang = [

View File

@ -4,7 +4,7 @@
<input type="hidden" name="fnc" value="checklogin"> <input type="hidden" name="fnc" value="checklogin">
<input type="hidden" name="cl" value="login"> <input type="hidden" name="cl" value="login">
[{if $Errors.default|@count}] [{if !empty($Errors.default)}]
[{include file="inc_error.tpl" Errorlist=$Errors.default}] [{include file="inc_error.tpl" Errorlist=$Errors.default}]
[{/if}] [{/if}]

View File

@ -30,6 +30,7 @@ $aLang = [
'D3_TOTP_CURROTP' => 'Bestätigung mit Einmalpasswort', 'D3_TOTP_CURROTP' => 'Bestätigung mit Einmalpasswort',
'D3_TOTP_CURROTP_HELP' => 'Haben Sie dieses Kundenkonto in Ihrer Authentisierungs-App registriert, generieren Sie damit ein Einmalpasswort, tragen Sie es hier ein und senden das Formular direkt darauf hin ab.', 'D3_TOTP_CURROTP_HELP' => 'Haben Sie dieses Kundenkonto in Ihrer Authentisierungs-App registriert, generieren Sie damit ein Einmalpasswort, tragen Sie es hier ein und senden das Formular direkt darauf hin ab.',
'SHOP_MODULE_GROUP_d3totp_main' => 'Grundeinstellungen',
'D3_TOTP_FORCE2FATITLE' => 'Verpflichtet Zwei-Faktor-Authentisierung', 'D3_TOTP_FORCE2FATITLE' => 'Verpflichtet Zwei-Faktor-Authentisierung',
'D3_TOTP_FORCE2FASUB' => 'Alle Administratoren müssen es aktivieren', 'D3_TOTP_FORCE2FASUB' => 'Alle Administratoren müssen es aktivieren',
'D3_TOTP_ADMINBACKEND' => 'Admin-Oberfläche', 'D3_TOTP_ADMINBACKEND' => 'Admin-Oberfläche',

View File

@ -30,6 +30,7 @@ $aLang = [
'D3_TOTP_CURROTP' => 'Confirmation with one-time password', 'D3_TOTP_CURROTP' => 'Confirmation with one-time password',
'D3_TOTP_CURROTP_HELP' => 'If you have registered this customer account in your authentication app, you generate a one-time password, enter it here and send the form out immediately.', 'D3_TOTP_CURROTP_HELP' => 'If you have registered this customer account in your authentication app, you generate a one-time password, enter it here and send the form out immediately.',
'SHOP_MODULE_GROUP_d3totp_main' => 'Basic settings',
'D3_TOTP_FORCE2FATITLE' => 'Mandates two-factor authentication', 'D3_TOTP_FORCE2FATITLE' => 'Mandates two-factor authentication',
'D3_TOTP_FORCE2FASUB' => 'All administrators need to activate it', 'D3_TOTP_FORCE2FASUB' => 'All administrators need to activate it',
'D3_TOTP_ADMINBACKEND' => 'Admin-Backend', 'D3_TOTP_ADMINBACKEND' => 'Admin-Backend',

View File

@ -15,7 +15,7 @@
<input type="hidden" name="cl" value="[{$oView->getPreviousClass()}]"> <input type="hidden" name="cl" value="[{$oView->getPreviousClass()}]">
[{$navFormParams}] [{$navFormParams}]
[{if $Errors.default|@count}] [{if !empty($Errors.default)}]
[{include file="inc_error.tpl" Errorlist=$Errors.default}] [{include file="inc_error.tpl" Errorlist=$Errors.default}]
[{/if}] [{/if}]

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Modules\Application\Component; namespace D3\Totp\Modules\Application\Component;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
@ -40,7 +42,7 @@ class d3_totp_UserComponent extends d3_totp_UserComponent_parent
$totp->loadByUserId($oUser->getId()); $totp->loadByUserId($oUser->getId());
if ($totp->isActive() if ($totp->isActive()
&& false == Registry::getSession()->getVariable(d3totp::TOTP_SESSION_VARNAME) && !Registry::getSession()->getVariable(d3totp::TOTP_SESSION_VARNAME)
) { ) {
Registry::getSession()->setVariable( Registry::getSession()->setVariable(
d3totp::TOTP_SESSION_CURRENTCLASS, d3totp::TOTP_SESSION_CURRENTCLASS,
@ -82,7 +84,7 @@ class d3_totp_UserComponent extends d3_totp_UserComponent_parent
$totp->loadByUserId($sUserId); $totp->loadByUserId($sUserId);
try { try {
if (false == $this->isNoTotpOrNoLogin($totp) && $this->hasValidTotp($sTotp, $totp)) { if (!$this->isNoTotpOrNoLogin($totp) && $this->hasValidTotp($sTotp, $totp)) {
$this->d3TotpRelogin($oUser, $sTotp); $this->d3TotpRelogin($oUser, $sTotp);
$this->d3TotpClearSessionVariables(); $this->d3TotpClearSessionVariables();

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Modules\Application\Controller\Admin; namespace D3\Totp\Modules\Application\Controller\Admin;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
@ -41,7 +43,7 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
if ($auth if ($auth
&& $totp->isActive() && $totp->isActive()
&& false == $this->d3GetSession()->getVariable(d3totp::TOTP_SESSION_VARNAME) && !$this->d3GetSession()->getVariable(d3totp::TOTP_SESSION_VARNAME)
) { ) {
// set auth as secured parameter; // set auth as secured parameter;
$this->d3GetSession()->setVariable("auth", $auth); $this->d3GetSession()->setVariable("auth", $auth);
@ -98,7 +100,7 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
$return = 'login'; $return = 'login';
try { try {
if ($this->isNoTotpOrNoLogin($totp)) { if ($this->isNoTotpOrNoLogin($totp) && $this->hasLoginCredentials()) {
$return = parent::checklogin(); $return = parent::checklogin();
} elseif ($this->hasValidTotp($sTotp, $totp)) { } elseif ($this->hasValidTotp($sTotp, $totp)) {
$this->d3GetSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, $sTotp); $this->d3GetSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, $sTotp);
@ -125,9 +127,7 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
Registry::getLang()->translateString('D3_TOTP_AVAILBACKUPCODECOUNT'), Registry::getLang()->translateString('D3_TOTP_AVAILBACKUPCODECOUNT'),
$iCount $iCount
); );
}; }
return;
} }
/** /**
@ -140,6 +140,12 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
|| false == $totp->isActive(); || false == $totp->isActive();
} }
protected function hasLoginCredentials()
{
return Registry::getRequest()->getRequestEscapedParameter( 'user') &&
Registry::getRequest()->getRequestEscapedParameter('pwd');
}
/** /**
* @param string $sTotp * @param string $sTotp
* @param d3totp $totp * @param d3totp $totp

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Modules\Application\Controller; namespace D3\Totp\Modules\Application\Controller;
class d3_totp_OrderController extends d3_totp_OrderController_parent class d3_totp_OrderController extends d3_totp_OrderController_parent

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Modules\Application\Controller; namespace D3\Totp\Modules\Application\Controller;
class d3_totp_PaymentController extends d3_totp_PaymentController_parent class d3_totp_PaymentController extends d3_totp_PaymentController_parent

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Modules\Application\Controller; namespace D3\Totp\Modules\Application\Controller;
class d3_totp_UserController extends d3_totp_UserController_parent class d3_totp_UserController extends d3_totp_UserController_parent

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Modules\Application\Controller; namespace D3\Totp\Modules\Application\Controller;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
@ -25,7 +27,6 @@ trait d3_totp_getUserTrait
/** /**
* @return bool|object|User * @return bool|object|User
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws DBALException
*/ */
public function getUser() public function getUser()
{ {
@ -36,7 +37,7 @@ trait d3_totp_getUserTrait
$totp->loadByUserId($oUser->getId()); $totp->loadByUserId($oUser->getId());
if ($totp->isActive() if ($totp->isActive()
&& false == $this->d3GetSessionObject()->getVariable(d3totp::TOTP_SESSION_VARNAME) && !$this->d3GetSessionObject()->getVariable(d3totp::TOTP_SESSION_VARNAME)
) { ) {
return false; return false;
} }

View File

@ -11,11 +11,11 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Modules\Application\Model; namespace D3\Totp\Modules\Application\Model;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Session; use OxidEsales\Eshop\Core\Session;

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Modules\Core; namespace D3\Totp\Modules\Core;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
@ -43,7 +45,7 @@ class d3_totp_utils extends d3_totp_utils_parent
&& $blAuth && $blAuth
&& $totp->isActive() === false && $totp->isActive() === false
) { ) {
$this->redirect('index.php?cl=d3force_2fa', true, 302); $this->redirect('index.php?cl=d3force_2fa');
if (false == defined('OXID_PHP_UNIT')) { if (false == defined('OXID_PHP_UNIT')) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
exit; exit;
@ -53,7 +55,7 @@ class d3_totp_utils extends d3_totp_utils_parent
//staten der prüfung vom einmalpasswort //staten der prüfung vom einmalpasswort
if ($blAuth && $totp->isActive() && false === $totpAuth) { if ($blAuth && $totp->isActive() && false === $totpAuth) {
$this->redirect('index.php?cl=login', true, 302); $this->redirect('index.php?cl=login');
if (false == defined('OXID_PHP_UNIT')) { if (false == defined('OXID_PHP_UNIT')) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
exit; exit;

View File

@ -11,32 +11,27 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
namespace D3\Totp\Setup; namespace D3\Totp\Setup;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException; use OxidEsales\Eshop\Core\DatabaseProvider;
use D3\ModCfg\Application\Model\Install\d3install;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Exception\SystemComponentException;
class Events class Events
{ {
/** /**
* @codeCoverageIgnore * @return void
* @throws d3ShopCompatibilityAdapterException
* @throws DBALException
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws DatabaseErrorException * @throws DatabaseErrorException
* @throws StandardException
* @throws SystemComponentException
*/ */
public static function onActivate() public static function onActivate(): void
{ {
if (class_exists(d3install::class)) { self::addTotpTable();
d3install::checkUpdateStart(); self::addTotpBackupCodesTable();
} self::addSeoItem1();
self::addSeoItem2();
} }
/** /**
@ -45,4 +40,94 @@ class Events
public static function onDeactivate() public static function onDeactivate()
{ {
} }
/**
* @return void
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
public static function addTotpTable(): void
{
$query = "CREATE TABLE IF NOT EXISTS `d3totp` (
`OXID` CHAR(32) NOT NULL ,
`OXUSERID` CHAR(32) NOT NULL ,
`USETOTP` TINYINT(1) NOT NULL DEFAULT 0,
`SEED` VARCHAR(256) NOT NULL ,
`OXTIMESTAMP` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp',
PRIMARY KEY (`OXID`) ,
UNIQUE KEY `OXUSERID` (`OXUSERID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='totp setting';";
DatabaseProvider::getDb()->execute( $query );
}
/**
* @return void
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
public static function addTotpBackupCodesTable(): void
{
$query = "CREATE TABLE IF NOT EXISTS `d3totp_backupcodes` (
`OXID` CHAR(32) NOT NULL ,
`OXUSERID` CHAR(32) NOT NULL COMMENT 'user id',
`BACKUPCODE` VARCHAR(64) NOT NULL COMMENT 'BackupCode',
`OXTIMESTAMP` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp',
PRIMARY KEY (`OXID`) ,
KEY `OXUSERID` (`OXUSERID`) ,
KEY `BACKUPCODE` (`BACKUPCODE`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='totp backup codes';";
DatabaseProvider::getDb()->execute( $query );
}
/**
* @return void
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
public static function addSeoItem1(): void
{
if (!DatabaseProvider::getDb()->getOne('SELECT 1 FROM oxseo WHERE oxident = "76282e134ad4e40a3578e121a6cb1f6a"')) {
$query = "INSERT INTO `oxseo`
(
`OXOBJECTID`, `OXIDENT`, `OXSHOPID`,
`OXLANG`, `OXSTDURL`, `OXSEOURL`,
`OXTYPE`, `OXFIXED`, `OXEXPIRED`,
`OXPARAMS`, `OXTIMESTAMP`
) VALUES (
'39f744f17e974988e515558698a29df4', '76282e134ad4e40a3578e121a6cb1f6a', 1,
1, 'index.php?cl=d3_account_totp', 'en/2-factor-authintication/',
'static', 0, 0,
'', NOW()
);";
DatabaseProvider::getDb()->execute( $query );
}
}
/**
* @return void
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
public static function addSeoItem2(): void
{
if (!DatabaseProvider::getDb()->getOne('SELECT 1 FROM oxseo WHERE oxident = "c1f8b5506e2b5d6ac184dcc5ebdfb591"')) {
$query = "INSERT INTO `oxseo`
(
`OXOBJECTID`, `OXIDENT`, `OXSHOPID`,
`OXLANG`, `OXSTDURL`, `OXSEOURL`,
`OXTYPE`, `OXFIXED`, `OXEXPIRED`,
`OXPARAMS`, `OXTIMESTAMP`
) VALUES (
'39f744f17e974988e515558698a29df4', 'c1f8b5506e2b5d6ac184dcc5ebdfb591', 1,
0, 'index.php?cl=d3_account_totp', '2-faktor-authentisierung/',
'static', 0, 0,
'', NOW()
);";
DatabaseProvider::getDb()->execute( $query );
}
}
} }

View File

@ -11,6 +11,8 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
declare(strict_types=1);
use D3\Totp\Application\Controller\Admin\d3user_totp; use D3\Totp\Application\Controller\Admin\d3user_totp;
use D3\Totp\Application\Controller\Admin\d3force_2fa; use D3\Totp\Application\Controller\Admin\d3force_2fa;
use D3\Totp\Application\Controller\d3_account_totp; use D3\Totp\Application\Controller\d3_account_totp;
@ -23,7 +25,6 @@ use D3\Totp\Modules\Application\Controller\d3_totp_UserController;
use D3\Totp\Modules\Application\Model\d3_totp_user; use D3\Totp\Modules\Application\Model\d3_totp_user;
use D3\Totp\Modules\Core\d3_totp_utils; use D3\Totp\Modules\Core\d3_totp_utils;
use D3\Totp\Setup as ModuleSetup; use D3\Totp\Setup as ModuleSetup;
use D3\ModCfg\Application\Model\d3utils;
use OxidEsales\Eshop\Application\Component\UserComponent; use OxidEsales\Eshop\Application\Component\UserComponent;
use OxidEsales\Eshop\Application\Controller\Admin\LoginController; use OxidEsales\Eshop\Application\Controller\Admin\LoginController;
use OxidEsales\Eshop\Application\Controller\OrderController; use OxidEsales\Eshop\Application\Controller\OrderController;
@ -35,7 +36,7 @@ use OxidEsales\Eshop\Application\Model as OxidModel;
/** /**
* Metadata version * Metadata version
*/ */
$sMetadataVersion = '2.0'; $sMetadataVersion = '2.1';
$sModuleId = 'd3totp'; $sModuleId = 'd3totp';
$logo = '<img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="height:1em;width:1em">'; $logo = '<img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="height:1em;width:1em">';
@ -46,18 +47,17 @@ $logo = '<img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="he
$aModule = [ $aModule = [
'id' => $sModuleId, 'id' => $sModuleId,
'title' => [ 'title' => [
'de' => $logo . 'Zwei-Faktor-Authentisierung', 'de' => $logo . ' Zwei-Faktor-Authentisierung',
'en' => $logo . 'two-factor authentication', 'en' => $logo . ' two-factor authentication',
], ],
'description' => [ 'description' => [
'de' => 'Zwei-Faktor-Authentisierung (TOTP) f&uuml;r OXID eSales Shop', 'de' => 'Zwei-Faktor-Authentisierung (TOTP) f&uuml;r OXID eSales Shop',
'en' => 'Two-factor authentication (TOTP) for OXID eSales shop', 'en' => 'Two-factor authentication (TOTP) for OXID eSales shop',
], ],
'thumbnail' => 'picture.png',
'version' => '1.0.0.0', 'version' => '1.0.0.0',
'author' => 'D&sup3; Data Development (Inh.: Thomas Dartsch)', 'author' => 'D&sup3; Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com', 'email' => 'support@shopmodule.com',
'url' => 'http://www.oxidmodule.com/', 'url' => 'https://www.oxidmodule.com/',
'extend' => [ 'extend' => [
UserController::class => d3_totp_UserController::class, UserController::class => d3_totp_UserController::class,
PaymentController::class => d3_totp_PaymentController::class, PaymentController::class => d3_totp_PaymentController::class,
@ -80,15 +80,15 @@ $aModule = [
], ],
'settings' => [ 'settings' => [
[ [
'group' => 'main', 'group' => 'd3totp_main',
'name' => 'D3_TOTP_ADMIN_FORCE_2FA', 'name' => 'D3_TOTP_ADMIN_FORCE_2FA',
'type' => 'bool', 'type' => 'bool',
'value' => false, 'value' => false,
] ]
], ],
'events' => [ 'events' => [
'onActivate' => '\D3\Totp\Setup\Events::onActivate', 'onActivate' => ModuleSetup\Events::class.'::onActivate',
'onDeactivate' => '\D3\Totp\Setup\Events::onDeactivate', 'onDeactivate' => ModuleSetup\Events::class.'::onDeactivate',
], ],
'blocks' => [ 'blocks' => [
[ [

View File

@ -11,5 +11,5 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
define('D3TOTP_REQUIRE_MODCFG', true); const D3TOTP_REQUIRE_MODCFG = true;

View File

@ -19,7 +19,7 @@ use D3\Totp\Application\Model\d3totp;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
use Exception; use Exception;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
class d3user_totpTest extends d3TotpUnitTestCase class d3user_totpTest extends d3TotpUnitTestCase
@ -30,14 +30,14 @@ class d3user_totpTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oController = oxNew(d3user_totp::class); $this->_oController = oxNew(d3user_totp::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();
@ -50,11 +50,13 @@ class d3user_totpTest extends d3TotpUnitTestCase
*/ */
public function canRenderNoSelectedUser() public function canRenderNoSelectedUser()
{ {
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMockBuilder(d3user_totp::class)
'getEditObjectId', ->onlyMethods([
'getUserObject' 'getEditObjectId',
)); 'getUserObject'
])
->getMock();
$oControllerMock->method('getEditObjectId')->willReturn('-1'); $oControllerMock->method('getEditObjectId')->willReturn('-1');
$oControllerMock->expects($this->never())->method('getUserObject')->willReturn(false); $oControllerMock->expects($this->never())->method('getUserObject')->willReturn(false);
@ -73,19 +75,23 @@ class d3user_totpTest extends d3TotpUnitTestCase
*/ */
public function canRenderSelectedUser() public function canRenderSelectedUser()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var User|MockObject $oControllerMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'getId', ->onlyMethods([
'load', 'getId',
)); 'load',
])
->getMock();
$oUserMock->expects($this->atLeast(1))->method('getId')->willReturn('foobar'); $oUserMock->expects($this->atLeast(1))->method('getId')->willReturn('foobar');
$oUserMock->expects($this->atLeast(1))->method('load')->willReturn(true); $oUserMock->expects($this->atLeast(1))->method('load')->willReturn(true);
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMockBuilder(d3user_totp::class)
'getEditObjectId', ->onlyMethods([
'getUserObject' 'getEditObjectId',
)); 'getUserObject'
])
->getMock();
$oControllerMock->method('getEditObjectId')->willReturn('foobar'); $oControllerMock->method('getEditObjectId')->willReturn('foobar');
$oControllerMock->expects($this->once())->method('getUserObject')->willReturn($oUserMock); $oControllerMock->expects($this->once())->method('getUserObject')->willReturn($oUserMock);
@ -106,20 +112,24 @@ class d3user_totpTest extends d3TotpUnitTestCase
*/ */
public function canRenderUnloadableUser() public function canRenderUnloadableUser()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var User|MockObject $oControllerMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'getId', ->onlyMethods([
'load', 'getId',
)); 'load',
])
->getMock();
$oUserMock->expects($this->never())->method('getId'); $oUserMock->expects($this->never())->method('getId');
$oUserMock->expects($this->atLeast(1))->method('load')->willReturn(false); $oUserMock->expects($this->atLeast(1))->method('load')->willReturn(false);
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMockBuilder(d3user_totp::class)
'getEditObjectId', ->onlyMethods([
'getUserObject', 'getEditObjectId',
'addTplParam' 'getUserObject',
)); 'addTplParam'
])
->getMock();
$oControllerMock->method('getEditObjectId')->willReturn('foobar'); $oControllerMock->method('getEditObjectId')->willReturn('foobar');
$oControllerMock->expects($this->once())->method('getUserObject')->willReturn($oUserMock); $oControllerMock->expects($this->once())->method('getUserObject')->willReturn($oUserMock);
$oControllerMock->expects($this->exactly(3))->method('addTplParam')->with( $oControllerMock->expects($this->exactly(3))->method('addTplParam')->with(
@ -151,7 +161,10 @@ class d3user_totpTest extends d3TotpUnitTestCase
{ {
$this->assertInstanceOf( $this->assertInstanceOf(
User::class, User::class,
$this->callMethod($this->_oController, 'getUserObject') $this->callMethod(
$this->_oController,
'getUserObject'
)
); );
} }
@ -163,7 +176,10 @@ class d3user_totpTest extends d3TotpUnitTestCase
{ {
$this->assertInstanceOf( $this->assertInstanceOf(
d3totp::class, d3totp::class,
$this->callMethod($this->_oController, 'getTotpObject') $this->callMethod(
$this->_oController,
'getTotpObject'
)
); );
} }
@ -175,7 +191,10 @@ class d3user_totpTest extends d3TotpUnitTestCase
{ {
$this->assertInstanceOf( $this->assertInstanceOf(
d3backupcodelist::class, d3backupcodelist::class,
$this->callMethod($this->_oController, 'getBackupCodeListObject') $this->callMethod(
$this->_oController,
'getBackupCodeListObject'
)
); );
} }
@ -185,21 +204,24 @@ class d3user_totpTest extends d3TotpUnitTestCase
*/ */
public function cantSaveBecauseOfNotVerifiable() public function cantSaveBecauseOfNotVerifiable()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3backupcodelist|MockObject $oControllerMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'save', ->onlyMethods(['save'])
)); ->getMock();
$oBackupCodeListMock->expects($this->never())->method('save')->willReturn(true); $oBackupCodeListMock->expects($this->never())->method('save')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3totp|MockObject $oControllerMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'load', ->onlyMethods([
'save', 'load',
'verify', 'save',
'saveSecret', 'verify',
'assign', 'saveSecret',
'checkIfAlreadyExist' 'assign',
), array(), '', false); 'checkIfAlreadyExist'
])
->disableOriginalConstructor()
->getMock();
$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());
@ -207,13 +229,15 @@ class d3user_totpTest extends d3TotpUnitTestCase
$oTotpMock->method('assign')->willReturn(true); $oTotpMock->method('assign')->willReturn(true);
$oTotpMock->method('checkIfAlreadyExist')->willReturn(false); $oTotpMock->method('checkIfAlreadyExist')->willReturn(false);
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMockBuilder(d3user_totp::class)
'getEditObjectId', ->onlyMethods([
'getUserObject', 'getEditObjectId',
'getTotpObject', 'getUserObject',
'getBackupcodeListObject' 'getTotpObject',
)); 'getBackupcodeListObject'
])
->getMock();
$oControllerMock->method('getEditObjectId')->willReturn('foobar'); $oControllerMock->method('getEditObjectId')->willReturn('foobar');
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock); $oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock); $oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
@ -229,21 +253,24 @@ class d3user_totpTest extends d3TotpUnitTestCase
*/ */
public function cantSaveBecauseExistingRegistration() public function cantSaveBecauseExistingRegistration()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3backupcodelist|MockObject $oControllerMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'save', ->onlyMethods(['save'])
)); ->getMock();
$oBackupCodeListMock->expects($this->never())->method('save')->willReturn(true); $oBackupCodeListMock->expects($this->never())->method('save')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3totp|MockObject $oControllerMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'load', ->disableOriginalConstructor()
'save', ->onlyMethods([
'verify', 'load',
'saveSecret', 'save',
'assign', 'verify',
'checkIfAlreadyExist' 'saveSecret',
), array(), '', false); 'assign',
'checkIfAlreadyExist'
])
->getMock();
$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->never())->method('verify')->willThrowException(new Exception()); $oTotpMock->expects($this->never())->method('verify')->willThrowException(new Exception());
@ -251,13 +278,15 @@ class d3user_totpTest extends d3TotpUnitTestCase
$oTotpMock->method('assign')->willReturn(true); $oTotpMock->method('assign')->willReturn(true);
$oTotpMock->method('checkIfAlreadyExist')->willReturn(true); $oTotpMock->method('checkIfAlreadyExist')->willReturn(true);
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMockBuilder(d3user_totp::class)
'getEditObjectId', ->onlyMethods([
'getUserObject', 'getEditObjectId',
'getTotpObject', 'getUserObject',
'getBackupcodeListObject' 'getTotpObject',
)); 'getBackupcodeListObject'
])
->getMock();
$oControllerMock->method('getEditObjectId')->willReturn('foobar'); $oControllerMock->method('getEditObjectId')->willReturn('foobar');
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock); $oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock); $oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
@ -273,23 +302,28 @@ class d3user_totpTest extends d3TotpUnitTestCase
*/ */
public function canSave() public function canSave()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3backupcodelist|MockObject $oControllerMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'save', ->onlyMethods([
'generateBackupCodes' 'save',
)); 'generateBackupCodes'
])
->getMock();
$oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true); $oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true);
$oBackupCodeListMock->method('generateBackupCodes')->willReturn(true); $oBackupCodeListMock->method('generateBackupCodes')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3totp|MockObject $oControllerMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'load', ->onlyMethods([
'save', 'load',
'verify', 'save',
'saveSecret', 'verify',
'assign', 'saveSecret',
'checkIfAlreadyExist' 'assign',
), array(), '', false); 'checkIfAlreadyExist'
])
->disableOriginalConstructor()
->getMock();
$oTotpMock->expects($this->never())->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);
@ -297,13 +331,15 @@ class d3user_totpTest extends d3TotpUnitTestCase
$oTotpMock->method('assign')->willReturn(true); $oTotpMock->method('assign')->willReturn(true);
$oTotpMock->method('checkIfAlreadyExist')->willReturn(false); $oTotpMock->method('checkIfAlreadyExist')->willReturn(false);
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMockBuilder(d3user_totp::class)
'getEditObjectId', ->onlyMethods([
'getUserObject', 'getEditObjectId',
'getTotpObject', 'getUserObject',
'getBackupcodeListObject' 'getTotpObject',
)); 'getBackupcodeListObject'
])
->getMock();
$oControllerMock->method('getEditObjectId')->willReturn('foobar'); $oControllerMock->method('getEditObjectId')->willReturn('foobar');
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock); $oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock); $oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
@ -324,23 +360,28 @@ class d3user_totpTest extends d3TotpUnitTestCase
]; ];
$_GET['editval'] = $aEditval; $_GET['editval'] = $aEditval;
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3backupcodelist|MockObject $oControllerMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'save', ->onlyMethods([
'generateBackupCodes' 'save',
)); 'generateBackupCodes'
])
->getMock();
$oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true); $oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true);
$oBackupCodeListMock->method('generateBackupCodes')->willReturn(true); $oBackupCodeListMock->method('generateBackupCodes')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3totp|MockObject $oControllerMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'load', ->onlyMethods([
'save', 'load',
'verify', 'save',
'saveSecret', 'verify',
'assign', 'saveSecret',
'checkIfAlreadyExist' 'assign',
), array(), '', false); 'checkIfAlreadyExist'
])
->disableOriginalConstructor()
->getMock();
$oTotpMock->expects($this->once())->method('load')->willReturn(true); $oTotpMock->expects($this->once())->method('load')->willReturn(true);
$oTotpMock->expects($this->once())->method('save')->willReturn(true); $oTotpMock->expects($this->once())->method('save')->willReturn(true);
$oTotpMock->expects($this->never())->method('verify')->willReturn(true); $oTotpMock->expects($this->never())->method('verify')->willReturn(true);
@ -348,13 +389,15 @@ class d3user_totpTest extends d3TotpUnitTestCase
$oTotpMock->method('assign')->willReturn(true); $oTotpMock->method('assign')->willReturn(true);
$oTotpMock->method('checkIfAlreadyExist')->willReturn(false); $oTotpMock->method('checkIfAlreadyExist')->willReturn(false);
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMockBuilder(d3user_totp::class)
'getEditObjectId', ->onlyMethods([
'getUserObject', 'getEditObjectId',
'getTotpObject', 'getUserObject',
'getBackupcodeListObject' 'getTotpObject',
)); 'getBackupcodeListObject'
])
->getMock();
$oControllerMock->method('getEditObjectId')->willReturn('foobar'); $oControllerMock->method('getEditObjectId')->willReturn('foobar');
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock); $oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock); $oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
@ -391,16 +434,17 @@ class d3user_totpTest extends d3TotpUnitTestCase
$editval = []; $editval = [];
$_GET['editval'] = $editval; $_GET['editval'] = $editval;
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'delete' ->disableOriginalConstructor()
), array(), '', false); ->onlyMethods(['delete'])
->getMock();
$oTotpMock->expects($this->never())->method('delete'); $oTotpMock->expects($this->never())->method('delete');
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMockBuilder(d3user_totp::class)
'getTotpObject' ->onlyMethods(['getTotpObject'])
)); ->getMock();
$oControllerMock->expects($this->never())->method('getTotpObject')->willReturn($oTotpMock); $oControllerMock->expects($this->never())->method('getTotpObject')->willReturn($oTotpMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -419,18 +463,21 @@ class d3user_totpTest extends d3TotpUnitTestCase
]; ];
$_GET['editval'] = $editval; $_GET['editval'] = $editval;
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'delete', ->disableOriginalConstructor()
'load' ->onlyMethods([
), array(), '', false); 'delete',
'load'
])
->getMock();
$oTotpMock->expects($this->once())->method('delete')->willReturn(true); $oTotpMock->expects($this->once())->method('delete')->willReturn(true);
$oTotpMock->method('load')->willReturn(true); $oTotpMock->method('load')->willReturn(true);
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMockBuilder(d3user_totp::class)
'getTotpObject' ->onlyMethods(['getTotpObject'])
)); ->getMock();
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock); $oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -444,20 +491,22 @@ class d3user_totpTest extends d3TotpUnitTestCase
*/ */
public function canGetAvailableBackupCodeCount() public function canGetAvailableBackupCodeCount()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3backupcodelist|MockObject $oControllerMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'getAvailableCodeCount', ->onlyMethods(['getAvailableCodeCount'])
)); ->getMock();
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(25); $oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(25);
$oUser = oxNew(User::class); $oUser = oxNew(User::class);
$oUser->setId('foo'); $oUser->setId('foo');
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3user_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3user_totp::class, array( $oControllerMock = $this->getMockBuilder(d3user_totp::class)
'getBackupCodeListObject', ->onlyMethods([
'getUser' 'getBackupCodeListObject',
)); 'getUser'
])
->getMock();
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock); $oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
$oControllerMock->method('getUser')->willReturn($oUser); $oControllerMock->method('getUser')->willReturn($oUser);

View File

@ -19,7 +19,7 @@ use D3\Totp\Application\Model\d3totp;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
use Exception; use Exception;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
class d3_account_totpTest extends d3TotpUnitTestCase class d3_account_totpTest extends d3TotpUnitTestCase
@ -58,10 +58,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
] ]
); );
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_account_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_account_totp::class, array( $oControllerMock = $this->getMockBuilder(d3_account_totp::class)
'getUser' ->onlyMethods(['getUser'])
)); ->getMock();
$oControllerMock->method('getUser')->willReturn($oUser); $oControllerMock->method('getUser')->willReturn($oUser);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -81,10 +81,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
{ {
$oUser = false; $oUser = false;
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_account_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_account_totp::class, array( $oControllerMock = $this->getMockBuilder(d3_account_totp::class)
'getUser' ->onlyMethods(['getUser'])
)); ->getMock();
$oControllerMock->method('getUser')->willReturn($oUser); $oControllerMock->method('getUser')->willReturn($oUser);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -122,7 +122,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
{ {
$this->assertInstanceOf( $this->assertInstanceOf(
d3backupcodelist::class, d3backupcodelist::class,
$this->callMethod($this->_oController, 'getBackupCodeListObject') $this->callMethod(
$this->_oController,
'getBackupCodeListObject'
)
); );
} }
@ -132,20 +135,22 @@ class d3_account_totpTest extends d3TotpUnitTestCase
*/ */
public function canGetAvailableBackupCodeCount() public function canGetAvailableBackupCodeCount()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3backupcodelist|MockObject $oControllerMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'getAvailableCodeCount', ->onlyMethods(['getAvailableCodeCount'])
)); ->getMock();
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(25); $oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(25);
$oUser = oxNew(User::class); $oUser = oxNew(User::class);
$oUser->setId('foo'); $oUser->setId('foo');
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_account_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_account_totp::class, array( $oControllerMock = $this->getMockBuilder(d3_account_totp::class)
'getBackupCodeListObject', ->onlyMethods([
'getUser' 'getBackupCodeListObject',
)); 'getUser'
])
->getMock();
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock); $oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
$oControllerMock->method('getUser')->willReturn($oUser); $oControllerMock->method('getUser')->willReturn($oUser);
@ -165,10 +170,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
{ {
$_GET['totp_use'] = 0; $_GET['totp_use'] = 0;
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_account_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_account_totp::class, array( $oControllerMock = $this->getMockBuilder(d3_account_totp::class)
'getTotpObject' ->onlyMethods(['getTotpObject'])
)); ->getMock();
$oControllerMock->expects($this->never())->method('getTotpObject')->willReturn(true); $oControllerMock->expects($this->never())->method('getTotpObject')->willReturn(true);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -184,21 +189,26 @@ class d3_account_totpTest extends d3TotpUnitTestCase
{ {
$_GET['totp_use'] = '1'; $_GET['totp_use'] = '1';
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */ /** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'generateBackupCodes', ->onlyMethods([
'save' 'generateBackupCodes',
)); 'save'
])
->getMock();
$oBackupCodeListMock->expects($this->never())->method('generateBackupCodes'); $oBackupCodeListMock->expects($this->never())->method('generateBackupCodes');
$oBackupCodeListMock->expects($this->never())->method('save'); $oBackupCodeListMock->expects($this->never())->method('save');
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'saveSecret', ->disableOriginalConstructor()
'assign', ->onlyMethods([
'verify', 'saveSecret',
'save' 'assign',
), array(), '', false); 'verify',
'save'
])
->getMock();
$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'));
@ -207,12 +217,14 @@ class d3_account_totpTest extends d3TotpUnitTestCase
$oUser = oxNew(User::class); $oUser = oxNew(User::class);
$oUser->setId('foo'); $oUser->setId('foo');
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_account_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_account_totp::class, array( $oControllerMock = $this->getMockBuilder(d3_account_totp::class)
'getTotpObject', ->onlyMethods([
'getUser', 'getTotpObject',
'getBackupCodeListObject' 'getUser',
)); 'getBackupCodeListObject'
])
->getMock();
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock); $oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('getUser')->willReturn($oUser); $oControllerMock->method('getUser')->willReturn($oUser);
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock); $oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
@ -230,23 +242,28 @@ class d3_account_totpTest extends d3TotpUnitTestCase
{ {
$_GET['totp_use'] = '1'; $_GET['totp_use'] = '1';
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */ /** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'generateBackupCodes', ->onlyMethods([
'save' 'generateBackupCodes',
)); 'save'
])
->getMock();
$oBackupCodeListMock->method('generateBackupCodes')->willReturn(['0123', '1234']); $oBackupCodeListMock->method('generateBackupCodes')->willReturn(['0123', '1234']);
$oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true); $oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true);
$oBackupCodeListMock->method('save')->willReturn(true); $oBackupCodeListMock->method('save')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'saveSecret', ->disableOriginalConstructor()
'assign', ->onlyMethods([
'verify', 'saveSecret',
'save', 'assign',
'setId', 'verify',
), array(), '', false); 'save',
'setId',
])
->getMock();
$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);
@ -256,12 +273,14 @@ class d3_account_totpTest extends d3TotpUnitTestCase
$oUser = oxNew(User::class); $oUser = oxNew(User::class);
$oUser->setId('foo'); $oUser->setId('foo');
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_account_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_account_totp::class, array( $oControllerMock = $this->getMockBuilder(d3_account_totp::class)
'getTotpObject', ->onlyMethods([
'getUser', 'getTotpObject',
'getBackupCodeListObject' 'getUser',
)); 'getBackupCodeListObject'
])
->getMock();
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock); $oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('getUser')->willReturn($oUser); $oControllerMock->method('getUser')->willReturn($oUser);
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock); $oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
@ -279,10 +298,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
{ {
$_GET['totp_use'] = '1'; $_GET['totp_use'] = '1';
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_account_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_account_totp::class, array( $oControllerMock = $this->getMockBuilder(d3_account_totp::class)
'getTotpObject' ->onlyMethods(['getTotpObject'])
)); ->getMock();
$oControllerMock->expects($this->never())->method('getTotpObject')->willReturn(true); $oControllerMock->expects($this->never())->method('getTotpObject')->willReturn(true);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -298,17 +317,20 @@ class d3_account_totpTest extends d3TotpUnitTestCase
{ {
$_GET['totp_use'] = '0'; $_GET['totp_use'] = '0';
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'delete' ->disableOriginalConstructor()
), array(), '', false); ->onlyMethods(['delete'])
->getMock();
$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|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_account_totp::class, array( $oControllerMock = $this->getMockBuilder(d3_account_totp::class)
'getTotpObject', ->onlyMethods([
'getUser' 'getTotpObject',
)); 'getUser'
])
->getMock();
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock); $oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
$oControllerMock->expects($this->once())->method('getUser')->willReturn(false); $oControllerMock->expects($this->once())->method('getUser')->willReturn(false);
@ -325,22 +347,27 @@ class d3_account_totpTest extends d3TotpUnitTestCase
{ {
$_GET['totp_use'] = '0'; $_GET['totp_use'] = '0';
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'delete', ->disableOriginalConstructor()
'loadByUserId' ->onlyMethods([
), array(), '', false); 'delete',
'loadByUserId'
])
->getMock();
$oTotpMock->expects($this->once())->method('delete')->willReturn(true); $oTotpMock->expects($this->once())->method('delete')->willReturn(true);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
$oUser = oxNew(User::class); $oUser = oxNew(User::class);
$oUser->setId('foo'); $oUser->setId('foo');
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_account_totp|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_account_totp::class, array( $oControllerMock = $this->getMockBuilder(d3_account_totp::class)
'getTotpObject', ->onlyMethods([
'getUser' 'getTotpObject',
)); 'getUser'
])
->getMock();
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock); $oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
$oControllerMock->expects($this->once())->method('getUser')->willReturn($oUser); $oControllerMock->expects($this->once())->method('getUser')->willReturn($oUser);
@ -357,7 +384,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
{ {
$this->assertInstanceOf( $this->assertInstanceOf(
d3totp::class, d3totp::class,
$this->callMethod($this->_oController, 'getTotpObject') $this->callMethod(
$this->_oController,
'getTotpObject'
)
); );
} }
} }

View File

@ -19,7 +19,7 @@ use D3\Totp\Application\Model\d3totp;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Utils; use OxidEsales\Eshop\Core\Utils;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
class d3totploginTest extends d3TotpUnitTestCase class d3totploginTest extends d3TotpUnitTestCase
@ -30,7 +30,7 @@ class d3totploginTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -40,7 +40,7 @@ class d3totploginTest extends d3TotpUnitTestCase
Registry::getSession()->deleteVariable(d3totp::TOTP_SESSION_CURRENTCLASS); Registry::getSession()->deleteVariable(d3totp::TOTP_SESSION_CURRENTCLASS);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();
@ -53,16 +53,16 @@ class d3totploginTest extends d3TotpUnitTestCase
*/ */
public function renderRedirectIfNoTotp() public function renderRedirectIfNoTotp()
{ {
/** @var Utils|PHPUnit_Framework_MockObject_MockObject $oUtilsMock */ /** @var Utils|MockObject $oUtilsMock */
$oUtilsMock = $this->getMock(Utils::class, array( $oUtilsMock = $this->getMockBuilder(Utils::class)
'redirect' ->onlyMethods(['redirect'])
)); ->getMock();
$oUtilsMock->expects($this->once())->method('redirect')->willReturn(true); $oUtilsMock->expects($this->once())->method('redirect')->willReturn(true);
/** @var d3totplogin|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3totplogin|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3totplogin::class, array( $oControllerMock = $this->getMockBuilder(d3totplogin::class)
'getUtils' ->onlyMethods(['getUtils'])
)); ->getMock();
$oControllerMock->method('getUtils')->willReturn($oUtilsMock); $oControllerMock->method('getUtils')->willReturn($oUtilsMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -78,16 +78,16 @@ class d3totploginTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, 'foo'); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, 'foo');
/** @var Utils|PHPUnit_Framework_MockObject_MockObject $oUtilsMock */ /** @var Utils|MockObject $oUtilsMock */
$oUtilsMock = $this->getMock(Utils::class, array( $oUtilsMock = $this->getMockBuilder(Utils::class)
'redirect' ->onlyMethods(['redirect'])
)); ->getMock();
$oUtilsMock->expects($this->never())->method('redirect')->willReturn(true); $oUtilsMock->expects($this->never())->method('redirect')->willReturn(true);
/** @var d3totplogin|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3totplogin|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3totplogin::class, array( $oControllerMock = $this->getMockBuilder(d3totplogin::class)
'getUtils' ->onlyMethods(['getUtils'])
)); ->getMock();
$oControllerMock->method('getUtils')->willReturn($oUtilsMock); $oControllerMock->method('getUtils')->willReturn($oUtilsMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -106,7 +106,10 @@ class d3totploginTest extends d3TotpUnitTestCase
{ {
$this->assertInstanceOf( $this->assertInstanceOf(
Utils::class, Utils::class,
$this->callMethod($this->_oController, 'getUtils') $this->callMethod(
$this->_oController,
'getUtils'
)
); );
} }
@ -116,16 +119,16 @@ class d3totploginTest extends d3TotpUnitTestCase
*/ */
public function getBackupCodeCountMessageReturnMessage() public function getBackupCodeCountMessageReturnMessage()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodesListMock */ /** @var d3backupcodelist|MockObject $oBackupCodesListMock */
$oBackupCodesListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodesListMock = $this->getMockBuilder(d3backupcodelist::class)
'getAvailableCodeCount' ->onlyMethods(['getAvailableCodeCount'])
)); ->getMock();
$oBackupCodesListMock->method('getAvailableCodeCount')->willReturn(1); $oBackupCodesListMock->method('getAvailableCodeCount')->willReturn(1);
/** @var d3totplogin|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3totplogin|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3totplogin::class, array( $oControllerMock = $this->getMockBuilder(d3totplogin::class)
'getBackupCodeListObject' ->onlyMethods(['getBackupCodeListObject'])
)); ->getMock();
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodesListMock); $oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodesListMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -145,16 +148,16 @@ class d3totploginTest extends d3TotpUnitTestCase
*/ */
public function getBackupCodeCountMessageReturnNoMessage() public function getBackupCodeCountMessageReturnNoMessage()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodesListMock */ /** @var d3backupcodelist|MockObject $oBackupCodesListMock */
$oBackupCodesListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodesListMock = $this->getMockBuilder(d3backupcodelist::class)
'getAvailableCodeCount' ->onlyMethods(['getAvailableCodeCount'])
)); ->getMock();
$oBackupCodesListMock->method('getAvailableCodeCount')->willReturn(1234); $oBackupCodesListMock->method('getAvailableCodeCount')->willReturn(1234);
/** @var d3totplogin|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3totplogin|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3totplogin::class, array( $oControllerMock = $this->getMockBuilder(d3totplogin::class)
'getBackupCodeListObject' ->onlyMethods(['getBackupCodeListObject'])
)); ->getMock();
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodesListMock); $oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodesListMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -263,9 +266,9 @@ class d3totploginTest extends d3TotpUnitTestCase
{ {
$aBreadCrumb = $this->callMethod($this->_oController, 'getBreadCrumb'); $aBreadCrumb = $this->callMethod($this->_oController, 'getBreadCrumb');
$this->assertInternalType('string', $aBreadCrumb[0]['title']); $this->assertIsString($aBreadCrumb[0]['title']);
$this->assertTrue(strlen($aBreadCrumb[0]['title']) > 1); $this->assertTrue(strlen($aBreadCrumb[0]['title']) > 1);
$this->assertInternalType('string', $aBreadCrumb[0]['link']); $this->assertIsString($aBreadCrumb[0]['link']);
$this->assertTrue(strlen($aBreadCrumb[0]['link']) > 1); $this->assertTrue(strlen($aBreadCrumb[0]['link']) > 1);
} }
} }

View File

@ -25,14 +25,14 @@ class d3totp_wrongOtpExceptionTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oModel = oxNew(d3totp_wrongOtpException::class); $this->_oModel = oxNew(d3totp_wrongOtpException::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();

View File

@ -25,14 +25,14 @@ class d3RandomGeneratorTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oModel = oxNew(d3RandomGenerator::class); $this->_oModel = oxNew(d3RandomGenerator::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();

View File

@ -18,7 +18,7 @@ use D3\Totp\Application\Model\d3totp;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
class d3backupcodeTest extends d3TotpUnitTestCase class d3backupcodeTest extends d3TotpUnitTestCase
@ -29,14 +29,14 @@ class d3backupcodeTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oModel = oxNew(d3backupcode::class); $this->_oModel = oxNew(d3backupcode::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();
@ -52,11 +52,13 @@ class d3backupcodeTest extends d3TotpUnitTestCase
$sTestUserId = 'testUserId'; $sTestUserId = 'testUserId';
$sBackupCode = '123456'; $sBackupCode = '123456';
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3backupcode|MockObject $oModelMock */
$oModelMock = $this->getMock(d3backupcode::class, array( $oModelMock = $this->getMockBuilder(d3backupcode::class)
'getRandomTotpBackupCode', ->onlyMethods([
'd3EncodeBC', 'getRandomTotpBackupCode',
)); 'd3EncodeBC'
])
->getMock();
$oModelMock->method('getRandomTotpBackupCode')->willReturn($sBackupCode); $oModelMock->method('getRandomTotpBackupCode')->willReturn($sBackupCode);
$oModelMock->method('d3EncodeBC')->will( $oModelMock->method('d3EncodeBC')->will(
$this->returnCallback(function ($arg) { $this->returnCallback(function ($arg) {
@ -90,26 +92,29 @@ class d3backupcodeTest extends d3TotpUnitTestCase
*/ */
public function d3EncodeBCPass() public function d3EncodeBCPass()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array('load'), array(), '', false); $oUserMock = $this->getMockBuilder(User::class)
->onlyMethods(['load'])
->disableOriginalConstructor()
->getMock();
$oUserMock->method('load')->willReturn(true); $oUserMock->method('load')->willReturn(true);
$oUserMock->assign( $oUserMock->assign(
array( [
'oxpasssalt' => 'abcdefghijk' 'oxpasssalt' => '6162636465666768696A6B'
) ]
); );
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3backupcode|MockObject $oModelMock */
$oModelMock = $this->getMock(d3backupcode::class, array( $oModelMock = $this->getMockBuilder(d3backupcode::class)
'd3GetUser', ->onlyMethods(['d3GetUserObject'])
)); ->getMock();
$oModelMock->method('d3GetUserObject')->willReturn($oUserMock); $oModelMock->method('d3GetUserObject')->willReturn($oUserMock);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
$this->assertSame( $this->assertSame(
'e10adc3949ba59abbe56e057f20f883e', '9f7f502a8148f90732a4aa4d880b8cf5',
$this->callMethod($this->_oModel, 'd3EncodeBC', array('123456', 'userId')) $this->callMethod($this->_oModel, 'd3EncodeBC', ['123456', 'userId'])
); );
} }
@ -119,12 +124,14 @@ class d3backupcodeTest extends d3TotpUnitTestCase
*/ */
public function d3GetUserReturnCachedUser() public function d3GetUserReturnCachedUser()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array(), array(), '', false); $oUserMock = $this->getMockBuilder(User::class)
->disableOriginalConstructor()
->getMock();
$oUserMock->assign( $oUserMock->assign(
array( [
'oxid' => 'foobar' 'oxid' => 'foobar'
) ]
); );
$this->_oModel->setUser($oUserMock); $this->_oModel->setUser($oUserMock);

View File

@ -20,7 +20,7 @@ use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database; use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
class d3backupcodelistTest extends d3TotpUnitTestCase class d3backupcodelistTest extends d3TotpUnitTestCase
@ -31,14 +31,14 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oModel = oxNew(d3backupcodelist::class); $this->_oModel = oxNew(d3backupcodelist::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();
@ -51,31 +51,32 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
*/ */
public function generateBackupCodes() public function generateBackupCodes()
{ {
/** @var FrontendController|PHPUnit_Framework_MockObject_MockObject $oConfigMock */ /** @var FrontendController|MockObject $oConfigMock */
$oViewMock = $this->getMock(FrontendController::class, array( $oViewMock = $this->getMockBuilder(FrontendController::class)
'setBackupCodes' ->addMethods(['setBackupCodes'])
)); ->getMock();
$oViewMock->expects($this->once())->method('setBackupCodes')->willReturn(true); $oViewMock->expects($this->once())->method('setBackupCodes')->willReturn(true);
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oConfigMock */ /** @var Config|MockObject $oConfigMock */
$oConfigMock = $this->getMock(d3backupcode::class, array( $oConfigMock = $this->getMockBuilder(Config::class)
'getActiveView' ->onlyMethods(['getActiveView'])
)); ->getMock();
$oConfigMock->method('getActiveView')->willReturn($oViewMock); $oConfigMock->method('getActiveView')->willReturn($oViewMock);
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */ /** @var d3backupcode|MockObject $oBackupCodeMock */
$oBackupCodeMock = $this->getMock(d3backupcode::class, array( $oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
'generateCode' ->onlyMethods(['generateCode'])
)); ->getMock();
$oBackupCodeMock->expects($this->exactly(10))->method('generateCode'); $oBackupCodeMock->expects($this->exactly(10))->method('generateCode');
$oBackupCodeMock->method('getD3BackupCodeObject')->willReturn($oBackupCodeMock);
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3backupcodelist|MockObject $oModelMock */
$oModelMock = $this->getMock(d3backupcodelist::class, array( $oModelMock = $this->getMockBuilder(d3backupcodelist::class)
'deleteAllFromUser', ->onlyMethods([
'getD3BackupCodeObject', 'deleteAllFromUser',
'd3GetConfig' 'getD3BackupCodeObject',
)); 'd3GetConfig'
])
->getMock();
$oModelMock->expects($this->once())->method('deleteAllFromUser')->willReturn(true); $oModelMock->expects($this->once())->method('deleteAllFromUser')->willReturn(true);
$oModelMock->method('getD3BackupCodeObject')->willReturn($oBackupCodeMock); $oModelMock->method('getD3BackupCodeObject')->willReturn($oBackupCodeMock);
$oModelMock->method('d3GetConfig')->willReturn($oConfigMock); $oModelMock->method('d3GetConfig')->willReturn($oConfigMock);
@ -115,20 +116,20 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
*/ */
public function savePass() public function savePass()
{ {
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */ /** @var d3backupcode|MockObject $oBackupCodeMock */
$oBackupCodeMock = $this->getMock(d3backupcode::class, array( $oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
'save' ->onlyMethods(['save'])
)); ->getMock();
$oBackupCodeMock->expects($this->once())->method('save')->willReturn(true); $oBackupCodeMock->expects($this->once())->method('save')->willReturn(true);
$aBackupCodeArray = [ $aBackupCodeArray = [
$oBackupCodeMock $oBackupCodeMock
]; ];
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3backupcodelist|MockObject $oModelMock */
$oModelMock = $this->getMock(d3backupcodelist::class, array( $oModelMock = $this->getMockBuilder(d3backupcodelist::class)
'getArray' ->onlyMethods(['getArray'])
)); ->getMock();
$oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray); $oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -144,7 +145,7 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
{ {
$oBaseObject = $this->callMethod($this->_oModel, 'getBaseObject'); $oBaseObject = $this->callMethod($this->_oModel, 'getBaseObject');
$this->assertInternalType('object', $oBaseObject); $this->assertIsObject($oBaseObject);
$this->assertInstanceOf(d3backupcode::class, $oBaseObject); $this->assertInstanceOf(d3backupcode::class, $oBaseObject);
} }
@ -154,34 +155,39 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
*/ */
public function verifyFoundTotp() public function verifyFoundTotp()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'getId' ->onlyMethods(['getId'])
)); ->getMock();
$oUserMock->method('getId')->willReturn('foobar'); $oUserMock->method('getId')->willReturn('foobar');
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */ /** @var d3backupcode|MockObject $oBackupCodeMock */
$oBackupCodeMock = $this->getMock(d3backupcode::class, array( $oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
'delete' ->onlyMethods(['delete'])
)); ->getMock();
$oBackupCodeMock->expects($this->once())->method('delete')->willReturn(true); $oBackupCodeMock->expects($this->once())->method('delete')->willReturn(true);
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */ /** @var Database|MockObject $oDbMock */
$oDbMock = $this->getMock(Database::class, array( $oDbMock = $this->getMockBuilder(Database::class)
'getOne', ->onlyMethods([
'quoteIdentifier', 'getOne',
'quote', 'quoteIdentifier',
), array(), '', false); 'quote'
])
->disableOriginalConstructor()
->getMock();
$oDbMock->expects($this->once())->method('getOne')->willReturn('foobar'); $oDbMock->expects($this->once())->method('getOne')->willReturn('foobar');
$oDbMock->method('quoteIdentifier')->willReturn(true); $oDbMock->method('quoteIdentifier')->willReturn(true);
$oDbMock->method('quote')->willReturn(true); $oDbMock->method('quote')->willReturn(true);
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3backupcodelist|MockObject $oModelMock */
$oModelMock = $this->getMock(d3backupcodelist::class, array( $oModelMock = $this->getMockBuilder(d3backupcodelist::class)
'd3GetDb', ->onlyMethods([
'getBaseObject', 'd3GetDb',
'd3GetUser' 'getBaseObject',
)); 'd3GetUser'
])
->getMock();
$oModelMock->method('d3GetDb')->willReturn($oDbMock); $oModelMock->method('d3GetDb')->willReturn($oDbMock);
$oModelMock->method('getBaseObject')->willReturn($oBackupCodeMock); $oModelMock->method('getBaseObject')->willReturn($oBackupCodeMock);
$oModelMock->method('d3GetUser')->willReturn($oUserMock); $oModelMock->method('d3GetUser')->willReturn($oUserMock);
@ -199,34 +205,39 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
*/ */
public function verifyNotFoundTotp() public function verifyNotFoundTotp()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'getId' ->onlyMethods(['getId'])
)); ->getMock();
$oUserMock->method('getId')->willReturn('foobar'); $oUserMock->method('getId')->willReturn('foobar');
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */ /** @var d3backupcode|MockObject $oBackupCodeMock */
$oBackupCodeMock = $this->getMock(d3backupcode::class, array( $oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
'delete' ->onlyMethods(['delete'])
)); ->getMock();
$oBackupCodeMock->expects($this->never())->method('delete')->willReturn(true); $oBackupCodeMock->expects($this->never())->method('delete')->willReturn(true);
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */ /** @var Database|MockObject $oDbMock */
$oDbMock = $this->getMock(Database::class, array( $oDbMock = $this->getMockBuilder(Database::class)
'getOne', ->onlyMethods([
'quoteIdentifier', 'getOne',
'quote', 'quoteIdentifier',
), array(), '', false); 'quote',
])
->disableOriginalConstructor()
->getMock();
$oDbMock->expects($this->once())->method('getOne')->willReturn(null); $oDbMock->expects($this->once())->method('getOne')->willReturn(null);
$oDbMock->method('quoteIdentifier')->willReturn(true); $oDbMock->method('quoteIdentifier')->willReturn(true);
$oDbMock->method('quote')->willReturn(true); $oDbMock->method('quote')->willReturn(true);
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3backupcodelist|MockObject $oModelMock */
$oModelMock = $this->getMock(d3backupcodelist::class, array( $oModelMock = $this->getMockBuilder(d3backupcodelist::class)
'd3GetDb', ->onlyMethods([
'getBaseObject', 'd3GetDb',
'd3GetUser' 'getBaseObject',
)); 'd3GetUser'
])
->getMock();
$oModelMock->method('d3GetDb')->willReturn($oDbMock); $oModelMock->method('d3GetDb')->willReturn($oDbMock);
$oModelMock->method('getBaseObject')->willReturn($oBackupCodeMock); $oModelMock->method('getBaseObject')->willReturn($oBackupCodeMock);
$oModelMock->method('d3GetUser')->willReturn($oUserMock); $oModelMock->method('d3GetUser')->willReturn($oUserMock);
@ -256,30 +267,35 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
*/ */
public function deleteAllFromUserCodesFound() public function deleteAllFromUserCodesFound()
{ {
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */ /** @var Database|MockObject $oDbMock */
$oDbMock = $this->getMock(Database::class, array( $oDbMock = $this->getMockBuilder(Database::class)
'quoteIdentifier', ->disableOriginalConstructor()
'quote', ->onlyMethods([
), array(), '', false); 'quoteIdentifier',
'quote',
])
->getMock();
$oDbMock->method('quoteIdentifier')->willReturn(true); $oDbMock->method('quoteIdentifier')->willReturn(true);
$oDbMock->method('quote')->willReturn(true); $oDbMock->method('quote')->willReturn(true);
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */ /** @var d3backupcode|MockObject $oBackupCodeMock */
$oBackupCodeMock = $this->getMock(d3backupcode::class, array( $oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
'delete' ->onlyMethods(['delete'])
)); ->getMock();
$oBackupCodeMock->expects($this->once())->method('delete')->willReturn(true); $oBackupCodeMock->expects($this->once())->method('delete')->willReturn(true);
$aBackupCodeArray = [ $aBackupCodeArray = [
$oBackupCodeMock $oBackupCodeMock
]; ];
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3backupcodelist|MockObject $oModelMock */
$oModelMock = $this->getMock(d3backupcodelist::class, array( $oModelMock = $this->getMockBuilder(d3backupcodelist::class)
'getArray', ->onlyMethods([
'selectString', 'getArray',
'd3GetDb' 'selectString',
)); 'd3GetDb'
])
->getMock();
$oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray); $oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray);
$oModelMock->expects($this->once())->method('selectString')->willReturn(true); $oModelMock->expects($this->once())->method('selectString')->willReturn(true);
$oModelMock->method('d3GetDb')->willReturn($oDbMock); $oModelMock->method('d3GetDb')->willReturn($oDbMock);
@ -295,28 +311,33 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
*/ */
public function deleteAllFromUserNoCodesFound() public function deleteAllFromUserNoCodesFound()
{ {
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */ /** @var Database|MockObject $oDbMock */
$oDbMock = $this->getMock(Database::class, array( $oDbMock = $this->getMockBuilder(Database::class)
'quoteIdentifier', ->onlyMethods([
'quote', 'quoteIdentifier',
), array(), '', false); 'quote',
])
->disableOriginalConstructor()
->getMock();
$oDbMock->method('quoteIdentifier')->willReturn(true); $oDbMock->method('quoteIdentifier')->willReturn(true);
$oDbMock->method('quote')->willReturn(true); $oDbMock->method('quote')->willReturn(true);
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */ /** @var d3backupcode|MockObject $oBackupCodeMock */
$oBackupCodeMock = $this->getMock(d3backupcode::class, array( $oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
'delete' ->onlyMethods(['delete'])
)); ->getMock();
$oBackupCodeMock->expects($this->never())->method('delete')->willReturn(true); $oBackupCodeMock->expects($this->never())->method('delete')->willReturn(true);
$aBackupCodeArray = []; $aBackupCodeArray = [];
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3backupcodelist|MockObject $oModelMock */
$oModelMock = $this->getMock(d3backupcodelist::class, array( $oModelMock = $this->getMockBuilder(d3backupcodelist::class)
'getArray', ->onlyMethods([
'selectString', 'getArray',
'd3GetDb' 'selectString',
)); 'd3GetDb'
])
->getMock();
$oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray); $oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray);
$oModelMock->expects($this->once())->method('selectString')->willReturn(true); $oModelMock->expects($this->once())->method('selectString')->willReturn(true);
$oModelMock->method('d3GetDb')->willReturn($oDbMock); $oModelMock->method('d3GetDb')->willReturn($oDbMock);
@ -332,20 +353,23 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
*/ */
public function getAvailableCodeCountPass() public function getAvailableCodeCountPass()
{ {
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */ /** @var Database|MockObject $oDbMock */
$oDbMock = $this->getMock(Database::class, array( $oDbMock = $this->getMockBuilder(Database::class)
'getOne', ->onlyMethods([
'quoteIdentifier', 'getOne',
'quote', 'quoteIdentifier',
), array(), '', false); 'quote'
])
->disableOriginalConstructor()
->getMock();
$oDbMock->expects($this->once())->method('getOne')->willReturn('25'); $oDbMock->expects($this->once())->method('getOne')->willReturn('25');
$oDbMock->method('quoteIdentifier')->willReturn(true); $oDbMock->method('quoteIdentifier')->willReturn(true);
$oDbMock->method('quote')->willReturn(true); $oDbMock->method('quote')->willReturn(true);
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3backupcodelist|MockObject $oModelMock */
$oModelMock = $this->getMock(d3backupcodelist::class, array( $oModelMock = $this->getMockBuilder(d3backupcodelist::class)
'd3GetDb', ->onlyMethods(['d3GetDb'])
)); ->getMock();
$oModelMock->method('d3GetDb')->willReturn($oDbMock); $oModelMock->method('d3GetDb')->willReturn($oDbMock);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;

View File

@ -23,8 +23,9 @@ use OTPHP\TOTP;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database; use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
use stdClass;
class d3totpTest extends d3TotpUnitTestCase class d3totpTest extends d3TotpUnitTestCase
{ {
@ -34,14 +35,14 @@ class d3totpTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oModel = oxNew(d3totp::class); $this->_oModel = oxNew(d3totp::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();
@ -54,10 +55,10 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function constructCallsInit() public function constructCallsInit()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'init', ->onlyMethods(['init'])
)); ->getMock();
$oModelMock->expects($this->once())->method('init'); $oModelMock->expects($this->once())->method('init');
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -71,17 +72,20 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function loadByUserIdTableNotExist() public function loadByUserIdTableNotExist()
{ {
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */ /** @var Database|MockObject $oDbMock */
$oDbMock = $this->getMock(Database::class, array( $oDbMock = $this->getMockBuilder(Database::class)
'getOne' ->disableOriginalConstructor()
), array(), '', false); ->onlyMethods(['getOne'])
->getMock();
$oDbMock->expects($this->once())->method('getOne')->willReturnOnConsecutiveCalls(false, true); $oDbMock->expects($this->once())->method('getOne')->willReturnOnConsecutiveCalls(false, true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'd3GetDb', ->onlyMethods([
'load' 'd3GetDb',
)); 'load'
])
->getMock();
$oModelMock->method('d3GetDb')->willReturn($oDbMock); $oModelMock->method('d3GetDb')->willReturn($oDbMock);
$oModelMock->expects($this->never())->method('load')->willReturn(true); $oModelMock->expects($this->never())->method('load')->willReturn(true);
@ -96,19 +100,23 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function loadByUserIdTableExist() public function loadByUserIdTableExist()
{ {
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */ /** @var Database|MockObject $oDbMock */
$oDbMock = $this->getMock(Database::class, array( $oDbMock = $this->getMockBuilder(Database::class)
'getOne', ->disableOriginalConstructor()
'quote' ->onlyMethods([
), array(), '', false); 'getOne',
'quote'
])->getMock();
$oDbMock->expects($this->exactly(2))->method('getOne')->willReturnOnConsecutiveCalls(true, true); $oDbMock->expects($this->exactly(2))->method('getOne')->willReturnOnConsecutiveCalls(true, true);
$oDbMock->method('quote')->willReturn(true); $oDbMock->method('quote')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'd3GetDb', ->onlyMethods([
'load' 'd3GetDb',
)); 'load'
])
->getMock();
$oModelMock->method('d3GetDb')->willReturn($oDbMock); $oModelMock->method('d3GetDb')->willReturn($oDbMock);
$oModelMock->expects($this->once())->method('load')->willReturn(true); $oModelMock->expects($this->once())->method('load')->willReturn(true);
@ -123,17 +131,19 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function getUserFromMember() public function getUserFromMember()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'load' ->onlyMethods(['load'])
)); ->getMock();
$oUserMock->method('load')->with('foobar')->willReturn(true); $oUserMock->method('load')->with('foobar')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'd3GetUser', ->onlyMethods([
'getFieldData', 'd3GetUser',
)); 'getFieldData',
])
->getMock();
$oModelMock->method('d3GetUser')->willReturn($oUserMock); $oModelMock->method('d3GetUser')->willReturn($oUserMock);
$oModelMock->expects($this->never())->method('getFieldData')->willReturn(true); $oModelMock->expects($this->never())->method('getFieldData')->willReturn(true);
@ -155,17 +165,19 @@ class d3totpTest extends d3TotpUnitTestCase
{ {
$this->setValue($this->_oModel, 'userId', null); $this->setValue($this->_oModel, 'userId', null);
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'load' ->onlyMethods(['load'])
)); ->getMock();
$oUserMock->method('load')->with('barfoo')->willReturn(true); $oUserMock->method('load')->with('barfoo')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'd3GetUser', ->onlyMethods([
'getFieldData', 'd3GetUser',
)); 'getFieldData',
])
->getMock();
$oModelMock->method('d3GetUser')->willReturn($oUserMock); $oModelMock->method('d3GetUser')->willReturn($oUserMock);
$oModelMock->expects($this->once())->method('getFieldData')->willReturn('barfoo'); $oModelMock->expects($this->once())->method('getFieldData')->willReturn('barfoo');
@ -183,18 +195,21 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function checkIfAlreadyExistPass() public function checkIfAlreadyExistPass()
{ {
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */ /** @var Database|MockObject $oDbMock */
$oDbMock = $this->getMock(Database::class, array( $oDbMock = $this->getMockBuilder(Database::class)
'getOne', ->onlyMethods([
'quote' 'getOne',
), array(), '', false); 'quote'
])
->disableOriginalConstructor()
->getMock();
$oDbMock->expects($this->once())->method('getOne')->willReturn(1); $oDbMock->expects($this->once())->method('getOne')->willReturn(1);
$oDbMock->method('quote')->willReturn(true); $oDbMock->method('quote')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'd3GetDb' ->onlyMethods(['d3GetDb'])
)); ->getMock();
$oModelMock->method('d3GetDb')->willReturn($oDbMock); $oModelMock->method('d3GetDb')->willReturn($oDbMock);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -236,10 +251,10 @@ class d3totpTest extends d3TotpUnitTestCase
{ {
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', false); Registry::getConfig()->setConfigParam('blDisableTotpGlobally', false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'UserUseTotp', ->onlyMethods(['UserUseTotp'])
)); ->getMock();
$oModelMock->method('UserUseTotp')->willReturn(true); $oModelMock->method('UserUseTotp')->willReturn(true);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -257,10 +272,10 @@ class d3totpTest extends d3TotpUnitTestCase
{ {
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', false); Registry::getConfig()->setConfigParam('blDisableTotpGlobally', false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'UserUseTotp', ->onlyMethods(['UserUseTotp'])
)); ->getMock();
$oModelMock->method('UserUseTotp')->willReturn(false); $oModelMock->method('UserUseTotp')->willReturn(false);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -278,10 +293,10 @@ class d3totpTest extends d3TotpUnitTestCase
{ {
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', true); Registry::getConfig()->setConfigParam('blDisableTotpGlobally', true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'UserUseTotp', ->onlyMethods(['UserUseTotp'])
)); ->getMock();
$oModelMock->method('UserUseTotp')->willReturn(true); $oModelMock->method('UserUseTotp')->willReturn(true);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -299,10 +314,10 @@ class d3totpTest extends d3TotpUnitTestCase
{ {
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', true); Registry::getConfig()->setConfigParam('blDisableTotpGlobally', true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'UserUseTotp', ->onlyMethods(['UserUseTotp'])
)); ->getMock();
$oModelMock->method('UserUseTotp')->willReturn(false); $oModelMock->method('UserUseTotp')->willReturn(false);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -318,10 +333,10 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function UserUseTotpPass() public function UserUseTotpPass()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getFieldData', ->onlyMethods(['getFieldData'])
)); ->getMock();
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(true, true); $oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(true, true);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -337,10 +352,10 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function UserUseTotpNoTotp() public function UserUseTotpNoTotp()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getFieldData', ->onlyMethods(['getFieldData'])
)); ->getMock();
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(false, true); $oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(false, true);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -356,10 +371,10 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function UserUseTotpNoSeed() public function UserUseTotpNoSeed()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getFieldData', ->onlyMethods(['getFieldData'])
)); ->getMock();
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(true, false); $oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(true, false);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -375,10 +390,10 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function UserUseTotpNoTotpAndNoSeed() public function UserUseTotpNoTotpAndNoSeed()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getFieldData', ->onlyMethods(['getFieldData'])
)); ->getMock();
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(false, false); $oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(false, false);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -394,11 +409,13 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function getSavedSecretExistingSeed() public function getSavedSecretExistingSeed()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getFieldData', ->onlyMethods([
'decrypt', 'getFieldData',
)); 'decrypt'
])
->getMock();
$oModelMock->method('getFieldData')->willReturn('seed'); $oModelMock->method('getFieldData')->willReturn('seed');
$oModelMock->method('decrypt')->willReturn('unencseed'); $oModelMock->method('decrypt')->willReturn('unencseed');
@ -416,11 +433,13 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function getSavedSecretNoSeed() public function getSavedSecretNoSeed()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getFieldData', ->onlyMethods([
'decrypt', 'getFieldData',
)); 'decrypt'
])
->getMock();
$oModelMock->method('getFieldData')->willReturn(null); $oModelMock->method('getFieldData')->willReturn(null);
$oModelMock->method('decrypt')->willReturn('unencseed'); $oModelMock->method('decrypt')->willReturn('unencseed');
@ -437,11 +456,13 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function getSavedSecretCantDecrypt() public function getSavedSecretCantDecrypt()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getFieldData', ->onlyMethods([
'decrypt', 'getFieldData',
)); 'decrypt'
])
->getMock();
$oModelMock->method('getFieldData')->willReturn('seed'); $oModelMock->method('getFieldData')->willReturn('seed');
$oModelMock->method('decrypt')->willReturn(false); $oModelMock->method('decrypt')->willReturn(false);
@ -458,8 +479,10 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function getTotpReturnsCachedObject() public function getTotpReturnsCachedObject()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array(), array(), '', false); $oTotpMock = $this->getMockBuilder(d3totp::class)
->disableOriginalConstructor()
->getMock();
$this->setValue($this->_oModel, 'totp', $oTotpMock); $this->setValue($this->_oModel, 'totp', $oTotpMock);
@ -475,17 +498,19 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function getTotpReturnsNewObject() public function getTotpReturnsNewObject()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'getFieldData', ->onlyMethods(['getFieldData'])
)); ->getMock();
$oUserMock->method('getFieldData')->willReturn('username'); $oUserMock->method('getFieldData')->willReturn('username');
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getUser', ->onlyMethods([
'getSavedSecret' 'getUser',
)); 'getSavedSecret'
])
->getMock();
$oModelMock->method('getUser')->willReturn($oUserMock); $oModelMock->method('getUser')->willReturn($oUserMock);
$oModelMock->method('getSavedSecret')->willReturn('savedSecret'); $oModelMock->method('getSavedSecret')->willReturn('savedSecret');
@ -505,17 +530,21 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function getTotpReturnsNewObjectNoUserGivenSeed() public function getTotpReturnsNewObjectNoUserGivenSeed()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'getFieldData', ->onlyMethods(['getFieldData'])
)); ->getMock();
$oUserMock->method('getFieldData')->willReturn(false); $oUserMock->method('getFieldData')->willReturnMap(
[['oxusername', 'oxusername']]
);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getUser', ->onlyMethods([
'getSavedSecret' 'getUser',
)); 'getSavedSecret'
])
->getMock();
$oModelMock->method('getUser')->willReturn($oUserMock); $oModelMock->method('getUser')->willReturn($oUserMock);
$oModelMock->method('getSavedSecret')->willReturn('savedSecret'); $oModelMock->method('getSavedSecret')->willReturn('savedSecret');
@ -525,33 +554,10 @@ class d3totpTest extends d3TotpUnitTestCase
$oTotp = $this->callMethod($this->_oModel, 'getTotp', ['givenSeed']); $oTotp = $this->callMethod($this->_oModel, 'getTotp', ['givenSeed']);
$this->assertInstanceOf(TOTP::class, $oTotp); $this->assertInstanceOf(TOTP::class, $oTotp);
$this->assertSame(null, $oTotp->getLabel()); $this->assertSame('oxusername', $oTotp->getLabel());
$this->assertSame('GIVENSEED', $oTotp->getSecret()); $this->assertSame('GIVENSEED', $oTotp->getSecret());
} }
/**
* @test
* @throws ReflectionException
*/
public function getQrCodeUriPass()
{
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array(
'getQrCodeUri'
));
$oTotpMock->expects($this->once())->method('getQrCodeUri')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array(
'getTotp'
));
$oModelMock->method('getTotp')->willReturn($oTotpMock);
$this->_oModel = $oModelMock;
$this->callMethod($this->_oModel, 'getQrCodeUri');
}
/** /**
* @test * @test
* @throws ReflectionException * @throws ReflectionException
@ -560,29 +566,24 @@ class d3totpTest extends d3TotpUnitTestCase
{ {
$renderer = BaconQrCodeFactory::renderer(200); $renderer = BaconQrCodeFactory::renderer(200);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var stdClass|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(stdClass::class)
'getProvisioningUri' ->addMethods(['getProvisioningUri'])
)); ->getMock();
$oTotpMock->method('getProvisioningUri')->willReturn(true); $oTotpMock->method('getProvisioningUri')->willReturn('uri');
/** @var Writer|PHPUnit_Framework_MockObject_MockObject $oWriterMock */ /** @var d3totp|MockObject $oModelMock */
$oWriterMock = $this->getMock(Writer::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'writeString' ->onlyMethods(['getTotp'])
), array($renderer)); ->disableOriginalConstructor()
$oWriterMock->expects($this->once())->method('writeString')->willReturn(true); ->getMock();
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array(
'd3GetWriter',
'getTotp'
));
$oModelMock->method('d3GetWriter')->willReturn($oWriterMock);
$oModelMock->method('getTotp')->willReturn($oTotpMock); $oModelMock->method('getTotp')->willReturn($oTotpMock);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
$this->callMethod($this->_oModel, 'getQrCodeElement'); $this->assertIsString(
$this->callMethod($this->_oModel, 'getQrCodeElement')
);
} }
/** /**
@ -591,7 +592,7 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function d3GetWriterReturnsRightInstance() public function d3GetWriterReturnsRightInstance()
{ {
$renderer = BaconQrCodeFactory::renderer(200);; $renderer = BaconQrCodeFactory::renderer(200);
$this->assertInstanceOf( $this->assertInstanceOf(
Writer::class, Writer::class,
@ -605,16 +606,16 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function getSecretPass() public function getSecretPass()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'getSecret' ->onlyMethods(['getSecret'])
)); ->getMock();
$oTotpMock->expects($this->once())->method('getSecret')->willReturn(true); $oTotpMock->expects($this->once())->method('getSecret')->willReturn('fixture');
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getTotp' ->onlyMethods(['getTotp'])
)); ->getMock();
$oModelMock->method('getTotp')->willReturn($oTotpMock); $oModelMock->method('getTotp')->willReturn($oTotpMock);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -628,10 +629,10 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function saveSecretPass() public function saveSecretPass()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'encrypt' ->onlyMethods(['encrypt'])
)); ->getMock();
$oModelMock->method('encrypt')->willReturn('enc_secret'); $oModelMock->method('encrypt')->willReturn('enc_secret');
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -649,16 +650,16 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function verifyPass() public function verifyPass()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify' ->onlyMethods(['verify'])
)); ->getMock();
$oTotpMock->expects($this->once())->method('verify')->willReturn(true); $oTotpMock->expects($this->once())->method('verify')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getTotp' ->onlyMethods(['getTotp'])
)); ->getMock();
$oModelMock->method('getTotp')->willReturn($oTotpMock); $oModelMock->method('getTotp')->willReturn($oTotpMock);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;
@ -674,23 +675,25 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function verifyBackupCodePass() public function verifyBackupCodePass()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */ /** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'verify' ->onlyMethods(['verify'])
)); ->getMock();
$oBackupCodeListMock->expects($this->once())->method('verify')->willReturn(true); $oBackupCodeListMock->expects($this->once())->method('verify')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify' ->onlyMethods(['verify'])
)); ->getMock();
$oTotpMock->expects($this->once())->method('verify')->willReturn(false); $oTotpMock->expects($this->once())->method('verify')->willReturn(false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getTotp', ->onlyMethods([
'd3GetBackupCodeListObject' 'getTotp',
)); 'd3GetBackupCodeListObject'
])
->getMock();
$oModelMock->method('getTotp')->willReturn($oTotpMock); $oModelMock->method('getTotp')->willReturn($oTotpMock);
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock); $oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
@ -707,25 +710,27 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function verifyFailed() public function verifyFailed()
{ {
$this->setExpectedException(d3totp_wrongOtpException::class); $this->expectException(d3totp_wrongOtpException::class);
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */ /** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'verify' ->onlyMethods(['verify'])
)); ->getMock();
$oBackupCodeListMock->expects($this->once())->method('verify')->willReturn(false); $oBackupCodeListMock->expects($this->once())->method('verify')->willReturn(false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify' ->onlyMethods(['verify'])
)); ->getMock();
$oTotpMock->expects($this->once())->method('verify')->willReturn(false); $oTotpMock->expects($this->once())->method('verify')->willReturn(false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getTotp', ->onlyMethods([
'd3GetBackupCodeListObject' 'getTotp',
)); 'd3GetBackupCodeListObject'
])
->getMock();
$oModelMock->method('getTotp')->willReturn($oTotpMock); $oModelMock->method('getTotp')->willReturn($oTotpMock);
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock); $oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
@ -740,25 +745,27 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function verifyWithSeedFailed() public function verifyWithSeedFailed()
{ {
$this->setExpectedException(d3totp_wrongOtpException::class); $this->expectException(d3totp_wrongOtpException::class);
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */ /** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'verify' ->onlyMethods(['verify'])
)); ->getMock();
$oBackupCodeListMock->expects($this->never())->method('verify')->willReturn(false); $oBackupCodeListMock->expects($this->never())->method('verify')->willReturn(false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify' ->onlyMethods(['verify'])
)); ->getMock();
$oTotpMock->expects($this->once())->method('verify')->willReturn(false); $oTotpMock->expects($this->once())->method('verify')->willReturn(false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'getTotp', ->onlyMethods([
'd3GetBackupCodeListObject' 'getTotp',
)); 'd3GetBackupCodeListObject'
])
->getMock();
$oModelMock->method('getTotp')->willReturn($oTotpMock); $oModelMock->method('getTotp')->willReturn($oTotpMock);
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock); $oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
@ -788,7 +795,7 @@ class d3totpTest extends d3TotpUnitTestCase
$sReturn = $this->callMethod($this->_oModel, 'encrypt', ['foobar']); $sReturn = $this->callMethod($this->_oModel, 'encrypt', ['foobar']);
// indirect tests, because string changes on every call // indirect tests, because string changes on every call
$this->assertInternalType('string', $sReturn); $this->assertIsString($sReturn);
$this->assertNotSame('foobar', $sReturn); $this->assertNotSame('foobar', $sReturn);
$this->assertStringEndsWith('==', $sReturn); $this->assertStringEndsWith('==', $sReturn);
$this->assertTrue(strlen($sReturn) === 88); $this->assertTrue(strlen($sReturn) === 88);
@ -815,10 +822,10 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function decryptFailed() public function decryptFailed()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'd3Base64_decode', ->onlyMethods(['d3Base64_decode'])
)); ->getMock();
$oModelMock->method('d3Base64_decode')->willReturn( $oModelMock->method('d3Base64_decode')->willReturn(
str_pad('foobar', 16, 0, STR_PAD_LEFT) str_pad('foobar', 16, 0, STR_PAD_LEFT)
); );
@ -852,18 +859,20 @@ class d3totpTest extends d3TotpUnitTestCase
*/ */
public function deletePass() public function deletePass()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */ /** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'deleteAllFromUser' ->onlyMethods(['deleteAllFromUser'])
)); ->getMock();
$oBackupCodeListMock->expects($this->once())->method('deleteAllFromUser')->willReturn(true); $oBackupCodeListMock->expects($this->once())->method('deleteAllFromUser')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3totp|MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array( $oModelMock = $this->getMockBuilder(d3totp::class)
'd3GetBackupCodeListObject', ->onlyMethods([
'getFieldData', 'd3GetBackupCodeListObject',
'canDelete' 'getFieldData',
)); 'canDelete'
])
->getMock();
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock); $oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
$oModelMock->method('getFieldData')->willReturn('newId'); $oModelMock->method('getFieldData')->willReturn('newId');
$oModelMock->method('canDelete')->willReturn(false); $oModelMock->method('canDelete')->willReturn(false);

View File

@ -23,7 +23,7 @@ use OxidEsales\Eshop\Core\Controller\BaseController;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Session; use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\Eshop\Core\UtilsView;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
class d3_totp_UserComponentTest extends d3TotpUnitTestCase class d3_totp_UserComponentTest extends d3TotpUnitTestCase
@ -34,7 +34,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -43,7 +43,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();
@ -58,28 +58,33 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
{ {
$oUser = false; $oUser = false;
/** @var BaseController|PHPUnit_Framework_MockObject_MockObject $oParentMock */ /** @var BaseController|MockObject $oParentMock */
$oParentMock = $this->getMock(BaseController::class, array( $oParentMock = $this->getMockBuilder(BaseController::class)
'isEnabledPrivateSales', ->addMethods(['isEnabledPrivateSales'])
)); ->getMock();
$oParentMock->method('isEnabledPrivateSales')->willReturn(false); $oParentMock->method('isEnabledPrivateSales')->willReturn(false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->onlyMethods(['isActive'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$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|MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMockBuilder(UserComponent::class)
'getUser', ->onlyMethods([
'd3GetTotpObject', 'getUser',
'getParent' 'd3GetTotpObject',
)); 'getParent'
])
->getMock();
$oControllerMock->method('getUser')->willReturn($oUser); $oControllerMock->method('getUser')->willReturn($oUser);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('getParent')->willReturn($oParentMock); $oControllerMock->method('getParent')->willReturn($oParentMock);
$_GET['lgn_usr'] = 'username';
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
$this->callMethod($this->_oController, 'login_noredirect'); $this->callMethod($this->_oController, 'login_noredirect');
@ -91,38 +96,47 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function login_noredirectFailTotpNotActive() public function login_noredirectFailTotpNotActive()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'logout', ->onlyMethods([
'getId', 'logout',
)); 'getId'
])
->getMock();
$oUserMock->expects($this->never())->method('logout')->willReturn(false); $oUserMock->expects($this->never())->method('logout')->willReturn(false);
$oUserMock->method('getId')->willReturn('foo'); $oUserMock->method('getId')->willReturn('foo');
/** @var BaseController|PHPUnit_Framework_MockObject_MockObject $oParentMock */ /** @var BaseController|MockObject $oParentMock */
$oParentMock = $this->getMock(BaseController::class, array( $oParentMock = $this->getMockBuilder(BaseController::class)
'isEnabledPrivateSales', ->addMethods(['isEnabledPrivateSales'])
)); ->getMock();
$oParentMock->method('isEnabledPrivateSales')->willReturn(false); $oParentMock->method('isEnabledPrivateSales')->willReturn(false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->onlyMethods([
'loadByUserId' 'isActive',
), array(), '', false); 'loadByUserId'
])
->disableOriginalConstructor()
->getMock();
$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);
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMockBuilder(UserComponent::class)
'getUser', ->onlyMethods([
'd3GetTotpObject', 'getUser',
'getParent' 'd3GetTotpObject',
)); 'getParent'
])
->getMock();
$oControllerMock->method('getUser')->willReturn($oUserMock); $oControllerMock->method('getUser')->willReturn($oUserMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('getParent')->willReturn($oParentMock); $oControllerMock->method('getParent')->willReturn($oParentMock);
$_GET['lgn_usr'] = 'username';
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
$this->callMethod($this->_oController, 'login_noredirect'); $this->callMethod($this->_oController, 'login_noredirect');
@ -134,38 +148,47 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function login_noredirectPass() public function login_noredirectPass()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'logout', ->onlyMethods([
'getId', 'logout',
)); 'getId',
])
->getMock();
$oUserMock->expects($this->once())->method('logout')->willReturn(false); $oUserMock->expects($this->once())->method('logout')->willReturn(false);
$oUserMock->method('getId')->willReturn('foo'); $oUserMock->method('getId')->willReturn('foo');
/** @var BaseController|PHPUnit_Framework_MockObject_MockObject $oParentMock */ /** @var BaseController|MockObject $oParentMock */
$oParentMock = $this->getMock(BaseController::class, array( $oParentMock = $this->getMockBuilder(BaseController::class)
'isEnabledPrivateSales', ->addMethods(['isEnabledPrivateSales'])
)); ->getMock();
$oParentMock->method('isEnabledPrivateSales')->willReturn(false); $oParentMock->method('isEnabledPrivateSales')->willReturn(false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->onlyMethods([
'loadByUserId' 'isActive',
), array(), '', false); 'loadByUserId'
])
->disableOriginalConstructor()
->getMock();
$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);
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMockBuilder(UserComponent::class)
'getUser', ->onlyMethods([
'd3GetTotpObject', 'getUser',
'getParent' 'd3GetTotpObject',
)); 'getParent'
])
->getMock();
$oControllerMock->method('getUser')->willReturn($oUserMock); $oControllerMock->method('getUser')->willReturn($oUserMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('getParent')->willReturn($oParentMock); $oControllerMock->method('getParent')->willReturn($oParentMock);
$_GET['lgn_usr'] = 'username';
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
$this->assertSame( $this->assertSame(
@ -192,19 +215,22 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function checkTotploginNoTotpLogin() public function checkTotploginNoTotpLogin()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'loadByUserId' ->onlyMethods(['loadByUserId'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMockBuilder(UserComponent::class)
'isNoTotpOrNoLogin', ->onlyMethods([
'hasValidTotp', 'isNoTotpOrNoLogin',
'd3TotpRelogin', 'hasValidTotp',
'd3GetTotpObject' 'd3TotpRelogin',
)); 'd3GetTotpObject'
])
->getMock();
$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);
@ -224,29 +250,34 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function checkTotploginUnvalidTotp() public function checkTotploginUnvalidTotp()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'loadByUserId' ->onlyMethods(['loadByUserId'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3totp_wrongOtpException|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */ /** @var d3totp_wrongOtpException|MockObject $oUtilsViewMock */
$oTotpExceptionMock = $this->getMock(d3totp_wrongOtpException::class, array(), array(), '', false); $oTotpExceptionMock = $this->getMockBuilder(d3totp_wrongOtpException::class)
->disableOriginalConstructor()
->getMock();
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */ /** @var UtilsView|MockObject $oUtilsViewMock */
$oUtilsViewMock = $this->getMock(UtilsView::class, array( $oUtilsViewMock = $this->getMockBuilder(UtilsView::class)
'addErrorToDisplay', ->onlyMethods(['addErrorToDisplay'])
)); ->getMock();
$oUtilsViewMock->expects($this->atLeast(1))->method('addErrorToDisplay')->willReturn(true); $oUtilsViewMock->expects($this->atLeast(1))->method('addErrorToDisplay')->willReturn(true);
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMockBuilder(UserComponent::class)
'isNoTotpOrNoLogin', ->onlyMethods([
'hasValidTotp', 'isNoTotpOrNoLogin',
'd3TotpRelogin', 'hasValidTotp',
'd3GetUtilsView', 'd3TotpRelogin',
'd3GetTotpObject' 'd3GetUtilsView',
)); 'd3GetTotpObject'
])
->getMock();
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false); $oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false);
$oControllerMock->expects($this->once())->method('hasValidTotp')->willThrowException($oTotpExceptionMock); $oControllerMock->expects($this->once())->method('hasValidTotp')->willThrowException($oTotpExceptionMock);
$oControllerMock->expects($this->never())->method('d3TotpRelogin')->willReturn(false); $oControllerMock->expects($this->never())->method('d3TotpRelogin')->willReturn(false);
@ -267,26 +298,29 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function checkTotploginValidTotp() public function checkTotploginValidTotp()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'loadByUserId' ->onlyMethods(['loadByUserId'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */ /** @var UtilsView|MockObject $oUtilsViewMock */
$oUtilsViewMock = $this->getMock(UtilsView::class, array( $oUtilsViewMock = $this->getMockBuilder(UtilsView::class)
'addErrorToDisplay', ->onlyMethods(['addErrorToDisplay'])
)); ->getMock();
$oUtilsViewMock->expects($this->never())->method('addErrorToDisplay')->willReturn(true); $oUtilsViewMock->expects($this->never())->method('addErrorToDisplay')->willReturn(true);
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMockBuilder(UserComponent::class)
'isNoTotpOrNoLogin', ->onlyMethods([
'hasValidTotp', 'isNoTotpOrNoLogin',
'd3TotpRelogin', 'hasValidTotp',
'd3GetUtilsView', 'd3TotpRelogin',
'd3GetTotpObject' 'd3GetUtilsView',
)); 'd3GetTotpObject'
])
->getMock();
$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);
@ -318,10 +352,10 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function canCancelTotpLogin() public function canCancelTotpLogin()
{ {
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMockBuilder(UserComponent::class)
'd3TotpClearSessionVariables', ->onlyMethods(['d3TotpClearSessionVariables'])
)); ->getMock();
$oControllerMock->expects($this->once())->method('d3TotpClearSessionVariables')->willReturn(false); $oControllerMock->expects($this->once())->method('d3TotpClearSessionVariables')->willReturn(false);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -337,10 +371,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, false); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->onlyMethods(['isActive'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
$this->assertTrue( $this->assertTrue(
@ -356,10 +391,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, true); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->onlyMethods(['isActive'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('isActive')->willReturn(false); $oTotpMock->method('isActive')->willReturn(false);
$this->assertTrue( $this->assertTrue(
@ -375,10 +411,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, true); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->onlyMethods(['isActive'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
$this->assertFalse( $this->assertFalse(
@ -394,10 +431,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, true); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify', ->onlyMethods(['verify'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(false); $oTotpMock->method('verify')->willReturn(false);
$this->assertTrue( $this->assertTrue(
@ -413,10 +451,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify', ->onlyMethods(['verify'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(true); $oTotpMock->method('verify')->willReturn(true);
$this->assertTrue( $this->assertTrue(
@ -432,10 +471,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify', ->onlyMethods(['verify'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(true); $oTotpMock->method('verify')->willReturn(true);
$this->assertFalse( $this->assertFalse(
@ -451,10 +491,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify', ->onlyMethods(['verify'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(false); $oTotpMock->method('verify')->willReturn(false);
$this->assertFalse( $this->assertFalse(
@ -468,25 +509,27 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function d3TotpReloginPass() public function d3TotpReloginPass()
{ {
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'setVariable', ->onlyMethods(['setVariable'])
)); ->getMock();
$oSessionMock->expects($this->atLeast(2))->method('setVariable')->willReturn(false); $oSessionMock->expects($this->atLeast(2))->method('setVariable')->willReturn(false);
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'getId', ->onlyMethods(['getId'])
)); ->getMock();
$oUserMock->method('getId')->willReturn('foo'); $oUserMock->method('getId')->willReturn('foo');
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMockBuilder(UserComponent::class)
'd3GetSession', ->onlyMethods([
'setUser', 'd3GetSession',
'setLoginStatus', 'setUser',
'_afterLogin', 'setLoginStatus',
)); '_afterLogin'
])
->getMock();
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock); $oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
$oControllerMock->expects($this->once())->method('setUser')->willReturn(false); $oControllerMock->expects($this->once())->method('setUser')->willReturn(false);
$oControllerMock->expects($this->once())->method('setLoginStatus')->willReturn(false); $oControllerMock->expects($this->once())->method('setLoginStatus')->willReturn(false);
@ -503,16 +546,16 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
*/ */
public function d3TotpClearSessionVariablesPass() public function d3TotpClearSessionVariablesPass()
{ {
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'deleteVariable', ->onlyMethods(['deleteVariable'])
)); ->getMock();
$oSessionMock->expects($this->atLeast(3))->method('deleteVariable')->willReturn(false); $oSessionMock->expects($this->atLeast(3))->method('deleteVariable')->willReturn(false);
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var UserComponent|MockObject $oControllerMock */
$oControllerMock = $this->getMock(UserComponent::class, array( $oControllerMock = $this->getMockBuilder(UserComponent::class)
'd3GetSession', ->onlyMethods(['d3GetSession'])
)); ->getMock();
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock); $oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;

View File

@ -22,7 +22,7 @@ use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Session; use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\Eshop\Core\UtilsView;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
class d3_totp_LoginControllerTest extends d3TotpUnitTestCase class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
@ -53,27 +53,34 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function canRenderNoAuth() public function canRenderNoAuth()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->onlyMethods([
'loadByUserId' 'isActive',
), array(), '', false); 'loadByUserId'
])
->disableOriginalConstructor()
->getMock();
$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);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods([
'setVariable', 'getVariable',
)); 'setVariable'
])
->getMock();
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(false, true)); $oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(false, true));
$oSessionMock->expects($this->never())->method('setVariable')->willReturn(false); $oSessionMock->expects($this->never())->method('setVariable')->willReturn(false);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetSession', ->onlyMethods([
'd3GetTotpObject' 'd3GetSession',
)); 'd3GetTotpObject'
])
->getMock();
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock); $oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
@ -89,27 +96,34 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function canRenderTotpNotActive() public function canRenderTotpNotActive()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->disableOriginalConstructor()
'loadByUserId' ->onlyMethods([
), array(), '', false); 'isActive',
'loadByUserId'
])
->getMock();
$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);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods([
'setVariable', 'getVariable',
)); 'setVariable',
])
->getMock();
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(true, true)); $oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(true, true));
$oSessionMock->expects($this->never())->method('setVariable')->willReturn(false); $oSessionMock->expects($this->never())->method('setVariable')->willReturn(false);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetSession', ->onlyMethods([
'd3GetTotpObject' 'd3GetSession',
)); 'd3GetTotpObject'
])
->getMock();
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock); $oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
@ -125,27 +139,34 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function canRenderInTotpLoginProcess() public function canRenderInTotpLoginProcess()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->onlyMethods([
'loadByUserId' 'isActive',
), array(), '', false); 'loadByUserId'
])
->disableOriginalConstructor()
->getMock();
$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);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods([
'setVariable', 'getVariable',
)); 'setVariable',
])
->getMock();
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(true, true)); $oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(true, true));
$oSessionMock->expects($this->never())->method('setVariable')->willReturn(false); $oSessionMock->expects($this->never())->method('setVariable')->willReturn(false);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetSession', ->onlyMethods([
'd3GetTotpObject' 'd3GetSession',
)); 'd3GetTotpObject'
])
->getMock();
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock); $oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
@ -161,27 +182,34 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function canRenderRequestTotp() public function canRenderRequestTotp()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->onlyMethods([
'loadByUserId' 'isActive',
), array(), '', false); 'loadByUserId'
])
->disableOriginalConstructor()
->getMock();
$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);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods([
'setVariable', 'getVariable',
)); 'setVariable',
])
->getMock();
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(true, false)); $oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(true, false));
$oSessionMock->expects($this->once())->method('setVariable')->willReturn(false); $oSessionMock->expects($this->once())->method('setVariable')->willReturn(false);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetSession', ->onlyMethods([
'd3GetTotpObject' 'd3GetSession',
)); 'd3GetTotpObject'
])
->getMock();
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock); $oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
@ -245,55 +273,69 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function checkloginNoTotp() public function checkloginNoTotp()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'loadByUserId' ->disableOriginalConstructor()
), array(), '', false); ->onlyMethods(['loadByUserId'])
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetTotpObject', ->onlyMethods([
'isNoTotpOrNoLogin', 'd3GetTotpObject',
'hasValidTotp', 'isNoTotpOrNoLogin',
)); 'hasValidTotp',
])
->getMock();
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(true); $oControllerMock->method('isNoTotpOrNoLogin')->willReturn(true);
$oControllerMock->method('hasValidTotp')->willReturn(false); $oControllerMock->method('hasValidTotp')->willReturn(false);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
$this->assertEmpty($this->callMethod($this->_oController, 'checklogin')); $this->assertSame(
'login',
$this->callMethod(
$this->_oController,
'checklogin'
)
);
} }
/** /**
* @test * @test
* @throws ReflectionException * @throws ReflectionException
*/ */
public function checkloginUnvalidTotp() public function checkloginInvalidTotp()
{ {
/** @var d3totp_wrongOtpException|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */ /** @var d3totp_wrongOtpException|MockObject $oUtilsViewMock */
$oTotpExceptionMock = $this->getMock(d3totp_wrongOtpException::class, array(), array(), '', false); $oTotpExceptionMock = $this->getMockBuilder(d3totp_wrongOtpException::class)
->disableOriginalConstructor()
->getMock();
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $utilsViewMock */ /** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMock(UtilsView::class, array( $utilsViewMock = $this->getMockBuilder(UtilsView::class)
'addErrorToDisplay', ->onlyMethods(['addErrorToDisplay'])
)); ->getMock();
$utilsViewMock->expects($oSpy = $this->once())->method('addErrorToDisplay')->willReturn(true); $utilsViewMock->expects($this->once())->method('addErrorToDisplay')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'loadByUserId' ->disableOriginalConstructor()
), array(), '', false); ->onlyMethods(['loadByUserId'])
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetTotpObject', ->onlyMethods([
'isNoTotpOrNoLogin', 'd3GetTotpObject',
'hasValidTotp', 'isNoTotpOrNoLogin',
'd3GetUtilsView', 'hasValidTotp',
)); 'd3GetUtilsView'
])
->getMock();
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false); $oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false);
$oControllerMock->method('hasValidTotp')->willThrowException($oTotpExceptionMock); $oControllerMock->method('hasValidTotp')->willThrowException($oTotpExceptionMock);
@ -301,7 +343,10 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
$this->assertSame('login', $this->callMethod($this->_oController, 'checklogin')); $this->assertSame(
'login',
$this->callMethod($this->_oController, 'checklogin')
);
} }
/** /**
@ -310,32 +355,35 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function checkloginValidTotp() public function checkloginValidTotp()
{ {
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $utilsViewMock */ /** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMock(UtilsView::class, array( $utilsViewMock = $this->getMockBuilder(UtilsView::class)
'addErrorToDisplay', ->onlyMethods(['addErrorToDisplay'])
)); ->getMock();
$utilsViewMock->expects($this->never())->method('addErrorToDisplay')->willReturn(true); $utilsViewMock->expects($this->never())->method('addErrorToDisplay')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'loadByUserId' ->onlyMethods(['loadByUserId'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'setVariable', ->onlyMethods(['setVariable'])
)); ->getMock();
$oSessionMock->expects($this->once())->method('setVariable')->willReturn(false); $oSessionMock->expects($this->once())->method('setVariable')->willReturn(false);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetTotpObject', ->onlyMethods([
'isNoTotpOrNoLogin', 'd3GetTotpObject',
'hasValidTotp', 'isNoTotpOrNoLogin',
'd3GetUtilsView', 'hasValidTotp',
'd3GetSession', 'd3GetUtilsView',
)); 'd3GetSession'
])
->getMock();
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false); $oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false);
$oControllerMock->method('hasValidTotp')->willReturn(true); $oControllerMock->method('hasValidTotp')->willReturn(true);
@ -353,16 +401,16 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function getBackupCodeCountMessageShowMessage() public function getBackupCodeCountMessageShowMessage()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */ /** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'getAvailableCodeCount', ->onlyMethods(['getAvailableCodeCount'])
)); ->getMock();
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(2); $oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(2);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetBackupCodeListObject', ->onlyMethods(['d3GetBackupCodeListObject'])
)); ->getMock();
$oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock); $oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -382,16 +430,16 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function getBackupCodeCountMessageDontShowMessage() public function getBackupCodeCountMessageDontShowMessage()
{ {
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */ /** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array( $oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
'getAvailableCodeCount', ->onlyMethods(['getAvailableCodeCount'])
)); ->getMock();
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(10); $oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(10);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetBackupCodeListObject', ->onlyMethods(['d3GetBackupCodeListObject'])
)); ->getMock();
$oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock); $oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -407,22 +455,23 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function isNoTotpOrNoLoginIsAuth() public function isNoTotpOrNoLoginIsAuth()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive' ->onlyMethods(['isActive'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods(['getVariable'])
)); ->getMock();
$oSessionMock->method('getVariable')->willReturn(true); $oSessionMock->method('getVariable')->willReturn(true);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetSession', ->onlyMethods(['d3GetSession'])
)); ->getMock();
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock); $oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -438,22 +487,23 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function isNoTotpOrNoLoginTotpNotActive() public function isNoTotpOrNoLoginTotpNotActive()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive' ->onlyMethods(['isActive'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods(['getVariable'])
)); ->getMock();
$oSessionMock->method('getVariable')->willReturn(true); $oSessionMock->method('getVariable')->willReturn(true);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetSession', ->onlyMethods(['d3GetSession'])
)); ->getMock();
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock); $oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -469,22 +519,23 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function isNoTotpOrNoLoginPass() public function isNoTotpOrNoLoginPass()
{ {
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive' ->onlyMethods(['isActive'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('isActive')->willReturn(false); $oTotpMock->method('isActive')->willReturn(false);
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods(['getVariable'])
)); ->getMock();
$oSessionMock->method('getVariable')->willReturn(false); $oSessionMock->method('getVariable')->willReturn(false);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetSession', ->onlyMethods(['d3GetSession'])
)); ->getMock();
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock); $oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -502,10 +553,11 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, true); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify', ->onlyMethods(['verify'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(false); $oTotpMock->method('verify')->willReturn(false);
$this->assertTrue( $this->assertTrue(
@ -521,10 +573,11 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify', ->onlyMethods(['verify'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(true); $oTotpMock->method('verify')->willReturn(true);
$this->assertTrue( $this->assertTrue(
@ -540,10 +593,11 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify', ->onlyMethods(['verify'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(true); $oTotpMock->method('verify')->willReturn(true);
$this->assertFalse( $this->assertFalse(
@ -559,10 +613,11 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false); Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'verify', ->onlyMethods(['verify'])
), array(), '', false); ->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(false); $oTotpMock->method('verify')->willReturn(false);
$this->assertFalse( $this->assertFalse(
@ -576,16 +631,16 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
*/ */
public function d3CancelLoginPass() public function d3CancelLoginPass()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'logout', ->onlyMethods(['logout'])
)); ->getMock();
$oUserMock->expects($this->once())->method('logout')->willReturn(true); $oUserMock->expects($this->once())->method('logout')->willReturn(true);
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array( $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
'd3GetUserObject', ->onlyMethods(['d3GetUserObject'])
)); ->getMock();
$oControllerMock->method('d3GetUserObject')->willReturn($oUserMock); $oControllerMock->method('d3GetUserObject')->willReturn($oUserMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;

View File

@ -16,12 +16,13 @@ namespace D3\Totp\tests\unit\Modules\Application\Controller;
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController; use D3\Totp\Modules\Application\Controller\d3_totp_OrderController;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
use OxidEsales\Eshop\Application\Controller\OrderController; use OxidEsales\Eshop\Application\Controller\OrderController;
use PHPUnit\Framework\MockObject\MockObject;
class d3_totp_OrderControllerTest extends d3TotpUnitTestCase class d3_totp_OrderControllerTest extends d3TotpUnitTestCase
{ {
use d3_totp_getUserTestTrait; use d3_totp_getUserTestTrait;
/** @var d3_totp_OrderController */ /** @var d3_totp_OrderController|MockObject */
protected $_oController; protected $_oController;
protected $sControllerClass = OrderController::class; protected $sControllerClass = OrderController::class;
@ -29,14 +30,14 @@ class d3_totp_OrderControllerTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oController = oxNew(OrderController::class); $this->_oController = oxNew(OrderController::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();

View File

@ -29,14 +29,14 @@ class d3_totp_PaymentControllerTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oController = oxNew(PaymentController::class); $this->_oController = oxNew(PaymentController::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();

View File

@ -29,14 +29,14 @@ class d3_totp_UserControllerTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oController = oxNew(UserController::class); $this->_oController = oxNew(UserController::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();

View File

@ -17,19 +17,21 @@ use D3\Totp\Application\Model\d3totp;
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController; use D3\Totp\Modules\Application\Controller\d3_totp_OrderController;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Session; use OxidEsales\Eshop\Core\Session;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
trait d3_totp_getUserTestTrait trait d3_totp_getUserTestTrait
{ {
/** /**
* @test * @test
* @throws ReflectionException
*/ */
public function getUserHasNoUser() public function getUserHasNoUser()
{ {
/** @var d3_totp_orderController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_orderController|MockObject $oControllerMock */
$oControllerMock = $this->getMock($this->sControllerClass, array( $oControllerMock = $this->getMockBuilder($this->sControllerClass)
'd3GetTotpObject', ->onlyMethods(['d3GetTotpObject'])
)); ->getMock();
$oControllerMock->expects($this->never())->method('d3GetTotpObject'); $oControllerMock->expects($this->never())->method('d3GetTotpObject');
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
@ -41,34 +43,40 @@ trait d3_totp_getUserTestTrait
/** /**
* @test * @test
* @throws ReflectionException
*/ */
public function getUserTotpNotActive() public function getUserTotpNotActive()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'getId' ->onlyMethods(['getId'])
)); ->getMock();
$oUserMock->method('getId')->willReturn('foo'); $oUserMock->method('getId')->willReturn('foo');
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods(['getVariable'])
)); ->getMock();
$oSessionMock->method('getVariable')->willReturn(true); $oSessionMock->method('getVariable')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->disableOriginalConstructor()
'loadByUserId' ->onlyMethods([
), array(), '', false); 'isActive',
'loadByUserId'
])
->getMock();
$oTotpMock->method('isActive')->willReturn(false); $oTotpMock->method('isActive')->willReturn(false);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3_totp_orderController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_orderController|MockObject $oControllerMock */
$oControllerMock = $this->getMock($this->sControllerClass, array( $oControllerMock = $this->getMockBuilder($this->sControllerClass)
'd3GetTotpObject', ->onlyMethods([
'd3GetSessionObject' 'd3GetTotpObject',
)); 'd3GetSessionObject'
])
->getMock();
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('d3GetSessionObject')->willReturn($oSessionMock); $oControllerMock->method('d3GetSessionObject')->willReturn($oSessionMock);
@ -84,34 +92,39 @@ trait d3_totp_getUserTestTrait
/** /**
* @test * @test
* @throws ReflectionException
*/ */
public function getUserTotpFinished() public function getUserTotpFinished()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'getId' ->onlyMethods(['getId'])
)); ->getMock();
$oUserMock->method('getId')->willReturn('foo'); $oUserMock->method('getId')->willReturn('foo');
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods(['getVariable'])
)); ->getMock();
$oSessionMock->method('getVariable')->willReturn(true); $oSessionMock->method('getVariable')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->onlyMethods([
'loadByUserId' 'isActive',
), array(), '', false); 'loadByUserId'
])
->getMock();
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3_totp_orderController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_orderController|MockObject $oControllerMock */
$oControllerMock = $this->getMock($this->sControllerClass, array( $oControllerMock = $this->getMockBuilder($this->sControllerClass)
'd3GetTotpObject', ->onlyMethods([
'd3GetSessionObject' 'd3GetTotpObject',
)); 'd3GetSessionObject'
])
->getMock();
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('d3GetSessionObject')->willReturn($oSessionMock); $oControllerMock->method('d3GetSessionObject')->willReturn($oSessionMock);
@ -127,34 +140,40 @@ trait d3_totp_getUserTestTrait
/** /**
* @test * @test
* @throws ReflectionException
*/ */
public function getUserTotpNotFinished() public function getUserTotpNotFinished()
{ {
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */ /** @var User|MockObject $oUserMock */
$oUserMock = $this->getMock(User::class, array( $oUserMock = $this->getMockBuilder(User::class)
'getId' ->onlyMethods(['getId'])
)); ->getMock();
$oUserMock->method('getId')->willReturn('foo'); $oUserMock->method('getId')->willReturn('foo');
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods(['getVariable'])
)); ->getMock();
$oSessionMock->method('getVariable')->willReturn(false); $oSessionMock->method('getVariable')->willReturn(false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'isActive', ->disableOriginalConstructor()
'loadByUserId' ->onlyMethods([
), array(), '', false); 'isActive',
'loadByUserId'
])
->getMock();
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3_totp_orderController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */ /** @var d3_totp_orderController|MockObject $oControllerMock */
$oControllerMock = $this->getMock($this->sControllerClass, array( $oControllerMock = $this->getMockBuilder($this->sControllerClass)
'd3GetTotpObject', ->onlyMethods([
'd3GetSessionObject' 'd3GetTotpObject',
)); 'd3GetSessionObject'
])
->getMock();
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('d3GetSessionObject')->willReturn($oSessionMock); $oControllerMock->method('d3GetSessionObject')->willReturn($oSessionMock);
@ -169,6 +188,7 @@ trait d3_totp_getUserTestTrait
/** /**
* @test * @test
* @throws ReflectionException
*/ */
public function d3GetTotpObjectReturnsRightObject() public function d3GetTotpObjectReturnsRightObject()
{ {
@ -180,12 +200,16 @@ trait d3_totp_getUserTestTrait
/** /**
* @test * @test
* @throws ReflectionException
*/ */
public function d3GetSessionObjectReturnsRightObject() public function d3GetSessionObjectReturnsRightObject()
{ {
$this->assertInstanceOf( $this->assertInstanceOf(
Session::class, Session::class,
$this->callMethod($this->_oController, 'd3GetSessionObject') $this->callMethod(
$this->_oController,
'd3GetSessionObject'
)
); );
} }
} }

View File

@ -18,7 +18,7 @@ use D3\Totp\Modules\Application\Model\d3_totp_user;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Session; use OxidEsales\Eshop\Core\Session;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
class d3_totp_userTest extends d3TotpUnitTestCase class d3_totp_userTest extends d3TotpUnitTestCase
@ -29,14 +29,14 @@ class d3_totp_userTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oModel = oxNew(User::class); $this->_oModel = oxNew(User::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();
@ -49,16 +49,16 @@ class d3_totp_userTest extends d3TotpUnitTestCase
*/ */
public function logout() public function logout()
{ {
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'deleteVariable' ->onlyMethods(['deleteVariable'])
)); ->getMock();
$oSessionMock->expects($this->once())->method('deleteVariable')->willReturn(true); $oSessionMock->expects($this->once())->method('deleteVariable')->willReturn(true);
/** @var d3_totp_user|PHPUnit_Framework_MockObject_MockObject $oModelMock */ /** @var d3_totp_user|MockObject $oModelMock */
$oModelMock = $this->getMock(User::class, array( $oModelMock = $this->getMockBuilder(User::class)
'd3GetSession' ->onlyMethods(['d3GetSession'])
)); ->getMock();
$oModelMock->method('d3GetSession')->willReturn($oSessionMock); $oModelMock->method('d3GetSession')->willReturn($oSessionMock);
$this->_oModel = $oModelMock; $this->_oModel = $oModelMock;

View File

@ -19,7 +19,7 @@ use D3\Totp\tests\unit\d3TotpUnitTestCase;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Session; use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\Utils; use OxidEsales\Eshop\Core\Utils;
use PHPUnit_Framework_MockObject_MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
class d3_totp_utilsTest extends d3TotpUnitTestCase class d3_totp_utilsTest extends d3TotpUnitTestCase
@ -30,14 +30,14 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
/** /**
* setup basic requirements * setup basic requirements
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->_oCoreClass = oxNew(Utils::class); $this->_oCoreClass = oxNew(Utils::class);
} }
public function tearDown() public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();
@ -52,21 +52,22 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable("auth", false); Registry::getSession()->setVariable("auth", false);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'loadByUserId', ->onlyMethods([
'isActive', 'loadByUserId',
), array(), '', false); 'isActive',
])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
$oTotpMock->method('isActive')->willReturn(false); $oTotpMock->method('isActive')->willReturn(false);
/** @var d3_totp_utils|PHPUnit_Framework_MockObject_MockObject $oCoreMock */ /** @var d3_totp_utils|MockObject $oCoreMock */
$oCoreMock = $this->getMock(Utils::class, array( $oCoreMock = $this->getMockBuilder(Utils::class)
'd3GetTotpObject', ->onlyMethods(['d3GetTotpObject'])
'd3GetUtilsObject' ->getMock();
));
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oCoreMock->expects($this->never())->method('d3GetUtilsObject');
$this->_oCoreClass = $oCoreMock; $this->_oCoreClass = $oCoreMock;
@ -83,22 +84,25 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable("auth", 'foo'); Registry::getSession()->setVariable("auth", 'foo');
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'loadByUserId', ->onlyMethods([
'isActive', 'loadByUserId',
), array(), '', false); 'isActive'
])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
$oTotpMock->method('isActive')->willReturn(false); $oTotpMock->method('isActive')->willReturn(false);
/** @var d3_totp_utils|PHPUnit_Framework_MockObject_MockObject $oCoreMock */ /** @var d3_totp_utils|MockObject $oCoreMock */
$oCoreMock = $this->getMock(Utils::class, array( $oCoreMock = $this->getMockBuilder(Utils::class)
'd3GetTotpObject', ->onlyMethods([
'd3GetUtilsObject', 'd3GetTotpObject',
'fetchRightsForUser' 'fetchRightsForUser'
)); ])
->getMock();
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oCoreMock->expects($this->never())->method('d3GetUtilsObject');
$oCoreMock->method('fetchRightsForUser')->willReturn('malladmin'); $oCoreMock->method('fetchRightsForUser')->willReturn('malladmin');
$this->_oCoreClass = $oCoreMock; $this->_oCoreClass = $oCoreMock;
@ -116,27 +120,32 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable("auth", 'foo'); Registry::getSession()->setVariable("auth", 'foo');
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods(['getVariable'])
)); ->getMock();
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', true)); $oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', true));
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'loadByUserId', ->onlyMethods([
'isActive', 'loadByUserId',
), array(), '', false); 'isActive'
])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
/** @var d3_totp_utils|PHPUnit_Framework_MockObject_MockObject $oCoreMock */ /** @var d3_totp_utils|MockObject $oCoreMock */
$oCoreMock = $this->getMock(Utils::class, array( $oCoreMock = $this->getMockBuilder(Utils::class)
'd3GetTotpObject', ->onlyMethods([
'd3GetSessionObject', 'd3GetTotpObject',
'fetchRightsForUser', 'd3GetSessionObject',
'redirect' 'fetchRightsForUser',
)); 'redirect'
])
->getMock();
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oCoreMock->method('d3GetSessionObject')->willReturn($oSessionMock); $oCoreMock->method('d3GetSessionObject')->willReturn($oSessionMock);
$oCoreMock->method('fetchRightsForUser')->willReturn('malladmin'); $oCoreMock->method('fetchRightsForUser')->willReturn('malladmin');
@ -157,33 +166,38 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
{ {
Registry::getSession()->setVariable("auth", 'foo'); Registry::getSession()->setVariable("auth", 'foo');
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods(['getVariable'])
)); ->getMock();
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', false)); $oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', false));
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */ /** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMock(Session::class, array( $oSessionMock = $this->getMockBuilder(Session::class)
'getVariable', ->onlyMethods(['getVariable'])
)); ->getMock();
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', false)); $oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', false));
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMock(d3totp::class, array( $oTotpMock = $this->getMockBuilder(d3totp::class)
'loadByUserId', ->onlyMethods([
'isActive', 'loadByUserId',
), array(), '', false); 'isActive',
])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
$oTotpMock->method('isActive')->willReturn(true); $oTotpMock->method('isActive')->willReturn(true);
/** @var d3_totp_utils|PHPUnit_Framework_MockObject_MockObject $oCoreMock */ /** @var d3_totp_utils|MockObject $oCoreMock */
$oCoreMock = $this->getMock(Utils::class, array( $oCoreMock = $this->getMockBuilder(Utils::class)
'd3GetTotpObject', ->onlyMethods([
'd3GetSessionObject', 'd3GetTotpObject',
'fetchRightsForUser', 'd3GetSessionObject',
'redirect' 'fetchRightsForUser',
)); 'redirect'
])
->getMock();
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oCoreMock->method('d3GetSessionObject')->willReturn($oSessionMock); $oCoreMock->method('d3GetSessionObject')->willReturn($oSessionMock);
$oCoreMock->method('fetchRightsForUser')->willReturn('malladmin'); $oCoreMock->method('fetchRightsForUser')->willReturn('malladmin');