add missing tests
This commit is contained in:
bovenliggende
be69ed889e
commit
e65c2e7acb
0
src/Application/Controller/Admin/d3totpadminlogin.php
Executable file → Normal file
0
src/Application/Controller/Admin/d3totpadminlogin.php
Executable file → Normal file
@ -55,7 +55,7 @@ class d3_totp_user extends d3_totp_user_parent
|
||||
{
|
||||
return $this->d3TotpGetSession()->hasVariable(d3totp_conf::SESSION_CURRENTUSER) ?
|
||||
$this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_CURRENTUSER) :
|
||||
(isAdmin() ?
|
||||
($this->isAdmin() ?
|
||||
$this->d3TotpGetSession()->getVariable(d3totp_conf::OXID_ADMIN_AUTH) :
|
||||
$this->d3TotpGetSession()->getVariable(d3totp_conf::OXID_FRONTEND_AUTH));
|
||||
}
|
||||
|
@ -416,6 +416,19 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpGetUtils
|
||||
*/
|
||||
public function d3GetUtilsReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Utils::class,
|
||||
$this->callMethod($this->_oController, 'd3TotpGetUtils')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
|
@ -13,10 +13,10 @@
|
||||
|
||||
namespace D3\Totp\tests\unit\Modules\Application\Controller\Admin;
|
||||
|
||||
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_conf;
|
||||
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;
|
||||
@ -172,6 +172,64 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $totpActive
|
||||
* @param $loggedin
|
||||
* @param $expected
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpLoginMissing
|
||||
* @dataProvider d3TotpLoginMissingTestDataProvider
|
||||
*/
|
||||
public function d3TotpLoginMissingTest($totpActive, $loggedin, $expected)
|
||||
{
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['isActive'])
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn($totpActive);
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->with(d3totp_conf::SESSION_AUTH)->willReturn($loggedin);
|
||||
|
||||
/** @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->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'd3TotpLoginMissing',
|
||||
[$oTotpMock]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function d3TotpLoginMissingTestDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'totp not active, not logged in'=> [false, false, false],
|
||||
'totp active, logged in' => [true , true, false],
|
||||
'totp active, not logged in' => [true , false, true],
|
||||
'totp not active, logged in' => [false, true, false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
@ -184,14 +242,4 @@ class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
$this->callMethod($this->_oController, 'd3TotpGetUserObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @te__st
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3CallMockableParent
|
||||
*/
|
||||
public function canCallMockableParent()
|
||||
{
|
||||
$this->callMockableParentTest($this->_oController);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ 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_conf;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
@ -100,4 +101,60 @@ class d3_totp_userTest extends d3TotpUnitTestCase
|
||||
$this->callMethod($this->_oModel, 'd3TotpGetSession')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $currentUser
|
||||
* @param $isAdmin
|
||||
* @param $adminAuth
|
||||
* @param $frontendAuth
|
||||
* @param $expected
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Model\d3_totp_user::d3TotpGetCurrentUser
|
||||
* @dataProvider d3TotpGetCurrentUserTestDataProvider
|
||||
*/
|
||||
public function d3TotpGetCurrentUserTest($currentUser, $isAdmin, $adminAuth, $frontendAuth, $expected)
|
||||
{
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->getMockBuilder(Session::class)
|
||||
->onlyMethods(['hasVariable', 'getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->once())->method('hasVariable')->willReturn((bool) $currentUser);
|
||||
$getVariableMap = [
|
||||
[d3totp_conf::SESSION_CURRENTUSER, $currentUser],
|
||||
[d3totp_conf::OXID_ADMIN_AUTH, $adminAuth],
|
||||
[d3totp_conf::OXID_FRONTEND_AUTH, $frontendAuth],
|
||||
];
|
||||
$oSessionMock->method('getVariable')->willReturnMap($getVariableMap);
|
||||
|
||||
/** @var d3_totp_user|MockObject $oModelMock */
|
||||
$oModelMock = $this->getMockBuilder(User::class)
|
||||
->onlyMethods(['d3TotpGetSession', 'isAdmin'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oModelMock->method('isAdmin')->willReturn($isAdmin);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'd3TotpGetCurrentUser'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function d3TotpGetCurrentUserTestDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'login request' => ['currentFixture', true, 'adminFixture', 'frontendFixture', 'currentFixture'],
|
||||
'admin auth' => [null, true, 'adminFixture', 'frontendFixture', 'adminFixture'],
|
||||
'frontend auth' => [null, false, 'adminFixture', 'frontendFixture', 'frontendFixture'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Laden…
Verwijs in nieuw issue
Block a user