adjust mockable function calls, make compatible to same class extensions from Webauthn plugin
Cette révision appartient à :
Parent
b18196613e
révision
b9db9e601d
@ -61,8 +61,7 @@ class d3_totp_LoginController extends d3_totp_LoginController_parent
|
||||
Registry::getRequest()->getRequestEscapedParameter('chlanguage')
|
||||
);
|
||||
|
||||
// parent::checklogin();
|
||||
return $this->d3CallMockableParent('checklogin');
|
||||
return $this->d3CallMockableFunction([d3_totp_LoginController_parent::class, 'checklogin']);
|
||||
}
|
||||
|
||||
public function d3totpAfterLogin()
|
||||
|
@ -18,4 +18,6 @@ namespace D3\Totp\Modules\Application\Controller;
|
||||
class d3_totp_OrderController extends d3_totp_OrderController_parent
|
||||
{
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
use d3_totp_getUserTrait;
|
||||
|
||||
private $parentClass = d3_totp_UserController_parent::class;
|
||||
}
|
||||
|
@ -33,12 +33,12 @@ trait d3_totp_getUserTrait
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
// $oUser = parent::getUser();
|
||||
$oUser = $this->d3CallMockableParent('getUser');
|
||||
/** @var User|null $user */
|
||||
$user = $this->d3CallMockableFunction([$this->parentClass, 'getUser']);
|
||||
|
||||
if ($oUser instanceof User && $oUser->getId()) {
|
||||
if ($user && $user->isLoaded() && $user->getId()) {
|
||||
$totp = $this->d3GetTotpObject();
|
||||
$totp->loadByUserId($oUser->getId());
|
||||
$totp->loadByUserId($user->getId());
|
||||
|
||||
if ($totp->isActive()
|
||||
&& !$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->d3CallMockableParent('onAdminLogin');
|
||||
$this->d3CallMockableFunction([totpSystemEventHandler_parent::class, 'onAdminLogin']);
|
||||
}
|
||||
|
||||
protected function d3requestTotp()
|
||||
|
@ -90,9 +90,9 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods(['d3CallMockableParent'])
|
||||
->onlyMethods(['d3CallMockableFunction'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3CallMockableParent')->willReturn($fixture);
|
||||
$oControllerMock->method('d3CallMockableFunction')->willReturn($fixture);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
|
@ -16,6 +16,7 @@ declare(strict_types=1);
|
||||
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_parent;
|
||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Controller\OrderController;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
@ -29,6 +29,25 @@ trait d3_totp_getUserTestTrait
|
||||
{
|
||||
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
|
||||
* @throws ReflectionException
|
||||
@ -58,12 +77,6 @@ trait d3_totp_getUserTestTrait
|
||||
*/
|
||||
public function getUserTotpNotActive()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
@ -86,17 +99,18 @@ trait d3_totp_getUserTestTrait
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSessionObject',
|
||||
'd3CallMockableParent',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3CallMockableParent')->willReturn($oUserMock);
|
||||
$oControllerMock->setUser($this->userFixture);
|
||||
|
||||
$this->assertSame(
|
||||
$oUserMock,
|
||||
$this->userFixture,
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
|
||||
$oControllerMock->setUser(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,12 +122,6 @@ trait d3_totp_getUserTestTrait
|
||||
*/
|
||||
public function getUserTotpFinished()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
@ -135,17 +143,18 @@ trait d3_totp_getUserTestTrait
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSessionObject',
|
||||
'd3CallMockableParent',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3CallMockableParent')->willReturn($oUserMock);
|
||||
$oControllerMock->setUser($this->userFixture);
|
||||
|
||||
$this->assertSame(
|
||||
$oUserMock,
|
||||
$this->userFixture,
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
|
||||
$oControllerMock->setUser(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,12 +166,6 @@ trait d3_totp_getUserTestTrait
|
||||
*/
|
||||
public function getUserTotpNotFinished()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
@ -185,16 +188,17 @@ trait d3_totp_getUserTestTrait
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSessionObject',
|
||||
'd3CallMockableParent',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3CallMockableParent')->willReturn($oUserMock);
|
||||
$oControllerMock->setUser($this->userFixture);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
|
||||
$oControllerMock->setUser(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,10 +41,10 @@ class totpSystemEventHandlerTest extends UnitTestCase
|
||||
{
|
||||
/** @var totpSystemEventHandler|MockObject $sut */
|
||||
$sut = $this->getMockBuilder(SystemEventHandler::class)
|
||||
->onlyMethods(['d3CallMockableParent', 'd3requestTotp'])
|
||||
->onlyMethods(['d3CallMockableFunction', 'd3requestTotp'])
|
||||
->getMock();
|
||||
|
||||
$sut->method('d3CallMockableParent')->willReturn(true);
|
||||
$sut->method('d3CallMockableFunction')->willReturn(true);
|
||||
$sut->expects($this->once())->method('d3requestTotp')->willReturn(true);
|
||||
|
||||
$this->callMethod(
|
||||
|
Chargement…
x
Référencer dans un nouveau ticket
Bloquer un utilisateur