2022-11-07 16:00:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
*
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\Webauthn\tests\integration;
|
|
|
|
|
|
|
|
use D3\ModCfg\Application\Model\DependencyInjectionContainer\d3DicHandler;
|
|
|
|
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
|
|
|
|
use Exception;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Article;
|
2022-12-12 23:41:07 +01:00
|
|
|
use OxidEsales\Eshop\Application\Model\Rights;
|
2022-11-07 16:00:53 +01:00
|
|
|
use OxidEsales\Eshop\Application\Model\User;
|
|
|
|
use OxidEsales\Eshop\Core\Model\BaseModel;
|
|
|
|
|
|
|
|
abstract class integrationTestCase extends d3ModCfgUnitTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Set up fixture.
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
d3DicHandler::getUncompiledInstance();
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->createTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tear down fixture.
|
|
|
|
*/
|
|
|
|
public function tearDown(): void
|
|
|
|
{
|
|
|
|
$this->cleanTestData();
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
d3DicHandler::removeInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract public function createTestData();
|
|
|
|
|
|
|
|
abstract public function cleanTestData();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sClass
|
|
|
|
* @param $sId
|
|
|
|
* @param array $aFields
|
2022-12-04 00:24:28 +01:00
|
|
|
* @param bool $blAdmin
|
2022-11-07 16:00:53 +01:00
|
|
|
* @throws Exception
|
|
|
|
*/
|
2022-12-12 23:41:07 +01:00
|
|
|
public function createObject($sClass, $sId, array $aFields = [], bool $blAdmin = false)
|
2022-11-07 16:00:53 +01:00
|
|
|
{
|
|
|
|
/** @var BaseModel $oObject */
|
|
|
|
$oObject = oxNew($sClass);
|
|
|
|
$oObject->setAdminMode($blAdmin);
|
|
|
|
|
|
|
|
if ($oObject->exists($sId)) {
|
|
|
|
$oObject->delete($sId);
|
|
|
|
}
|
|
|
|
|
|
|
|
$oObject->setId($sId);
|
|
|
|
|
|
|
|
$oObject->assign($aFields);
|
|
|
|
$oObject->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sTableName
|
|
|
|
* @param $sId
|
|
|
|
* @param array $aFields
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2022-12-12 23:41:07 +01:00
|
|
|
public function createBaseModelObject($sTableName, $sId, array $aFields = [])
|
2022-11-07 16:00:53 +01:00
|
|
|
{
|
|
|
|
/** @var BaseModel $oObject */
|
|
|
|
$oObject = oxNew(BaseModel::class);
|
|
|
|
$oObject->init($sTableName);
|
|
|
|
$oObject->setId($sId);
|
|
|
|
$oObject->assign($aFields);
|
|
|
|
$oObject->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sId
|
|
|
|
* @param array $aFields
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2022-12-12 23:41:07 +01:00
|
|
|
public function createArticle($sId, array $aFields = [])
|
2022-11-07 16:00:53 +01:00
|
|
|
{
|
|
|
|
$this->createObject(
|
|
|
|
Article::class,
|
|
|
|
$sId,
|
|
|
|
array_merge(
|
|
|
|
['oxprice' => 0],
|
|
|
|
$aFields
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sId
|
|
|
|
* @param array $aFields
|
2022-12-04 00:24:28 +01:00
|
|
|
* @param bool $blAdmin
|
2022-11-07 16:00:53 +01:00
|
|
|
* @throws Exception
|
|
|
|
*/
|
2022-12-12 23:41:07 +01:00
|
|
|
public function createUser($sId, array $aFields = [], bool $blAdmin = false)
|
2022-11-07 16:00:53 +01:00
|
|
|
{
|
|
|
|
$this->createObject(
|
|
|
|
User::class,
|
|
|
|
$sId,
|
|
|
|
array_merge(['oxusername' => $sId], $aFields),
|
|
|
|
$blAdmin
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sClass
|
|
|
|
* @param $sId
|
|
|
|
*/
|
|
|
|
public function deleteObject($sClass, $sId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
/** @var BaseModel $oObject */
|
2022-11-08 10:19:43 +01:00
|
|
|
$oObject = oxNew($sClass);
|
2022-11-07 16:00:53 +01:00
|
|
|
if (method_exists($oObject, 'setRights')) {
|
2022-12-12 23:41:07 +01:00
|
|
|
$oObject->setRights(oxNew(Rights::class));
|
2022-11-07 16:00:53 +01:00
|
|
|
}
|
|
|
|
if ($oObject->exists($sId)) {
|
|
|
|
$oObject->delete($sId);
|
|
|
|
}
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sTableName
|
|
|
|
* @param $sId
|
|
|
|
*/
|
|
|
|
public function deleteBaseModelObject($sTableName, $sId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
/** @var BaseModel $oObject */
|
|
|
|
$oObject = oxNew(BaseModel::class);
|
|
|
|
$oObject->init($sTableName);
|
|
|
|
if (method_exists($oObject, 'setRights')) {
|
2022-12-12 23:41:07 +01:00
|
|
|
$oObject->setRights(oxNew(Rights::class));
|
2022-11-07 16:00:53 +01:00
|
|
|
}
|
|
|
|
if ($oObject->exists($sId)) {
|
|
|
|
$oObject->delete($sId);
|
|
|
|
}
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sId
|
|
|
|
*/
|
|
|
|
public function deleteUser($sId)
|
|
|
|
{
|
|
|
|
$this->deleteObject(User::class, $sId);
|
|
|
|
}
|
|
|
|
}
|