adjust mockable function calls, make compatible to same class extensions from Webauthn plugin
This commit is contained in:
parent
b18196613e
commit
b9db9e601d
@ -61,8 +61,7 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
|
|||||||
Registry::getRequest()->getRequestEscapedParameter('chlanguage')
|
Registry::getRequest()->getRequestEscapedParameter('chlanguage')
|
||||||
);
|
);
|
||||||
|
|
||||||
// parent::checklogin();
|
return $this->d3CallMockableFunction([d3_totp_LoginController_parent::class, 'checklogin']);
|
||||||
return $this->d3CallMockableParent('checklogin');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function d3totpAfterLogin()
|
public function d3totpAfterLogin()
|
||||||
|
@ -18,4 +18,6 @@ namespace D3\Totp\Modules\Application\Controller;
|
|||||||
class d3_totp_OrderController extends d3_totp_OrderController_parent
|
class d3_totp_OrderController extends d3_totp_OrderController_parent
|
||||||
{
|
{
|
||||||
use d3_totp_getUserTrait;
|
use d3_totp_getUserTrait;
|
||||||
|
|
||||||
|
private $parentClass = d3_totp_OrderController_parent::class;
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,6 @@ namespace D3\Totp\Modules\Application\Controller;
|
|||||||
class d3_totp_PaymentController extends d3_totp_PaymentController_parent
|
class d3_totp_PaymentController extends d3_totp_PaymentController_parent
|
||||||
{
|
{
|
||||||
use d3_totp_getUserTrait;
|
use d3_totp_getUserTrait;
|
||||||
|
|
||||||
|
private $parentClass = d3_totp_PaymentController_parent::class;
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,6 @@ namespace D3\Totp\Modules\Application\Controller;
|
|||||||
class d3_totp_UserController extends d3_totp_UserController_parent
|
class d3_totp_UserController extends d3_totp_UserController_parent
|
||||||
{
|
{
|
||||||
use d3_totp_getUserTrait;
|
use d3_totp_getUserTrait;
|
||||||
|
|
||||||
|
private $parentClass = d3_totp_UserController_parent::class;
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,12 @@ trait d3_totp_getUserTrait
|
|||||||
*/
|
*/
|
||||||
public function getUser()
|
public function getUser()
|
||||||
{
|
{
|
||||||
// $oUser = parent::getUser();
|
/** @var User|null $user */
|
||||||
$oUser = $this->d3CallMockableParent('getUser');
|
$user = $this->d3CallMockableFunction([$this->parentClass, 'getUser']);
|
||||||
|
|
||||||
if ($oUser instanceof User && $oUser->getId()) {
|
if ($user && $user->isLoaded() && $user->getId()) {
|
||||||
$totp = $this->d3GetTotpObject();
|
$totp = $this->d3GetTotpObject();
|
||||||
$totp->loadByUserId($oUser->getId());
|
$totp->loadByUserId($user->getId());
|
||||||
|
|
||||||
if ($totp->isActive()
|
if ($totp->isActive()
|
||||||
&& !$this->d3TotpGetSessionObject()->getVariable(
|
&& !$this->d3TotpGetSessionObject()->getVariable(
|
||||||
@ -49,7 +49,7 @@ trait d3_totp_getUserTrait
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $oUser;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +32,7 @@ class totpSystemEventHandler extends totpSystemEventHandler_parent
|
|||||||
{
|
{
|
||||||
$this->d3RequestTotp();
|
$this->d3RequestTotp();
|
||||||
|
|
||||||
$this->d3CallMockableParent('onAdminLogin');
|
$this->d3CallMockableFunction([totpSystemEventHandler_parent::class, 'onAdminLogin']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function d3requestTotp()
|
protected function d3requestTotp()
|
||||||
|
@ -90,9 +90,9 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
|||||||
|
|
||||||
/** @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(['d3CallMockableParent'])
|
->onlyMethods(['d3CallMockableFunction'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$oControllerMock->method('d3CallMockableParent')->willReturn($fixture);
|
$oControllerMock->method('d3CallMockableFunction')->willReturn($fixture);
|
||||||
|
|
||||||
$this->_oController = $oControllerMock;
|
$this->_oController = $oControllerMock;
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ declare(strict_types=1);
|
|||||||
namespace D3\Totp\tests\unit\Modules\Application\Controller;
|
namespace D3\Totp\tests\unit\Modules\Application\Controller;
|
||||||
|
|
||||||
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController;
|
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController;
|
||||||
|
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController_parent;
|
||||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||||
use OxidEsales\Eshop\Application\Controller\OrderController;
|
use OxidEsales\Eshop\Application\Controller\OrderController;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
@ -29,6 +29,25 @@ trait d3_totp_getUserTestTrait
|
|||||||
{
|
{
|
||||||
use CanAccessRestricted;
|
use CanAccessRestricted;
|
||||||
|
|
||||||
|
protected $userFixtureId = 'userIdFixture1';
|
||||||
|
|
||||||
|
/** @var User */
|
||||||
|
protected $userFixture;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->userFixture = oxNew(User::class);
|
||||||
|
$this->userFixture->setId($this->userFixtureId);
|
||||||
|
$this->userFixture->assign(['oxlname' => __METHOD__]);
|
||||||
|
$this->userFixture->save();
|
||||||
|
$this->userFixture->load($this->userFixtureId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
$this->userFixture->delete($this->userFixtureId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
@ -58,12 +77,6 @@ trait d3_totp_getUserTestTrait
|
|||||||
*/
|
*/
|
||||||
public function getUserTotpNotActive()
|
public function getUserTotpNotActive()
|
||||||
{
|
{
|
||||||
/** @var User|MockObject $oUserMock */
|
|
||||||
$oUserMock = $this->getMockBuilder(User::class)
|
|
||||||
->onlyMethods(['getId'])
|
|
||||||
->getMock();
|
|
||||||
$oUserMock->method('getId')->willReturn('foo');
|
|
||||||
|
|
||||||
/** @var Session|MockObject $oSessionMock */
|
/** @var Session|MockObject $oSessionMock */
|
||||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||||
->onlyMethods(['getVariable'])
|
->onlyMethods(['getVariable'])
|
||||||
@ -86,17 +99,18 @@ 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);
|
$oControllerMock->setUser($this->userFixture);
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
$oUserMock,
|
$this->userFixture,
|
||||||
$this->callMethod($oControllerMock, 'getUser')
|
$this->callMethod($oControllerMock, 'getUser')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$oControllerMock->setUser(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,12 +122,6 @@ trait d3_totp_getUserTestTrait
|
|||||||
*/
|
*/
|
||||||
public function getUserTotpFinished()
|
public function getUserTotpFinished()
|
||||||
{
|
{
|
||||||
/** @var User|MockObject $oUserMock */
|
|
||||||
$oUserMock = $this->getMockBuilder(User::class)
|
|
||||||
->onlyMethods(['getId'])
|
|
||||||
->getMock();
|
|
||||||
$oUserMock->method('getId')->willReturn('foo');
|
|
||||||
|
|
||||||
/** @var Session|MockObject $oSessionMock */
|
/** @var Session|MockObject $oSessionMock */
|
||||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||||
->onlyMethods(['getVariable'])
|
->onlyMethods(['getVariable'])
|
||||||
@ -135,17 +143,18 @@ 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);
|
$oControllerMock->setUser($this->userFixture);
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
$oUserMock,
|
$this->userFixture,
|
||||||
$this->callMethod($oControllerMock, 'getUser')
|
$this->callMethod($oControllerMock, 'getUser')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$oControllerMock->setUser(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,12 +166,6 @@ trait d3_totp_getUserTestTrait
|
|||||||
*/
|
*/
|
||||||
public function getUserTotpNotFinished()
|
public function getUserTotpNotFinished()
|
||||||
{
|
{
|
||||||
/** @var User|MockObject $oUserMock */
|
|
||||||
$oUserMock = $this->getMockBuilder(User::class)
|
|
||||||
->onlyMethods(['getId'])
|
|
||||||
->getMock();
|
|
||||||
$oUserMock->method('getId')->willReturn('foo');
|
|
||||||
|
|
||||||
/** @var Session|MockObject $oSessionMock */
|
/** @var Session|MockObject $oSessionMock */
|
||||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||||
->onlyMethods(['getVariable'])
|
->onlyMethods(['getVariable'])
|
||||||
@ -185,16 +188,17 @@ 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);
|
$oControllerMock->setUser($this->userFixture);
|
||||||
|
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$this->callMethod($oControllerMock, 'getUser')
|
$this->callMethod($oControllerMock, 'getUser')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$oControllerMock->setUser(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,10 +41,10 @@ class totpSystemEventHandlerTest extends UnitTestCase
|
|||||||
{
|
{
|
||||||
/** @var totpSystemEventHandler|MockObject $sut */
|
/** @var totpSystemEventHandler|MockObject $sut */
|
||||||
$sut = $this->getMockBuilder(SystemEventHandler::class)
|
$sut = $this->getMockBuilder(SystemEventHandler::class)
|
||||||
->onlyMethods(['d3CallMockableParent', 'd3requestTotp'])
|
->onlyMethods(['d3CallMockableFunction', 'd3requestTotp'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$sut->method('d3CallMockableParent')->willReturn(true);
|
$sut->method('d3CallMockableFunction')->willReturn(true);
|
||||||
$sut->expects($this->once())->method('d3requestTotp')->willReturn(true);
|
$sut->expects($this->once())->method('d3requestTotp')->willReturn(true);
|
||||||
|
|
||||||
$this->callMethod(
|
$this->callMethod(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user