refactor tests
Dieser Commit ist enthalten in:
Ursprung
7be2c32cf5
Commit
9c4e7cfcc3
2
.gitignore
vendored
Normale Datei
2
.gitignore
vendored
Normale Datei
@ -0,0 +1,2 @@
|
||||
src/tests/.phpunit.result.cache
|
||||
src/tests/reports/
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Application\Controller\Admin;
|
||||
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
@ -93,12 +95,10 @@ class d3user_totp extends AdminDetailsController
|
||||
$aParams = Registry::getRequest()->getRequestEscapedParameter("editval");
|
||||
|
||||
try {
|
||||
/** @var d3totp $oTotp */
|
||||
$oTotp = $this->getTotpObject();
|
||||
if ($oTotp->checkIfAlreadyExist($this->getEditObjectId())) {
|
||||
$oException = oxNew(StandardException::class, 'D3_TOTP_ALREADY_EXIST');
|
||||
throw $oException;
|
||||
};
|
||||
throw oxNew(StandardException::class, 'D3_TOTP_ALREADY_EXIST');
|
||||
}
|
||||
|
||||
$oTotpBackupCodes = $this->getBackupcodeListObject();
|
||||
if ($aParams['d3totp__oxid']) {
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Application\Controller;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -119,7 +121,6 @@ class d3_account_totp extends AccountController
|
||||
|
||||
/**
|
||||
* @throws DatabaseConnectionException
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Application\Controller;
|
||||
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
@ -29,7 +31,7 @@ class d3totplogin extends FrontendController
|
||||
if (Registry::getSession()->hasVariable(d3totp::TOTP_SESSION_VARNAME) ||
|
||||
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')) {
|
||||
// @codeCoverageIgnoreStart
|
||||
exit;
|
||||
@ -64,9 +66,7 @@ class d3totplogin extends FrontendController
|
||||
Registry::getLang()->translateString('D3_TOTP_AVAILBACKUPCODECOUNT', null, true),
|
||||
$iCount
|
||||
);
|
||||
};
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,7 +86,7 @@ class d3totplogin extends FrontendController
|
||||
{
|
||||
$sClassKey = Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS);
|
||||
$resolvedClass = Registry::getControllerClassNameResolver()->getClassNameById($sClassKey);
|
||||
$resolvedClass = $resolvedClass ? $resolvedClass : 'start';
|
||||
$resolvedClass = $resolvedClass ?: 'start';
|
||||
|
||||
/** @var FrontendController $oController */
|
||||
$oController = oxNew($resolvedClass);
|
||||
|
@ -22,12 +22,10 @@ class BaconQrCodeFactory
|
||||
|
||||
private static function v200($size)
|
||||
{
|
||||
$renderer = oxNew(
|
||||
return oxNew(
|
||||
ImageRenderer::class,
|
||||
oxNew(RendererStyle::class, $size),
|
||||
oxNew(SvgImageBackEnd::class),
|
||||
);
|
||||
|
||||
return $renderer;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Application\Model\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
@ -1,20 +1,25 @@
|
||||
<?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;
|
||||
|
||||
use Laminas\Math\Rand;
|
||||
|
||||
class d3RandomGenerator extends Rand
|
||||
{
|
||||
const CHAR_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
const CHAR_LOWER = 'abcdefghijklmnopqrstuvwxyz';
|
||||
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
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Application\Model;
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
@ -48,6 +50,7 @@ class d3backupcode extends BaseModel
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @param $sUserId
|
||||
* @return false|string
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Application\Model;
|
||||
|
||||
use D3\Totp\Application\Controller\Admin\d3user_totp;
|
||||
@ -46,7 +48,7 @@ class d3backupcodelist extends ListModel
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$oBackupCode = $this->getD3BackupCodeObject();
|
||||
$this->_backupCodes[] = $oBackupCode->generateCode($sUserId);
|
||||
$this->offsetSet(md5(rand()), $oBackupCode);
|
||||
$this->offsetSet(md5((string) rand()), $oBackupCode);
|
||||
}
|
||||
|
||||
/** @var d3user_totp $oActView */
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Application\Model;
|
||||
|
||||
use BaconQrCode\Renderer\RendererInterface;
|
||||
@ -201,22 +203,20 @@ class d3totp extends BaseModel
|
||||
*/
|
||||
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();
|
||||
$blVerify = $oBC->verify($totp);
|
||||
$blNotVerified = $oBC->verify($totp) == false;
|
||||
|
||||
if (false == $blVerify) {
|
||||
$oException = oxNew(d3totp_wrongOtpException::class);
|
||||
throw $oException;
|
||||
if ($blNotVerified) {
|
||||
throw oxNew(d3totp_wrongOtpException::class);
|
||||
}
|
||||
} elseif (false == $blVerify && $seed) {
|
||||
$oException = oxNew(d3totp_wrongOtpException::class);
|
||||
throw $oException;
|
||||
} elseif ($blNotVerified && $seed) {
|
||||
throw oxNew(d3totp_wrongOtpException::class);
|
||||
}
|
||||
|
||||
return $blVerify;
|
||||
return !$blNotVerified;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -282,8 +282,6 @@ class d3totp extends BaseModel
|
||||
$oBackupCodeList = $this->d3GetBackupCodeListObject();
|
||||
$oBackupCodeList->deleteAllFromUser($this->getFieldData('oxuserid'));
|
||||
|
||||
$blDelete = parent::delete();
|
||||
|
||||
return $blDelete;
|
||||
return parent::delete();
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$sLangName = "Deutsch";
|
||||
|
||||
$aLang = [
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$sLangName = "English";
|
||||
|
||||
$aLang = [
|
||||
|
@ -4,7 +4,7 @@
|
||||
<input type="hidden" name="fnc" value="checklogin">
|
||||
<input type="hidden" name="cl" value="login">
|
||||
|
||||
[{if $Errors.default|@count}]
|
||||
[{if !empty($Errors.default)}]
|
||||
[{include file="inc_error.tpl" Errorlist=$Errors.default}]
|
||||
[{/if}]
|
||||
|
||||
|
@ -30,6 +30,7 @@ $aLang = [
|
||||
'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.',
|
||||
|
||||
'SHOP_MODULE_GROUP_d3totp_main' => 'Grundeinstellungen',
|
||||
'D3_TOTP_FORCE2FATITLE' => 'Verpflichtet Zwei-Faktor-Authentisierung',
|
||||
'D3_TOTP_FORCE2FASUB' => 'Alle Administratoren müssen es aktivieren',
|
||||
'D3_TOTP_ADMINBACKEND' => 'Admin-Oberfläche',
|
||||
|
@ -30,6 +30,7 @@ $aLang = [
|
||||
'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.',
|
||||
|
||||
'SHOP_MODULE_GROUP_d3totp_main' => 'Basic settings',
|
||||
'D3_TOTP_FORCE2FATITLE' => 'Mandates two-factor authentication',
|
||||
'D3_TOTP_FORCE2FASUB' => 'All administrators need to activate it',
|
||||
'D3_TOTP_ADMINBACKEND' => 'Admin-Backend',
|
||||
|
@ -15,7 +15,7 @@
|
||||
<input type="hidden" name="cl" value="[{$oView->getPreviousClass()}]">
|
||||
[{$navFormParams}]
|
||||
|
||||
[{if $Errors.default|@count}]
|
||||
[{if !empty($Errors.default)}]
|
||||
[{include file="inc_error.tpl" Errorlist=$Errors.default}]
|
||||
[{/if}]
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Modules\Application\Component;
|
||||
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
@ -40,7 +42,7 @@ class d3_totp_UserComponent extends d3_totp_UserComponent_parent
|
||||
$totp->loadByUserId($oUser->getId());
|
||||
|
||||
if ($totp->isActive()
|
||||
&& false == Registry::getSession()->getVariable(d3totp::TOTP_SESSION_VARNAME)
|
||||
&& !Registry::getSession()->getVariable(d3totp::TOTP_SESSION_VARNAME)
|
||||
) {
|
||||
Registry::getSession()->setVariable(
|
||||
d3totp::TOTP_SESSION_CURRENTCLASS,
|
||||
@ -82,7 +84,7 @@ class d3_totp_UserComponent extends d3_totp_UserComponent_parent
|
||||
$totp->loadByUserId($sUserId);
|
||||
|
||||
try {
|
||||
if (false == $this->isNoTotpOrNoLogin($totp) && $this->hasValidTotp($sTotp, $totp)) {
|
||||
if (!$this->isNoTotpOrNoLogin($totp) && $this->hasValidTotp($sTotp, $totp)) {
|
||||
$this->d3TotpRelogin($oUser, $sTotp);
|
||||
$this->d3TotpClearSessionVariables();
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Modules\Application\Controller\Admin;
|
||||
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
@ -41,7 +43,7 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
|
||||
|
||||
if ($auth
|
||||
&& $totp->isActive()
|
||||
&& false == $this->d3GetSession()->getVariable(d3totp::TOTP_SESSION_VARNAME)
|
||||
&& !$this->d3GetSession()->getVariable(d3totp::TOTP_SESSION_VARNAME)
|
||||
) {
|
||||
// set auth as secured parameter;
|
||||
$this->d3GetSession()->setVariable("auth", $auth);
|
||||
@ -98,7 +100,7 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
|
||||
$return = 'login';
|
||||
|
||||
try {
|
||||
if ($this->isNoTotpOrNoLogin($totp)) {
|
||||
if ($this->isNoTotpOrNoLogin($totp) && $this->hasLoginCredentials()) {
|
||||
$return = parent::checklogin();
|
||||
} elseif ($this->hasValidTotp($sTotp, $totp)) {
|
||||
$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'),
|
||||
$iCount
|
||||
);
|
||||
};
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,6 +140,12 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
|
||||
|| false == $totp->isActive();
|
||||
}
|
||||
|
||||
protected function hasLoginCredentials()
|
||||
{
|
||||
return Registry::getRequest()->getRequestEscapedParameter( 'user') &&
|
||||
Registry::getRequest()->getRequestEscapedParameter('pwd');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTotp
|
||||
* @param d3totp $totp
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Modules\Application\Controller;
|
||||
|
||||
class d3_totp_OrderController extends d3_totp_OrderController_parent
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Modules\Application\Controller;
|
||||
|
||||
class d3_totp_PaymentController extends d3_totp_PaymentController_parent
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Modules\Application\Controller;
|
||||
|
||||
class d3_totp_UserController extends d3_totp_UserController_parent
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Modules\Application\Controller;
|
||||
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
@ -25,7 +27,6 @@ trait d3_totp_getUserTrait
|
||||
/**
|
||||
* @return bool|object|User
|
||||
* @throws DatabaseConnectionException
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
@ -36,7 +37,7 @@ trait d3_totp_getUserTrait
|
||||
$totp->loadByUserId($oUser->getId());
|
||||
|
||||
if ($totp->isActive()
|
||||
&& false == $this->d3GetSessionObject()->getVariable(d3totp::TOTP_SESSION_VARNAME)
|
||||
&& !$this->d3GetSessionObject()->getVariable(d3totp::TOTP_SESSION_VARNAME)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
@ -11,11 +11,11 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Modules\Application\Model;
|
||||
|
||||
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\Session;
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Modules\Core;
|
||||
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
@ -43,7 +45,7 @@ class d3_totp_utils extends d3_totp_utils_parent
|
||||
&& $blAuth
|
||||
&& $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')) {
|
||||
// @codeCoverageIgnoreStart
|
||||
exit;
|
||||
@ -53,7 +55,7 @@ class d3_totp_utils extends d3_totp_utils_parent
|
||||
|
||||
//staten der prüfung vom einmalpasswort
|
||||
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')) {
|
||||
// @codeCoverageIgnoreStart
|
||||
exit;
|
||||
|
@ -11,32 +11,27 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Setup;
|
||||
|
||||
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
|
||||
use D3\ModCfg\Application\Model\Install\d3install;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use OxidEsales\Eshop\Core\DatabaseProvider;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
use OxidEsales\Eshop\Core\Exception\SystemComponentException;
|
||||
|
||||
class Events
|
||||
{
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @throws d3ShopCompatibilityAdapterException
|
||||
* @throws DBALException
|
||||
* @return void
|
||||
* @throws DatabaseConnectionException
|
||||
* @throws DatabaseErrorException
|
||||
* @throws StandardException
|
||||
* @throws SystemComponentException
|
||||
*/
|
||||
public static function onActivate()
|
||||
public static function onActivate(): void
|
||||
{
|
||||
if (class_exists(d3install::class)) {
|
||||
d3install::checkUpdateStart();
|
||||
}
|
||||
self::addTotpTable();
|
||||
self::addTotpBackupCodesTable();
|
||||
self::addSeoItem1();
|
||||
self::addSeoItem2();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,4 +40,94 @@ class Events
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use D3\Totp\Application\Controller\Admin\d3user_totp;
|
||||
use D3\Totp\Application\Controller\Admin\d3force_2fa;
|
||||
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\Core\d3_totp_utils;
|
||||
use D3\Totp\Setup as ModuleSetup;
|
||||
use D3\ModCfg\Application\Model\d3utils;
|
||||
use OxidEsales\Eshop\Application\Component\UserComponent;
|
||||
use OxidEsales\Eshop\Application\Controller\Admin\LoginController;
|
||||
use OxidEsales\Eshop\Application\Controller\OrderController;
|
||||
@ -35,7 +36,7 @@ use OxidEsales\Eshop\Application\Model as OxidModel;
|
||||
/**
|
||||
* Metadata version
|
||||
*/
|
||||
$sMetadataVersion = '2.0';
|
||||
$sMetadataVersion = '2.1';
|
||||
|
||||
$sModuleId = 'd3totp';
|
||||
$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 = [
|
||||
'id' => $sModuleId,
|
||||
'title' => [
|
||||
'de' => $logo . 'Zwei-Faktor-Authentisierung',
|
||||
'en' => $logo . 'two-factor authentication',
|
||||
'de' => $logo . ' Zwei-Faktor-Authentisierung',
|
||||
'en' => $logo . ' two-factor authentication',
|
||||
],
|
||||
'description' => [
|
||||
'de' => 'Zwei-Faktor-Authentisierung (TOTP) für OXID eSales Shop',
|
||||
'en' => 'Two-factor authentication (TOTP) for OXID eSales shop',
|
||||
],
|
||||
'thumbnail' => 'picture.png',
|
||||
'version' => '1.0.0.0',
|
||||
'author' => 'D³ Data Development (Inh.: Thomas Dartsch)',
|
||||
'email' => 'support@shopmodule.com',
|
||||
'url' => 'http://www.oxidmodule.com/',
|
||||
'url' => 'https://www.oxidmodule.com/',
|
||||
'extend' => [
|
||||
UserController::class => d3_totp_UserController::class,
|
||||
PaymentController::class => d3_totp_PaymentController::class,
|
||||
@ -80,15 +80,15 @@ $aModule = [
|
||||
],
|
||||
'settings' => [
|
||||
[
|
||||
'group' => 'main',
|
||||
'group' => 'd3totp_main',
|
||||
'name' => 'D3_TOTP_ADMIN_FORCE_2FA',
|
||||
'type' => 'bool',
|
||||
'value' => false,
|
||||
]
|
||||
],
|
||||
'events' => [
|
||||
'onActivate' => '\D3\Totp\Setup\Events::onActivate',
|
||||
'onDeactivate' => '\D3\Totp\Setup\Events::onDeactivate',
|
||||
'onActivate' => ModuleSetup\Events::class.'::onActivate',
|
||||
'onDeactivate' => ModuleSetup\Events::class.'::onDeactivate',
|
||||
],
|
||||
'blocks' => [
|
||||
[
|
||||
|
@ -11,5 +11,5 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
define('D3TOTP_REQUIRE_MODCFG', true);
|
||||
const D3TOTP_REQUIRE_MODCFG = true;
|
||||
|
||||
|
@ -19,7 +19,7 @@ use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3user_totpTest extends d3TotpUnitTestCase
|
||||
@ -30,14 +30,14 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3user_totp::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@ -50,11 +50,13 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canRenderNoSelectedUser()
|
||||
{
|
||||
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3user_totp::class, array(
|
||||
'getEditObjectId',
|
||||
'getUserObject'
|
||||
));
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('-1');
|
||||
$oControllerMock->expects($this->never())->method('getUserObject')->willReturn(false);
|
||||
|
||||
@ -73,19 +75,23 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canRenderSelectedUser()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'getId',
|
||||
'load',
|
||||
));
|
||||
/** @var User|MockObject $oControllerMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'getId',
|
||||
'load',
|
||||
])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->atLeast(1))->method('getId')->willReturn('foobar');
|
||||
$oUserMock->expects($this->atLeast(1))->method('load')->willReturn(true);
|
||||
|
||||
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3user_totp::class, array(
|
||||
'getEditObjectId',
|
||||
'getUserObject'
|
||||
));
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->expects($this->once())->method('getUserObject')->willReturn($oUserMock);
|
||||
|
||||
@ -106,20 +112,24 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canRenderUnloadableUser()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'getId',
|
||||
'load',
|
||||
));
|
||||
/** @var User|MockObject $oControllerMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'getId',
|
||||
'load',
|
||||
])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->never())->method('getId');
|
||||
$oUserMock->expects($this->atLeast(1))->method('load')->willReturn(false);
|
||||
|
||||
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3user_totp::class, array(
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'addTplParam'
|
||||
));
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'addTplParam'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->expects($this->once())->method('getUserObject')->willReturn($oUserMock);
|
||||
$oControllerMock->expects($this->exactly(3))->method('addTplParam')->with(
|
||||
@ -151,7 +161,10 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
User::class,
|
||||
$this->callMethod($this->_oController, 'getUserObject')
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getUserObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -163,7 +176,10 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod($this->_oController, 'getTotpObject')
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getTotpObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -175,7 +191,10 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3backupcodelist::class,
|
||||
$this->callMethod($this->_oController, 'getBackupCodeListObject')
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getBackupCodeListObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -185,21 +204,24 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function cantSaveBecauseOfNotVerifiable()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'save',
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['save'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->never())->method('save')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oControllerMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('load')->willReturn(true);
|
||||
$oTotpMock->expects($this->never())->method('save')->willReturn(true);
|
||||
$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('checkIfAlreadyExist')->willReturn(false);
|
||||
|
||||
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3user_totp::class, array(
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject'
|
||||
));
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
|
||||
@ -229,21 +253,24 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function cantSaveBecauseExistingRegistration()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'save',
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['save'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->never())->method('save')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oControllerMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist'
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('load')->willReturn(true);
|
||||
$oTotpMock->expects($this->never())->method('save')->willReturn(true);
|
||||
$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('checkIfAlreadyExist')->willReturn(true);
|
||||
|
||||
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3user_totp::class, array(
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject'
|
||||
));
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
|
||||
@ -273,23 +302,28 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canSave()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'save',
|
||||
'generateBackupCodes'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'save',
|
||||
'generateBackupCodes'
|
||||
])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true);
|
||||
$oBackupCodeListMock->method('generateBackupCodes')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oControllerMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->never())->method('load')->willReturn(true);
|
||||
$oTotpMock->expects($this->once())->method('save')->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('checkIfAlreadyExist')->willReturn(false);
|
||||
|
||||
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3user_totp::class, array(
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject'
|
||||
));
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
|
||||
@ -324,23 +360,28 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
];
|
||||
$_GET['editval'] = $aEditval;
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'save',
|
||||
'generateBackupCodes'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'save',
|
||||
'generateBackupCodes'
|
||||
])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true);
|
||||
$oBackupCodeListMock->method('generateBackupCodes')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oControllerMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('load')->willReturn(true);
|
||||
$oTotpMock->expects($this->once())->method('save')->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('checkIfAlreadyExist')->willReturn(false);
|
||||
|
||||
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3user_totp::class, array(
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject'
|
||||
));
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
|
||||
@ -391,16 +434,17 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
$editval = [];
|
||||
$_GET['editval'] = $editval;
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'delete'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->never())->method('delete');
|
||||
|
||||
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3user_totp::class, array(
|
||||
'getTotpObject'
|
||||
));
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods(['getTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->never())->method('getTotpObject')->willReturn($oTotpMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -419,18 +463,21 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
];
|
||||
$_GET['editval'] = $editval;
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'delete',
|
||||
'load'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'delete',
|
||||
'load'
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('delete')->willReturn(true);
|
||||
$oTotpMock->method('load')->willReturn(true);
|
||||
|
||||
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3user_totp::class, array(
|
||||
'getTotpObject'
|
||||
));
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods(['getTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -444,20 +491,22 @@ class d3user_totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canGetAvailableBackupCodeCount()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'getAvailableCodeCount',
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(25);
|
||||
|
||||
$oUser = oxNew(User::class);
|
||||
$oUser->setId('foo');
|
||||
|
||||
/** @var d3user_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3user_totp::class, array(
|
||||
'getBackupCodeListObject',
|
||||
'getUser'
|
||||
));
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getBackupCodeListObject',
|
||||
'getUser'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
|
||||
|
@ -19,7 +19,7 @@ use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
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 */
|
||||
$oControllerMock = $this->getMock(d3_account_totp::class, array(
|
||||
'getUser'
|
||||
));
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods(['getUser'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -81,10 +81,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$oUser = false;
|
||||
|
||||
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_account_totp::class, array(
|
||||
'getUser'
|
||||
));
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods(['getUser'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -122,7 +122,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
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()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'getAvailableCodeCount',
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oControllerMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(25);
|
||||
|
||||
$oUser = oxNew(User::class);
|
||||
$oUser->setId('foo');
|
||||
|
||||
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_account_totp::class, array(
|
||||
'getBackupCodeListObject',
|
||||
'getUser'
|
||||
));
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getBackupCodeListObject',
|
||||
'getUser'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
|
||||
@ -165,10 +170,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$_GET['totp_use'] = 0;
|
||||
|
||||
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_account_totp::class, array(
|
||||
'getTotpObject'
|
||||
));
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods(['getTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->never())->method('getTotpObject')->willReturn(true);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -184,21 +189,26 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$_GET['totp_use'] = '1';
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'generateBackupCodes',
|
||||
'save'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'generateBackupCodes',
|
||||
'save'
|
||||
])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->never())->method('generateBackupCodes');
|
||||
$oBackupCodeListMock->expects($this->never())->method('save');
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'verify',
|
||||
'save'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'verify',
|
||||
'save'
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('saveSecret')->willReturn(true);
|
||||
$oTotpMock->method('assign')->willReturn(true);
|
||||
$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->setId('foo');
|
||||
|
||||
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_account_totp::class, array(
|
||||
'getTotpObject',
|
||||
'getUser',
|
||||
'getBackupCodeListObject'
|
||||
));
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getTotpObject',
|
||||
'getUser',
|
||||
'getBackupCodeListObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
@ -230,23 +242,28 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$_GET['totp_use'] = '1';
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'generateBackupCodes',
|
||||
'save'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'generateBackupCodes',
|
||||
'save'
|
||||
])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->method('generateBackupCodes')->willReturn(['0123', '1234']);
|
||||
$oBackupCodeListMock->expects($this->once())->method('save')->willReturn(true);
|
||||
$oBackupCodeListMock->method('save')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'verify',
|
||||
'save',
|
||||
'setId',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'verify',
|
||||
'save',
|
||||
'setId',
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('saveSecret')->willReturn(true);
|
||||
$oTotpMock->method('assign')->willReturn(true);
|
||||
$oTotpMock->method('verify')->willReturn(true);
|
||||
@ -256,12 +273,14 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
$oUser = oxNew(User::class);
|
||||
$oUser->setId('foo');
|
||||
|
||||
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_account_totp::class, array(
|
||||
'getTotpObject',
|
||||
'getUser',
|
||||
'getBackupCodeListObject'
|
||||
));
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getTotpObject',
|
||||
'getUser',
|
||||
'getBackupCodeListObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
@ -279,10 +298,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$_GET['totp_use'] = '1';
|
||||
|
||||
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_account_totp::class, array(
|
||||
'getTotpObject'
|
||||
));
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods(['getTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->never())->method('getTotpObject')->willReturn(true);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -298,17 +317,20 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$_GET['totp_use'] = '0';
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'delete'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->never())->method('delete');
|
||||
|
||||
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_account_totp::class, array(
|
||||
'getTotpObject',
|
||||
'getUser'
|
||||
));
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getTotpObject',
|
||||
'getUser'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->expects($this->once())->method('getUser')->willReturn(false);
|
||||
|
||||
@ -325,22 +347,27 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$_GET['totp_use'] = '0';
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'delete',
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'delete',
|
||||
'loadByUserId'
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('delete')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
$oUser = oxNew(User::class);
|
||||
$oUser->setId('foo');
|
||||
|
||||
/** @var d3_account_totp|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_account_totp::class, array(
|
||||
'getTotpObject',
|
||||
'getUser'
|
||||
));
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getTotpObject',
|
||||
'getUser'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->expects($this->once())->method('getUser')->willReturn($oUser);
|
||||
|
||||
@ -357,7 +384,10 @@ class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod($this->_oController, 'getTotpObject')
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getTotpObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3totploginTest extends d3TotpUnitTestCase
|
||||
@ -30,7 +30,7 @@ class d3totploginTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
@ -40,7 +40,7 @@ class d3totploginTest extends d3TotpUnitTestCase
|
||||
Registry::getSession()->deleteVariable(d3totp::TOTP_SESSION_CURRENTCLASS);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@ -53,16 +53,16 @@ class d3totploginTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function renderRedirectIfNoTotp()
|
||||
{
|
||||
/** @var Utils|PHPUnit_Framework_MockObject_MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->getMock(Utils::class, array(
|
||||
'redirect'
|
||||
));
|
||||
/** @var Utils|MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->getMockBuilder(Utils::class)
|
||||
->onlyMethods(['redirect'])
|
||||
->getMock();
|
||||
$oUtilsMock->expects($this->once())->method('redirect')->willReturn(true);
|
||||
|
||||
/** @var d3totplogin|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3totplogin::class, array(
|
||||
'getUtils'
|
||||
));
|
||||
/** @var d3totplogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3totplogin::class)
|
||||
->onlyMethods(['getUtils'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUtils')->willReturn($oUtilsMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -78,16 +78,16 @@ class d3totploginTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, 'foo');
|
||||
|
||||
/** @var Utils|PHPUnit_Framework_MockObject_MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->getMock(Utils::class, array(
|
||||
'redirect'
|
||||
));
|
||||
/** @var Utils|MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->getMockBuilder(Utils::class)
|
||||
->onlyMethods(['redirect'])
|
||||
->getMock();
|
||||
$oUtilsMock->expects($this->never())->method('redirect')->willReturn(true);
|
||||
|
||||
/** @var d3totplogin|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3totplogin::class, array(
|
||||
'getUtils'
|
||||
));
|
||||
/** @var d3totplogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3totplogin::class)
|
||||
->onlyMethods(['getUtils'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUtils')->willReturn($oUtilsMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -106,7 +106,10 @@ class d3totploginTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Utils::class,
|
||||
$this->callMethod($this->_oController, 'getUtils')
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getUtils'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -116,16 +119,16 @@ class d3totploginTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getBackupCodeCountMessageReturnMessage()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodesListMock */
|
||||
$oBackupCodesListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'getAvailableCodeCount'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodesListMock */
|
||||
$oBackupCodesListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodesListMock->method('getAvailableCodeCount')->willReturn(1);
|
||||
|
||||
/** @var d3totplogin|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3totplogin::class, array(
|
||||
'getBackupCodeListObject'
|
||||
));
|
||||
/** @var d3totplogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3totplogin::class)
|
||||
->onlyMethods(['getBackupCodeListObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodesListMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -145,16 +148,16 @@ class d3totploginTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getBackupCodeCountMessageReturnNoMessage()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodesListMock */
|
||||
$oBackupCodesListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'getAvailableCodeCount'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodesListMock */
|
||||
$oBackupCodesListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodesListMock->method('getAvailableCodeCount')->willReturn(1234);
|
||||
|
||||
/** @var d3totplogin|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3totplogin::class, array(
|
||||
'getBackupCodeListObject'
|
||||
));
|
||||
/** @var d3totplogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3totplogin::class)
|
||||
->onlyMethods(['getBackupCodeListObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodesListMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -263,9 +266,9 @@ class d3totploginTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$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->assertInternalType('string', $aBreadCrumb[0]['link']);
|
||||
$this->assertIsString($aBreadCrumb[0]['link']);
|
||||
$this->assertTrue(strlen($aBreadCrumb[0]['link']) > 1);
|
||||
}
|
||||
}
|
@ -25,14 +25,14 @@ class d3totp_wrongOtpExceptionTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(d3totp_wrongOtpException::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
|
@ -25,14 +25,14 @@ class d3RandomGeneratorTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(d3RandomGenerator::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
|
@ -18,7 +18,7 @@ use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3backupcodeTest extends d3TotpUnitTestCase
|
||||
@ -29,14 +29,14 @@ class d3backupcodeTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(d3backupcode::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@ -52,11 +52,13 @@ class d3backupcodeTest extends d3TotpUnitTestCase
|
||||
$sTestUserId = 'testUserId';
|
||||
$sBackupCode = '123456';
|
||||
|
||||
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3backupcode::class, array(
|
||||
'getRandomTotpBackupCode',
|
||||
'd3EncodeBC',
|
||||
));
|
||||
/** @var d3backupcode|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods([
|
||||
'getRandomTotpBackupCode',
|
||||
'd3EncodeBC'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getRandomTotpBackupCode')->willReturn($sBackupCode);
|
||||
$oModelMock->method('d3EncodeBC')->will(
|
||||
$this->returnCallback(function ($arg) {
|
||||
@ -90,26 +92,29 @@ class d3backupcodeTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3EncodeBCPass()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array('load'), array(), '', false);
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['load'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oUserMock->method('load')->willReturn(true);
|
||||
$oUserMock->assign(
|
||||
array(
|
||||
'oxpasssalt' => 'abcdefghijk'
|
||||
)
|
||||
[
|
||||
'oxpasssalt' => '6162636465666768696A6B'
|
||||
]
|
||||
);
|
||||
|
||||
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3backupcode::class, array(
|
||||
'd3GetUser',
|
||||
));
|
||||
/** @var d3backupcode|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['d3GetUserObject'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetUserObject')->willReturn($oUserMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertSame(
|
||||
'e10adc3949ba59abbe56e057f20f883e',
|
||||
$this->callMethod($this->_oModel, 'd3EncodeBC', array('123456', 'userId'))
|
||||
'9f7f502a8148f90732a4aa4d880b8cf5',
|
||||
$this->callMethod($this->_oModel, 'd3EncodeBC', ['123456', 'userId'])
|
||||
);
|
||||
}
|
||||
|
||||
@ -119,12 +124,14 @@ class d3backupcodeTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3GetUserReturnCachedUser()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(), array(), '', false);
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oUserMock->assign(
|
||||
array(
|
||||
[
|
||||
'oxid' => 'foobar'
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->_oModel->setUser($oUserMock);
|
||||
|
@ -20,7 +20,7 @@ use OxidEsales\Eshop\Application\Controller\FrontendController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Config;
|
||||
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
@ -31,14 +31,14 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(d3backupcodelist::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@ -51,31 +51,32 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function generateBackupCodes()
|
||||
{
|
||||
/** @var FrontendController|PHPUnit_Framework_MockObject_MockObject $oConfigMock */
|
||||
$oViewMock = $this->getMock(FrontendController::class, array(
|
||||
'setBackupCodes'
|
||||
));
|
||||
/** @var FrontendController|MockObject $oConfigMock */
|
||||
$oViewMock = $this->getMockBuilder(FrontendController::class)
|
||||
->addMethods(['setBackupCodes'])
|
||||
->getMock();
|
||||
$oViewMock->expects($this->once())->method('setBackupCodes')->willReturn(true);
|
||||
|
||||
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oConfigMock */
|
||||
$oConfigMock = $this->getMock(d3backupcode::class, array(
|
||||
'getActiveView'
|
||||
));
|
||||
/** @var Config|MockObject $oConfigMock */
|
||||
$oConfigMock = $this->getMockBuilder(Config::class)
|
||||
->onlyMethods(['getActiveView'])
|
||||
->getMock();
|
||||
$oConfigMock->method('getActiveView')->willReturn($oViewMock);
|
||||
|
||||
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMock(d3backupcode::class, array(
|
||||
'generateCode'
|
||||
));
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['generateCode'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->exactly(10))->method('generateCode');
|
||||
$oBackupCodeMock->method('getD3BackupCodeObject')->willReturn($oBackupCodeMock);
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'deleteAllFromUser',
|
||||
'getD3BackupCodeObject',
|
||||
'd3GetConfig'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'deleteAllFromUser',
|
||||
'getD3BackupCodeObject',
|
||||
'd3GetConfig'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->expects($this->once())->method('deleteAllFromUser')->willReturn(true);
|
||||
$oModelMock->method('getD3BackupCodeObject')->willReturn($oBackupCodeMock);
|
||||
$oModelMock->method('d3GetConfig')->willReturn($oConfigMock);
|
||||
@ -115,20 +116,20 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function savePass()
|
||||
{
|
||||
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMock(d3backupcode::class, array(
|
||||
'save'
|
||||
));
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['save'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->once())->method('save')->willReturn(true);
|
||||
|
||||
$aBackupCodeArray = [
|
||||
$oBackupCodeMock
|
||||
];
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'getArray'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getArray'])
|
||||
->getMock();
|
||||
$oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -144,7 +145,7 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$oBaseObject = $this->callMethod($this->_oModel, 'getBaseObject');
|
||||
|
||||
$this->assertInternalType('object', $oBaseObject);
|
||||
$this->assertIsObject($oBaseObject);
|
||||
$this->assertInstanceOf(d3backupcode::class, $oBaseObject);
|
||||
}
|
||||
|
||||
@ -154,34 +155,39 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function verifyFoundTotp()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'getId'
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foobar');
|
||||
|
||||
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMock(d3backupcode::class, array(
|
||||
'delete'
|
||||
));
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->once())->method('delete')->willReturn(true);
|
||||
|
||||
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */
|
||||
$oDbMock = $this->getMock(Database::class, array(
|
||||
'getOne',
|
||||
'quoteIdentifier',
|
||||
'quote',
|
||||
), array(), '', false);
|
||||
/** @var Database|MockObject $oDbMock */
|
||||
$oDbMock = $this->getMockBuilder(Database::class)
|
||||
->onlyMethods([
|
||||
'getOne',
|
||||
'quoteIdentifier',
|
||||
'quote'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oDbMock->expects($this->once())->method('getOne')->willReturn('foobar');
|
||||
$oDbMock->method('quoteIdentifier')->willReturn(true);
|
||||
$oDbMock->method('quote')->willReturn(true);
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'd3GetDb',
|
||||
'getBaseObject',
|
||||
'd3GetUser'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'd3GetDb',
|
||||
'getBaseObject',
|
||||
'd3GetUser'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetDb')->willReturn($oDbMock);
|
||||
$oModelMock->method('getBaseObject')->willReturn($oBackupCodeMock);
|
||||
$oModelMock->method('d3GetUser')->willReturn($oUserMock);
|
||||
@ -199,34 +205,39 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function verifyNotFoundTotp()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'getId'
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foobar');
|
||||
|
||||
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMock(d3backupcode::class, array(
|
||||
'delete'
|
||||
));
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->never())->method('delete')->willReturn(true);
|
||||
|
||||
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */
|
||||
$oDbMock = $this->getMock(Database::class, array(
|
||||
'getOne',
|
||||
'quoteIdentifier',
|
||||
'quote',
|
||||
), array(), '', false);
|
||||
/** @var Database|MockObject $oDbMock */
|
||||
$oDbMock = $this->getMockBuilder(Database::class)
|
||||
->onlyMethods([
|
||||
'getOne',
|
||||
'quoteIdentifier',
|
||||
'quote',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oDbMock->expects($this->once())->method('getOne')->willReturn(null);
|
||||
$oDbMock->method('quoteIdentifier')->willReturn(true);
|
||||
$oDbMock->method('quote')->willReturn(true);
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'd3GetDb',
|
||||
'getBaseObject',
|
||||
'd3GetUser'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'd3GetDb',
|
||||
'getBaseObject',
|
||||
'd3GetUser'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetDb')->willReturn($oDbMock);
|
||||
$oModelMock->method('getBaseObject')->willReturn($oBackupCodeMock);
|
||||
$oModelMock->method('d3GetUser')->willReturn($oUserMock);
|
||||
@ -256,30 +267,35 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function deleteAllFromUserCodesFound()
|
||||
{
|
||||
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */
|
||||
$oDbMock = $this->getMock(Database::class, array(
|
||||
'quoteIdentifier',
|
||||
'quote',
|
||||
), array(), '', false);
|
||||
/** @var Database|MockObject $oDbMock */
|
||||
$oDbMock = $this->getMockBuilder(Database::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'quoteIdentifier',
|
||||
'quote',
|
||||
])
|
||||
->getMock();
|
||||
$oDbMock->method('quoteIdentifier')->willReturn(true);
|
||||
$oDbMock->method('quote')->willReturn(true);
|
||||
|
||||
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMock(d3backupcode::class, array(
|
||||
'delete'
|
||||
));
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->once())->method('delete')->willReturn(true);
|
||||
|
||||
$aBackupCodeArray = [
|
||||
$oBackupCodeMock
|
||||
];
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'getArray',
|
||||
'selectString',
|
||||
'd3GetDb'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'getArray',
|
||||
'selectString',
|
||||
'd3GetDb'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray);
|
||||
$oModelMock->expects($this->once())->method('selectString')->willReturn(true);
|
||||
$oModelMock->method('d3GetDb')->willReturn($oDbMock);
|
||||
@ -295,28 +311,33 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function deleteAllFromUserNoCodesFound()
|
||||
{
|
||||
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */
|
||||
$oDbMock = $this->getMock(Database::class, array(
|
||||
'quoteIdentifier',
|
||||
'quote',
|
||||
), array(), '', false);
|
||||
/** @var Database|MockObject $oDbMock */
|
||||
$oDbMock = $this->getMockBuilder(Database::class)
|
||||
->onlyMethods([
|
||||
'quoteIdentifier',
|
||||
'quote',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oDbMock->method('quoteIdentifier')->willReturn(true);
|
||||
$oDbMock->method('quote')->willReturn(true);
|
||||
|
||||
/** @var d3backupcode|PHPUnit_Framework_MockObject_MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMock(d3backupcode::class, array(
|
||||
'delete'
|
||||
));
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->never())->method('delete')->willReturn(true);
|
||||
|
||||
$aBackupCodeArray = [];
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'getArray',
|
||||
'selectString',
|
||||
'd3GetDb'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'getArray',
|
||||
'selectString',
|
||||
'd3GetDb'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray);
|
||||
$oModelMock->expects($this->once())->method('selectString')->willReturn(true);
|
||||
$oModelMock->method('d3GetDb')->willReturn($oDbMock);
|
||||
@ -332,20 +353,23 @@ class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getAvailableCodeCountPass()
|
||||
{
|
||||
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */
|
||||
$oDbMock = $this->getMock(Database::class, array(
|
||||
'getOne',
|
||||
'quoteIdentifier',
|
||||
'quote',
|
||||
), array(), '', false);
|
||||
/** @var Database|MockObject $oDbMock */
|
||||
$oDbMock = $this->getMockBuilder(Database::class)
|
||||
->onlyMethods([
|
||||
'getOne',
|
||||
'quoteIdentifier',
|
||||
'quote'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oDbMock->expects($this->once())->method('getOne')->willReturn('25');
|
||||
$oDbMock->method('quoteIdentifier')->willReturn(true);
|
||||
$oDbMock->method('quote')->willReturn(true);
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'd3GetDb',
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['d3GetDb'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetDb')->willReturn($oDbMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
@ -23,8 +23,9 @@ use OTPHP\TOTP;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
use stdClass;
|
||||
|
||||
class d3totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
@ -34,14 +35,14 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(d3totp::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@ -54,10 +55,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function constructCallsInit()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'init',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['init'])
|
||||
->getMock();
|
||||
$oModelMock->expects($this->once())->method('init');
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -71,17 +72,20 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function loadByUserIdTableNotExist()
|
||||
{
|
||||
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */
|
||||
$oDbMock = $this->getMock(Database::class, array(
|
||||
'getOne'
|
||||
), array(), '', false);
|
||||
/** @var Database|MockObject $oDbMock */
|
||||
$oDbMock = $this->getMockBuilder(Database::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['getOne'])
|
||||
->getMock();
|
||||
$oDbMock->expects($this->once())->method('getOne')->willReturnOnConsecutiveCalls(false, true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'd3GetDb',
|
||||
'load'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'd3GetDb',
|
||||
'load'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetDb')->willReturn($oDbMock);
|
||||
$oModelMock->expects($this->never())->method('load')->willReturn(true);
|
||||
|
||||
@ -96,19 +100,23 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function loadByUserIdTableExist()
|
||||
{
|
||||
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */
|
||||
$oDbMock = $this->getMock(Database::class, array(
|
||||
'getOne',
|
||||
'quote'
|
||||
), array(), '', false);
|
||||
/** @var Database|MockObject $oDbMock */
|
||||
$oDbMock = $this->getMockBuilder(Database::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'getOne',
|
||||
'quote'
|
||||
])->getMock();
|
||||
$oDbMock->expects($this->exactly(2))->method('getOne')->willReturnOnConsecutiveCalls(true, true);
|
||||
$oDbMock->method('quote')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'd3GetDb',
|
||||
'load'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'd3GetDb',
|
||||
'load'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetDb')->willReturn($oDbMock);
|
||||
$oModelMock->expects($this->once())->method('load')->willReturn(true);
|
||||
|
||||
@ -123,17 +131,19 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getUserFromMember()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'load'
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['load'])
|
||||
->getMock();
|
||||
$oUserMock->method('load')->with('foobar')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'd3GetUser',
|
||||
'getFieldData',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'd3GetUser',
|
||||
'getFieldData',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetUser')->willReturn($oUserMock);
|
||||
$oModelMock->expects($this->never())->method('getFieldData')->willReturn(true);
|
||||
|
||||
@ -155,17 +165,19 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$this->setValue($this->_oModel, 'userId', null);
|
||||
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'load'
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['load'])
|
||||
->getMock();
|
||||
$oUserMock->method('load')->with('barfoo')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'd3GetUser',
|
||||
'getFieldData',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'd3GetUser',
|
||||
'getFieldData',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetUser')->willReturn($oUserMock);
|
||||
$oModelMock->expects($this->once())->method('getFieldData')->willReturn('barfoo');
|
||||
|
||||
@ -183,18 +195,21 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function checkIfAlreadyExistPass()
|
||||
{
|
||||
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */
|
||||
$oDbMock = $this->getMock(Database::class, array(
|
||||
'getOne',
|
||||
'quote'
|
||||
), array(), '', false);
|
||||
/** @var Database|MockObject $oDbMock */
|
||||
$oDbMock = $this->getMockBuilder(Database::class)
|
||||
->onlyMethods([
|
||||
'getOne',
|
||||
'quote'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oDbMock->expects($this->once())->method('getOne')->willReturn(1);
|
||||
$oDbMock->method('quote')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'd3GetDb'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['d3GetDb'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetDb')->willReturn($oDbMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -236,10 +251,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'UserUseTotp',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['UserUseTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('UserUseTotp')->willReturn(true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -257,10 +272,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'UserUseTotp',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['UserUseTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('UserUseTotp')->willReturn(false);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -278,10 +293,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'UserUseTotp',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['UserUseTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('UserUseTotp')->willReturn(true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -299,10 +314,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'UserUseTotp',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['UserUseTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('UserUseTotp')->willReturn(false);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -318,10 +333,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function UserUseTotpPass()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getFieldData',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(true, true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -337,10 +352,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function UserUseTotpNoTotp()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getFieldData',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(false, true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -356,10 +371,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function UserUseTotpNoSeed()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getFieldData',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(true, false);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -375,10 +390,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function UserUseTotpNoTotpAndNoSeed()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getFieldData',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(false, false);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -394,11 +409,13 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getSavedSecretExistingSeed()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getFieldData',
|
||||
'decrypt',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getFieldData',
|
||||
'decrypt'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturn('seed');
|
||||
$oModelMock->method('decrypt')->willReturn('unencseed');
|
||||
|
||||
@ -416,11 +433,13 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getSavedSecretNoSeed()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getFieldData',
|
||||
'decrypt',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getFieldData',
|
||||
'decrypt'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturn(null);
|
||||
$oModelMock->method('decrypt')->willReturn('unencseed');
|
||||
|
||||
@ -437,11 +456,13 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getSavedSecretCantDecrypt()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getFieldData',
|
||||
'decrypt',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getFieldData',
|
||||
'decrypt'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturn('seed');
|
||||
$oModelMock->method('decrypt')->willReturn(false);
|
||||
|
||||
@ -458,8 +479,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getTotpReturnsCachedObject()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->setValue($this->_oModel, 'totp', $oTotpMock);
|
||||
|
||||
@ -475,17 +498,19 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getTotpReturnsNewObject()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'getFieldData',
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oUserMock->method('getFieldData')->willReturn('username');
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getUser',
|
||||
'getSavedSecret'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getUser',
|
||||
'getSavedSecret'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getUser')->willReturn($oUserMock);
|
||||
$oModelMock->method('getSavedSecret')->willReturn('savedSecret');
|
||||
|
||||
@ -505,17 +530,21 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getTotpReturnsNewObjectNoUserGivenSeed()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'getFieldData',
|
||||
));
|
||||
$oUserMock->method('getFieldData')->willReturn(false);
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oUserMock->method('getFieldData')->willReturnMap(
|
||||
[['oxusername', 'oxusername']]
|
||||
);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getUser',
|
||||
'getSavedSecret'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getUser',
|
||||
'getSavedSecret'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getUser')->willReturn($oUserMock);
|
||||
$oModelMock->method('getSavedSecret')->willReturn('savedSecret');
|
||||
|
||||
@ -525,33 +554,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
$oTotp = $this->callMethod($this->_oModel, 'getTotp', ['givenSeed']);
|
||||
|
||||
$this->assertInstanceOf(TOTP::class, $oTotp);
|
||||
$this->assertSame(null, $oTotp->getLabel());
|
||||
$this->assertSame('oxusername', $oTotp->getLabel());
|
||||
$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
|
||||
* @throws ReflectionException
|
||||
@ -560,29 +566,24 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$renderer = BaconQrCodeFactory::renderer(200);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'getProvisioningUri'
|
||||
));
|
||||
$oTotpMock->method('getProvisioningUri')->willReturn(true);
|
||||
/** @var stdClass|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(stdClass::class)
|
||||
->addMethods(['getProvisioningUri'])
|
||||
->getMock();
|
||||
$oTotpMock->method('getProvisioningUri')->willReturn('uri');
|
||||
|
||||
/** @var Writer|PHPUnit_Framework_MockObject_MockObject $oWriterMock */
|
||||
$oWriterMock = $this->getMock(Writer::class, array(
|
||||
'writeString'
|
||||
), array($renderer));
|
||||
$oWriterMock->expects($this->once())->method('writeString')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'd3GetWriter',
|
||||
'getTotp'
|
||||
));
|
||||
$oModelMock->method('d3GetWriter')->willReturn($oWriterMock);
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getTotp'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($oTotpMock);
|
||||
|
||||
$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()
|
||||
{
|
||||
$renderer = BaconQrCodeFactory::renderer(200);;
|
||||
$renderer = BaconQrCodeFactory::renderer(200);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Writer::class,
|
||||
@ -605,16 +606,16 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getSecretPass()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'getSecret'
|
||||
));
|
||||
$oTotpMock->expects($this->once())->method('getSecret')->willReturn(true);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getSecret'])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('getSecret')->willReturn('fixture');
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getTotp'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($oTotpMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -628,10 +629,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function saveSecretPass()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'encrypt'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['encrypt'])
|
||||
->getMock();
|
||||
$oModelMock->method('encrypt')->willReturn('enc_secret');
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -649,16 +650,16 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function verifyPass()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify'
|
||||
));
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('verify')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getTotp'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($oTotpMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
@ -674,23 +675,25 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function verifyBackupCodePass()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'verify'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['verify'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->once())->method('verify')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify'
|
||||
));
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('verify')->willReturn(false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getTotp',
|
||||
'd3GetBackupCodeListObject'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getTotp',
|
||||
'd3GetBackupCodeListObject'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($oTotpMock);
|
||||
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
@ -707,25 +710,27 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function verifyFailed()
|
||||
{
|
||||
$this->setExpectedException(d3totp_wrongOtpException::class);
|
||||
$this->expectException(d3totp_wrongOtpException::class);
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'verify'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['verify'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->once())->method('verify')->willReturn(false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify'
|
||||
));
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('verify')->willReturn(false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getTotp',
|
||||
'd3GetBackupCodeListObject'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getTotp',
|
||||
'd3GetBackupCodeListObject'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($oTotpMock);
|
||||
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
@ -740,25 +745,27 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function verifyWithSeedFailed()
|
||||
{
|
||||
$this->setExpectedException(d3totp_wrongOtpException::class);
|
||||
$this->expectException(d3totp_wrongOtpException::class);
|
||||
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'verify'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['verify'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->never())->method('verify')->willReturn(false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify'
|
||||
));
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('verify')->willReturn(false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'getTotp',
|
||||
'd3GetBackupCodeListObject'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getTotp',
|
||||
'd3GetBackupCodeListObject'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($oTotpMock);
|
||||
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
@ -788,7 +795,7 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
$sReturn = $this->callMethod($this->_oModel, 'encrypt', ['foobar']);
|
||||
|
||||
// indirect tests, because string changes on every call
|
||||
$this->assertInternalType('string', $sReturn);
|
||||
$this->assertIsString($sReturn);
|
||||
$this->assertNotSame('foobar', $sReturn);
|
||||
$this->assertStringEndsWith('==', $sReturn);
|
||||
$this->assertTrue(strlen($sReturn) === 88);
|
||||
@ -815,10 +822,10 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function decryptFailed()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'd3Base64_decode',
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['d3Base64_decode'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3Base64_decode')->willReturn(
|
||||
str_pad('foobar', 16, 0, STR_PAD_LEFT)
|
||||
);
|
||||
@ -852,18 +859,20 @@ class d3totpTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function deletePass()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'deleteAllFromUser'
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['deleteAllFromUser'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->once())->method('deleteAllFromUser')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(d3totp::class, array(
|
||||
'd3GetBackupCodeListObject',
|
||||
'getFieldData',
|
||||
'canDelete'
|
||||
));
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'd3GetBackupCodeListObject',
|
||||
'getFieldData',
|
||||
'canDelete'
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
$oModelMock->method('getFieldData')->willReturn('newId');
|
||||
$oModelMock->method('canDelete')->willReturn(false);
|
||||
|
@ -23,7 +23,7 @@ use OxidEsales\Eshop\Core\Controller\BaseController;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\UtilsView;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
@ -34,7 +34,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
@ -43,7 +43,7 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@ -58,28 +58,33 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
{
|
||||
$oUser = false;
|
||||
|
||||
/** @var BaseController|PHPUnit_Framework_MockObject_MockObject $oParentMock */
|
||||
$oParentMock = $this->getMock(BaseController::class, array(
|
||||
'isEnabledPrivateSales',
|
||||
));
|
||||
/** @var BaseController|MockObject $oParentMock */
|
||||
$oParentMock = $this->getMockBuilder(BaseController::class)
|
||||
->addMethods(['isEnabledPrivateSales'])
|
||||
->getMock();
|
||||
$oParentMock->method('isEnabledPrivateSales')->willReturn(false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->never())->method('isActive')->willReturn(false);
|
||||
|
||||
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(UserComponent::class, array(
|
||||
'getUser',
|
||||
'd3GetTotpObject',
|
||||
'getParent'
|
||||
));
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'getUser',
|
||||
'd3GetTotpObject',
|
||||
'getParent'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getParent')->willReturn($oParentMock);
|
||||
|
||||
$_GET['lgn_usr'] = 'username';
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'login_noredirect');
|
||||
@ -91,38 +96,47 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function login_noredirectFailTotpNotActive()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'logout',
|
||||
'getId',
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'logout',
|
||||
'getId'
|
||||
])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->never())->method('logout')->willReturn(false);
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var BaseController|PHPUnit_Framework_MockObject_MockObject $oParentMock */
|
||||
$oParentMock = $this->getMock(BaseController::class, array(
|
||||
'isEnabledPrivateSales',
|
||||
));
|
||||
/** @var BaseController|MockObject $oParentMock */
|
||||
$oParentMock = $this->getMockBuilder(BaseController::class)
|
||||
->addMethods(['isEnabledPrivateSales'])
|
||||
->getMock();
|
||||
$oParentMock->method('isEnabledPrivateSales')->willReturn(false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('isActive')->willReturn(false);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(UserComponent::class, array(
|
||||
'getUser',
|
||||
'd3GetTotpObject',
|
||||
'getParent'
|
||||
));
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'getUser',
|
||||
'd3GetTotpObject',
|
||||
'getParent'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUser')->willReturn($oUserMock);
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getParent')->willReturn($oParentMock);
|
||||
|
||||
$_GET['lgn_usr'] = 'username';
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'login_noredirect');
|
||||
@ -134,38 +148,47 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function login_noredirectPass()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'logout',
|
||||
'getId',
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'logout',
|
||||
'getId',
|
||||
])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->once())->method('logout')->willReturn(false);
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var BaseController|PHPUnit_Framework_MockObject_MockObject $oParentMock */
|
||||
$oParentMock = $this->getMock(BaseController::class, array(
|
||||
'isEnabledPrivateSales',
|
||||
));
|
||||
/** @var BaseController|MockObject $oParentMock */
|
||||
$oParentMock = $this->getMockBuilder(BaseController::class)
|
||||
->addMethods(['isEnabledPrivateSales'])
|
||||
->getMock();
|
||||
$oParentMock->method('isEnabledPrivateSales')->willReturn(false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('isActive')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(UserComponent::class, array(
|
||||
'getUser',
|
||||
'd3GetTotpObject',
|
||||
'getParent'
|
||||
));
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'getUser',
|
||||
'd3GetTotpObject',
|
||||
'getParent'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUser')->willReturn($oUserMock);
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getParent')->willReturn($oParentMock);
|
||||
|
||||
$_GET['lgn_usr'] = 'username';
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
@ -192,19 +215,22 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function checkTotploginNoTotpLogin()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(UserComponent::class, array(
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
'd3TotpRelogin',
|
||||
'd3GetTotpObject'
|
||||
));
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
'd3TotpRelogin',
|
||||
'd3GetTotpObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(true);
|
||||
$oControllerMock->expects($this->never())->method('hasValidTotp')->willReturn(false);
|
||||
$oControllerMock->expects($this->never())->method('d3TotpRelogin')->willReturn(false);
|
||||
@ -224,29 +250,34 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function checkTotploginUnvalidTotp()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var d3totp_wrongOtpException|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */
|
||||
$oTotpExceptionMock = $this->getMock(d3totp_wrongOtpException::class, array(), array(), '', false);
|
||||
/** @var d3totp_wrongOtpException|MockObject $oUtilsViewMock */
|
||||
$oTotpExceptionMock = $this->getMockBuilder(d3totp_wrongOtpException::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */
|
||||
$oUtilsViewMock = $this->getMock(UtilsView::class, array(
|
||||
'addErrorToDisplay',
|
||||
));
|
||||
/** @var UtilsView|MockObject $oUtilsViewMock */
|
||||
$oUtilsViewMock = $this->getMockBuilder(UtilsView::class)
|
||||
->onlyMethods(['addErrorToDisplay'])
|
||||
->getMock();
|
||||
$oUtilsViewMock->expects($this->atLeast(1))->method('addErrorToDisplay')->willReturn(true);
|
||||
|
||||
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(UserComponent::class, array(
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
'd3TotpRelogin',
|
||||
'd3GetUtilsView',
|
||||
'd3GetTotpObject'
|
||||
));
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
'd3TotpRelogin',
|
||||
'd3GetUtilsView',
|
||||
'd3GetTotpObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false);
|
||||
$oControllerMock->expects($this->once())->method('hasValidTotp')->willThrowException($oTotpExceptionMock);
|
||||
$oControllerMock->expects($this->never())->method('d3TotpRelogin')->willReturn(false);
|
||||
@ -267,26 +298,29 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function checkTotploginValidTotp()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */
|
||||
$oUtilsViewMock = $this->getMock(UtilsView::class, array(
|
||||
'addErrorToDisplay',
|
||||
));
|
||||
/** @var UtilsView|MockObject $oUtilsViewMock */
|
||||
$oUtilsViewMock = $this->getMockBuilder(UtilsView::class)
|
||||
->onlyMethods(['addErrorToDisplay'])
|
||||
->getMock();
|
||||
$oUtilsViewMock->expects($this->never())->method('addErrorToDisplay')->willReturn(true);
|
||||
|
||||
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(UserComponent::class, array(
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
'd3TotpRelogin',
|
||||
'd3GetUtilsView',
|
||||
'd3GetTotpObject'
|
||||
));
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
'd3TotpRelogin',
|
||||
'd3GetUtilsView',
|
||||
'd3GetTotpObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false);
|
||||
$oControllerMock->expects($this->once())->method('hasValidTotp')->willReturn(true);
|
||||
$oControllerMock->expects($this->once())->method('d3TotpRelogin')->willReturn(true);
|
||||
@ -318,10 +352,10 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canCancelTotpLogin()
|
||||
{
|
||||
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(UserComponent::class, array(
|
||||
'd3TotpClearSessionVariables',
|
||||
));
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(UserComponent::class)
|
||||
->onlyMethods(['d3TotpClearSessionVariables'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3TotpClearSessionVariables')->willReturn(false);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -337,10 +371,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
$this->assertTrue(
|
||||
@ -356,10 +391,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
|
||||
$this->assertTrue(
|
||||
@ -375,10 +411,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_CURRENTUSER, true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
$this->assertFalse(
|
||||
@ -394,10 +431,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(false);
|
||||
|
||||
$this->assertTrue(
|
||||
@ -413,10 +451,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(true);
|
||||
|
||||
$this->assertTrue(
|
||||
@ -432,10 +471,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(true);
|
||||
|
||||
$this->assertFalse(
|
||||
@ -451,10 +491,11 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(false);
|
||||
|
||||
$this->assertFalse(
|
||||
@ -468,25 +509,27 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3TotpReloginPass()
|
||||
{
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'setVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['setVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->atLeast(2))->method('setVariable')->willReturn(false);
|
||||
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'getId',
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(UserComponent::class, array(
|
||||
'd3GetSession',
|
||||
'setUser',
|
||||
'setLoginStatus',
|
||||
'_afterLogin',
|
||||
));
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'd3GetSession',
|
||||
'setUser',
|
||||
'setLoginStatus',
|
||||
'_afterLogin'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->expects($this->once())->method('setUser')->willReturn(false);
|
||||
$oControllerMock->expects($this->once())->method('setLoginStatus')->willReturn(false);
|
||||
@ -503,16 +546,16 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3TotpClearSessionVariablesPass()
|
||||
{
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'deleteVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['deleteVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->atLeast(3))->method('deleteVariable')->willReturn(false);
|
||||
|
||||
/** @var UserComponent|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(UserComponent::class, array(
|
||||
'd3GetSession',
|
||||
));
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(UserComponent::class)
|
||||
->onlyMethods(['d3GetSession'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
@ -22,7 +22,7 @@ use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\UtilsView;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
@ -53,27 +53,34 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canRenderNoAuth()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->never())->method('isActive')->willReturn(false);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
'setVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods([
|
||||
'getVariable',
|
||||
'setVariable'
|
||||
])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(false, true));
|
||||
$oSessionMock->expects($this->never())->method('setVariable')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetSession',
|
||||
'd3GetTotpObject'
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods([
|
||||
'd3GetSession',
|
||||
'd3GetTotpObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
|
||||
@ -89,27 +96,34 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canRenderTotpNotActive()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('isActive')->willReturn(false);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
'setVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods([
|
||||
'getVariable',
|
||||
'setVariable',
|
||||
])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(true, true));
|
||||
$oSessionMock->expects($this->never())->method('setVariable')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetSession',
|
||||
'd3GetTotpObject'
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods([
|
||||
'd3GetSession',
|
||||
'd3GetTotpObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
|
||||
@ -125,27 +139,34 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canRenderInTotpLoginProcess()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('isActive')->willReturn(false);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
'setVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods([
|
||||
'getVariable',
|
||||
'setVariable',
|
||||
])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(true, true));
|
||||
$oSessionMock->expects($this->never())->method('setVariable')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetSession',
|
||||
'd3GetTotpObject'
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods([
|
||||
'd3GetSession',
|
||||
'd3GetTotpObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
|
||||
@ -161,27 +182,34 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function canRenderRequestTotp()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('isActive')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
'setVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods([
|
||||
'getVariable',
|
||||
'setVariable',
|
||||
])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls(true, false));
|
||||
$oSessionMock->expects($this->once())->method('setVariable')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetSession',
|
||||
'd3GetTotpObject'
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods([
|
||||
'd3GetSession',
|
||||
'd3GetTotpObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
|
||||
@ -245,55 +273,69 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function checkloginNoTotp()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetTotpObject',
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(true);
|
||||
$oControllerMock->method('hasValidTotp')->willReturn(false);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertEmpty($this->callMethod($this->_oController, 'checklogin'));
|
||||
$this->assertSame(
|
||||
'login',
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'checklogin'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function checkloginUnvalidTotp()
|
||||
public function checkloginInvalidTotp()
|
||||
{
|
||||
/** @var d3totp_wrongOtpException|PHPUnit_Framework_MockObject_MockObject $oUtilsViewMock */
|
||||
$oTotpExceptionMock = $this->getMock(d3totp_wrongOtpException::class, array(), array(), '', false);
|
||||
/** @var d3totp_wrongOtpException|MockObject $oUtilsViewMock */
|
||||
$oTotpExceptionMock = $this->getMockBuilder(d3totp_wrongOtpException::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $utilsViewMock */
|
||||
$utilsViewMock = $this->getMock(UtilsView::class, array(
|
||||
'addErrorToDisplay',
|
||||
));
|
||||
$utilsViewMock->expects($oSpy = $this->once())->method('addErrorToDisplay')->willReturn(true);
|
||||
/** @var UtilsView|MockObject $utilsViewMock */
|
||||
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
|
||||
->onlyMethods(['addErrorToDisplay'])
|
||||
->getMock();
|
||||
$utilsViewMock->expects($this->once())->method('addErrorToDisplay')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetTotpObject',
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
'd3GetUtilsView',
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
'd3GetUtilsView'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false);
|
||||
$oControllerMock->method('hasValidTotp')->willThrowException($oTotpExceptionMock);
|
||||
@ -301,7 +343,10 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
|
||||
$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()
|
||||
{
|
||||
/** @var UtilsView|PHPUnit_Framework_MockObject_MockObject $utilsViewMock */
|
||||
$utilsViewMock = $this->getMock(UtilsView::class, array(
|
||||
'addErrorToDisplay',
|
||||
));
|
||||
/** @var UtilsView|MockObject $utilsViewMock */
|
||||
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
|
||||
->onlyMethods(['addErrorToDisplay'])
|
||||
->getMock();
|
||||
$utilsViewMock->expects($this->never())->method('addErrorToDisplay')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'setVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['setVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->once())->method('setVariable')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetTotpObject',
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
'd3GetUtilsView',
|
||||
'd3GetSession',
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'isNoTotpOrNoLogin',
|
||||
'hasValidTotp',
|
||||
'd3GetUtilsView',
|
||||
'd3GetSession'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('isNoTotpOrNoLogin')->willReturn(false);
|
||||
$oControllerMock->method('hasValidTotp')->willReturn(true);
|
||||
@ -353,16 +401,16 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getBackupCodeCountMessageShowMessage()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'getAvailableCodeCount',
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(2);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetBackupCodeListObject',
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods(['d3GetBackupCodeListObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -382,16 +430,16 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function getBackupCodeCountMessageDontShowMessage()
|
||||
{
|
||||
/** @var d3backupcodelist|PHPUnit_Framework_MockObject_MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMock(d3backupcodelist::class, array(
|
||||
'getAvailableCodeCount',
|
||||
));
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(10);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetBackupCodeListObject',
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods(['d3GetBackupCodeListObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -407,22 +455,23 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function isNoTotpOrNoLoginIsAuth()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetSession',
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods(['d3GetSession'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -438,22 +487,23 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function isNoTotpOrNoLoginTotpNotActive()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetSession',
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods(['d3GetSession'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -469,22 +519,23 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function isNoTotpOrNoLoginPass()
|
||||
{
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetSession',
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods(['d3GetSession'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -502,10 +553,11 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(false);
|
||||
|
||||
$this->assertTrue(
|
||||
@ -521,10 +573,11 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(true);
|
||||
|
||||
$this->assertTrue(
|
||||
@ -540,10 +593,11 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(true);
|
||||
|
||||
$this->assertFalse(
|
||||
@ -559,10 +613,11 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp::TOTP_SESSION_VARNAME, false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'verify',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(false);
|
||||
|
||||
$this->assertFalse(
|
||||
@ -576,16 +631,16 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function d3CancelLoginPass()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'logout',
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['logout'])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->once())->method('logout')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_LoginController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock(d3_totp_LoginController::class, array(
|
||||
'd3GetUserObject',
|
||||
));
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods(['d3GetUserObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetUserObject')->willReturn($oUserMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
@ -16,12 +16,13 @@ namespace D3\Totp\tests\unit\Modules\Application\Controller;
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController;
|
||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Controller\OrderController;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class d3_totp_OrderControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use d3_totp_getUserTestTrait;
|
||||
|
||||
/** @var d3_totp_OrderController */
|
||||
/** @var d3_totp_OrderController|MockObject */
|
||||
protected $_oController;
|
||||
|
||||
protected $sControllerClass = OrderController::class;
|
||||
@ -29,14 +30,14 @@ class d3_totp_OrderControllerTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(OrderController::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
|
@ -29,14 +29,14 @@ class d3_totp_PaymentControllerTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(PaymentController::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
|
@ -29,14 +29,14 @@ class d3_totp_UserControllerTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(UserController::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
|
@ -17,19 +17,21 @@ use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
trait d3_totp_getUserTestTrait
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function getUserHasNoUser()
|
||||
{
|
||||
/** @var d3_totp_orderController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock($this->sControllerClass, array(
|
||||
'd3GetTotpObject',
|
||||
));
|
||||
/** @var d3_totp_orderController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods(['d3GetTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->never())->method('d3GetTotpObject');
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
@ -41,34 +43,40 @@ trait d3_totp_getUserTestTrait
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function getUserTotpNotActive()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'getId'
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_orderController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock($this->sControllerClass, array(
|
||||
'd3GetTotpObject',
|
||||
'd3GetSessionObject'
|
||||
));
|
||||
/** @var d3_totp_orderController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3GetSessionObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3GetSessionObject')->willReturn($oSessionMock);
|
||||
|
||||
@ -84,34 +92,39 @@ trait d3_totp_getUserTestTrait
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function getUserTotpFinished()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'getId'
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->willReturn(true);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_orderController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock($this->sControllerClass, array(
|
||||
'd3GetTotpObject',
|
||||
'd3GetSessionObject'
|
||||
));
|
||||
/** @var d3_totp_orderController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3GetSessionObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3GetSessionObject')->willReturn($oSessionMock);
|
||||
|
||||
@ -127,34 +140,40 @@ trait d3_totp_getUserTestTrait
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function getUserTotpNotFinished()
|
||||
{
|
||||
/** @var User|PHPUnit_Framework_MockObject_MockObject $oUserMock */
|
||||
$oUserMock = $this->getMock(User::class, array(
|
||||
'getId'
|
||||
));
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->willReturn(false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId'
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_orderController|PHPUnit_Framework_MockObject_MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMock($this->sControllerClass, array(
|
||||
'd3GetTotpObject',
|
||||
'd3GetSessionObject'
|
||||
));
|
||||
/** @var d3_totp_orderController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3GetSessionObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3GetSessionObject')->willReturn($oSessionMock);
|
||||
|
||||
@ -169,6 +188,7 @@ trait d3_totp_getUserTestTrait
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function d3GetTotpObjectReturnsRightObject()
|
||||
{
|
||||
@ -180,12 +200,16 @@ trait d3_totp_getUserTestTrait
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function d3GetSessionObjectReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod($this->_oController, 'd3GetSessionObject')
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'd3GetSessionObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3_totp_userTest extends d3TotpUnitTestCase
|
||||
@ -29,14 +29,14 @@ class d3_totp_userTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(User::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@ -49,16 +49,16 @@ class d3_totp_userTest extends d3TotpUnitTestCase
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'deleteVariable'
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['deleteVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->once())->method('deleteVariable')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_user|PHPUnit_Framework_MockObject_MockObject $oModelMock */
|
||||
$oModelMock = $this->getMock(User::class, array(
|
||||
'd3GetSession'
|
||||
));
|
||||
/** @var d3_totp_user|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['d3GetSession'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
@ -19,7 +19,7 @@ use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3_totp_utilsTest extends d3TotpUnitTestCase
|
||||
@ -30,14 +30,14 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oCoreClass = oxNew(Utils::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@ -52,21 +52,22 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable("auth", false);
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_utils|PHPUnit_Framework_MockObject_MockObject $oCoreMock */
|
||||
$oCoreMock = $this->getMock(Utils::class, array(
|
||||
'd3GetTotpObject',
|
||||
'd3GetUtilsObject'
|
||||
));
|
||||
/** @var d3_totp_utils|MockObject $oCoreMock */
|
||||
$oCoreMock = $this->getMockBuilder(Utils::class)
|
||||
->onlyMethods(['d3GetTotpObject'])
|
||||
->getMock();
|
||||
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oCoreMock->expects($this->never())->method('d3GetUtilsObject');
|
||||
|
||||
$this->_oCoreClass = $oCoreMock;
|
||||
|
||||
@ -83,22 +84,25 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable("auth", 'foo');
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'loadByUserId',
|
||||
'isActive'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_utils|PHPUnit_Framework_MockObject_MockObject $oCoreMock */
|
||||
$oCoreMock = $this->getMock(Utils::class, array(
|
||||
'd3GetTotpObject',
|
||||
'd3GetUtilsObject',
|
||||
'fetchRightsForUser'
|
||||
));
|
||||
/** @var d3_totp_utils|MockObject $oCoreMock */
|
||||
$oCoreMock = $this->getMockBuilder(Utils::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'fetchRightsForUser'
|
||||
])
|
||||
->getMock();
|
||||
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oCoreMock->expects($this->never())->method('d3GetUtilsObject');
|
||||
$oCoreMock->method('fetchRightsForUser')->willReturn('malladmin');
|
||||
|
||||
$this->_oCoreClass = $oCoreMock;
|
||||
@ -116,27 +120,32 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable("auth", 'foo');
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', true));
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'loadByUserId',
|
||||
'isActive'
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_utils|PHPUnit_Framework_MockObject_MockObject $oCoreMock */
|
||||
$oCoreMock = $this->getMock(Utils::class, array(
|
||||
'd3GetTotpObject',
|
||||
'd3GetSessionObject',
|
||||
'fetchRightsForUser',
|
||||
'redirect'
|
||||
));
|
||||
/** @var d3_totp_utils|MockObject $oCoreMock */
|
||||
$oCoreMock = $this->getMockBuilder(Utils::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3GetSessionObject',
|
||||
'fetchRightsForUser',
|
||||
'redirect'
|
||||
])
|
||||
->getMock();
|
||||
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oCoreMock->method('d3GetSessionObject')->willReturn($oSessionMock);
|
||||
$oCoreMock->method('fetchRightsForUser')->willReturn('malladmin');
|
||||
@ -157,33 +166,38 @@ class d3_totp_utilsTest extends d3TotpUnitTestCase
|
||||
{
|
||||
Registry::getSession()->setVariable("auth", 'foo');
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', false));
|
||||
|
||||
/** @var Session|PHPUnit_Framework_MockObject_MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMock(Session::class, array(
|
||||
'getVariable',
|
||||
));
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', false));
|
||||
|
||||
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMock(d3totp::class, array(
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
), array(), '', false);
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId')->willReturn(true);
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_utils|PHPUnit_Framework_MockObject_MockObject $oCoreMock */
|
||||
$oCoreMock = $this->getMock(Utils::class, array(
|
||||
'd3GetTotpObject',
|
||||
'd3GetSessionObject',
|
||||
'fetchRightsForUser',
|
||||
'redirect'
|
||||
));
|
||||
/** @var d3_totp_utils|MockObject $oCoreMock */
|
||||
$oCoreMock = $this->getMockBuilder(Utils::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3GetSessionObject',
|
||||
'fetchRightsForUser',
|
||||
'redirect'
|
||||
])
|
||||
->getMock();
|
||||
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oCoreMock->method('d3GetSessionObject')->willReturn($oSessionMock);
|
||||
$oCoreMock->method('fetchRightsForUser')->willReturn('malladmin');
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren