adjust tests

This commit is contained in:
Daniel Seifert 2022-11-10 16:45:57 +01:00 committed by Daniel Seifert
parent 02f2f6a843
commit 3327fc9242
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
24 changed files with 811 additions and 718 deletions

View File

@ -43,15 +43,13 @@
"oxid-esales/oxideshop-ce": "6.8.0 - 6.12", "oxid-esales/oxideshop-ce": "6.8.0 - 6.12",
"spomky-labs/otphp": "^10.0 || ^11.0", "spomky-labs/otphp": "^10.0 || ^11.0",
"bacon/bacon-qr-code": "^2.0", "bacon/bacon-qr-code": "^2.0",
"laminas/laminas-math": "^3.2" "laminas/laminas-math": "^3.2",
"d3/testingtools": "^1.0"
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^2.19", "friendsofphp/php-cs-fixer": "^2.19",
"phpstan/phpstan": "^1.8" "phpstan/phpstan": "^1.8"
}, },
"suggest": {
"d3/modcfg": "Provides automatic installation routines"
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"D3\\Totp\\": "../../../source/modules/d3/totp" "D3\\Totp\\": "../../../source/modules/d3/totp"

View File

@ -24,7 +24,9 @@ use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\Utils; use OxidEsales\Eshop\Core\Utils;
use Psr\Log\LoggerInterface;
class d3totpadminlogin extends AdminController class d3totpadminlogin extends AdminController
{ {
@ -38,26 +40,49 @@ class d3totpadminlogin extends AdminController
return true; return true;
} }
/**
* @return d3totp|mixed
*/
public function d3TotpGetTotpObject()
{
return oxNew(d3totp::class);
}
/**
* @return bool
* @throws DatabaseConnectionException
*/
protected function isTotpIsNotRequired(): bool
{
$user = $this->d3TotpGetUserObject();
$userId = $user->d3TotpGetCurrentUser();
$totp = $this->d3TotpGetTotpObject();
$totp->loadByUserId($userId);
return $this->d3TotpGetSession()->hasVariable(d3totp_conf::SESSION_AUTH) ||
!$totp->isActive();
}
/**
* @return bool
*/
protected function isTotpLoginNotPossible(): bool
{
return !$this->d3TotpGetSession()->hasVariable(d3totp_conf::OXID_ADMIN_AUTH) &&
!$this->d3TotpGetSession()->hasVariable(d3totp_conf::SESSION_CURRENTUSER);
}
/** /**
* @return string * @return string
* @throws DatabaseConnectionException
*/ */
public function render(): string public function render(): string
{ {
if (Registry::getSession()->hasVariable(d3totp_conf::SESSION_AUTH) && if ($this->isTotpIsNotRequired()) {
!Registry::getSession()->hasVariable(d3totp_conf::SESSION_CURRENTUSER) $this->d3TotpGetUtils()->redirect('index.php?cl=admin_start');
) { } elseif ($this->isTotpLoginNotPossible()) {
$this->getUtils()->redirect('index.php?cl=admin_start'); $this->d3TotpGetUtils()->redirect('index.php?cl=login');
if (!defined('OXID_PHP_UNIT')) {
// @codeCoverageIgnoreStart
exit;
// @codeCoverageIgnoreEnd
}
}
if (!Registry::getSession()->hasVariable(d3totp_conf::OXID_ADMIN_AUTH) &&
!Registry::getSession()->hasVariable(d3totp_conf::SESSION_CURRENTUSER)
) {
$this->getUtils()->redirect('index.php?cl=login');
} }
return parent::render(); return parent::render();
@ -66,7 +91,7 @@ class d3totpadminlogin extends AdminController
/** /**
* @return d3backupcodelist * @return d3backupcodelist
*/ */
public function d3GetBackupCodeListObject() public function d3GetBackupCodeListObject(): d3backupcodelist
{ {
return oxNew(d3backupcodelist::class); return oxNew(d3backupcodelist::class);
} }
@ -92,25 +117,20 @@ class d3totpadminlogin extends AdminController
} }
} }
public function d3CancelLogin() /**
* @return string
*/
public function d3CancelLogin(): string
{ {
$oUser = $this->d3GetUserObject(); $oUser = $this->d3TotpGetUserObject();
$oUser->logout(); $oUser->logout();
return "login"; return "login";
} }
/** /**
* @return d3totp * @return d3_totp_user
*/ */
public function d3GetTotpObject() public function d3TotpGetUserObject(): d3_totp_user
{
return oxNew(d3totp::class);
}
/**
* @return User
*/
public function d3GetUserObject()
{ {
return oxNew(User::class); return oxNew(User::class);
} }
@ -121,7 +141,7 @@ class d3totpadminlogin extends AdminController
*/ */
public function checklogin() public function checklogin()
{ {
$session = Registry::getSession(); $session = $this->d3TotpGetSession();
/** @var d3_totp_user $user */ /** @var d3_totp_user $user */
$user = oxNew(User::class); $user = oxNew(User::class);
$userId = $user->d3TotpGetCurrentUser(); $userId = $user->d3TotpGetCurrentUser();
@ -129,7 +149,7 @@ class d3totpadminlogin extends AdminController
try { try {
$sTotp = Registry::getRequest()->getRequestEscapedParameter('d3totp'); $sTotp = Registry::getRequest()->getRequestEscapedParameter('d3totp');
$totp = $this->d3GetTotpObject(); $totp = $this->d3TotpGetTotpObject();
$totp->loadByUserId($userId); $totp->loadByUserId($userId);
$this->d3TotpHasValidTotp($sTotp, $totp); $this->d3TotpHasValidTotp($sTotp, $totp);
@ -145,21 +165,21 @@ class d3totpadminlogin extends AdminController
return "admin_start"; return "admin_start";
} catch (d3totp_wrongOtpException $e) { } catch (d3totp_wrongOtpException $e) {
Registry::getUtilsView()->addErrorToDisplay($e); Registry::getUtilsView()->addErrorToDisplay($e);
Registry::getLogger()->error($e->getMessage(), ['UserId' => $userId]); $this->getLogger()->error($e->getMessage(), ['UserId' => $userId]);
Registry::getLogger()->debug($e->getTraceAsString()); $this->getLogger()->debug($e->getTraceAsString());
} }
} }
/** /**
* @param string $sTotp * @param string|null $sTotp
* @param d3totp $totp * @param d3totp $totp
* @return bool * @return bool
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws d3totp_wrongOtpException * @throws d3totp_wrongOtpException
*/ */
public function d3TotpHasValidTotp($sTotp, $totp) public function d3TotpHasValidTotp(string $sTotp = null, d3totp $totp): bool
{ {
return Registry::getSession()->getVariable(d3totp_conf::SESSION_AUTH) || return $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_AUTH) ||
( (
$sTotp && $totp->verify($sTotp) $sTotp && $totp->verify($sTotp)
); );
@ -168,26 +188,24 @@ class d3totpadminlogin extends AdminController
/** /**
* @return Utils * @return Utils
*/ */
public function getUtils(): Utils public function d3TotpGetUtils(): Utils
{ {
return Registry::getUtils(); return Registry::getUtils();
} }
/** /**
* Returns Bread Crumb - you are here page1/page2/page3... * @return Session
*
* @return array
*/ */
public function getBreadCrumb(): array public function d3TotpGetSession(): Session
{ {
$aPaths = []; return Registry::getSession();
$aPath = []; }
$iBaseLanguage = Registry::getLang()->getBaseLanguage();
$aPath['title'] = Registry::getLang()->translateString('D3_WEBAUTHN_BREADCRUMB', $iBaseLanguage, false);
$aPath['link'] = $this->getLink();
$aPaths[] = $aPath; /**
* @return LoggerInterface
return $aPaths; */
public function getLogger(): LoggerInterface
{
return Registry::getLogger();
} }
} }

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace D3\Totp\Modules\Application\Controller\Admin; namespace D3\Totp\Modules\Application\Controller\Admin;
use D3\TestingTools\Production\IsMockable;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
use D3\Totp\Application\Model\d3totp_conf; use D3\Totp\Application\Model\d3totp_conf;
use D3\Totp\Modules\Application\Model\d3_totp_user; use D3\Totp\Modules\Application\Model\d3_totp_user;
@ -25,6 +26,8 @@ use OxidEsales\Eshop\Core\Session;
class d3_totp_LoginController extends d3_totp_LoginController_parent class d3_totp_LoginController extends d3_totp_LoginController_parent
{ {
use IsMockable;
/** /**
* @return d3totp * @return d3totp
*/ */
@ -47,7 +50,8 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
*/ */
public function checklogin() public function checklogin()
{ {
$return = parent::checklogin(); // parent::checklogin();
$return = $this->d3CallMockableParent('checklogin');
$totp = $this->d3GetTotpObject(); $totp = $this->d3GetTotpObject();
$totp->loadByUserId(Registry::getSession()->getVariable("auth")); $totp->loadByUserId(Registry::getSession()->getVariable("auth"));
@ -56,11 +60,10 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
$userId = $this->d3TotpGetSession()->getVariable('auth'); $userId = $this->d3TotpGetSession()->getVariable('auth');
/** @var d3_totp_user $user */ /** @var d3_totp_user $user */
$user = oxNew(User::class); $user = $this->d3TotpGetUserObject();
$user->logout(); $user->logout();
$this->d3TotpGetSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, $userId); $this->d3TotpGetSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, $userId);
return "d3totpadminlogin"; return "d3totpadminlogin";
} }
@ -76,4 +79,12 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
return $totp->isActive() return $totp->isActive()
&& false == $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_AUTH); && false == $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_AUTH);
} }
/**
* @return d3_totp_user
*/
protected function d3TotpGetUserObject(): d3_totp_user
{
return oxNew( User::class );
}
} }

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace D3\Totp\Modules\Application\Controller; namespace D3\Totp\Modules\Application\Controller;
use D3\TestingTools\Production\IsMockable;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
use D3\Totp\Application\Model\d3totp_conf; use D3\Totp\Application\Model\d3totp_conf;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
@ -24,13 +25,16 @@ use OxidEsales\Eshop\Core\Session;
trait d3_totp_getUserTrait trait d3_totp_getUserTrait
{ {
use IsMockable;
/** /**
* @return bool|object|User * @return bool|object|User
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
*/ */
public function getUser() public function getUser()
{ {
$oUser = parent::getUser(); // $oUser = parent::getUser();
$oUser = $this->d3CallMockableParent('getUser');
if ($oUser instanceof User && $oUser->getId()) { if ($oUser instanceof User && $oUser->getId()) {
$totp = $this->d3GetTotpObject(); $totp = $this->d3GetTotpObject();

View File

@ -1,37 +0,0 @@
<?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
*/
// Include totp test config
namespace D3\Totp\tests;
use D3\ModCfg\Tests\additional_abstract;
use OxidEsales\Eshop\Core\Exception\StandardException;
include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'd3totp_config.php');
class additional extends additional_abstract
{
/**
* additional constructor.
* @throws StandardException
*/
public function __construct()
{
if (D3TOTP_REQUIRE_MODCFG) {
$this->reactivateModCfg();
}
}
}
oxNew(additional::class);

View File

@ -1,14 +0,0 @@
<?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
*/
const D3TOTP_REQUIRE_MODCFG = true;

View File

@ -0,0 +1,616 @@
<?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
*/
namespace D3\Totp\tests\unit\Application\Controller\Admin;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Controller\Admin\d3totpadminlogin;
use D3\Totp\Application\Model\d3backupcodelist;
use D3\Totp\Application\Model\d3totp;
use D3\Totp\Application\Model\d3totp_conf;
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
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\Registry;
use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\Utils;
use OxidEsales\EshopCommunity\Internal\Framework\Logger\Wrapper\LoggerWrapper;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use ReflectionException;
class d3totpadminloginTest extends d3TotpUnitTestCase
{
use CanAccessRestricted;
/** @var d3totpadminlogin */
protected $_oController;
/**
* setup basic requirements
*/
public function setUp(): void
{
parent::setUp();
$this->_oController = oxNew(d3totpadminlogin::class);
}
public function tearDown(): void
{
parent::tearDown();
unset($this->_oController);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::_authorize
*/
public function testAuthorize()
{
$this->assertTrue(
$this->callMethod(
$this->_oController,
'_authorize'
)
);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpGetTotpObject
*/
public function d3TotpGetTotpObjectReturnsRightInstance()
{
$this->assertInstanceOf(
d3totp::class,
$this->callMethod(
$this->_oController,
'd3TotpGetTotpObject'
)
);
}
/**
* @test
* @param $hasAuthAlready
* @param $totpActive
* @param $expected
* @return void
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::isTotpIsNotRequired
* @dataProvider isTotpIsNotRequiredPassedDataProvider
*/
public function isTotpIsNotRequiredPassed($hasAuthAlready, $totpActive, $expected)
{
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods([
'isActive',
'loadByUserId',
])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('isActive')->willReturn($totpActive);
$oTotpMock->method('loadByUserId')->willReturn(true);
/** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMockBuilder(Session::class)
->onlyMethods([
'hasVariable'
])
->getMock();
$hasVariableMap = [
[d3totp_conf::SESSION_AUTH, $hasAuthAlready]
];
$oSessionMock->method('hasVariable')->willReturnMap($hasVariableMap);
/** @var d3totpadminlogin|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3totpadminlogin::class)
->onlyMethods([
'd3TotpGetSession',
'd3TotpGetTotpObject'
])
->getMock();
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$oControllerMock->method('d3TotpGetTotpObject')->willReturn($oTotpMock);
$this->_oController = $oControllerMock;
$this->assertSame(
$expected,
$this->callMethod(
$this->_oController,
'isTotpIsNotRequired'
)
);
}
/**
* @return array
*/
public function isTotpIsNotRequiredPassedDataProvider(): array
{
return [
'auth already finished' => [true, true, true],
'auth required' => [false, true, false],
'totp inactive' => [false, false, true],
];
}
/**
* @test
* @param $hasAdminAuth
* @param $hasCurrentUser
* @param $expected
* @return void
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::isTotpLoginNotPossible
* @dataProvider isTotpLoginNotPossiblePassedDataProvider
*/
public function isTotpLoginNotPossiblePassed($hasAdminAuth, $hasCurrentUser, $expected)
{
/** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMockBuilder(Session::class)
->onlyMethods([
'hasVariable'
])
->getMock();
$hasVariableMap = [
[d3totp_conf::OXID_ADMIN_AUTH, $hasAdminAuth],
[d3totp_conf::SESSION_CURRENTUSER, $hasCurrentUser],
];
$oSessionMock->method('hasVariable')->willReturnMap($hasVariableMap);
/** @var d3totpadminlogin|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3totpadminlogin::class)
->onlyMethods([
'd3TotpGetSession'
])
->getMock();
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$this->_oController = $oControllerMock;
$this->assertSame(
$expected,
$this->callMethod(
$this->_oController,
'isTotpLoginNotPossible'
)
);
}
/**
* @return array
*/
public function isTotpLoginNotPossiblePassedDataProvider(): array
{
return [
'no admin auth, no user' => [false, false, true],
'has admin auth' => [true, false, false],
'has current user' => [false, true, false],
];
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::render
* @dataProvider canRenderDataProvider
*/
public function canRender($totpRequired, $totpNotPossible, $redirect)
{
/** @var Utils|MockObject $oUtilsMock */
$oUtilsMock = $this->getMockBuilder(Utils::class)
->onlyMethods(['redirect'])
->getMock();
$oUtilsMock
->expects(is_null($redirect) ? $this->never() : $this->once())
->method('redirect')
->with($this->identicalTo('index.php?cl='.$redirect))
->willReturn(true);
/** @var d3totpadminlogin|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3totpadminlogin::class)
->onlyMethods([
'isTotpIsNotRequired',
'isTotpLoginNotPossible',
'd3TotpGetUtils'
])
->getMock();
$oControllerMock->method('isTotpIsNotRequired')->willReturn($totpRequired);
$oControllerMock->method('isTotpLoginNotPossible')->willReturn($totpNotPossible);
$oControllerMock->method('d3TotpGetUtils')->willReturn($oUtilsMock);
$this->_oController = $oControllerMock;
$this->callMethod(
$this->_oController,
'render'
);
}
/**
* @return array[]
*/
public function canRenderDataProvider(): array
{
return [
'not required' => [true, true, 'admin_start'],
'not possible' => [false, true, 'login'],
'do auth' => [false, false, null],
];
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3GetBackupCodeListObject
*/
public function d3GetBackupCodeListObjectReturnsRightObject()
{
$this->assertInstanceOf(
d3backupcodelist::class,
$this->callMethod($this->_oController, 'd3GetBackupCodeListObject')
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::getBackupCodeCountMessage
*/
public function getBackupCodeCountMessageShowMessage()
{
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
->onlyMethods(['getAvailableCodeCount'])
->getMock();
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(2);
/** @var d3totpadminlogin|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3totpadminlogin::class)
->onlyMethods(['d3GetBackupCodeListObject'])
->getMock();
$oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
$this->_oController = $oControllerMock;
$this->assertGreaterThan(
0,
strpos(
$this->callMethod($this->_oController, 'getBackupCodeCountMessage'),
' 2 '
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::getBackupCodeCountMessage
*/
public function getBackupCodeCountMessageDontShowMessage()
{
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
->onlyMethods(['getAvailableCodeCount'])
->getMock();
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(10);
/** @var d3totpadminlogin|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3totpadminlogin::class)
->onlyMethods(['d3GetBackupCodeListObject'])
->getMock();
$oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
$this->_oController = $oControllerMock;
$this->assertEmpty(
$this->callMethod($this->_oController, 'getBackupCodeCountMessage')
);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3CancelLogin
*/
public function canCancelLogin()
{
/** @var d3_totp_user|MockObject $userMock */
$userMock = $this->getMockBuilder(User::class)
->onlyMethods(['logout'])
->getMock();
$userMock->expects($this->once())->method('logout')->willReturn(true);
/** @var d3totpadminlogin|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3totpadminlogin::class)
->onlyMethods(['d3TotpGetUserObject'])
->getMock();
$oControllerMock->method('d3TotpGetUserObject')->willReturn($userMock);
$this->_oController = $oControllerMock;
$this->assertSame(
'login',
$this->callMethod(
$this->_oController,
'd3CancelLogin'
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpGetUserObject
*/
public function d3GetUserObjectReturnsRightObject()
{
$this->assertInstanceOf(
User::class,
$this->callMethod($this->_oController, 'd3TotpGetUserObject')
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::checklogin
*/
public function checkloginUnvalidTotp()
{
/** @var LoggerWrapper|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(LoggerWrapper::class)
->disableOriginalConstructor()
->onlyMethods(['error', 'debug'])
->getMock();
$loggerMock->expects($this->atLeastOnce())->method('error')->willReturn(true);
$loggerMock->expects($this->atLeastOnce())->method('debug')->willReturn(true);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->disableOriginalConstructor()
->onlyMethods(['loadByUserId'])
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true);
/** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMockBuilder(Session::class)
->onlyMethods([
'initNewSession',
'setVariable',
'deleteVariable',
])
->getMock();
$oSessionMock->expects($this->never())->method('initNewSession')->willReturn(false);
$oSessionMock->expects($this->never())->method('setVariable')->willReturn(false);
$oSessionMock->expects($this->never())->method('deleteVariable')->willReturn(false);
/** @var d3totpadminlogin|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3totpadminlogin::class)
->onlyMethods([
'getLogger',
'd3TotpHasValidTotp',
'd3TotpGetSession'
])
->getMock();
$oControllerMock->method('d3TotpHasValidTotp')
->willThrowException(oxNew(d3totp_wrongOtpException::class));
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$oControllerMock->method('getLogger')->willReturn($loggerMock);
$this->_oController = $oControllerMock;
$this->callMethod(
$this->_oController,
'checklogin'
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::checklogin
*/
public function checkloginValidTotp()
{
/** @var LoggerWrapper|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(LoggerWrapper::class)
->disableOriginalConstructor()
->onlyMethods(['error', 'debug'])
->getMock();
$loggerMock->expects($this->never())->method('error')->willReturn(true);
$loggerMock->expects($this->never())->method('debug')->willReturn(true);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->disableOriginalConstructor()
->onlyMethods(['loadByUserId'])
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true);
/** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMockBuilder(Session::class)
->onlyMethods([
'initNewSession',
'setVariable',
'deleteVariable',
])
->getMock();
$oSessionMock->expects($this->atLeastOnce())->method('initNewSession')->willReturn(false);
$oSessionMock->expects($this->atLeastOnce())->method('setVariable')->willReturn(false);
$oSessionMock->expects($this->atLeastOnce())->method('deleteVariable')->willReturn(false);
/** @var d3totpadminlogin|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3totpadminlogin::class)
->onlyMethods([
'getLogger',
'd3TotpHasValidTotp',
'd3TotpGetSession'
])
->getMock();
$oControllerMock->method('d3TotpHasValidTotp')->willReturn(true);
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$oControllerMock->method('getLogger')->willReturn($loggerMock);
$this->_oController = $oControllerMock;
$this->callMethod(
$this->_oController,
'checklogin'
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpHasValidTotp
*/
public function hasValidTotpTrueSessionVarname()
{
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, true);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['verify'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(false);
$this->assertTrue(
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpHasValidTotp
*/
public function hasValidTotpTrueValidTotp()
{
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, false);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['verify'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(true);
$this->assertTrue(
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpHasValidTotp
*/
public function hasValidTotpFalseMissingTotp()
{
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, false);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['verify'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(true);
$this->assertFalse(
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', [null, $oTotpMock])
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpHasValidTotp
*/
public function hasValidTotpFalseUnverifiedTotp()
{
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, false);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['verify'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(false);
$this->assertFalse(
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpGetUtils
*/
public function d3TotpGetUtilsReturnsRightInstance()
{
$this->assertInstanceOf(
Utils::class,
$this->callMethod(
$this->_oController,
'd3TotpGetUtils'
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpGetSession
*/
public function d3GetSessionReturnsRightObject()
{
$this->assertInstanceOf(
Session::class,
$this->callMethod(
$this->_oController,
'd3TotpGetSession'
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::getLogger
*/
public function getLoggerReturnsRightObject()
{
$this->assertInstanceOf(
LoggerInterface::class,
$this->callMethod(
$this->_oController,
'getLogger'
)
);
}
}

View File

@ -13,6 +13,7 @@
namespace D3\Totp\tests\unit\Application\Controller\Admin; namespace D3\Totp\tests\unit\Application\Controller\Admin;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Controller\Admin\d3user_totp; use D3\Totp\Application\Controller\Admin\d3user_totp;
use D3\Totp\Application\Model\d3backupcodelist; use D3\Totp\Application\Model\d3backupcodelist;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
@ -24,6 +25,8 @@ use ReflectionException;
class d3user_totpTest extends d3TotpUnitTestCase class d3user_totpTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3user_totp */ /** @var d3user_totp */
protected $_oController; protected $_oController;

View File

@ -13,6 +13,7 @@
namespace D3\Totp\tests\unit\Application\Controller; namespace D3\Totp\tests\unit\Application\Controller;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Controller\d3_account_totp; use D3\Totp\Application\Controller\d3_account_totp;
use D3\Totp\Application\Model\d3backupcodelist; use D3\Totp\Application\Model\d3backupcodelist;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
@ -24,6 +25,8 @@ use ReflectionException;
class d3_account_totpTest extends d3TotpUnitTestCase class d3_account_totpTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3_account_totp */ /** @var d3_account_totp */
protected $_oController; protected $_oController;

View File

@ -13,6 +13,7 @@
namespace D3\Totp\tests\unit\Application\Controller; namespace D3\Totp\tests\unit\Application\Controller;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Controller\d3totplogin; use D3\Totp\Application\Controller\d3totplogin;
use D3\Totp\Application\Model\d3backupcodelist; use D3\Totp\Application\Model\d3backupcodelist;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
@ -25,6 +26,8 @@ use ReflectionException;
class d3totploginTest extends d3TotpUnitTestCase class d3totploginTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3totplogin */ /** @var d3totplogin */
protected $_oController; protected $_oController;

View File

@ -13,12 +13,15 @@
namespace D3\Totp\tests\unit\Application\Model\Exceptions; namespace D3\Totp\tests\unit\Application\Model\Exceptions;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException; use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
use ReflectionException; use ReflectionException;
class d3totp_wrongOtpExceptionTest extends d3TotpUnitTestCase class d3totp_wrongOtpExceptionTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3totp_wrongOtpException */ /** @var d3totp_wrongOtpException */
protected $_oModel; protected $_oModel;

View File

@ -13,12 +13,15 @@
namespace D3\Totp\tests\unit\Application\Model; namespace D3\Totp\tests\unit\Application\Model;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Model\d3RandomGenerator; use D3\Totp\Application\Model\d3RandomGenerator;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
use ReflectionException; use ReflectionException;
class d3RandomGeneratorTest extends d3TotpUnitTestCase class d3RandomGeneratorTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3RandomGenerator */ /** @var d3RandomGenerator */
protected $_oModel; protected $_oModel;

View File

@ -13,6 +13,7 @@
namespace D3\Totp\tests\unit\Application\Model; namespace D3\Totp\tests\unit\Application\Model;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Model\d3backupcode; use D3\Totp\Application\Model\d3backupcode;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
use D3\Totp\Application\Model\d3totp_conf; use D3\Totp\Application\Model\d3totp_conf;
@ -24,6 +25,8 @@ use ReflectionException;
class d3backupcodeTest extends d3TotpUnitTestCase class d3backupcodeTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3backupcode */ /** @var d3backupcode */
protected $_oModel; protected $_oModel;

View File

@ -13,6 +13,7 @@
namespace D3\Totp\tests\unit\Application\Model; namespace D3\Totp\tests\unit\Application\Model;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Model\d3backupcode; use D3\Totp\Application\Model\d3backupcode;
use D3\Totp\Application\Model\d3backupcodelist; use D3\Totp\Application\Model\d3backupcodelist;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
@ -25,6 +26,8 @@ use ReflectionException;
class d3backupcodelistTest extends d3TotpUnitTestCase class d3backupcodelistTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3backupcodelist */ /** @var d3backupcodelist */
protected $_oModel; protected $_oModel;

View File

@ -14,6 +14,7 @@
namespace D3\Totp\tests\unit\Application\Model; namespace D3\Totp\tests\unit\Application\Model;
use BaconQrCode\Writer; use BaconQrCode\Writer;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Factory\BaconQrCodeFactory; use D3\Totp\Application\Factory\BaconQrCodeFactory;
use D3\Totp\Application\Model\d3backupcodelist; use D3\Totp\Application\Model\d3backupcodelist;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
@ -29,6 +30,8 @@ use stdClass;
class d3totpTest extends d3TotpUnitTestCase class d3totpTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3totp */ /** @var d3totp */
protected $_oModel; protected $_oModel;

View File

@ -13,6 +13,7 @@
namespace D3\Totp\tests\unit\Modules\Application\Component; namespace D3\Totp\tests\unit\Modules\Application\Component;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
use D3\Totp\Application\Model\d3totp_conf; use D3\Totp\Application\Model\d3totp_conf;
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException; use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
@ -31,6 +32,8 @@ use ReflectionException;
class d3_totp_UserComponentTest extends d3TotpUnitTestCase class d3_totp_UserComponentTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3_totp_UserComponent */ /** @var d3_totp_UserComponent */
protected $_oController; protected $_oController;

View File

@ -13,22 +13,23 @@
namespace D3\Totp\tests\unit\Modules\Application\Controller\Admin; namespace D3\Totp\tests\unit\Modules\Application\Controller\Admin;
use D3\Totp\Application\Model\d3backupcodelist; use D3\TestingTools\Development\Constants;
use D3\TestingTools\Development\IsMockable;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
use D3\Totp\Application\Model\d3totp_conf;
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
use D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController; use D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController;
use D3\Totp\Modules\Application\Model\d3_totp_user;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
use Exception;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Session; use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\UtilsView;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;
class d3_totp_LoginControllerTest extends d3TotpUnitTestCase class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
use IsMockable;
/** @var d3_totp_LoginController */ /** @var d3_totp_LoginController */
protected $_oController; protected $_oController;
@ -49,186 +50,6 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
unset($this->_oController); unset($this->_oController);
} }
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::render
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::getViewDataElement
*/
public function canRenderNoAuth()
{
/** @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|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|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods([
'd3TotpGetSession',
'd3GetTotpObject',
])
->getMock();
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$this->_oController = $oControllerMock;
$this->assertSame('login.tpl', $this->callMethod($this->_oController, 'render'));
$this->assertNotTrue($this->callMethod($this->_oController, 'getViewDataElement', ['request_totp']));
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::render
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::getViewDataElement
*/
public function canRenderTotpNotActive()
{
/** @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|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|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods([
'd3TotpGetSession',
'd3GetTotpObject',
])
->getMock();
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$this->_oController = $oControllerMock;
$this->assertSame('login.tpl', $this->callMethod($this->_oController, 'render'));
$this->assertNotTrue($this->callMethod($this->_oController, 'getViewDataElement', ['request_totp']));
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::render
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::getViewDataElement
*/
public function canRenderInTotpLoginProcess()
{
/** @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|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|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods([
'd3TotpGetSession',
'd3GetTotpObject',
])
->getMock();
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$this->_oController = $oControllerMock;
$this->assertSame('login.tpl', $this->callMethod($this->_oController, 'render'));
$this->assertNotTrue($this->callMethod($this->_oController, 'getViewDataElement', ['request_totp']));
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::render
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::getViewDataElement
*/
public function canRenderRequestTotp()
{
/** @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|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|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods([
'd3TotpGetSession',
'd3GetTotpObject',
])
->getMock();
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$this->_oController = $oControllerMock;
$this->assertSame('login.tpl', $this->callMethod($this->_oController, 'render'));
$this->assertTrue($this->callMethod($this->_oController, 'getViewDataElement', ['request_totp']));
}
/** /**
* @test * @test
* @throws ReflectionException * @throws ReflectionException
@ -242,32 +63,6 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
); );
} }
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3GetBackupCodeListObject
*/
public function d3GetBackupCodeListObjectReturnsRightObject()
{
$this->assertInstanceOf(
d3backupcodelist::class,
$this->callMethod($this->_oController, 'd3GetBackupCodeListObject')
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpGetUtilsView
*/
public function d3GetUtilsViewReturnsRightObject()
{
$this->assertInstanceOf(
UtilsView::class,
$this->callMethod($this->_oController, 'd3TotpGetUtilsView')
);
}
/** /**
* @test * @test
* @throws ReflectionException * @throws ReflectionException
@ -285,10 +80,11 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
* @test * @test
* @throws ReflectionException * @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::checklogin * @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::checklogin
* @dataProvider checkloginNoTotpDataProvider
*/ */
public function checkloginNoTotp($hasLoginCredentials) public function checkloginMissingTotp()
{ {
$fixture = 'returnString';
/** @var d3totp|MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class) $oTotpMock = $this->getMockBuilder(d3totp::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -296,36 +92,31 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
->getMock(); ->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3_totp_user|MockObject $userMock */
$userMock = $this->getMockBuilder(User::class)
->onlyMethods(['logout'])
->getMock();
$userMock->expects($this->once())->method('logout')->willReturn(true);
/** @var d3_totp_LoginController|MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class) $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods([ ->onlyMethods([
'd3GetTotpObject', 'd3GetTotpObject',
'd3TotpIsNoTotpOrNoLogin', 'd3TotpGetUserObject',
'd3TotpHasValidTotp', 'd3TotpLoginMissing',
'hasLoginCredentials', 'd3CallMockableParent'
]) ])
->getMock(); ->getMock();
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('d3TotpIsNoTotpOrNoLogin')->willReturn(true); $oControllerMock->method('d3TotpGetUserObject')->willReturn($userMock);
$oControllerMock->method('d3TotpHasValidTotp')->willReturn(false); $oControllerMock->method('d3TotpLoginMissing')->with($this->identicalTo($oTotpMock))
$oControllerMock->method('hasLoginCredentials')->willReturn($hasLoginCredentials); ->willReturn(true);
$oControllerMock->method('d3CallMockableParent')->willReturn($fixture);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
if ($hasLoginCredentials) {
// workaround, because test case runs into parent call, stop execution with exception and check thrown
/** @var Session|MockObject $sessionMock */
$sessionMock = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()
->onlyMethods(['initNewSession'])
->getMock();
$sessionMock->method('initNewSession')->willThrowException(new Exception('foo'));
Registry::set(Session::class, $sessionMock);
$this->expectException(Exception::class);
}
$this->assertSame( $this->assertSame(
'login', 'd3totpadminlogin',
$this->callMethod( $this->callMethod(
$this->_oController, $this->_oController,
'checklogin' 'checklogin'
@ -333,34 +124,14 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
); );
} }
/**
* @return array
*/
public function checkloginNoTotpDataProvider(): array
{
return [
'no totp, no login credentials' => [false],
'no totp, given login credentials' => [true],
];
}
/** /**
* @test * @test
* @throws ReflectionException * @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::checklogin * @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::checklogin
*/ */
public function checkloginInvalidTotp() public function checkloginNotMissingTotp()
{ {
/** @var d3totp_wrongOtpException|MockObject $oUtilsViewMock */ $fixture = 'returnString';
$oTotpExceptionMock = $this->getMockBuilder(d3totp_wrongOtpException::class)
->disableOriginalConstructor()
->getMock();
/** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
->onlyMethods(['addErrorToDisplay'])
->getMock();
$utilsViewMock->expects($this->once())->method('addErrorToDisplay')->willReturn(true);
/** @var d3totp|MockObject $oTotpMock */ /** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class) $oTotpMock = $this->getMockBuilder(d3totp::class)
@ -369,338 +140,38 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
->getMock(); ->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true); $oTotpMock->method('loadByUserId')->willReturn(true);
/** @var d3_totp_user|MockObject $userMock */
$userMock = $this->getMockBuilder(User::class)
->onlyMethods(['logout'])
->getMock();
$userMock->expects($this->never())->method('logout')->willReturn(true);
/** @var d3_totp_LoginController|MockObject $oControllerMock */ /** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class) $oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods([ ->onlyMethods([
'd3GetTotpObject', 'd3GetTotpObject',
'd3TotpIsNoTotpOrNoLogin', 'd3TotpGetUserObject',
'd3TotpHasValidTotp', 'd3TotpLoginMissing',
'd3TotpGetUtilsView', 'd3CallMockableParent'
]) ])
->getMock(); ->getMock();
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('d3TotpIsNoTotpOrNoLogin')->willReturn(false); $oControllerMock->method('d3TotpGetUserObject')->willReturn($userMock);
$oControllerMock->method('d3TotpHasValidTotp')->willThrowException($oTotpExceptionMock); $oControllerMock->method('d3TotpLoginMissing')->with($this->identicalTo($oTotpMock))
$oControllerMock->method('d3TotpGetUtilsView')->willReturn($utilsViewMock); ->willReturn(false);
$oControllerMock->method('d3CallMockableParent')->willReturn($fixture);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
$this->assertSame( $this->assertSame(
'login', $fixture,
$this->callMethod($this->_oController, 'checklogin') $this->callMethod(
); $this->_oController,
} 'checklogin'
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::checklogin
*/
public function checkloginValidTotp()
{
/** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
->onlyMethods(['addErrorToDisplay'])
->getMock();
$utilsViewMock->expects($this->never())->method('addErrorToDisplay')->willReturn(true);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['loadByUserId'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('loadByUserId')->willReturn(true);
/** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMockBuilder(Session::class)
->onlyMethods(['setVariable'])
->getMock();
$oSessionMock->expects($this->once())->method('setVariable')->willReturn(false);
/** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods([
'd3GetTotpObject',
'd3TotpIsNoTotpOrNoLogin',
'd3TotpHasValidTotp',
'd3TotpGetUtilsView',
'd3TotpGetSession',
])
->getMock();
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('d3TotpIsNoTotpOrNoLogin')->willReturn(false);
$oControllerMock->method('d3TotpHasValidTotp')->willReturn(true);
$oControllerMock->method('d3TotpGetUtilsView')->willReturn($utilsViewMock);
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$this->_oController = $oControllerMock;
$this->assertSame('admin_start', $this->callMethod($this->_oController, 'checklogin'));
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::getBackupCodeCountMessage
*/
public function getBackupCodeCountMessageShowMessage()
{
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
->onlyMethods(['getAvailableCodeCount'])
->getMock();
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(2);
/** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods(['d3GetBackupCodeListObject'])
->getMock();
$oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
$this->_oController = $oControllerMock;
$this->assertGreaterThan(
0,
strpos(
$this->callMethod($this->_oController, 'getBackupCodeCountMessage'),
' 2 '
) )
); );
} }
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::getBackupCodeCountMessage
*/
public function getBackupCodeCountMessageDontShowMessage()
{
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
$oBackupCodeListMock = $this->getMockBuilder(d3backupcodelist::class)
->onlyMethods(['getAvailableCodeCount'])
->getMock();
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(10);
/** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods(['d3GetBackupCodeListObject'])
->getMock();
$oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
$this->_oController = $oControllerMock;
$this->assertEmpty(
$this->callMethod($this->_oController, 'getBackupCodeCountMessage')
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpIsNoTotpOrNoLogin
*/
public function isNoTotpOrNoLoginIsAuth()
{
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['isActive'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('isActive')->willReturn(true);
/** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMockBuilder(Session::class)
->onlyMethods(['getVariable'])
->getMock();
$oSessionMock->method('getVariable')->willReturn(true);
/** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods(['d3TotpGetSession'])
->getMock();
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$this->_oController = $oControllerMock;
$this->assertFalse(
$this->callMethod($this->_oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpIsNoTotpOrNoLogin
*/
public function isNoTotpOrNoLoginTotpNotActive()
{
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['isActive'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('isActive')->willReturn(true);
/** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMockBuilder(Session::class)
->onlyMethods(['getVariable'])
->getMock();
$oSessionMock->method('getVariable')->willReturn(true);
/** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods(['d3TotpGetSession'])
->getMock();
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$this->_oController = $oControllerMock;
$this->assertFalse(
$this->callMethod($this->_oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpIsNoTotpOrNoLogin
*/
public function isNoTotpOrNoLoginPass()
{
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['isActive'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('isActive')->willReturn(false);
/** @var Session|MockObject $oSessionMock */
$oSessionMock = $this->getMockBuilder(Session::class)
->onlyMethods(['getVariable'])
->getMock();
$oSessionMock->method('getVariable')->willReturn(false);
/** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods(['d3TotpGetSession'])
->getMock();
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
$this->_oController = $oControllerMock;
$this->assertTrue(
$this->callMethod($this->_oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpHasValidTotp
*/
public function hasValidTotpTrueSessionVarname()
{
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, true);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['verify'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(false);
$this->assertTrue(
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpHasValidTotp
*/
public function hasValidTotpTrueValidTotp()
{
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, false);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['verify'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(true);
$this->assertTrue(
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpHasValidTotp
*/
public function hasValidTotpFalseMissingTotp()
{
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, false);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['verify'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(true);
$this->assertFalse(
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', [null, $oTotpMock])
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpHasValidTotp
*/
public function hasValidTotpFalseUnverifiedTotp()
{
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, false);
/** @var d3totp|MockObject $oTotpMock */
$oTotpMock = $this->getMockBuilder(d3totp::class)
->onlyMethods(['verify'])
->disableOriginalConstructor()
->getMock();
$oTotpMock->method('verify')->willReturn(false);
$this->assertFalse(
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3CancelLogin
*/
public function d3CancelLoginPass()
{
/** @var User|MockObject $oUserMock */
$oUserMock = $this->getMockBuilder(User::class)
->onlyMethods(['logout'])
->getMock();
$oUserMock->expects($this->once())->method('logout')->willReturn(true);
/** @var d3_totp_LoginController|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
->onlyMethods(['d3TotpGetUserObject'])
->getMock();
$oControllerMock->method('d3TotpGetUserObject')->willReturn($oUserMock);
$this->_oController = $oControllerMock;
$this->callMethod($this->_oController, 'd3CancelLogin');
}
/** /**
* @test * @test
* @throws ReflectionException * @throws ReflectionException
@ -715,35 +186,12 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
} }
/** /**
* @test * @te__st
* @return void
* @throws ReflectionException * @throws ReflectionException
* @dataProvider hasLoginCredentialsDataProvider * @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3CallMockableParent
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::hasLoginCredentials
*/ */
public function hasLoginCredentials($user, $pass, $expected) public function canCallMockableParent()
{ {
$_GET['user'] = $user; $this->callMockableParentTest($this->_oController);
$_GET['pwd'] = $pass;
$this->assertSame(
$expected,
$this->callMethod(
$this->_oController,
'hasLoginCredentials'
)
);
}
/**
* @return array[]
*/
public function hasLoginCredentialsDataProvider(): array
{
return [
'user only' => ['user', null, false],
'pass only' => [null, 'password', false],
'both' => ['user', 'password', true],
];
} }
} }

View File

@ -25,7 +25,7 @@ class d3_totp_OrderControllerTest extends d3TotpUnitTestCase
/** @var d3_totp_OrderController|MockObject */ /** @var d3_totp_OrderController|MockObject */
protected $_oController; protected $_oController;
protected $sControllerClass = OrderController::class; protected $sControllerClass = d3_totp_OrderController::class;
/** /**
* setup basic requirements * setup basic requirements

View File

@ -24,7 +24,7 @@ class d3_totp_PaymentControllerTest extends d3TotpUnitTestCase
/** @var d3_totp_PaymentController */ /** @var d3_totp_PaymentController */
protected $_oController; protected $_oController;
protected $sControllerClass = PaymentController::class; protected $sControllerClass = d3_totp_PaymentController::class;
/** /**
* setup basic requirements * setup basic requirements

View File

@ -24,7 +24,7 @@ class d3_totp_UserControllerTest extends d3TotpUnitTestCase
/** @var d3_totp_UserController */ /** @var d3_totp_UserController */
protected $_oController; protected $_oController;
protected $sControllerClass = UserController::class; protected $sControllerClass = d3_totp_UserController::class;
/** /**
* setup basic requirements * setup basic requirements

View File

@ -13,6 +13,8 @@
namespace D3\Totp\tests\unit\Modules\Application\Controller; namespace D3\Totp\tests\unit\Modules\Application\Controller;
use D3\TestingTools\Development\IsMockable;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController; use D3\Totp\Modules\Application\Controller\d3_totp_OrderController;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
@ -22,6 +24,8 @@ use ReflectionException;
trait d3_totp_getUserTestTrait trait d3_totp_getUserTestTrait
{ {
use CanAccessRestricted;
/** /**
* @test * @test
* @throws ReflectionException * @throws ReflectionException
@ -81,15 +85,15 @@ trait d3_totp_getUserTestTrait
->onlyMethods([ ->onlyMethods([
'd3GetTotpObject', 'd3GetTotpObject',
'd3TotpGetSessionObject', 'd3TotpGetSessionObject',
'd3CallMockableParent'
]) ])
->getMock(); ->getMock();
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock); $oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
$oControllerMock->method('d3CallMockableParent')->willReturn($oUserMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
$this->setValue($this->_oController, '_oActUser', $oUserMock);
$this->assertSame( $this->assertSame(
$oUserMock, $oUserMock,
$this->callMethod($this->_oController, 'getUser') $this->callMethod($this->_oController, 'getUser')
@ -132,15 +136,15 @@ trait d3_totp_getUserTestTrait
->onlyMethods([ ->onlyMethods([
'd3GetTotpObject', 'd3GetTotpObject',
'd3TotpGetSessionObject', 'd3TotpGetSessionObject',
'd3CallMockableParent'
]) ])
->getMock(); ->getMock();
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock); $oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
$oControllerMock->method('d3CallMockableParent')->willReturn($oUserMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
$this->setValue($this->_oController, '_oActUser', $oUserMock);
$this->assertSame( $this->assertSame(
$oUserMock, $oUserMock,
$this->callMethod($this->_oController, 'getUser') $this->callMethod($this->_oController, 'getUser')
@ -184,15 +188,15 @@ trait d3_totp_getUserTestTrait
->onlyMethods([ ->onlyMethods([
'd3GetTotpObject', 'd3GetTotpObject',
'd3TotpGetSessionObject', 'd3TotpGetSessionObject',
'd3CallMockableParent'
]) ])
->getMock(); ->getMock();
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock); $oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock); $oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
$oControllerMock->method('d3CallMockableParent')->willReturn($oUserMock);
$this->_oController = $oControllerMock; $this->_oController = $oControllerMock;
$this->setValue($this->_oController, '_oActUser', $oUserMock);
$this->assertFalse( $this->assertFalse(
$this->callMethod($this->_oController, 'getUser') $this->callMethod($this->_oController, 'getUser')
); );
@ -230,4 +234,16 @@ trait d3_totp_getUserTestTrait
) )
); );
} }
/**
* @te__st
* @throws ReflectionException
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_OrderController::d3CallMockableParent
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_PaymentController::d3CallMockableParent
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_UserController::d3CallMockableParent
*/
public function d3callMockableParentTest()
{
$this->callMockableParentTest($this->_oController);
}
} }

View File

@ -13,6 +13,7 @@
namespace D3\Totp\tests\unit\Modules\Application\Model; namespace D3\Totp\tests\unit\Modules\Application\Model;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
use D3\Totp\Modules\Application\Model\d3_totp_user; use D3\Totp\Modules\Application\Model\d3_totp_user;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
@ -23,6 +24,8 @@ use ReflectionException;
class d3_totp_userTest extends d3TotpUnitTestCase class d3_totp_userTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3_totp_user */ /** @var d3_totp_user */
protected $_oModel; protected $_oModel;
@ -54,7 +57,7 @@ class d3_totp_userTest extends d3TotpUnitTestCase
$oSessionMock = $this->getMockBuilder(Session::class) $oSessionMock = $this->getMockBuilder(Session::class)
->onlyMethods(['deleteVariable']) ->onlyMethods(['deleteVariable'])
->getMock(); ->getMock();
$oSessionMock->expects($this->once())->method('deleteVariable')->willReturn(true); $oSessionMock->expects($this->atLeast(2))->method('deleteVariable')->willReturn(true);
/** @var d3_totp_user|MockObject $oModelMock */ /** @var d3_totp_user|MockObject $oModelMock */
$oModelMock = $this->getMockBuilder(User::class) $oModelMock = $this->getMockBuilder(User::class)

View File

@ -13,6 +13,7 @@
namespace D3\Totp\tests\unit\Modules\Core; namespace D3\Totp\tests\unit\Modules\Core;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Totp\Application\Model\d3totp; use D3\Totp\Application\Model\d3totp;
use D3\Totp\Modules\Core\d3_totp_utils; use D3\Totp\Modules\Core\d3_totp_utils;
use D3\Totp\tests\unit\d3TotpUnitTestCase; use D3\Totp\tests\unit\d3TotpUnitTestCase;
@ -25,6 +26,8 @@ use ReflectionException;
class d3_totp_utilsTest extends d3TotpUnitTestCase class d3_totp_utilsTest extends d3TotpUnitTestCase
{ {
use CanAccessRestricted;
/** @var d3_totp_utils */ /** @var d3_totp_utils */
protected $_oCoreClass; protected $_oCoreClass;

View File

@ -12,8 +12,8 @@
namespace D3\Totp\tests\unit; namespace D3\Totp\tests\unit;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use OxidEsales\TestingLibrary\UnitTestCase;
abstract class d3TotpUnitTestCase extends d3ModCfgUnitTestCase abstract class d3TotpUnitTestCase extends UnitTestCase
{ {
} }