add further tests

This commit is contained in:
Daniel Seifert 2022-12-01 00:45:39 +01:00
parent c7f48bf960
commit f3d8e55db1
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
19 changed files with 891 additions and 13 deletions

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace D3\Webauthn\Application\Controller\Traits;
use D3\TestingTools\Production\IsMockable;
use D3\Webauthn\Application\Model\Webauthn;
use D3\Webauthn\Application\Model\WebauthnConf;
use Doctrine\DBAL\Driver\Exception;
@ -27,6 +28,8 @@ use Psr\Container\NotFoundExceptionInterface;
trait checkoutGetUserTrait
{
use IsMockable;
/**
* @return false|User
* @throws ContainerExceptionInterface
@ -36,7 +39,7 @@ trait checkoutGetUserTrait
*/
public function getUser()
{
$user = parent::getUser();
$user = $this->d3CallMockableParent('getUser');
if ($user && $user->getId()) {
$webauthn = $this->d3GetWebauthnObject();

View File

@ -15,20 +15,80 @@ declare(strict_types=1);
namespace D3\Webauthn\Application\Model;
use D3\TestingTools\Production\IsMockable;
use OxidEsales\Eshop\Application\Model\Shop;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
use Webauthn\PublicKeyCredentialRpEntity;
class RelyingPartyEntity extends PublicKeyCredentialRpEntity
{
use IsMockable;
public function __construct()
{
$shopUrl = is_string(Registry::getConfig()->getConfigParam('d3webauthn_diffshopurl')) ?
trim(Registry::getConfig()->getConfigParam('d3webauthn_diffshopurl')) :
null;
parent::__construct(
Registry::getConfig()->getActiveShop()->getFieldData('oxname'),
$shopUrl ?: preg_replace('/(^www\.)(.*)/mi', '$2', $_SERVER['HTTP_HOST'])
$this->d3CallMockableParent(
'__construct',
[
$this->getActiveShop()->getFieldData('oxname'),
$this->getRPShopUrl()
]
);
/**
parent::__construct(
$this->getActiveShop()->getFieldData('oxname'),
$this->getRPShopUrl()
);
*/
}
/**
* @return bool
*/
public function hasConfiguredShopUrl(): bool
{
return (bool) strlen(trim((string) $this->getConfiguredShopUrl()));
}
/**
* @return mixed
*/
public function getConfiguredShopUrl()
{
return $this->getConfig()->getConfigParam('d3webauthn_diffshopurl');
}
/**
* @return string
*/
public function getShopUrlByHost(): string
{
return preg_replace('/(^www\.)(.*)/mi', '$2', $_SERVER['HTTP_HOST']);
}
/**
* @return string|null
*/
public function getRPShopUrl(): ?string
{
return $this->hasConfiguredShopUrl() ?
trim($this->getConfiguredShopUrl()) :
$this->getShopUrlByHost();
}
/**
* @return Config
*/
public function getConfig(): Config
{
return Registry::getConfig();
}
/**
* @return Shop
*/
public function getActiveShop(): Shop
{
return Registry::getConfig()->getActiveShop();
}
}

View File

@ -18,15 +18,11 @@ namespace D3\Webauthn\tests\unit\Application\Controller\Admin;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Webauthn\Application\Controller\Admin\d3webauthnadminlogin;
use D3\Webauthn\Application\Controller\d3webauthnlogin;
use D3\Webauthn\Application\Model\Exceptions\WebauthnException;
use D3\Webauthn\Application\Model\Exceptions\WebauthnGetException;
use D3\Webauthn\Application\Model\Webauthn;
use D3\Webauthn\Application\Model\WebauthnAfterLogin;
use D3\Webauthn\Application\Model\WebauthnConf;
use D3\Webauthn\Application\Model\WebauthnLogin;
use D3\Webauthn\tests\unit\Application\Controller\d3webauthnloginTest;
use OxidEsales\Eshop\Application\Controller\Admin\LoginController;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Request;
use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\SystemEventHandler;
@ -34,7 +30,6 @@ use OxidEsales\Eshop\Core\Utils;
use OxidEsales\Eshop\Core\UtilsServer;
use OxidEsales\Eshop\Core\UtilsView;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use ReflectionException;
class d3webauthnadminloginTest extends d3webauthnloginTest

View File

@ -0,0 +1,257 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Application\Model;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Webauthn\Application\Model\RelyingPartyEntity;
use OxidEsales\Eshop\Application\Model\Shop;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\TestingLibrary\UnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class RelyingPartyEntityTest extends UnitTestCase
{
use CanAccessRestricted;
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Model\RelyingPartyEntity::__construct
*/
public function canConstruct()
{
/** @var Shop|MockObject $shopMock */
$shopMock = $this->getMockBuilder(Shop::class)
->onlyMethods(['getFieldData'])
->getMock();
$shopMock->method('getFieldData')->with($this->identicalTo('oxname'))->willReturn('myShopName');
/** @var RelyingPartyEntity|MockObject $sut */
$sut = $this->getMockBuilder(RelyingPartyEntity::class)
->disableOriginalConstructor()
->onlyMethods(['d3CallMockableParent', 'getActiveShop', 'getRPShopUrl'])
->getMock();
$sut->expects($this->once())->method('d3CallMockableParent')->with(
$this->anything(),
$this->identicalTo(['myShopName', 'myShopUrl'])
);
$sut->method('getActiveShop')->willReturn($shopMock);
$sut->method('getRPShopUrl')->willReturn('myShopUrl');
$this->callMethod(
$sut,
'__construct'
);
}
/**
* @test
* @param $configuredShopUrl
* @param $expected
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Model\RelyingPartyEntity::hasConfiguredShopUrl
* @dataProvider checkHasConfiguredShopUrlDataProvider
*/
public function checkHasConfiguredShopUrl($configuredShopUrl, $expected)
{
/** @var RelyingPartyEntity|MockObject $sut */
$sut = $this->getMockBuilder(RelyingPartyEntity::class)
->disableOriginalConstructor()
->onlyMethods(['getConfiguredShopUrl'])
->getMock();
$sut->method('getConfiguredShopUrl')->willReturn($configuredShopUrl);
$this->assertSame(
$expected,
$this->callMethod(
$sut,
'hasConfiguredShopUrl'
)
);
}
/**
* @return array
*/
public function checkHasConfiguredShopUrlDataProvider(): array
{
return [
'null' => [null, false],
'empty string' => ['', false],
'space string' => [' ', false],
'non empty string' => ['content', true]
];
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Model\RelyingPartyEntity::getConfiguredShopUrl
*/
public function canGetConfiguredShopUrl()
{
$fixture = 'configuredShopUrl';
/** @var Config|MockObject $configMock */
$configMock = $this->getMockBuilder(Config::class)
->onlyMethods(['getConfigParam'])
->getMock();
$configMock->method('getConfigParam')->with($this->identicalTo('d3webauthn_diffshopurl'))
->willReturn($fixture);
/** @var RelyingPartyEntity|MockObject $sut */
$sut = $this->getMockBuilder(RelyingPartyEntity::class)
->disableOriginalConstructor()
->onlyMethods(['getConfig'])
->getMock();
$sut->method('getConfig')->willReturn($configMock);
$this->assertSame(
$fixture,
$this->callMethod(
$sut,
'getConfiguredShopUrl'
)
);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Model\RelyingPartyEntity::getShopUrlByHost
* @dataProvider canGetShopUrlByHostDataProvider
*/
public function canGetShopUrlByHost($host, $expected)
{
$_SERVER['HTTP_HOST'] = $host;
/** @var RelyingPartyEntity|MockObject $sut */
$sut = $this->getMockBuilder(RelyingPartyEntity::class)
->onlyMethods(['d3CallMockableParent']) // must mock, because can't disable constructor
->getMock();
$sut->method('d3CallMockableParent')->willReturn(true);
$this->assertSame(
$expected,
$this->callMethod(
$sut,
'getShopUrlByHost'
)
);
}
/**
* @return array
*/
public function canGetShopUrlByHostDataProvider(): array
{
return [
'base url' => ['mydomain.com', 'mydomain.com'],
'www url' => ['www.mydomain.com', 'mydomain.com'],
'www2 url' => ['www2.mydomain.com', 'www2.mydomain.com'],
'subdomain url' => ['subd.mydomain.com', 'subd.mydomain.com'],
'subdomain www url' => ['subd.www.mydomain.com', 'subd.www.mydomain.com'],
'multipart TLD' => ['www.mydomain.co.uk', 'mydomain.co.uk'],
];
}
/**
* @test
* @param $hasConfiguredUrl
* @param $configuredUrl
* @param $hostUrl
* @param $expected
* @return void
* @throws ReflectionException
* @dataProvider canGetRPShopUrlDataProvider
* @covers \D3\Webauthn\Application\Model\RelyingPartyEntity::getRPShopUrl
*/
public function canGetRPShopUrl($hasConfiguredUrl, $configuredUrl, $hostUrl, $expected)
{
/** @var RelyingPartyEntity|MockObject $sut */
$sut = $this->getMockBuilder(RelyingPartyEntity::class)
->disableOriginalConstructor()
->onlyMethods(['hasConfiguredShopUrl', 'getConfiguredShopUrl', 'getShopUrlByHost'])
->getMock();
$sut->method('hasConfiguredShopUrl')->willReturn($hasConfiguredUrl);
$sut->method('getConfiguredShopUrl')->willReturn($configuredUrl);
$sut->method('getShopUrlByHost')->willReturn($hostUrl);
$this->assertSame(
$expected,
$this->callMethod(
$sut,
'getRPShopUrl'
)
);
}
/**
* @return array
*/
public function canGetRPShopUrlDataProvider(): array
{
return [
'configured' => [true, ' subd.mydomain.com', 'www.myhost.de', 'subd.mydomain.com'],
'not configured'=> [false, ' subd.mydomain.com', 'www.myhost.de', 'www.myhost.de']
];
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Model\RelyingPartyEntity::getConfig
*/
public function canGetConfig()
{
/** @var RelyingPartyEntity $sut */
$sut = oxNew(RelyingPartyEntity::class);
$this->assertInstanceOf(
Config::class,
$this->callMethod(
$sut,
'getConfig'
)
);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Model\RelyingPartyEntity::getActiveShop
*/
public function canGetActiveShop()
{
/** @var RelyingPartyEntity $sut */
$sut = oxNew(RelyingPartyEntity::class);
$this->assertInstanceOf(
Shop::class,
$this->callMethod(
$sut,
'getActiveShop'
)
);
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\AccountController;
use OxidEsales\TestingLibrary\UnitTestCase;
class AccountControllerTest extends UnitTestCase
{
use AccountTestTrait;
protected $sutClass = AccountController::class;
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\AccountDownloadsController;
use OxidEsales\TestingLibrary\UnitTestCase;
class AccountDownloadsControllerTest extends UnitTestCase
{
use AccountTestTrait;
protected $sutClass = AccountDownloadsController::class;
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\AccountNewsletterController;
use OxidEsales\TestingLibrary\UnitTestCase;
class AccountNewsletterControllerTest extends UnitTestCase
{
use AccountTestTrait;
protected $sutClass = AccountNewsletterController::class;
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\AccountNoticeListController;
use OxidEsales\TestingLibrary\UnitTestCase;
class AccountNoticeListControllerTest extends UnitTestCase
{
use AccountTestTrait;
protected $sutClass = AccountNoticeListController::class;
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\AccountOrderController;
use OxidEsales\TestingLibrary\UnitTestCase;
class AccountOrderControllerTest extends UnitTestCase
{
use AccountTestTrait;
protected $sutClass = AccountOrderController::class;
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\AccountPasswordController;
use OxidEsales\TestingLibrary\UnitTestCase;
class AccountPasswordControllerTest extends UnitTestCase
{
use AccountTestTrait;
protected $sutClass = AccountPasswordController::class;
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\AccountRecommlistController;
use OxidEsales\TestingLibrary\UnitTestCase;
class AccountRecommlistControllerTest extends UnitTestCase
{
use AccountTestTrait;
protected $sutClass = AccountRecommlistController::class;
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\AccountReviewController;
use OxidEsales\TestingLibrary\UnitTestCase;
class AccountReviewControllerTest extends UnitTestCase
{
use AccountTestTrait;
protected $sutClass = AccountReviewController::class;
}

View File

@ -0,0 +1,73 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use D3\TestingTools\Development\CanAccessRestricted;
use OxidEsales\Eshop\Application\Controller\AccountController;
use OxidEsales\Eshop\Application\Controller\AccountDownloadsController;
use OxidEsales\Eshop\Application\Controller\AccountNewsletterController;
use OxidEsales\Eshop\Application\Controller\AccountNoticeListController;
use OxidEsales\Eshop\Application\Controller\AccountOrderController;
use OxidEsales\Eshop\Application\Controller\AccountPasswordController;
use OxidEsales\Eshop\Application\Controller\AccountRecommlistController;
use OxidEsales\Eshop\Application\Controller\AccountReviewController;
use OxidEsales\Eshop\Application\Controller\AccountUserController;
use OxidEsales\Eshop\Application\Controller\AccountWishlistController;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
trait AccountTestTrait
{
use CanAccessRestricted;
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Modules\Application\Controller\d3_AccountController_Webauthn::__construct
* @covers \D3\Webauthn\Modules\Application\Controller\d3_AccountDownloadsController_Webauthn::__construct
* @covers \D3\Webauthn\Modules\Application\Controller\d3_AccountNewsletterController_Webauthn::__construct
* @covers \D3\Webauthn\Modules\Application\Controller\d3_AccountNoticeListController_Webauthn::__construct
* @covers \D3\Webauthn\Modules\Application\Controller\d3_AccountOrderController_Webauthn::__construct
* @covers \D3\Webauthn\Modules\Application\Controller\d3_AccountPasswordController_Webauthn::__construct
* @covers \D3\Webauthn\Modules\Application\Controller\d3_AccountRecommlistController_Webauthn::__construct
* @covers \D3\Webauthn\Modules\Application\Controller\d3_AccountReviewController_Webauthn::__construct
* @covers \D3\Webauthn\Modules\Application\Controller\d3_AccountUserController_Webauthn::__construct
* @covers \D3\Webauthn\Modules\Application\Controller\d3_AccountWishlistController_Webauthn::__construct
*/
public function canConstruct()
{
/** @var AccountController|AccountDownloadsController|AccountNewsletterController|AccountNoticeListController|AccountOrderController|AccountPasswordController|AccountRecommlistController|AccountReviewController|AccountUserController|AccountWishlistController|MockObject $sut */
$sut = $this->getMockBuilder($this->sutClass)
->onlyMethods(['addTplParam'])
->disableOriginalConstructor()
->getMock();
$sut->expects($this->atLeastOnce())->method('addTplParam')->with($this->identicalTo('oxLoginTpl'));
$this->callMethod(
$sut,
'__construct'
);
$this->assertSame(
'd3webauthnaccountlogin.tpl',
$this->getValue(
$sut,
'_sThisLoginTemplate'
)
);
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\AccountUserController;
use OxidEsales\TestingLibrary\UnitTestCase;
class AccountUserControllerTest extends UnitTestCase
{
use AccountTestTrait;
protected $sutClass = AccountUserController::class;
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\AccountWishlistController;
use OxidEsales\TestingLibrary\UnitTestCase;
class AccountWishlistControllerTest extends UnitTestCase
{
use AccountTestTrait;
protected $sutClass = AccountWishlistController::class;
}

View File

@ -0,0 +1,152 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Webauthn\Application\Model\Webauthn;
use D3\Webauthn\Application\Model\WebauthnConf;
use OxidEsales\Eshop\Application\Controller\OrderController;
use OxidEsales\Eshop\Application\Controller\PaymentController;
use OxidEsales\Eshop\Application\Controller\UserController;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Session;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
trait CheckoutTestTrait
{
use CanAccessRestricted;
/**
* @test
* @param $hasUser
* @param $userId
* @param $isActive
* @param $sessionAuth
* @param $expected
* @return void
* @throws ReflectionException
* @dataProvider canGetUserDataProvider
* @covers \D3\Webauthn\Application\Controller\Traits\checkoutGetUserTrait::getUser
* @covers \D3\Webauthn\Modules\Application\Controller\d3_webauthn_PaymentController::getUser
* @covers \D3\Webauthn\Modules\Application\Controller\d3_webauthn_OrderController::getUser
* @covers \D3\Webauthn\Modules\Application\Controller\d3_webauthn_UserController::getUser
*/
public function canGetUser($hasUser, $userId, $isActive, $sessionAuth, $expected)
{
if ($hasUser) {
/** @var User|MockObject $userMock */
$userMock = $this->getMockBuilder(User::class)
->onlyMethods(['getId'])
->getMock();
$userMock->method('getId')->willReturn($userId);
} else {
$userMock = false;
}
/** @var Session|MockObject $sessionMock */
$sessionMock = $this->getMockBuilder(Session::class)
->onlyMethods(['getVariable'])
->getMock();
$sessionMock->method('getVariable')
->with($this->identicalTo(WebauthnConf::WEBAUTHN_SESSION_AUTH))->willReturn($sessionAuth);
/** @var Webauthn|MockObject $webauthnMock */
$webauthnMock = $this->getMockBuilder(Webauthn::class)
->onlyMethods(['isActive'])
->getMock();
$webauthnMock->method('isActive')->willReturn($isActive);
/** @var PaymentController|OrderController|UserController|MockObject $sut */
$sut = $this->getMockBuilder($this->sutClass)
->onlyMethods(['d3GetWebauthnObject', 'd3WebauthnGetSessionObject', 'd3CallMockableParent'])
->getMock();
$sut->method('d3GetWebauthnObject')->willReturn($webauthnMock);
$sut->method('d3WebauthnGetSessionObject')->willReturn($sessionMock);
$sut->method('d3CallMockableParent')->willReturn($userMock);
$return = $this->callMethod(
$sut,
'getUser'
);
if ($expected === 'parent') {
$this->assertSame($return, $userMock);
} else {
$this->assertSame($return, $expected);
}
}
/**
* @return array
*/
public function canGetUserDataProvider(): array
{
return [
'no user' => [false, null, false, null, 'parent'],
'no user id' => [true, 'null', false, null, 'parent'],
'webauthn not active' => [true, 'userIdFixture', false, null, 'parent'],
'has webauthn auth' => [true, 'userIdFixture', true, 'userIdFixture', 'parent'],
'no webauthn auth' => [true, 'userIdFixture', true, null, false],
];
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Traits\checkoutGetUserTrait::d3GetWebauthnObject
* @covers \D3\Webauthn\Modules\Application\Controller\d3_webauthn_PaymentController::d3GetWebauthnObject
* @covers \D3\Webauthn\Modules\Application\Controller\d3_webauthn_OrderController::d3GetWebauthnObject
* @covers \D3\Webauthn\Modules\Application\Controller\d3_webauthn_UserController::d3GetWebauthnObject
*/
public function canGetWebauthnObject()
{
/** @var PaymentController|OrderController|UserController $sut */
$sut = oxNew($this->sutClass);
$this->assertInstanceOf(
Webauthn::class,
$this->callMethod(
$sut,
'd3GetWebauthnObject'
)
);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Traits\checkoutGetUserTrait::d3WebauthnGetSessionObject
* @covers \D3\Webauthn\Modules\Application\Controller\d3_webauthn_PaymentController::d3WebauthnGetSessionObject
* @covers \D3\Webauthn\Modules\Application\Controller\d3_webauthn_OrderController::d3WebauthnGetSessionObject
* @covers \D3\Webauthn\Modules\Application\Controller\d3_webauthn_UserController::d3WebauthnGetSessionObject
*/
public function canGetSessionObject()
{
/** @var PaymentController|OrderController|UserController $sut */
$sut = oxNew($this->sutClass);
$this->assertInstanceOf(
Session::class,
$this->callMethod(
$sut,
'd3WebauthnGetSessionObject'
)
);
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\OrderController;
use OxidEsales\TestingLibrary\UnitTestCase;
class OrderControllerTest extends UnitTestCase
{
use CheckoutTestTrait;
protected $sutClass = OrderController::class;
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\PaymentController;
use OxidEsales\TestingLibrary\UnitTestCase;
class PaymentControllerTest extends UnitTestCase
{
use CheckoutTestTrait;
protected $sutClass = PaymentController::class;
}

View File

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Modules\Application\Controller;
use OxidEsales\Eshop\Application\Controller\UserController;
use OxidEsales\TestingLibrary\UnitTestCase;
class UserControllerTest extends UnitTestCase
{
use CheckoutTestTrait;
protected $sutClass = UserController::class;
}