8
0

31 Commits

Autor SHA1 Nachricht Datum
e604b84849 improve code 2021-12-20 13:41:24 +01:00
67c462ccda Merge branch 'dev_2.x_PHP73' of git.d3data.de:D3Public/DataWizard into dev_2.x_PHP73 2021-12-20 12:06:15 +01:00
2549003c71 adjust version informations 2021-12-20 12:05:55 +01:00
f86e3a9daf make installable in OXID 6.4 2021-12-20 11:53:55 +01:00
91b18a9196 Merge branch 'rel_1.x' into dev_2.x_PHP73 2021-11-28 23:09:15 +01:00
675b18aaa8 define test dependencies 2021-11-28 23:05:04 +01:00
a0788ba666 add missing tests 2021-11-28 23:02:15 +01:00
3aa64f8f63 add tests for configuration class 2021-11-28 01:04:46 +01:00
b1946c4aae improve tests for EE 2021-11-27 00:59:02 +01:00
61827e7825 add tests for renderers 2021-11-25 23:42:41 +01:00
5fda1baecb add tests for admin controller classes 2021-11-24 23:38:28 +01:00
e0bd9f02b6 Merge branch 'rel_1.x' into dev_2.x_PHP73 2021-11-11 11:18:16 +01:00
f5d35021f5 fix composer.json 2021-11-11 11:15:23 +01:00
5251490b74 handle JSON exception 2021-11-11 09:41:36 +01:00
e134a4c14a adjust version informations 2021-11-11 09:35:35 +01:00
b5d6936074 change deprecated CSV export code 2021-11-11 09:34:30 +01:00
ac7ae90310 update READMEs 2021-11-10 15:29:30 +01:00
067326e704 add data wizard link suggestion 2021-11-10 14:09:19 +01:00
ae09cf88a5 enable controller based exception handling 2021-11-10 13:50:22 +01:00
3b47f4da05 add extendable tpl blocks for submit elements on tasks 2021-11-10 13:50:21 +01:00
903d178124 add tpl block for easy extension 2021-11-10 13:50:20 +01:00
bd90f18a87 force get translations from admin 2021-11-10 13:50:20 +01:00
74edceafc8 add JSON export renderer 2021-11-10 13:49:55 +01:00
ea77239510 change deprecated CSV export code 2021-10-29 11:38:29 +02:00
e1502b274e show registered export renderers in admin submit without required tpl block extension 2021-10-29 11:37:51 +02:00
500f226399 make installable in OXID 6.3.1 2021-09-10 15:18:11 +02:00
1023bd2fa6 adjust note for example tasks 2021-09-08 13:42:57 +02:00
dd7b8ed1e6 add screenshot 2021-09-08 11:34:20 +02:00
a1cd84b415 can handle long task description text 2021-07-29 17:31:15 +02:00
af10e80086 make admin controller templates more generic 2021-07-29 16:35:25 +02:00
148f4f8213 move example tasks to Data Wizard tasks module 2021-07-27 15:37:54 +02:00
50 geänderte Dateien mit 3717 neuen und 727 gelöschten Zeilen

Datei anzeigen

@ -19,13 +19,11 @@ use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\ModCfg\Application\Model\d3database;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry;
class d3ActionWizard extends AdminDetailsController
@ -42,43 +40,58 @@ class d3ActionWizard extends AdminDetailsController
$this->configuration = oxNew(Configuration::class);
}
public function getGroups()
public function getGroups(): array
{
return $this->configuration->getActionGroups();
}
public function getGroupActions($group)
public function getGroupTasks($group)
{
return $this->configuration->getActionsByGroup($group);
}
/**
* @throws DatabaseConnectionException
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
*/
public function doAction()
public function runTask()
{
try {
$id = Registry::getRequest()->getRequestEscapedParameter('actionid');
$action = $this->configuration->getActionById($id);
[ $queryString, $parameters ] = $action->getQuery();
if (Registry::getConfig()->getConfigParam('d3datawizard_debug')) {
throw oxNew(
DebugException::class,
d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters)
);
}
$action->run();
$this->execute();
} catch (DataWizardException|DBALException|DatabaseErrorException $e) {
Registry::getLogger()->error($e->getMessage());
Registry::getUtilsView()->addErrorToDisplay($e);
}
}
/**
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
protected function execute()
{
$id = Registry::getRequest()->getRequestEscapedParameter('taskid');
$action = $this->configuration->getActionById($id);
[ $queryString, $parameters ] = $action->getQuery();
if ($this->d3GetConfig()->getConfigParam('d3datawizard_debug')) {
throw oxNew(
DebugException::class,
d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters)
);
}
$action->run();
}
/**
* @return Config
*/
public function d3GetConfig(): Config
{
return Registry::getConfig();
}
public function getUserMessages()
{
return null;

Datei anzeigen

@ -18,11 +18,14 @@ namespace D3\DataWizard\Application\Controller\Admin;
use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException;
use D3\DataWizard\Application\Model\Exceptions\TaskException;
use D3\ModCfg\Application\Model\d3database;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
@ -42,12 +45,12 @@ class d3ExportWizard extends AdminDetailsController
$this->configuration = oxNew(Configuration::class);
}
public function getGroups()
public function getGroups(): array
{
return $this->configuration->getExportGroups();
}
public function getGroupExports($group)
public function getGroupTasks($group)
{
return $this->configuration->getExportsByGroup($group);
}
@ -58,27 +61,51 @@ class d3ExportWizard extends AdminDetailsController
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
*/
public function doExport()
public function runTask()
{
try {
$id = Registry::getRequest()->getRequestEscapedParameter('exportid');
$export = $this->configuration->getExportById($id);
[ $queryString, $parameters ] = $export->getQuery();
if (Registry::getConfig()->getConfigParam('d3datawizard_debug')) {
throw oxNew(
DebugException::class,
d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters)
);
}
$export->run(Registry::getRequest()->getRequestEscapedParameter('exportformat'));
$this->execute();
} catch (DataWizardException|DBALException|DatabaseErrorException $e) {
Registry::getLogger()->error($e->getMessage());
Registry::getUtilsView()->addErrorToDisplay($e);
}
}
/**
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws StandardException
* @throws NoSuitableRendererException
* @throws TaskException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
*/
protected function execute()
{
$id = Registry::getRequest()->getRequestEscapedParameter('taskid');
$export = $this->configuration->getExportById($id);
[ $queryString, $parameters ] = $export->getQuery();
if ($this->d3GetConfig()->getConfigParam('d3datawizard_debug')) {
throw oxNew(
DebugException::class,
d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters)
);
}
$export->run(Registry::getRequest()->getRequestEscapedParameter('format'));
}
/**
* @return Config
*/
public function d3GetConfig(): Config
{
return Registry::getConfig();
}
public function getUserMessages()
{
return null;

Datei anzeigen

@ -19,6 +19,7 @@ use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
use FormManager\Inputs\Checkbox;
use FormManager\Inputs\Input;
use FormManager\Inputs\Radio;
use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
@ -29,6 +30,7 @@ abstract class ActionBase implements QueryBase
protected $formElements = [];
/**
* Ensure that the translations are equally available in the frontend and the backend
* @return string
*/
public function getDescription() : string
@ -75,7 +77,7 @@ abstract class ActionBase implements QueryBase
);
}
$affected = DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC )->execute( $queryString, $parameters );
$affected = $this->d3GetDb()->execute( $queryString, $parameters );
throw oxNew(
Exceptions\TaskException::class,
@ -89,6 +91,15 @@ abstract class ActionBase implements QueryBase
);
}
/**
* @return DatabaseInterface|null
* @throws DatabaseConnectionException
*/
public function d3GetDb(): ?DatabaseInterface
{
return DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC );
}
/**
* @return string
*/
@ -102,15 +113,12 @@ abstract class ActionBase implements QueryBase
*/
public function registerFormElement(Input $input)
{
switch (get_class($input)) {
case Radio::class:
case Checkbox::class:
$input->setTemplate('<p class="form-check">{{ input }} {{ label }}</p>');
$input->setAttribute('class', 'form-check-input');
break;
default:
$input->setTemplate('<p class="formElements">{{ label }} {{ input }}</p>');
$input->setAttribute('class', 'form-control');
if ($input instanceof Radio || $input instanceof Checkbox) {
$input->setTemplate('<p class="form-check">{{ input }} {{ label }}</p>');
$input->setAttribute('class', 'form-check-input');
} else {
$input->setTemplate('<p class="formElements">{{ label }} {{ input }}</p>');
$input->setAttribute('class', 'form-control');
}
$this->formElements[] = $input;
}

Datei anzeigen

@ -1,89 +0,0 @@
<?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.
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\DataWizard\Application\Model\Actions;
use D3\DataWizard\Application\Model\ActionBase;
use OxidEsales\Eshop\Core\Model\BaseModel;
use OxidEsales\Eshop\Core\Model\MultiLanguageModel;
use OxidEsales\Eshop\Core\Registry;
class FixArtextendsItems extends ActionBase
{
/**
* fehlende oxartextends-Einträge nachtragen
*/
/**
* @return string
*/
public function getTitle() : string
{
return Registry::getLang()->translateString('D3_DATAWIZARD_ACTIONS_FIXARTEXTENDSITEMS');
}
/**
* @return array
*/
public function getQuery() : array
{
$aDefaultValueFields = array(
'oxtimestamp' => "''",
);
$aNonArtExtendsFields = array(
'oxid' => 'oxarticles.oxid',
);
$aArtExtendsFields = array_fill_keys($this->getArtExtendsFields(), "''");
$aMergedFields = array_merge($aNonArtExtendsFields, $aArtExtendsFields);
$aQueryFields = array_diff_key($aMergedFields, $aDefaultValueFields);
$sArtExtendsFields = implode(', ', array_keys($aQueryFields));
$select = "SELECT ".implode(', ', $aQueryFields).
" FROM oxarticles".
" LEFT JOIN oxartextends AS arx ON oxarticles.oxid = arx.oxid".
" WHERE arx.oxid IS NULL";
$query = "INSERT INTO oxartextends ($sArtExtendsFields) ".
$select;
return [$query, []];
}
/**
* @return array
*/
public function getArtExtendsFields(): array
{
/** @var $oArtExtends MultiLanguageModel */
$oArtExtends = oxNew(BaseModel::class);
$oArtExtends->init('oxartextends', false);
$aFieldNames = $oArtExtends->getFieldNames();
if (false == $aFieldNames) {
$oArtExtends->disableLazyLoading();
$aFieldNames = $oArtExtends->getFieldNames();
}
unset($aFieldNames[array_search('oxid', $aFieldNames)]);
return $aFieldNames;
}
}

Datei anzeigen

@ -15,11 +15,7 @@ declare(strict_types=1);
namespace D3\DataWizard\Application\Model;
use D3\DataWizard\Application\Model\Actions\FixArtextendsItems;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exports\InactiveCategories;
use D3\DataWizard\Application\Model\Exports\KeyFigures;
use OxidEsales\Eshop\Core\Registry;
class Configuration
{
@ -29,6 +25,7 @@ class Configuration
const GROUP_USERS = 'D3_DATAWIZARD_GROUP_USERS';
const GROUP_ORDERS = 'D3_DATAWIZARD_GROUP_ORDERS';
const GROUP_REMARKS = 'D3_DATAWIZARD_GROUP_REMARKS';
const GROUP_CMS = 'D3_DATAWIZARD_GROUP_CMS';
protected $actions = [];
protected $exports = [];
@ -40,12 +37,7 @@ class Configuration
public function configure()
{
if (false === Registry::getConfig()->getConfigParam('d3datawizard_hideexamples', false)) {
$this->registerAction(self::GROUP_ARTICLES, oxNew(FixArtextendsItems::class));
$this->registerExport(self::GROUP_CATEGORY, oxNew(InactiveCategories::class));
$this->registerExport(self::GROUP_SHOP, oxNew(KeyFigures::class));
}
// extend to add exports and actions via 'registerAction()' or 'registerExport()' method
}
/**
@ -153,7 +145,13 @@ class Configuration
*/
public function getActionById($id) : ActionBase
{
return $this->getAllActions()[$id];
$allActions = $this->getAllActions();
if (false == $allActions[$id]) {
throw oxNew(DataWizardException::class, 'no action with id '.$id);
}
return $allActions[$id];
}
/**

Datei anzeigen

@ -25,6 +25,7 @@ use Doctrine\DBAL\DBALException;
use FormManager\Inputs\Checkbox;
use FormManager\Inputs\Input;
use FormManager\Inputs\Radio;
use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
@ -36,6 +37,7 @@ abstract class ExportBase implements QueryBase
protected $formElements = [];
/**
* Ensure that the translations are equally available in the frontend and the backend
* @return string
*/
public function getDescription() : string
@ -68,23 +70,7 @@ abstract class ExportBase implements QueryBase
}
}
[ $rows, $fieldNames ] = $this->getExportData( $this->getQuery() );
$content = $this->renderContent($rows, $fieldNames, $format);
/** @var $oFS d3filesystem */
$oFS = oxNew( d3filesystem::class );
if (is_null($path)) {
$oFS->startDirectDownload( $oFS->filterFilename( $this->getExportFileName( $format ) ), $content );
} else {
$filePath = $oFS->trailingslashit($path).$oFS->filterFilename( $this->getExportFileName( $format ) );
if (false === $oFS->createFile($filePath, $content,true)) {
throw oxNew(ExportFileException::class, $filePath);
}
return $filePath;
}
return '';
return $this->executeExport($format, $path);
}
/**
@ -103,7 +89,15 @@ abstract class ExportBase implements QueryBase
*/
public function getRenderer($format): ExportRenderer\RendererInterface
{
return oxNew(RendererBridge::class)->getRenderer($format);
return $this->getRendererBridge()->getRenderer($format);
}
/**
* @return RendererBridge
*/
public function getRendererBridge(): RendererBridge
{
return oxNew(RendererBridge::class);
}
/**
@ -171,13 +165,13 @@ abstract class ExportBase implements QueryBase
);
}
$rows = DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC )->getAll( $queryString, $parameters );
$rows = $this->d3GetDb()->getAll( $queryString, $parameters );
if ( count( $rows ) <= 0 ) {
throw oxNew(
Exceptions\TaskException::class,
$this,
Registry::getLang()->translateString( 'D3_DATAWIZARD_ERR_NOEXPORTCONTENT' )
Registry::getLang()->translateString( 'D3_DATAWIZARD_ERR_NOEXPORTCONTENT', null, true )
);
}
@ -191,15 +185,12 @@ abstract class ExportBase implements QueryBase
*/
public function registerFormElement(Input $input)
{
switch (get_class($input)) {
case Radio::class:
case Checkbox::class:
$input->setTemplate('<p class="form-check">{{ input }} {{ label }}</p>');
$input->setAttribute('class', 'form-check-input');
break;
default:
$input->setTemplate('<p class="formElements">{{ label }} {{ input }}</p>');
$input->setAttribute('class', 'form-control');
if ($input instanceof Radio || $input instanceof Checkbox) {
$input->setTemplate('<p class="form-check">{{ input }} {{ label }}</p>');
$input->setAttribute('class', 'form-check-input');
} else {
$input->setTemplate('<p class="formElements">{{ label }} {{ input }}</p>');
$input->setAttribute('class', 'form-control');
}
$this->formElements[] = $input;
}
@ -219,4 +210,54 @@ abstract class ExportBase implements QueryBase
{
return $this->formElements;
}
/**
* @param string $format
* @param $path
* @return string
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws Exceptions\NoSuitableRendererException
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
*/
protected function executeExport(string $format, $path): string
{
[$rows, $fieldNames] = $this->getExportData($this->getQuery());
$content = $this->renderContent($rows, $fieldNames, $format);
/** @var $oFS d3filesystem */
$oFS = $this->getFileSystem();
if (is_null($path)) {
$oFS->startDirectDownload($oFS->filterFilename($this->getExportFileName($format)), $content);
} else {
$filePath = $oFS->trailingslashit($path) . $oFS->filterFilename($this->getExportFileName($format));
if (false === $oFS->createFile($filePath, $content, true)) {
throw oxNew(ExportFileException::class, $filePath);
}
return $filePath;
}
return '';
}
/**
* @return DatabaseInterface|null
* @throws DatabaseConnectionException
*/
protected function d3GetDb(): ?DatabaseInterface
{
return DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
}
/**
* @return d3filesystem|mixed
*/
protected function getFileSystem()
{
return oxNew(d3filesystem::class);
}
}

Datei anzeigen

@ -19,6 +19,7 @@ use D3\DataWizard\Application\Model\Exceptions\RenderException;
use League\Csv\EncloseField;
use League\Csv\Exception;
use League\Csv\Writer;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
class Csv implements RendererInterface
@ -36,13 +37,12 @@ class Csv implements RendererInterface
$csv = $this->getCsv();
$csv->insertOne( $fieldNames );
$csv->insertAll( $rows );
return (string) $csv;
} catch (Exception $e) {
/** @var RenderException $newException */
$newException = oxNew(RenderException::class, $e->getMessage(), $e->getCode(), $e );
throw $newException;
}
return $csv->getContent();
}
public function getFileExtension(): string
@ -60,13 +60,13 @@ class Csv implements RendererInterface
EncloseField::addTo($csv, "\t\x1f");
$sEncloser = Registry::getConfig()->getConfigParam('sGiCsvFieldEncloser');
$sEncloser = $this->d3GetConfig()->getConfigParam('sGiCsvFieldEncloser');
if (false == $sEncloser) {
$sEncloser = '"';
}
$csv->setEnclosure($sEncloser);
$sDelimiter = Registry::getConfig()->getConfigParam('sCSVSign');
$sDelimiter = $this->d3GetConfig()->getConfigParam('sCSVSign');
if (false == $sDelimiter) {
$sDelimiter = ';';
}
@ -74,4 +74,20 @@ class Csv implements RendererInterface
return $csv;
}
/**
* @return string
*/
public function getTitleTranslationId(): string
{
return 'D3_DATAWIZARD_EXPORT_FORMAT_CSV';
}
/**
* @return Config
*/
public function d3GetConfig(): Config
{
return Registry::getConfig();
}
}

Datei anzeigen

@ -0,0 +1,55 @@
<?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\DataWizard\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\Exceptions\RenderException;
use JsonException;
class Json implements RendererInterface
{
/**
* @param $rows
* @param $fieldNames
*
* @return string
* @throws RenderException
*/
public function getContent($rows, $fieldNames): string
{
try {
$flags = JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR;
$json = json_encode( $rows, $flags );
return $json;
} catch ( JsonException $e) {
/** @var RenderException $newException */
$newException = oxNew(RenderException::class, $e->getMessage(), $e->getCode(), $e );
throw $newException;
}
}
public function getFileExtension(): string
{
return 'json';
}
/**
* @return string
*/
public function getTitleTranslationId(): string
{
return "D3_DATAWIZARD_EXPORT_FORMAT_JSON";
}
}

Datei anzeigen

@ -27,10 +27,19 @@ class Pretty implements RendererInterface
*/
public function getContent($rows, $fieldNames) : string
{
$renderer = oxNew(ArrayToTextTable::class, $rows);
$renderer = $this->getArrayToTextTableInstance($rows);
return $renderer->getTable();
}
/**
* @param $rows
* @return ArrayToTextTable
*/
public function getArrayToTextTableInstance($rows): ArrayToTextTable
{
return oxNew(ArrayToTextTable::class, $rows);
}
/**
* @return string
*/
@ -38,4 +47,12 @@ class Pretty implements RendererInterface
{
return 'txt';
}
/**
* @return string
*/
public function getTitleTranslationId(): string
{
return "D3_DATAWIZARD_EXPORT_FORMAT_PRETTY";
}
}

Datei anzeigen

@ -21,6 +21,7 @@ class RendererBridge
{
const FORMAT_CSV = 'CSV';
const FORMAT_PRETTY = 'Pretty';
const FORMAT_JSON = 'JSON';
/**
* @return array
@ -29,10 +30,26 @@ class RendererBridge
{
return [
self::FORMAT_CSV => oxNew(Csv::class),
self::FORMAT_PRETTY => oxNew(Pretty::class)
self::FORMAT_PRETTY => oxNew(Pretty::class),
self::FORMAT_JSON => oxNew(Json::class)
];
}
public function getTranslatedRendererIdList(): array
{
$rendererList = $this->getRendererList();
array_walk($rendererList, [$this, 'translateRendererId']);
return $rendererList;
}
/**
* @param RendererInterface $instance
*/
protected function translateRendererId(RendererInterface &$instance)
{
$instance = $instance->getTitleTranslationId();
}
/**
* @param string $format
*

Datei anzeigen

@ -29,4 +29,9 @@ interface RendererInterface
* @return string
*/
public function getFileExtension() : string;
/**
* @return string
*/
public function getTitleTranslationId() : string;
}

Datei anzeigen

@ -1,77 +0,0 @@
<?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.
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\DataWizard\Application\Model\Exports;
use D3\DataWizard\Application\Model\ExportBase;
use OxidEsales\Eshop\Application\Model\Article;
use OxidEsales\Eshop\Application\Model\Category;
use OxidEsales\Eshop\Application\Model\Object2Category;
use OxidEsales\Eshop\Core\Registry;
class InactiveCategories extends ExportBase
{
/**
* Kategorien -deaktiviert, mit aktiven Artikeln
*/
/**
* @return string
*/
public function getTitle() : string
{
return Registry::getLang()->translateString('D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES');
}
/**
* @return array
*/
public function getQuery() : array
{
$categoryTableName = oxNew(Category::class)->getCoreTableName();
$object2categoryTableName = oxNew(Object2Category::class)->getCoreTableName();
$articleTableName = oxNew(Article::class)->getCoreTableName();
$treeTitle = Registry::getLang()->translateString('D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_TREE');
$titleTitle = Registry::getLang()->translateString('D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_TITLE');
$countTitle = Registry::getLang()->translateString('D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_COUNT');
return [
"SELECT
oc.OXID,
oc.OXSHOPID,
oc.oxtitle as :titleTitle,
(
SELECT GROUP_CONCAT(oxtitle ORDER BY oxleft ASC SEPARATOR ' > ')
from ".$categoryTableName."
WHERE OXLEFT < oc.oxleft AND OXRIGHT > oc.oxright AND OXROOTID = oc.OXROOTID AND OXSHOPID = oc.OXSHOPID
) as :treeTitle,
COUNT(oa.oxid) as :countTitle
FROM ".$categoryTableName." oc
LEFT JOIN ".$object2categoryTableName." o2c ON oc.OXID = o2c.OXCATNID
LEFT JOIN ".$articleTableName." oa ON o2c.OXOBJECTID = oa.OXID
WHERE oc.OXACTIVE = :categoryActive AND oa.OXACTIVE = :articleActive
GROUP BY oc.oxid
ORDER BY oc.oxleft ASC",
[
'categoryActive' => 0,
'articleActive' => 1,
'titleTitle' => $titleTitle,
'treeTitle' => $treeTitle,
'countTitle' => $countTitle
]
];
}
}

Datei anzeigen

@ -1,98 +0,0 @@
<?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.
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\DataWizard\Application\Model\Exports;
use D3\DataWizard\Application\Model\ExportBase;
use FormManager\Inputs\Date;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\Registry;
use FormManager\Factory as FormFactory;
class KeyFigures extends ExportBase
{
const STARTDATE_NAME = 'startdate';
const ENDDATE_NAME = 'enddate';
/**
* Shopkennzahlen
*/
public function __construct()
{
/** @var Date $startDate */
$startDateValue = Registry::getRequest()->getRequestEscapedParameter(self::STARTDATE_NAME);
$startDate = FormFactory::date(
Registry::getLang()->translateString('D3_DATAWIZARD_EXPORTS_KEYFIGURES_FIELD_STARTDATE'),
[
'name' => self::STARTDATE_NAME,
'value' => $startDateValue
]
);
$this->registerFormElement($startDate);
/** @var Date $endDate */
$endDateValue = Registry::getRequest()->getRequestEscapedParameter(self::ENDDATE_NAME);
$endDate = FormFactory::date(
Registry::getLang()->translateString('D3_DATAWIZARD_EXPORTS_KEYFIGURES_FIELD_ENDDATE'),
[
'name' => self::ENDDATE_NAME,
'value' => $endDateValue
]
);
$this->registerFormElement($endDate);
}
/**
* @return string
*/
public function getTitle() : string
{
return Registry::getLang()->translateString('D3_DATAWIZARD_EXPORTS_KEYFIGURES');
}
/**
* @return array
*/
public function getQuery() : array
{
$orderTable = oxNew(Order::class)->getCoreTableName();
$ordersTitle = Registry::getLang()->translateString('D3_DATAWIZARD_EXPORTS_KEYFIGURES_ORDERSPERMONTH');
$basketsTitle = Registry::getLang()->translateString('D3_DATAWIZARD_EXPORTS_KEYFIGURES_BASKETSIZE');
$monthTitle = Registry::getLang()->translateString('D3_DATAWIZARD_EXPORTS_KEYFIGURES_MONTH');
$startDateValue = Registry::getRequest()->getRequestEscapedParameter(self::STARTDATE_NAME) ?: '1970-01-01';
$endDateValue = Registry::getRequest()->getRequestEscapedParameter(self::ENDDATE_NAME) ?: date('Y-m-d');
return [
'SELECT
DATE_FORMAT(oo.oxorderdate, "%Y-%m") as :monthTitle,
FORMAT(COUNT(oo.oxid), 0) AS :ordersTitle,
FORMAT(SUM(oo.OXTOTALBRUTSUM / oo.oxcurrate) / COUNT(oo.oxid), 2) as :basketsTitle
FROM '.$orderTable.' AS oo
WHERE oo.oxorderdate >= :startDate AND oo.oxorderdate <= :endDate
GROUP BY DATE_FORMAT(oo.oxorderdate, "%Y-%m")
ORDER BY DATE_FORMAT(oo.oxorderdate, "%Y-%m") DESC
LIMIT 30',
[
'startDate' => $startDateValue,
'endDate' => $endDateValue,
'monthTitle' => $monthTitle,
'ordersTitle' => $ordersTitle,
'basketsTitle' => $basketsTitle
]
];
}
}

Datei anzeigen

@ -22,11 +22,13 @@ interface QueryBase
public function run();
/**
* Ensure that the translations are equally available in the frontend and the backend
* @return string
*/
public function getTitle() : string;
/**
* Ensure that the translations are equally available in the frontend and the backend
* @return string
*/
public function getDescription() : string;

Datei anzeigen

@ -27,18 +27,19 @@ $aLang = array(
'SHOP_MODULE_GROUP_d3datawizard_general' => 'Grundeinstellungen',
'SHOP_MODULE_d3datawizard_debug' => 'zeigt Abfragen anstatt diese auszuführen',
'SHOP_MODULE_d3datawizard_hideexamples' => 'Beispielexporte ausblenden',
'D3_DATAWIZARD_GROUP_ARTICLES' => 'Artikel',
'D3_DATAWIZARD_GROUP_CATEGORIES' => 'Kategorien',
'D3_DATAWIZARD_GROUP_ORDERS' => 'Bestellungen',
'D3_DATAWIZARD_GROUP_REMARKS' => 'Bewertungen',
'D3_DATAWIZARD_GROUP_SHOP' => 'Shop',
'D3_DATAWIZARD_GROUP_CMS' => 'CMS-Texte',
'D3_DATAWIZARD_GROUP_USERS' => 'Benutzer',
'D3_DATAWIZARD_EXPORT_SUBMIT' => 'Export starten',
'D3_DATAWIZARD_EXPORT_FORMAT_CSV' => 'CSV-Format',
'D3_DATAWIZARD_EXPORT_FORMAT_PRETTY' => 'Pretty-Format',
'D3_DATAWIZARD_EXPORT_FORMAT_JSON' => 'JSON-Format',
'D3_DATAWIZARD_ACTION_SUBMIT' => 'Aktion starten',
@ -50,21 +51,8 @@ $aLang = array(
'D3_DATAWIZARD_ERR_NOSUITABLERENDERER' => 'kein Renderer für Format "%1$s" registriert',
'D3_DATAWIZARD_ERR_EXPORTFILEERROR' => 'Exportdatei "%1$s" kann nicht angelegt werden',
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES' => 'deaktivierte Kategorien, mit aktiven Artikeln',
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_TREE' => 'Baum',
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_TITLE' => 'Titel',
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_COUNT' => 'Anzahl',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES' => 'Bestellungskennzahlen nach Monat',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_FIELD_STARTDATE'=> 'Startdatum (optional)',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_FIELD_ENDDATE' => 'Enddatum (optional)',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_ORDERSPERMONTH' => 'Bestellungen pro Monat',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_BASKETSIZE' => 'Warenkorbhöhe',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_MONTH' => 'Monat',
'D3_DATAWIZARD_ERR_ACTIONSELECT' => 'Aktion kann nicht ausgeführt werden. Aktionen können keine SELECTs exportieren.',
'D3_DATAWIZARD_ERR_NOACTION_INSTALLED' => 'Es sind keine Aktionen installiert oder aktiviert.',
'D3_DATAWIZARD_ERR_ACTIONRESULT' => '%1$s Eintrag verändert',
'D3_DATAWIZARD_ERR_ACTIONRESULTS' => '%1$s Einträge verändert',
'D3_DATAWIZARD_ACTIONS_FIXARTEXTENDSITEMS' => 'fehlende oxartextends-Einträge nachtragen',
);

Datei anzeigen

@ -27,18 +27,19 @@ $aLang = array(
'SHOP_MODULE_GROUP_d3datawizard_general' => 'basic settings',
'SHOP_MODULE_d3datawizard_debug' => 'shows queries instead of executing them',
'SHOP_MODULE_d3datawizard_hideexamples' => 'hide sample exports',
'D3_DATAWIZARD_GROUP_ARTICLES' => 'articles',
'D3_DATAWIZARD_GROUP_CATEGORIES' => 'categories',
'D3_DATAWIZARD_GROUP_ORDERS' => 'orders',
'D3_DATAWIZARD_GROUP_REMARKS' => 'remarks',
'D3_DATAWIZARD_GROUP_SHOP' => 'shop',
'D3_DATAWIZARD_GROUP_CMS' => 'CMS items',
'D3_DATAWIZARD_GROUP_USERS' => 'users',
'D3_DATAWIZARD_EXPORT_SUBMIT' => 'generate export',
'D3_DATAWIZARD_EXPORT_FORMAT_CSV' => 'CSV format',
'D3_DATAWIZARD_EXPORT_FORMAT_PRETTY' => 'Pretty format',
'D3_DATAWIZARD_EXPORT_FORMAT_JSON' => 'JSON format',
'D3_DATAWIZARD_ACTION_SUBMIT' => 'run action',
@ -50,21 +51,8 @@ $aLang = array(
'D3_DATAWIZARD_ERR_NOSUITABLERENDERER' => 'No renderer registered for format "%1$s"',
'D3_DATAWIZARD_ERR_EXPORTFILEERROR' => 'Export file "%1$s" cannot be created',
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES' => 'deactivated categories, with active articles',
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_TREE' => 'tree',
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_TITLE' => 'title',
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_COUNT' => 'count',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES' => 'Order key figures by month',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_FIELD_STARTDATE'=> 'start date (optional)',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_FIELD_ENDDATE' => 'end date (optional)',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_ORDERSPERMONTH' => 'orders per month',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_BASKETSIZE' => 'shopping cart value',
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_MONTH' => 'month',
'D3_DATAWIZARD_ERR_ACTIONSELECT' => 'Action cannot be executed. Actions cannot export SELECTs.',
'D3_DATAWIZARD_ERR_NOACTION_INSTALLED' => 'No actions are installed or activated.',
'D3_DATAWIZARD_ERR_ACTIONRESULT' => '%1$s entry changed',
'D3_DATAWIZARD_ERR_ACTIONRESULTS' => '%1$s entries changed',
'D3_DATAWIZARD_ACTIONS_FIXARTEXTENDSITEMS' => 'add missing oxartextends entries',
);

Datei anzeigen

@ -1,127 +1,4 @@
[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]
[{capture assign="d3dw_backgroundimage"}]linear-gradient(22.5deg, rgba(66, 66, 66, 0.02) 0%, rgba(66, 66, 66, 0.02) 11%,rgba(135, 135, 135, 0.02) 11%, rgba(135, 135, 135, 0.02) 24%,rgba(29, 29, 29, 0.02) 24%, rgba(29, 29, 29, 0.02) 38%,rgba(15, 15, 15, 0.02) 38%, rgba(15, 15, 15, 0.02) 50%,rgba(180, 180, 180, 0.02) 50%, rgba(180, 180, 180, 0.02) 77%,rgba(205, 205, 205, 0.02) 77%, rgba(205, 205, 205, 0.02) 100%),linear-gradient(67.5deg, rgba(10, 10, 10, 0.02) 0%, rgba(10, 10, 10, 0.02) 22%,rgba(52, 52, 52, 0.02) 22%, rgba(52, 52, 52, 0.02) 29%,rgba(203, 203, 203, 0.02) 29%, rgba(203, 203, 203, 0.02) 30%,rgba(69, 69, 69, 0.02) 30%, rgba(69, 69, 69, 0.02) 75%,rgba(231, 231, 231, 0.02) 75%, rgba(231, 231, 231, 0.02) 95%,rgba(138, 138, 138, 0.02) 95%, rgba(138, 138, 138, 0.02) 100%),linear-gradient(112.5deg, rgba(221, 221, 221, 0.02) 0%, rgba(221, 221, 221, 0.02) 17%,rgba(190, 190, 190, 0.02) 17%, rgba(190, 190, 190, 0.02) 39%,rgba(186, 186, 186, 0.02) 39%, rgba(186, 186, 186, 0.02) 66%,rgba(191, 191, 191, 0.02) 66%, rgba(191, 191, 191, 0.02) 68%,rgba(16, 16, 16, 0.02) 68%, rgba(16, 16, 16, 0.02) 70%,rgba(94, 94, 94, 0.02) 70%, rgba(94, 94, 94, 0.02) 100%),linear-gradient(90deg, #ffffff,#ffffff)[{/capture}]
[{capture assign="d3dw_noitemmessageid"}]D3_DATAWIZARD_ERR_NOACTION_INSTALLED[{/capture}]
[{oxstyle include="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"}]
[{oxscript include="https://code.jquery.com/jquery-3.2.1.slim.min.js"}]
[{oxscript include="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"}]
[{oxscript include="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"}]
[{oxstyle include="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/solid.min.css"}]
<style>
button {
margin: 1em 1em 1em 5em;
}
html {
font-size: 0.8em;
}
/* Image courtesy of gradientmagic.com */
body {
background-image: linear-gradient(22.5deg, rgba(66, 66, 66, 0.02) 0%, rgba(66, 66, 66, 0.02) 11%,rgba(135, 135, 135, 0.02) 11%, rgba(135, 135, 135, 0.02) 24%,rgba(29, 29, 29, 0.02) 24%, rgba(29, 29, 29, 0.02) 38%,rgba(15, 15, 15, 0.02) 38%, rgba(15, 15, 15, 0.02) 50%,rgba(180, 180, 180, 0.02) 50%, rgba(180, 180, 180, 0.02) 77%,rgba(205, 205, 205, 0.02) 77%, rgba(205, 205, 205, 0.02) 100%),linear-gradient(67.5deg, rgba(10, 10, 10, 0.02) 0%, rgba(10, 10, 10, 0.02) 22%,rgba(52, 52, 52, 0.02) 22%, rgba(52, 52, 52, 0.02) 29%,rgba(203, 203, 203, 0.02) 29%, rgba(203, 203, 203, 0.02) 30%,rgba(69, 69, 69, 0.02) 30%, rgba(69, 69, 69, 0.02) 75%,rgba(231, 231, 231, 0.02) 75%, rgba(231, 231, 231, 0.02) 95%,rgba(138, 138, 138, 0.02) 95%, rgba(138, 138, 138, 0.02) 100%),linear-gradient(112.5deg, rgba(221, 221, 221, 0.02) 0%, rgba(221, 221, 221, 0.02) 17%,rgba(190, 190, 190, 0.02) 17%, rgba(190, 190, 190, 0.02) 39%,rgba(186, 186, 186, 0.02) 39%, rgba(186, 186, 186, 0.02) 66%,rgba(191, 191, 191, 0.02) 66%, rgba(191, 191, 191, 0.02) 68%,rgba(16, 16, 16, 0.02) 68%, rgba(16, 16, 16, 0.02) 70%,rgba(94, 94, 94, 0.02) 70%, rgba(94, 94, 94, 0.02) 100%),linear-gradient(90deg, #ffffff,#ffffff);
}
h4 .btn {
font-size: 1.3rem;
}
h5.card-header {
font-size: 1.1rem;
}
.formElements label {
display: inline-block;
margin: .5rem 0;
}
</style>
[{capture name="d3script"}][{strip}]
function startAction(id) {
let elements = document.getElementsByClassName('errorbox');
for (var i = 0; i < elements.length; i++){
elements[i].style.display = 'none';
}
setTimeout(function(){
document.getElementById('mask').className='';
document.getElementById('popup2').className='d3loader-2';
}, 3000);
document.getElementById('mask').className='on';
document.getElementById('popup2').className='d3loader-2 on';
document.getElementById('actionid').value = id;
document.getElementById('myedit').submit();
}
[{/strip}][{/capture}]
[{oxscript add=$smarty.capture.d3script}]
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post" style="padding: 0;margin: 0;height:0;">
[{$oViewConf->getHiddenSid()}]
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
<input type="hidden" name="fnc" value="doAction">
<input type="hidden" name="actionid" id="actionid" value="">
[{assign var="groups" value=$oView->getGroups()}]
[{if $groups|@count}]
<div id="accordion">
[{foreach from=$oView->getGroups() item="group"}]
<div class="card mb-2">
<div class="card-header p-1" id="heading[{$group}]">
<h4 class="mb-0">
<span class="btn p-1" data-toggle="collapse" data-target="#collapse[{$group}]" aria-expanded="false" aria-controls="collapse[{$group}]">
[{oxmultilang ident=$group}]
</span>
</h4>
</div>
<div id="collapse[{$group}]" class="collapse" aria-labelledby="heading[{$group}]" data-parent="#accordion">
<div class="card-body pb-0">
<div class="row">
[{foreach from=$oView->getGroupActions($group) key="id" item="action"}]
<div class="col-sm-6 col-md-4 col-lg-3 pb-4">
<div class="card">
<h5 class="card-header">
[{$action->getTitle()}]
</h5>
<div class="card-body">
[{if $action->getDescription()}]
<p class="card-text">
[{$action->getDescription()}]
</p>
[{/if}]
[{if $action->hasFormElements()}]
[{foreach from=$action->getFormElements() item="formElement"}]
[{$formElement}]
[{/foreach}]
[{/if}]
<div class="btn-group">
<button type="button" class="btn btn-primary" onclick="startAction('[{$id}]')">
<i class="fas fa-magic"></i>
[{oxmultilang ident=$action->getButtonText()}]
</button>
</div>
</div>
</div>
</div>
[{/foreach}]
</div>
<div class="clear"></div>
</div>
</div>
</div>
[{/foreach}]
</div>
[{else}]
<div class="alert alert-primary" role="alert">
[{oxmultilang ident="D3_DATAWIZARD_ERR_NOACTION_INSTALLED"}]
</div>
[{/if}]
</form>
<div id="mask" class=""></div>
<div id="popup2" class="d3loader-2">
<div class="d3loader-spinner">
<div class="d3loader-circle-1"></div>
<div class="d3loader-circle-2"></div>
<div class="d3loader-circle-3"></div>
</div>
</div>
[{include file="d3_cfg_mod_inc.tpl"}]
[{include file="d3Wizards.tpl" submit="d3ActionSubmit.tpl"}]

Datei anzeigen

@ -1,145 +1,4 @@
[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]
[{capture assign="d3dw_backgroundimage"}]linear-gradient(339deg, rgba(47, 47, 47,0.02) 0%, rgba(47, 47, 47,0.02) 42%,transparent 42%, transparent 99%,rgba(17, 17, 17,0.02) 99%, rgba(17, 17, 17,0.02) 100%),linear-gradient(257deg, rgba(65, 65, 65,0.02) 0%, rgba(65, 65, 65,0.02) 11%,transparent 11%, transparent 92%,rgba(53, 53, 53,0.02) 92%, rgba(53, 53, 53,0.02) 100%),linear-gradient(191deg, rgba(5, 5, 5,0.02) 0%, rgba(5, 5, 5,0.02) 1%,transparent 1%, transparent 45%,rgba(19, 19, 19,0.02) 45%, rgba(19, 19, 19,0.02) 100%),linear-gradient(29deg, rgba(28, 28, 28,0.02) 0%, rgba(28, 28, 28,0.02) 33%,transparent 33%, transparent 40%,rgba(220, 220, 220,0.02) 40%, rgba(220, 220, 220,0.02) 100%),linear-gradient(90deg, rgb(255,255,255),rgb(255,255,255))[{/capture}]
[{capture assign="d3dw_noitemmessageid"}]D3_DATAWIZARD_ERR_NOEXPORT_INSTALLED[{/capture}]
[{oxstyle include="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"}]
[{oxscript include="https://code.jquery.com/jquery-3.2.1.slim.min.js"}]
[{oxscript include="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"}]
[{oxscript include="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"}]
[{oxstyle include="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/solid.min.css"}]
<style>
button {
margin: 1em 1em 1em 5em;
}
html {
font-size: 0.8em;
}
/* Image courtesy of gradientmagic.com */
body {
background-image: linear-gradient(339deg, rgba(47, 47, 47,0.02) 0%, rgba(47, 47, 47,0.02) 42%,transparent 42%, transparent 99%,rgba(17, 17, 17,0.02) 99%, rgba(17, 17, 17,0.02) 100%),linear-gradient(257deg, rgba(65, 65, 65,0.02) 0%, rgba(65, 65, 65,0.02) 11%,transparent 11%, transparent 92%,rgba(53, 53, 53,0.02) 92%, rgba(53, 53, 53,0.02) 100%),linear-gradient(191deg, rgba(5, 5, 5,0.02) 0%, rgba(5, 5, 5,0.02) 1%,transparent 1%, transparent 45%,rgba(19, 19, 19,0.02) 45%, rgba(19, 19, 19,0.02) 100%),linear-gradient(29deg, rgba(28, 28, 28,0.02) 0%, rgba(28, 28, 28,0.02) 33%,transparent 33%, transparent 40%,rgba(220, 220, 220,0.02) 40%, rgba(220, 220, 220,0.02) 100%),linear-gradient(90deg, rgb(255,255,255),rgb(255,255,255));
}
h4 .btn {
font-size: 1.3rem;
}
h5.card-header {
font-size: 1.1rem;
}
.formElements label {
display: inline-block;
margin: .5rem 0;
}
</style>
[{capture name="d3script"}][{strip}]
function startExport(id, format) {
let elements = document.getElementsByClassName('errorbox');
for (var i = 0; i < elements.length; i++){
elements[i].style.display = 'none';
}
setTimeout(function(){
document.getElementById('mask').className='';
document.getElementById('popup2').className='d3loader-2';
}, 3000);
document.getElementById('mask').className='on';
document.getElementById('popup2').className='d3loader-2 on';
document.getElementById('exportid').value = id;
document.getElementById('exportformat').value = format;
document.getElementById('myedit').submit();
}
[{/strip}][{/capture}]
[{oxscript add=$smarty.capture.d3script}]
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post" style="padding: 0;margin: 0;height:0;">
[{$oViewConf->getHiddenSid()}]
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
<input type="hidden" name="fnc" value="doExport">
<input type="hidden" name="exportid" id="exportid" value="">
<input type="hidden" name="exportformat" id="exportformat" value="CSV">
[{assign var="groups" value=$oView->getGroups()}]
[{if $groups|@count}]
<div id="accordion">
[{foreach from=$oView->getGroups() item="group"}]
<div class="card mb-2">
<div class="card-header p-1" id="heading[{$group}]">
<h4 class="mb-0">
<span class="btn p-1" data-toggle="collapse" data-target="#collapse[{$group}]" aria-expanded="false" aria-controls="collapse[{$group}]">
[{oxmultilang ident=$group}]
</span>
</h4>
</div>
<div id="collapse[{$group}]" class="collapse" aria-labelledby="heading[{$group}]" data-parent="#accordion">
<div class="card-body pb-0">
<div class="row">
[{foreach from=$oView->getGroupExports($group) key="id" item="export"}]
<div class="col-sm-6 col-md-4 col-lg-3 pb-4">
<div class="card">
<h5 class="card-header">
[{$export->getTitle()}]
</h5>
<div class="card-body">
[{if $export->getDescription()}]
<p class="card-text">
[{$export->getDescription()}]
</p>
[{/if}]
[{if $export->hasFormElements()}]
[{foreach from=$export->getFormElements() item="formElement"}]
[{$formElement}]
[{/foreach}]
[{/if}]
<div class="btn-group">
<button type="button" class="btn btn-primary" onclick="startExport('[{$id}]', 'CSV')">
<i class="fas fa-magic"></i>
[{oxmultilang ident=$export->getButtonText()}]
</button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">
<i class="fas fa-magic"></i>
[{oxmultilang ident=$export->getButtonText()}]
</span>
</button>
<div class="dropdown-menu">
[{block name="dataWizardExportFormat"}]
<button class="dropdown-item" onclick="startExport('[{$id}]', 'CSV')">
[{oxmultilang ident="D3_DATAWIZARD_EXPORT_FORMAT_CSV"}]
</button>
<button class="dropdown-item" onclick="startExport('[{$id}]', 'Pretty')">
[{oxmultilang ident="D3_DATAWIZARD_EXPORT_FORMAT_PRETTY"}]
</button>
[{/block}]
</div>
</div>
</div>
</div>
</div>
[{/foreach}]
</div>
<div class="clear"></div>
</div>
</div>
</div>
[{/foreach}]
</div>
[{else}]
<div class="alert alert-primary" role="alert">
[{oxmultilang ident="D3_DATAWIZARD_ERR_NOEXPORT_INSTALLED"}]
</div>
[{/if}]
</form>
<div id="mask" class=""></div>
<div id="popup2" class="d3loader-2">
<div class="d3loader-spinner">
<div class="d3loader-circle-1"></div>
<div class="d3loader-circle-2"></div>
<div class="d3loader-circle-3"></div>
</div>
</div>
[{include file="d3_cfg_mod_inc.tpl"}]
[{include file="d3Wizards.tpl" submit="d3ExportSubmit.tpl"}]

Datei anzeigen

@ -0,0 +1,136 @@
[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]
[{oxstyle include="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"}]
[{oxscript include="https://code.jquery.com/jquery-3.2.1.slim.min.js"}]
[{oxscript include="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"}]
[{oxscript include="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"}]
[{oxstyle include="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/solid.min.css"}]
<style>
button {
margin: 1em 1em 1em 5em;
}
html {
font-size: 0.8em;
}
/* Image courtesy of gradientmagic.com */
body {
background-image: [{$d3dw_backgroundimage}];
}
h4 .btn {
font-size: 1.3rem;
}
h5.card-header {
font-size: 1.1rem;
}
.formElements label {
display: inline-block;
margin: .5rem 0;
}
</style>
[{capture name="d3script"}][{strip}]
function startTask(id, format = '') {
let elements = document.getElementsByClassName('errorbox');
for (var i = 0; i < elements.length; i++){
elements[i].style.display = 'none';
}
setTimeout(function(){
document.getElementById('mask').className='';
document.getElementById('popup2').className='d3loader-2';
}, 3000);
document.getElementById('mask').className='on';
document.getElementById('popup2').className='d3loader-2 on';
document.getElementById('taskid').value = id;
document.getElementById('format').value = format;
document.getElementById('myedit').submit();
}
[{/strip}][{/capture}]
[{oxscript add=$smarty.capture.d3script}]
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post" style="padding: 0;margin: 0;height:0;">
[{$oViewConf->getHiddenSid()}]
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
<input type="hidden" name="fnc" value="runTask">
<input type="hidden" name="taskid" id="taskid" value="">
<input type="hidden" name="format" id="format" value="CSV">
[{assign var="groups" value=$oView->getGroups()}]
[{if $groups|@count}]
<div id="accordion">
[{foreach from=$oView->getGroups() item="group"}]
<div class="card mb-2">
<div class="card-header p-1" id="heading[{$group}]">
<h4 class="mb-0">
<span class="btn p-1" data-toggle="collapse" data-target="#collapse[{$group}]" aria-expanded="false" aria-controls="collapse[{$group}]">
[{oxmultilang ident=$group}]
</span>
</h4>
</div>
<div id="collapse[{$group}]" class="collapse" aria-labelledby="heading[{$group}]" data-parent="#accordion">
<div class="card-body pb-0">
<div class="row">
[{foreach from=$oView->getGroupTasks($group) key="id" item="item"}]
<div class="col-sm-6 col-md-4 col-lg-3 pb-4">
<div class="card">
<h5 class="card-header">
[{$item->getTitle()}]
</h5>
<div class="card-body">
[{if $item->getDescription()}]
[{assign var="description" value=$item->getDescription()}]
[{assign var="sectionlength" value="100"}]
[{if $description|count_characters:true <= $sectionlength}]
<p class="card-text">[{$description}]</p>
[{else}]
[{assign var="shorttext" value=$description|truncate:$sectionlength:''}]
<p class="card-text" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample" style="cursor: pointer">
[{$shorttext}]...
</p>
<p class="card-text collapse" id="collapseExample">
...[{$description|replace:$shorttext:''}]
</p>
[{/if}]
[{/if}]
[{if $item->hasFormElements()}]
[{foreach from=$item->getFormElements() item="formElement"}]
[{$formElement}]
[{/foreach}]
[{/if}]
[{block name="exportSubmit"}]
[{include file=$submit}]
[{/block}]
</div>
</div>
</div>
[{/foreach}]
</div>
<div class="clear"></div>
</div>
</div>
</div>
[{/foreach}]
</div>
[{else}]
<div class="alert alert-primary" role="alert">
[{oxmultilang ident=$d3dw_noitemmessageid}]
</div>
[{/if}]
</form>
<div id="mask" class=""></div>
<div id="popup2" class="d3loader-2">
<div class="d3loader-spinner">
<div class="d3loader-circle-1"></div>
<div class="d3loader-circle-2"></div>
<div class="d3loader-circle-3"></div>
</div>
</div>
[{include file="d3_cfg_mod_inc.tpl"}]

Datei anzeigen

@ -0,0 +1,8 @@
[{block name="submitElements"}]
<div class="btn-group">
<button type="button" class="btn btn-primary" onclick="startTask('[{$id}]')">
<i class="fas fa-fw fa-magic"></i>
[{oxmultilang ident=$item->getButtonText()}]
</button>
</div>
[{/block}]

Datei anzeigen

@ -0,0 +1,24 @@
[{block name="submitElements"}]
<div class="btn-group">
<button type="button" class="btn btn-primary" onclick="startTask('[{$id}]', 'CSV')">
<i class="fas fa-fw fa-magic"></i>
[{oxmultilang ident=$item->getButtonText()}]
</button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">
<i class="fas fa-fw fa-magic"></i>
[{oxmultilang ident=$item->getButtonText()}]
</span>
</button>
<div class="dropdown-menu">
[{block name="dataWizardFormat"}]
[{assign var="rendererBridge" value=$item->getRendererBridge()}]
[{foreach from=$rendererBridge->getTranslatedRendererIdList() key="key" item="translationId"}]
<button class="dropdown-item" onclick="startTask('[{$id}]', '[{$key}]')">
[{oxmultilang ident=$translationId}]
</button>
[{/foreach}]
[{/block}]
</div>
</div>
[{/block}]

Datei anzeigen

@ -1,15 +1,57 @@
# Changelog
## 2.0.0.0
#### Added
- add tests
- make installable in OXID 6.4
#### Changed
- adjust code to PHP 7.3 and up
---
## 1.4.0.0 (2021-11-11)
#### Added
- add JSON export renderer
- add tpl block for easier extension
- enable controller based exception handling
#### Changed
- change deprecated CSV export code
- show registered export renderers in admin submit without required tpl block extension
- force get translations from admin
---
## 1.3.1.0 (2021-09-10)
- installable in OXID 6.3.1
---
## 1.3.0.0 (2021-07-29)
- can handle long task description text
- has more generic admin controller templates
---
## 1.2.0.0 (2021-07-27)
- adjustments for CLI extension
- fix OXID 6.1 incompatibilities
---
## 1.1.0.0 (2021-06-25)
- implement form builder
- fix key figures export
---
## 1.0.0.0 (2021-06-22)
- initial implementation

Datei anzeigen

@ -1,4 +1,5 @@
> [deutsche Version](README.md)
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md)
[![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md)
# D³ Data Wizard for OXID eShop
@ -6,16 +7,18 @@ The module `DataWizard` offers a framework for the simple integration of exports
The exports are defined via database queries or ready-made data lists. Various export formats are available. The generation is possible at any time and always recurring (within the system limits). These are offered as downloads in the browser.
All exports are grouped together for better clarity.
All exports and tasks are grouped together for better clarity.
Sample exports are included in the scope of delivery. These are intended to serve as an implementation reference for individual exports. The display of the sample exports can be deactivated in the basic module settings.
Sample exports are included in the package d3/datawizardtasks. These are intended to serve as an implementation reference for individual exports.
![administration area](assets/administration_exports.jpg "administration area")
## Installation
In the console in the shop root (above source and vendor), execute the following command:
```bash
php composer require d3/datawizard
php composer require d3/datawizard:^2.0
```
Activate the module in the admin area of the shop in "Extensions -> Modules".
@ -24,38 +27,17 @@ Activate the module in the admin area of the shop in "Extensions -> Modules".
The module represents the technical basic framework of the exports and does not claim to be complete. In order to adapt the scope to individual requirements, the following extensions are prepared:
- Add exports
- Add exports or tasks
- Use existing and new groups
- Add export formats
Independently of this, all extension options are available that the OXID Shop provides for modules.
### Add exports
## Extension packages
#### Define export
Each export is defined in a separate class. This export class must extend the class `D3\DataWizard\Application\Model\ExportBase`. All necessary functions are predefined in it. The following methods are available:
##### mandatory method calls:
- getTitle() - defines the title in the admin area and the base of the later export file name.
- getQuery() - contains the query as a prepared statement that defines the data to be exported
##### optional method calls:
- getDescription() - contains a short additional description of the export, this will be shown in the admin area
- getButtonText() - defines the text of the submit button in the admin area
- getExportFilenameBase() - defines the base of the later export filename
- executeQuery() - returns the compiled export data
- further methods, the adaptation of which, however, can lead to changed module behaviour and should therefore only be changed with caution
#### Register exports
In order to be able to use the created export in the module, it must be registered. For this purpose there is the class `D3\DataWizard\Application\Model\Configuration`. This is to be overloaded with the possibilities of the OXID shop and the method `configure()` contained therein is to be supplemented. The following call is available for registering an export:
```
$this->registerExport(self::GROUP_CATEGORY, oxNew(myCustomExport::class));
```
The first parameter contains the language identifier for the export group. Typical identifiers are already prepared in constants of the configuration class. The instance of the export class is expected as the 2nd parameter.
- `d3/datawizardtasks` - provides sample exports and their implementation reference
- `d3/datawizardcli` - provides the execution of exports or tasks via the command prompt (e.g. as cronjobs)
- `d3/datawizardlink` - provides URLs to generate exports from third party systems
## Changelog

Datei anzeigen

@ -1,21 +1,24 @@
> [english version](README.en.md)
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md)
[![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md)
# D³ Data Wizard für OXID eShop
Das Modul `DataWizard` bietet ein Framework zur einfachen Integration von Exporten über den Adminbereich des OXID Shops.
Das Modul `DataWizard` bietet ein Framework zur einfachen Integration von Exporten und ausführbaren Tasks über den Adminbereich des OXID Shops.
Die Exporte werden über Datenbankabfragen oder fertige Datenlisten definiert. Es stehen verschiedene Exportformate zur Verfügung. Die Generierung ist jederzeit und immer wiederkehrend möglich (im Rahmen der Systemgrenzen). Diese werden im Browser als Download angeboten.
Alle Exporte sind für eine bessere Übersichtlichkeit in Gruppen zusammengefasst.
Alle Exporte bzw. Tasks sind für eine bessere Übersichtlichkeit in Gruppen zusammengefasst.
Im Lieferumfang sind Beispielexporte enthalten. Diese sollen als Implementierungsreferenz für individuelle Exporte dienen. Die Anzeige der Beispielexporte kann in den Modulgrundeinstellungen deaktiviert werden.
Im Paket d3/datawizardtasks sind Beispielexporte enthalten. Diese sollen als Implementierungsreferenz für individuelle Exporte dienen.
![Adminbereich](assets/administration_exports.jpg "Adminbereich")
## Schnellinstallation
Auf der Konsole im Shoproot (oberhalb von source und vendor) folgenden Befehl ausführen:
```bash
php composer require d3/datawizard
php composer require d3/datawizard:^2.0
```
Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module".
@ -24,38 +27,17 @@ Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module".
Das Modul stellt das technische Grundgerüst der Exporte dar und erhebt keinen Anspruch auf Vollständigkeit. Um den Umfang an die individuellen Anforderungen anzupassen, sind folgende Erweiterungen vorbereitet:
- Exporte hinzufügen
- Exporte oder Tasks hinzufügen
- Verwendung bestehender und neuer Gruppen
- Exportformate ergänzen
Unabhängig dessen stehen alle Erweiterungsmöglichkeiten zur Verfügung, die der OXID Shop für Module bereitstellt.
### Exporte hinzufügen
## Erweiterungspakete
#### Export definieren
Jeder Export wird in einer separaten Klasse definiert. Diese Exportklasse muss die Klasse `D3\DataWizard\Application\Model\ExportBase` erweitern. Darin sind alle nötigen Funktionen vordefiniert. Folgende Methoden stehen hierbei zur Verfügung:
##### verpflichtende Methodenaufrufe:
- getTitle() - definiert den Titel im Adminbereich und die Basis des späteren Exportdateinamens
- getQuery() - enthält den Abfragequery als prepared statement, der die zu exportierenden Daten definiert
##### optionale Methodenaufrufe:
- getDescription() - enthält eine kurze zusätzliche Beschreibung des Exports, dieser wird im Adminbereich gezeigt
- getButtonText() - definiert den Text des Absenden-Buttons im Adminbereich
- getExportFilenameBase() - definiert die Basis des späteren Exportdateinamens
- executeQuery() - liefert die zusammengestellten Exportdaten
- weitere Methoden, deren Anpassung jedoch zum geänderten Modulverhalten führen können und daher nur mit Vorsicht zu verändern sind
#### Exporte registrieren
Um den erstellten Export auch im Modul verwenden zu können, muss dieser noch registriert werden. Hierzu gibt des die Klasse `D3\DataWizard\Application\Model\Configuration`. Diese ist mit den Möglichkeiten des OXID Shops zu überladen und die darin enthaltene Methode `configure()` zu ergänzen. Für die Registrierung eines Exportes steht Ihnen dazu folgender Aufruf zur Verfügung:
```
$this->registerExport(self::GROUP_CATEGORY, oxNew(myCustomExport::class));
```
Der erste Parameter enthält den Sprachident für die Exportgruppe. In Konstanten der configuration-Klasse sind schon typische Idents vorbereitet. Als 2. Parameter wird die Instanz der Exportklasse erwartet.
- `d3/datawizardtasks` - liefert Beispielexporte und deren Implementierungsreferenz
- `d3/datawizardcli` - ermöglicht die Ausführung der Exporte oder Tasks über die Eingabeaufforderung (z.B. als Cronjobs)
- `d3/datawizardlink` - stellt URLs zur Verfügung, um Exporte von Drittsystemen generieren zu lassen
## Changelog

Binäre Datei nicht angezeigt.

Nachher

Breite:  |  Höhe:  |  Größe: 76 KiB

Datei anzeigen

@ -25,12 +25,15 @@
"GPL-3.0-or-later"
],
"require": {
"php": ">=7.1",
"oxid-esales/oxideshop-ce": "6.3 - 6.8",
"php": ">=7.3",
"oxid-esales/oxideshop-ce": "6.8 - 6.10",
"league/csv": "^9.0",
"mathieuviossat/arraytotexttable": "^1.0",
"form-manager/form-manager": "^5.1 || ^6.1"
},
"require-dev": {
"oxid-esales/oxideshop-ce": "6.8 - 6.9"
},
"extra": {
"oxideshop": {
"blacklist-filter": [
@ -40,6 +43,11 @@
"target-directory": "d3/datawizard"
}
},
"suggest": {
"d3/datawizardtasks": "useful example tasks for Data Wizard",
"d3/datawizardcli": "command line implementation for fully automated Data Wizard tasks",
"d3/datawizardlink": "remote http link for Data Wizard module exports"
},
"autoload": {
"psr-4": {
"D3\\DataWizard\\": "../../../source/modules/d3/datawizard"

Datei anzeigen

@ -32,7 +32,7 @@ $aModule = [
'en' => '',
],
'thumbnail' => '',
'version' => '1.2.0.0',
'version' => '2.0.0.0',
'author' => 'D&sup3; Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/',
@ -45,6 +45,9 @@ $aModule = [
'templates' => [
'd3ExportWizard.tpl' => 'd3/datawizard/Application/views/admin/tpl/d3ExportWizard.tpl',
'd3ActionWizard.tpl' => 'd3/datawizard/Application/views/admin/tpl/d3ActionWizard.tpl',
'd3Wizards.tpl' => 'd3/datawizard/Application/views/admin/tpl/inc/Wizards.tpl',
'd3ExportSubmit.tpl' => 'd3/datawizard/Application/views/admin/tpl/inc/exportSubmit.tpl',
'd3ActionSubmit.tpl' => 'd3/datawizard/Application/views/admin/tpl/inc/actionSubmit.tpl',
],
'settings' => [
[
@ -52,13 +55,7 @@ $aModule = [
'name' => $sModuleId.'_debug',
'type' => 'bool',
'value' => false
],
[
'group' => $sModuleId.'_general',
'name' => $sModuleId.'_hideexamples',
'type' => 'bool',
'value' => false
],
]
],
'blocks' => []
];

2
tests/.gitignore vendored Normale Datei
Datei anzeigen

@ -0,0 +1,2 @@
reports
.phpunit.result.cache

52
tests/README.md Normale Datei
Datei anzeigen

@ -0,0 +1,52 @@
# D3 Datawizard Tests
## Requirements
Both unit and acceptance tests require OXID Testing Library installed.
See https://github.com/OXID-eSales/testing_library.
### Configuration
Please install the packages listed in the composer.json in "require-dev". Unfortunately Composer does not provide an automatic installation.
Here is an example of Testing Library configuration file `oxideshop/test_config.yml`
```
# This file is auto-generated during the composer install
mandatory_parameters:
shop_path: /var/www/oxideshop/source
shop_tests_path: /var/www/oxideshop/tests
partial_module_paths: d3/datawizard
optional_parameters:
shop_url: null
shop_serial: ''
enable_varnish: false
is_subshop: false
install_shop: false
remote_server_dir: null
shop_setup_path: null
restore_shop_after_tests_suite: false
test_database_name: null
restore_after_acceptance_tests: false
restore_after_unit_tests: false
tmp_path: /tmp/oxid_test_library/
database_restoration_class: DatabaseRestorer
activate_all_modules: false
run_tests_for_shop: false
run_tests_for_modules: true
screen_shots_path: null
screen_shots_url: null
browser_name: firefox
selenium_server_ip: 127.0.0.1
selenium_server_port: '4444'
additional_test_paths: null
```
## Unit Tests
To execute unit tests run the following:
```
cd /var/www/oxideshop/
vendor/bin/runtests
```

39
tests/additional.inc.php Ausführbare Datei
Datei anzeigen

@ -0,0 +1,39 @@
<?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
*/
// Include datawizard test config
namespace D3\DataWizard\tests;
use D3\ModCfg\Tests\additional_abstract;
use Exception;
use OxidEsales\Eshop\Core\Exception\StandardException;
include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'd3datawizard_config.php');
class additional extends additional_abstract
{
/**
* additional constructor.
* @throws StandardException
*/
public function __construct()
{
if (D3DATAWIZARD_REQUIRE_MODCFG) {
$this->reactivateModCfg();
}
}
}
try {
d3GetModCfgDIC()->get(additional::class);
} catch (Exception $e) {}

15
tests/d3datawizard_config.php Ausführbare Datei
Datei anzeigen

@ -0,0 +1,15 @@
<?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
*/
const D3DATAWIZARD_REQUIRE_MODCFG = true;

27
tests/phpunit.xml Normale Datei
Datei anzeigen

@ -0,0 +1,27 @@
<phpunit backupGlobals="true"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
cacheTokens="true"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="false"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false">
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../Application</directory>
<directory suffix=".php">../Modules</directory>
<directory suffix=".php">../public</directory>
<directory suffix=".php">../Setup</directory>
</whitelist>
</filter>
<logging>
<log type="junit" target="reports/logfile.xml"/>
</logging>
</phpunit>

18
tests/tools/d3TestAction.php Normale Datei
Datei anzeigen

@ -0,0 +1,18 @@
<?php
namespace D3\DataWizard\tests\tools;
use D3\DataWizard\Application\Model\ActionBase;
class d3TestAction extends ActionBase
{
public function getTitle(): string
{
return 'TestTitle';
}
public function getQuery(): array
{
return ["UPDATE 1"];
}
}

18
tests/tools/d3TestExport.php Normale Datei
Datei anzeigen

@ -0,0 +1,18 @@
<?php
namespace D3\DataWizard\tests\tools;
use D3\DataWizard\Application\Model\ExportBase;
class d3TestExport extends ExportBase
{
public function getTitle(): string
{
return 'TestTitle';
}
public function getQuery(): array
{
return ["SELECT 1"];
}
}

Datei anzeigen

@ -0,0 +1,193 @@
<?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\DataWizard\tests\unit\Application\Controller\Admin;
use D3\DataWizard\Application\Controller\Admin\d3ActionWizard;
use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
use D3\DataWizard\tests\tools\d3TestAction;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Request;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class d3ActionWizardTest extends d3AdminControllerTest
{
/** @var d3ActionWizard */
protected $_oController;
protected $testClassName = d3ActionWizard::class;
public function setUp() : void
{
parent::setUp();
$this->_oController = oxNew($this->testClassName);
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getGroups()
* @test
* @throws ReflectionException
*/
public function canGetGroups()
{
$expected = ['expected' => 'array'];
/** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getActionGroups'])
->getMock();
$configurationMock->expects($this->atLeastOnce())->method('getActionGroups')->willReturn($expected);
$this->setValue($this->_oController, 'configuration', $configurationMock);
$this->assertSame(
$expected,
$this->callMethod(
$this->_oController,
'getGroups'
)
);
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getGroupTasks()
* @test
* @throws ReflectionException
* @dataProvider canGetGroupTasksDataProvider
*/
public function canGetGroupTasks($argument)
{
$expected = ['expected' => 'array'];
/** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getActionsByGroup'])
->getMock();
$configurationMock->expects($this->atLeastOnce())->method('getActionsByGroup')->with($argument)->willReturn($expected);
$this->setValue($this->_oController, 'configuration', $configurationMock);
$this->assertSame(
$expected,
$this->callMethod(
$this->_oController,
'getGroupTasks',
[$argument]
)
);
}
/**
* @return array
*/
public function canGetGroupTasksDataProvider(): array
{
return [
['test1'],
['test2']
];
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::execute()
* @test
* @throws ReflectionException
* @dataProvider executePassDataProvider
*/
public function executePass($blDebug)
{
/** @var Request|MockObject $requestMock */
$requestMock = $this->getMockBuilder(get_class(Registry::getRequest()))
->onlyMethods(['getRequestEscapedParameter'])
->getMock();
$requestMock->expects($this->any())->method('getRequestEscapedParameter')->willReturnCallback([$this, 'executePassRequestCallback']);
Registry::set(Request::class, $requestMock);
/** @var Config|MockObject $configMock */
$configMock = $this->getMockBuilder(Config::class)
->onlyMethods(['getConfigParam'])
->getMock();
$configMock->expects($this->atLeastOnce())->method('getConfigParam')->willReturnCallback(
function ($argName) use ($blDebug) {
switch ($argName) {
case 'd3datawizard_debug':
return $blDebug;
default:
return Registry::getConfig()->getConfigParam($argName);
}
}
);
/** @var d3ActionWizard|MockObject $controllerMock */
$controllerMock = $this->getMockBuilder(d3ActionWizard::class)
->onlyMethods(['d3GetConfig'])
->getMock();
$controllerMock->method('d3GetConfig')->willReturn($configMock);
$this->_oController = $controllerMock;
/** @var d3TestAction|MockObject $actionMock */
$actionMock = $this->getMockBuilder(d3TestAction::class)
->onlyMethods([
'getQuery',
'run'
])
->getMock();
$actionMock->expects($this->atLeastOnce())->method('getQuery')->willReturn(['SELECT 1', ['1']]);
$actionMock->expects($this->exactly((int) !$blDebug))->method('run')->willReturn(true);
/** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getActionById'])
->disableOriginalConstructor()
->getMock();
$configurationMock->expects($this->atLeastOnce())->method('getActionById')->with('testTaskId')->willReturn($actionMock);
$this->setValue($this->_oController, 'configuration', $configurationMock);
if ($blDebug) {
$this->expectException(DebugException::class);
}
$this->callMethod(
$this->_oController,
'execute'
);
}
public function executePassRequestCallback($varName)
{
switch ($varName) {
case 'taskid':
return 'testTaskId';
case 'format':
return RendererBridge::FORMAT_CSV;
default:
return oxNew(Request::class)->getRequestEscapedParameter($varName);
}
}
/**
* @return array
*/
public function executePassDataProvider(): array
{
return [
'no debug' => [false],
'debug' => [true],
];
}
}

Datei anzeigen

@ -0,0 +1,262 @@
<?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\DataWizard\tests\unit\Application\Controller\Admin;
use D3\DataWizard\Application\Controller\Admin\d3ActionWizard;
use D3\DataWizard\Application\Controller\Admin\d3ExportWizard;
use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\DataWizard\tests\tools\d3TestAction;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Request;
use OxidEsales\Eshop\Core\UtilsView;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use ReflectionException;
abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
{
/** @var d3ActionWizard|d3ExportWizard */
protected $_oController;
protected $testClassName;
public function tearDown() : void
{
parent::tearDown();
unset($this->_oController);
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::__construct
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::__construct
* @test
* @throws ReflectionException
*/
public function testConstructor()
{
$this->setValue($this->_oController, 'configuration', null);
$this->callMethod(
$this->_oController,
'__construct'
);
$this->assertInstanceOf(
Configuration::class,
$this->getValue(
$this->_oController,
'configuration'
)
);
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::runTask()
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::runTask()
* @test
* @throws ReflectionException
*/
public function runTaskPass()
{
/** @var d3ActionWizard|d3ExportWizard|MockObject $controllerMock */
$controllerMock = $this->getMockBuilder($this->testClassName)
->onlyMethods(['execute'])
->getMock();
$controllerMock->expects($this->once())->method('execute')->willReturn(true);
$this->_oController = $controllerMock;
$this->callMethod(
$this->_oController,
'runTask'
);
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::runTask()
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::runTask()
* @test
* @param $exceptionClass
* @throws ReflectionException
* @dataProvider runTaskFailedDataProvider
*/
public function runTaskFailed($exceptionClass)
{
/** @var DataWizardException|DBALException|DatabaseErrorException|MockObject $exceptionMock */
$exceptionMock = $this->getMockBuilder($exceptionClass)
->disableOriginalConstructor()
->getMock();
$this->setValue($exceptionMock, 'message', 'exc_msg');
/** @var d3ActionWizard|d3ExportWizard|MockObject $controllerMock */
$controllerMock = $this->getMockBuilder($this->testClassName)
->onlyMethods(['execute'])
->getMock();
$controllerMock->expects($this->once())->method('execute')->willThrowException($exceptionMock);
/** @var LoggerInterface|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(get_class(Registry::getLogger()))
->onlyMethods(['error'])
->disableOriginalConstructor()
->getMock();
$loggerMock->expects($this->atLeastOnce())->method('error')->with('exc_msg')->willReturn(true);
Registry::set('logger', $loggerMock);
/** @var UtilsView|MockObject $utilsViewMock */
$utilsViewMock = $this->getMockBuilder(get_class(Registry::getUtilsView()))
->onlyMethods(['addErrorToDisplay'])
->getMock();
$utilsViewMock->expects($this->atLeastOnce())->method('addErrorToDisplay')->with($exceptionMock)->willReturn(true);
Registry::set(UtilsView::class, $utilsViewMock);
$this->_oController = $controllerMock;
$this->callMethod(
$this->_oController,
'runTask'
);
}
/**
* @return \string[][]
*/
public function runTaskFailedDataProvider(): array
{
return [
[DataWizardException::class],
[DBALException::class],
[DatabaseErrorException::class],
];
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::execute()
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::execute()
* @test
* @throws ReflectionException
* @dataProvider executePassDataProvider
*/
public function executePass($blDebug)
{
/** @var Request|MockObject $requestMock */
$requestMock = $this->getMockBuilder(get_class(Registry::getRequest()))
->onlyMethods(['getRequestEscapedParameter'])
->getMock();
$requestMock->expects($this->atLeastOnce())->method('getRequestEscapedParameter')->with('taskid')->willReturn('testTaskId');
Registry::set(Request::class, $requestMock);
/** @var d3TestAction|MockObject $actionMock */
$actionMock = $this->getMockBuilder(d3TestAction::class)
->onlyMethods([
'getQuery',
'run'
])
->getMock();
$actionMock->expects($this->atLeastOnce())->method('getQuery')->willReturn(['SELECT 1', ['1']]);
$actionMock->expects($this->exactly((int) !$blDebug))->method('run')->willReturn(true);
/** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getActionById'])
->disableOriginalConstructor()
->getMock();
$configurationMock->expects($this->atLeastOnce())->method('getActionById')->with('testTaskId')->willReturn($actionMock);
$this->setValue($this->_oController, 'configuration', $configurationMock);
/** @var Config|MockObject $configMock */
$configMock = $this->getMockBuilder(Config::class)
->onlyMethods(['getConfigParam'])
->getMock();
$configMock->expects($this->atLeastOnce())->method('getConfigParam')->willReturn($blDebug);
Registry::set(Config::class, $configMock);
if ($blDebug) {
$this->expectException(DebugException::class);
}
$this->callMethod(
$this->_oController,
'execute'
);
}
/**
* @return array
*/
public function executePassDataProvider(): array
{
return [
'no debug' => [false],
'debug' => [true],
];
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getUserMessages()
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::getUserMessages()
* @test
* @throws ReflectionException
*/
public function canGetUserMessages()
{
$this->assertNull(
$this->callMethod(
$this->_oController,
'getUserMessages'
)
);
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getHelpURL()
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::getHelpURL()
* @test
* @throws ReflectionException
*/
public function canGetHelpUrl()
{
$this->assertNull(
$this->callMethod(
$this->_oController,
'getHelpURL'
)
);
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::d3GetConfig
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::d3GetConfig
* @test
* @throws ReflectionException
*/
public function canGetConfig()
{
$this->assertInstanceOf(
Config::class,
$this->callMethod(
$this->_oController,
'd3GetConfig'
)
);
}
}

Datei anzeigen

@ -0,0 +1,195 @@
<?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\DataWizard\tests\unit\Application\Controller\Admin;
use D3\DataWizard\Application\Controller\Admin\d3ExportWizard;
use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
use D3\DataWizard\tests\tools\d3TestAction;
use D3\DataWizard\tests\tools\d3TestExport;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Request;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class d3ExportWizardTest extends d3AdminControllerTest
{
/** @var d3ExportWizard */
protected $_oController;
protected $testClassName = d3ExportWizard::class;
public function setUp() : void
{
parent::setUp();
$this->_oController = oxNew($this->testClassName);
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::getGroups()
* @test
* @throws ReflectionException
*/
public function canGetGroups()
{
$expected = ['expected' => 'array'];
/** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getExportGroups'])
->getMock();
$configurationMock->expects($this->atLeastOnce())->method('getExportGroups')->willReturn($expected);
$this->setValue($this->_oController, 'configuration', $configurationMock);
$this->assertSame(
$expected,
$this->callMethod(
$this->_oController,
'getGroups'
)
);
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::getGroupTasks()
* @test
* @throws ReflectionException
* @dataProvider canGetGroupTasksDataProvider
*/
public function canGetGroupTasks($argument)
{
$expected = ['expected' => 'array'];
/** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getExportsByGroup'])
->getMock();
$configurationMock->expects($this->atLeastOnce())->method('getExportsByGroup')->with($argument)->willReturn($expected);
$this->setValue($this->_oController, 'configuration', $configurationMock);
$this->assertSame(
$expected,
$this->callMethod(
$this->_oController,
'getGroupTasks',
[$argument]
)
);
}
/**
* @return array
*/
public function canGetGroupTasksDataProvider(): array
{
return [
['test1'],
['test2']
];
}
/**
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::execute()
* @test
* @throws ReflectionException
* @dataProvider executePassDataProvider
*/
public function executePass($blDebug)
{
/** @var Request|MockObject $requestMock */
$requestMock = $this->getMockBuilder(get_class(Registry::getRequest()))
->onlyMethods(['getRequestEscapedParameter'])
->getMock();
$requestMock->expects($this->any())->method('getRequestEscapedParameter')->willReturnCallback([$this, 'executePassRequestCallback']);
//OnConsecutiveCalls('testTaskId', 'CSV');
Registry::set(Request::class, $requestMock);
/** @var Config|MockObject $configMock */
$configMock = $this->getMockBuilder(Config::class)
->onlyMethods(['getConfigParam'])
->getMock();
$configMock->expects($this->atLeastOnce())->method('getConfigParam')->willReturnCallback(
function ($argName) use ($blDebug) {
switch ($argName) {
case 'd3datawizard_debug':
return $blDebug;
default:
return Registry::getConfig()->getConfigParam($argName);
}
}
);
/** @var d3ExportWizard|MockObject $controllerMock */
$controllerMock = $this->getMockBuilder(d3ExportWizard::class)
->onlyMethods(['d3GetConfig'])
->getMock();
$controllerMock->method('d3GetConfig')->willReturn($configMock);
$this->_oController = $controllerMock;
/** @var d3TestAction|MockObject $exportMock */
$exportMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'getQuery',
'run'
])
->getMock();
$exportMock->expects($this->atLeastOnce())->method('getQuery')->willReturn(['SELECT 1', ['1']]);
$exportMock->expects($this->exactly((int) !$blDebug))->method('run')->willReturn('');
/** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getExportById'])
->disableOriginalConstructor()
->getMock();
$configurationMock->expects($this->atLeastOnce())->method('getExportById')->with('testTaskId')->willReturn($exportMock);
$this->setValue($this->_oController, 'configuration', $configurationMock);
if ($blDebug) {
$this->expectException(DebugException::class);
}
$this->callMethod(
$this->_oController,
'execute'
);
}
public function executePassRequestCallback($varName)
{
switch ($varName) {
case 'taskid':
return 'testTaskId';
case 'format':
return RendererBridge::FORMAT_CSV;
default:
return oxNew(Request::class)->getRequestEscapedParameter($varName);
}
}
/**
* @return array
*/
public function executePassDataProvider(): array
{
return [
'no debug' => [false],
'debug' => [true],
];
}
}

Datei anzeigen

@ -0,0 +1,316 @@
<?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\DataWizard\tests\unit\Application\Model;
use D3\DataWizard\Application\Model\Exceptions\TaskException;
use D3\DataWizard\tests\tools\d3TestAction;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use FormManager\Inputs\Hidden;
use FormManager\Inputs\Number;
use FormManager\Inputs\Radio;
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
use OxidEsales\Eshop\Core\Exception\StandardException;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class ActionBaseTest extends d3ModCfgUnitTestCase
{
/** @var d3TestAction */
protected $_oModel;
public function setUp() : void
{
parent::setUp();
$this->_oModel = oxNew(d3TestAction::class);
}
public function tearDown() : void
{
parent::tearDown();
unset($this->_oModel);
}
/**
* @covers \D3\DataWizard\Application\Model\ActionBase::getDescription
* @test
* @throws ReflectionException
*/
public function canGetDescription()
{
$this->assertIsString(
$this->callMethod(
$this->_oModel,
'getDescription'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ActionBase::getButtonText
* @test
* @throws ReflectionException
*/
public function canGetButtonText()
{
$this->assertIsString(
$this->callMethod(
$this->_oModel,
'getButtonText'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ActionBase::hasFormElements
* @test
* @throws ReflectionException
* @dataProvider canGetHasFormElementsDataProvider
*/
public function canGetHasFormElements($formElements, $expected)
{
$this->setValue($this->_oModel, 'formElements', $formElements);
$this->assertSame(
$expected,
$this->callMethod(
$this->_oModel,
'hasFormElements'
)
);
}
public function canGetHasFormElementsDataProvider(): array
{
return [
'hasFormElements' => [['abc', 'def'], true],
'hasNoFormElements' => [[], false],
];
}
/**
* @covers \D3\DataWizard\Application\Model\ActionBase::getFormElements
* @test
* @throws ReflectionException
* @dataProvider canGetHasFormElementsDataProvider
*/
public function canGetFormElements($formElements)
{
$this->setValue($this->_oModel, 'formElements', $formElements);
$this->assertSame(
$formElements,
$this->callMethod(
$this->_oModel,
'getFormElements'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ActionBase::registerFormElement
* @test
* @throws ReflectionException
* @dataProvider canRegisterFormElementDataProvider
*/
public function canRegisterFormElement($inputClass)
{
$oldCount = count($this->getValue($this->_oModel, 'formElements'));
/** @var Radio|MockObject $inputMock */
$inputMock = $this->getMockBuilder($inputClass)
->onlyMethods([
'setTemplate',
'setAttribute'
])
->getMock();
$inputMock->expects($this->atLeastOnce())->method('setTemplate');
$inputMock->expects($this->atLeastOnce())->method('setAttribute');
$this->callMethod(
$this->_oModel,
'registerFormElement',
[$inputMock]
);
$newCount = count($this->getValue($this->_oModel, 'formElements'));
$this->assertGreaterThan($oldCount, $newCount);
}
/**
* @return \string[][]
*/
public function canRegisterFormElementDataProvider(): array
{
return [
'Radio' => [Radio::class],
'Checkbox' => [Radio::class],
'Hidden' => [Hidden::class]
];
}
/**
* @covers \D3\DataWizard\Application\Model\ActionBase::run
* @test
* @throws ReflectionException
*/
public function canRunWithoutFormElements()
{
$modelMock = $this->getMockBuilder(d3TestAction::class)
->onlyMethods([
'hasFormElements',
'executeAction',
'getQuery'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('hasFormElements')->willReturn(false);
$modelMock->expects($this->atLeastOnce())->method('executeAction')->willReturn(1);
$modelMock->expects($this->atLeastOnce())->method('getQuery')->willReturn([]);
$this->_oModel = $modelMock;
$this->callMethod(
$this->_oModel,
'run'
);
}
/**
* @covers \D3\DataWizard\Application\Model\ActionBase::run
* @test
* @throws ReflectionException
* @dataProvider canRunWithFormElementsDataProvider
*/
public function canRunWithFormElements($elements, $blThrowException)
{
$expectedException = oxNew(StandardException::class);
$modelMock = $this->getMockBuilder(d3TestAction::class)
->onlyMethods([
'hasFormElements',
'executeAction',
'getQuery',
'getFormElements'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('hasFormElements')->willReturn(true);
$modelMock->expects($this->exactly((int) !$blThrowException))->method('executeAction')->willReturn(1);
$modelMock->expects($this->exactly((int) !$blThrowException))->method('getQuery')->willReturn([]);
$modelMock->expects($this->atLeastOnce())->method('getFormElements')->willReturn($elements);
$this->_oModel = $modelMock;
if ($blThrowException) {
$this->expectException(get_class($expectedException));
}
$this->callMethod(
$this->_oModel,
'run'
);
}
/**
* @return array[]
*/
public function canRunWithFormElementsDataProvider(): array
{
/** @var Radio|MockObject $validMock */
$validMock = $this->getMockBuilder(Radio::class)
->onlyMethods(['isValid'])
->getMock();
$validMock->expects($this->atLeastOnce())->method('isValid')->willReturn(true);
$invalidField = new Number(null, [
'required' => true,
'min' => 1,
'max' => 10,
'step' => 5,
]);
$invalidField
->setValue(20)
->setErrorMessages(['errorMsgs']);
return [
'validElements' => [[$validMock, $validMock], false],
'invalidElements' => [[$validMock, $invalidField], true]
];
}
/**
* @covers \D3\DataWizard\Application\Model\ActionBase::executeAction
* @test
* @throws ReflectionException
* @dataProvider canExecuteActionDataProvider
*/
public function canExecuteAction($query, $throwsException)
{
/** @var Database|MockObject $dbMock */
$dbMock = $this->getMockBuilder(Database::class)
->onlyMethods(['execute'])
->getMock();
$dbMock->expects($this->exactly((int) !$throwsException))->method('execute')->willReturn(true);
/** @var d3TestAction|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestAction::class)
->onlyMethods(['d3GetDb'])
->getMock();
$modelMock->expects($this->exactly((int) !$throwsException))->method('d3GetDb')->willReturn($dbMock);
$this->_oModel = $modelMock;
try {
$this->callMethod(
$this->_oModel,
'executeAction',
[[$query, ['parameters']]]
);
} catch (TaskException $e) {
if ($throwsException) {
$this->assertStringContainsString('ACTIONSELECT', $e->getMessage());
} else {
$this->assertStringContainsString('ACTIONRESULT', $e->getMessage());
}
}
}
/**
* @return array[]
*/
public function canExecuteActionDataProvider(): array
{
return [
'Select throws exception' => ['SELECT 1', true],
'Update dont throws exception' => ['UPDATE 1', false],
];
}
/**
* @covers \D3\DataWizard\Application\Model\ActionBase::d3GetDb
* @test
* @throws ReflectionException
*/
public function canGetDb()
{
$this->assertInstanceOf(
Database::class,
$this->callMethod(
$this->_oModel,
'd3GetDb'
)
);
}
}

Datei anzeigen

@ -0,0 +1,455 @@
<?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\DataWizard\tests\unit\Application\Model;
use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\tests\tools\d3TestAction;
use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class ConfigurationTest extends d3ModCfgUnitTestCase
{
/** @var Configuration */
protected $_oModel;
public function setUp() : void
{
parent::setUp();
$this->_oModel = oxNew(Configuration::class);
}
public function tearDown() : void
{
parent::tearDown();
unset($this->_oModel);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::__construct
* @test
* @throws ReflectionException
*/
public function canConstruct()
{
/** @var Configuration|MockObject $modelMock */
$modelMock = $this->getMockBuilder(Configuration::class)
->disableOriginalConstructor()
->onlyMethods(['configure'])
->getMock();
$modelMock->expects($this->once())->method('configure');
$this->_oModel = $modelMock;
$this->callMethod(
$this->_oModel,
'__construct'
);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::configure()
* @test
* @throws ReflectionException
*/
public function canConfigure()
{
$this->assertEmpty(
$this->callMethod(
$this->_oModel,
'configure'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::registerAction
* @test
* @throws ReflectionException
*/
public function canRegisterAction()
{
$action = oxNew(d3TestAction::class);
$oldCount = count($this->getValue(
$this->_oModel,
'actions'
));
$this->callMethod(
$this->_oModel,
'registerAction',
['testGroup', $action]
);
$actions = $this->getValue(
$this->_oModel,
'actions'
);
$newCount = count($actions);
$flattedActions = $this->array_flatten($actions);
$this->assertGreaterThan($oldCount, $newCount);
$this->assertContains($action, $flattedActions);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::registerExport
* @test
* @throws ReflectionException
*/
public function canRegisterExport()
{
$export = oxNew(d3TestExport::class);
$oldCount = count($this->getValue(
$this->_oModel,
'exports'
));
$this->callMethod(
$this->_oModel,
'registerExport',
['testGroup', $export]
);
$exports = $this->getValue(
$this->_oModel,
'exports'
);
$newCount = count($exports);
$flattedExports = $this->array_flatten($exports);
$this->assertGreaterThan($oldCount, $newCount);
$this->assertContains($export, $flattedExports);
}
/**
* @param $array
* @return array|false
*/
public function array_flatten($array) {
if (!is_array($array)) {
return false;
}
$result = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$result = array_merge($result, $this->array_flatten($value));
}
else {
$result[$key] = $value;
}
}
return $result;
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getGroupedActions()
* @test
* @throws ReflectionException
*/
public function canGetGroupedActions()
{
$actionList = ['abc', 'def'];
$this->setValue(
$this->_oModel,
'actions',
$actionList
);
$this->assertSame(
$actionList,
$this->callMethod(
$this->_oModel,
'getGroupedActions'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getGroupedExports()
* @test
* @throws ReflectionException
*/
public function canGetGroupedExports()
{
$exportList = ['abc', 'def'];
$this->setValue(
$this->_oModel,
'exports',
$exportList
);
$this->assertSame(
$exportList,
$this->callMethod(
$this->_oModel,
'getGroupedExports'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getActionGroups()
* @test
* @throws ReflectionException
*/
public function canGetActionGroups()
{
$actionList = ['abc' => '123', 'def' => '456'];
$this->setValue(
$this->_oModel,
'actions',
$actionList
);
$this->assertSame(
['abc', 'def'],
$this->callMethod(
$this->_oModel,
'getActionGroups'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getExportGroups()
* @test
* @throws ReflectionException
*/
public function canGetExportGroups()
{
$exportList = ['abc' => '123', 'def' => '456'];
$this->setValue(
$this->_oModel,
'exports',
$exportList
);
$this->assertSame(
['abc', 'def'],
$this->callMethod(
$this->_oModel,
'getExportGroups'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getActionsByGroup()
* @test
* @throws ReflectionException
*/
public function canGetActionsByGroup()
{
$actionList = ['abc' => '123', 'def' => '456'];
$this->setValue(
$this->_oModel,
'actions',
$actionList
);
$this->assertSame(
'456',
$this->callMethod(
$this->_oModel,
'getActionsByGroup',
['def']
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getExportsByGroup()
* @test
* @throws ReflectionException
*/
public function canGetExportsByGroup()
{
$exportList = ['abc' => '123', 'def' => '456'];
$this->setValue(
$this->_oModel,
'exports',
$exportList
);
$this->assertSame(
'456',
$this->callMethod(
$this->_oModel,
'getExportsByGroup',
['def']
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getAllActions()
* @test
* @throws ReflectionException
*/
public function canGetAllActions()
{
/** @var Configuration|MockObject $modelMock */
$modelMock = $this->getMockBuilder(Configuration::class)
->onlyMethods([
'getActionGroups',
'getActionsByGroup'
])
->getMock();
$modelMock->expects($this->once())->method('getActionGroups')->willReturn(['123', '456']);
$modelMock->expects($this->exactly(2))->method('getActionsByGroup')->willReturnOnConsecutiveCalls(
['123', '456'],
['789', '012']
);
$this->_oModel = $modelMock;
$this->assertSame(
['123','456', '789', '012'],
$this->callMethod(
$this->_oModel,
'getAllActions'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getAllExports()
* @test
* @throws ReflectionException
*/
public function canGetAllExports()
{
/** @var Configuration|MockObject $modelMock */
$modelMock = $this->getMockBuilder(Configuration::class)
->onlyMethods([
'getExportGroups',
'getExportsByGroup'
])
->getMock();
$modelMock->expects($this->once())->method('getExportGroups')->willReturn(['123', '456']);
$modelMock->expects($this->exactly(2))->method('getExportsByGroup')->willReturnOnConsecutiveCalls(
['123', '456'],
['789', '012']
);
$this->_oModel = $modelMock;
$this->assertSame(
['123', '456', '789', '012'],
$this->callMethod(
$this->_oModel,
'getAllExports'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getActionById()
* @test
* @throws ReflectionException
* @dataProvider canGetActionByIdDataProvider
*/
public function canGetActionById($id, $throwException)
{
$expected = oxNew(d3TestAction::class);
/** @var Configuration|MockObject $modelMock */
$modelMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getAllActions'])
->getMock();
$modelMock->expects($this->once())->method('getAllActions')->willReturn(['123' => oxNew(d3TestAction::class), '456' => $expected]);
$this->_oModel = $modelMock;
if ($throwException) {
$this->expectException(DataWizardException::class);
}
$return = $this->callMethod(
$this->_oModel,
'getActionById',
[$id]
);
if (!$throwException) {
$this->assertSame(
$expected,
$return
);
}
}
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getExportById()
* @test
* @throws ReflectionException
* @dataProvider canGetActionByIdDataProvider
*/
public function canGetExportById($id, $throwException)
{
$expected = oxNew(d3TestExport::class);
/** @var Configuration|MockObject $modelMock */
$modelMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getAllExports'])
->getMock();
$modelMock->expects($this->once())->method('getAllExports')->willReturn(['123' => oxNew(d3TestExport::class), '456' => $expected]);
$this->_oModel = $modelMock;
if ($throwException) {
$this->expectException(DataWizardException::class);
}
$return = $this->callMethod(
$this->_oModel,
'getExportById',
[$id]
);
if (!$throwException) {
$this->assertSame(
$expected,
$return
);
}
}
/**
* @return array[]
*/
public function canGetActionByIdDataProvider(): array
{
return [
'unset id' => ['987', true],
'set id' => ['456', false],
];
}
}

Datei anzeigen

@ -0,0 +1,78 @@
<?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\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class DebugExceptionTest extends d3ModCfgUnitTestCase
{
/** @var DebugException */
protected $_oModel;
/**
* @covers \D3\DataWizard\Application\Model\Exceptions\DebugException::__construct
* @test
* @throws ReflectionException
*/
public function canConstruct()
{
$code = '500';
$exception = oxNew( Exception::class);
/** @var DebugException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(DebugException::class)
->disableOriginalConstructor()
->getMock();
$this->_oModel = $modelMock;
$this->callMethod(
$this->_oModel,
'__construct',
['testMessage', $code, $exception]
);
$this->assertStringContainsString(
'DEBUG',
$this->callMethod(
$this->_oModel,
'getMessage'
)
);
$this->assertEquals(
$code,
$this->callMethod(
$this->_oModel,
'getCode'
)
);
$this->assertSame(
$exception,
$this->callMethod(
$this->_oModel,
'getPrevious'
)
);
}
}

Datei anzeigen

@ -0,0 +1,78 @@
<?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\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\ExportFileException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class ExportFileExceptionTest extends d3ModCfgUnitTestCase
{
/** @var ExportFileException */
protected $_oModel;
/**
* @covers \D3\DataWizard\Application\Model\Exceptions\ExportFileException::__construct
* @test
* @throws ReflectionException
*/
public function canConstruct()
{
$code = '500';
$exception = oxNew( Exception::class);
/** @var ExportFileException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(ExportFileException::class)
->disableOriginalConstructor()
->getMock();
$this->_oModel = $modelMock;
$this->callMethod(
$this->_oModel,
'__construct',
['testMessage', $code, $exception]
);
$this->assertStringContainsString(
'EXPORTFILEERROR',
$this->callMethod(
$this->_oModel,
'getMessage'
)
);
$this->assertEquals(
$code,
$this->callMethod(
$this->_oModel,
'getCode'
)
);
$this->assertSame(
$exception,
$this->callMethod(
$this->_oModel,
'getPrevious'
)
);
}
}

Datei anzeigen

@ -0,0 +1,97 @@
<?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\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
use D3\DataWizard\Application\Model\ExportBase;
use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use FormManager\Inputs\Number;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class InputUnvalidExceptionTest extends d3ModCfgUnitTestCase
{
/** @var InputUnvalidException */
protected $_oModel;
/**
* @covers \D3\DataWizard\Application\Model\Exceptions\InputUnvalidException::__construct
* @test
* @throws ReflectionException
*/
public function canConstruct()
{
$code = '500';
$exception = oxNew( Exception::class);
$invalidField = new Number(null, [
'required' => true,
'min' => 1,
'max' => 10,
'step' => 5,
]);
$invalidField
->setValue(20)
->setErrorMessages(['errorMsgs']);
/** @var ExportBase|MockObject $taskMock */
$taskMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods(['getTitle'])
->getMock();
$taskMock->expects($this->atLeastOnce())->method('getTitle')->willReturn('testTitle');
/** @var InputUnvalidException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(InputUnvalidException::class)
->disableOriginalConstructor()
->getMock();
$this->_oModel = $modelMock;
$this->callMethod(
$this->_oModel,
'__construct',
[$taskMock, $invalidField, $code, $exception]
);
$this->assertRegExp(
'/^testTitle\s-\s*->\s.*\sless\s/m',
$this->callMethod(
$this->_oModel,
'getMessage'
)
);
$this->assertEquals(
$code,
$this->callMethod(
$this->_oModel,
'getCode'
)
);
$this->assertSame(
$exception,
$this->callMethod(
$this->_oModel,
'getPrevious'
)
);
}
}

Datei anzeigen

@ -0,0 +1,78 @@
<?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\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class NoSuitableRendererExceptionTest extends d3ModCfgUnitTestCase
{
/** @var NoSuitableRendererException */
protected $_oModel;
/**
* @covers \D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException::__construct
* @test
* @throws ReflectionException
*/
public function canConstruct()
{
$code = '500';
$exception = oxNew( Exception::class);
/** @var NoSuitableRendererException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(NoSuitableRendererException::class)
->disableOriginalConstructor()
->getMock();
$this->_oModel = $modelMock;
$this->callMethod(
$this->_oModel,
'__construct',
['testMessage', $code, $exception]
);
$this->assertStringContainsString(
'NOSUITABLERENDERER',
$this->callMethod(
$this->_oModel,
'getMessage'
)
);
$this->assertEquals(
$code,
$this->callMethod(
$this->_oModel,
'getCode'
)
);
$this->assertSame(
$exception,
$this->callMethod(
$this->_oModel,
'getPrevious'
)
);
}
}

Datei anzeigen

@ -0,0 +1,86 @@
<?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\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\TaskException;
use D3\DataWizard\Application\Model\ExportBase;
use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class TaskExceptionTest extends d3ModCfgUnitTestCase
{
/** @var TaskException */
protected $_oModel;
/**
* @covers \D3\DataWizard\Application\Model\Exceptions\TaskException::__construct
* @test
* @throws ReflectionException
*/
public function canConstruct()
{
$code = '500';
$exception = oxNew( Exception::class);
/** @var ExportBase|MockObject $taskMock */
$taskMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods(['getTitle'])
->getMock();
$taskMock->expects($this->atLeastOnce())->method('getTitle')->willReturn('testTitle');
/** @var TaskException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(TaskException::class)
->disableOriginalConstructor()
->getMock();
$this->_oModel = $modelMock;
$this->callMethod(
$this->_oModel,
'__construct',
[$taskMock, 'testMessage', $code, $exception]
);
$this->assertSame(
'testTitle - testMessage',
$this->callMethod(
$this->_oModel,
'getMessage'
)
);
$this->assertEquals(
$code,
$this->callMethod(
$this->_oModel,
'getCode'
)
);
$this->assertSame(
$exception,
$this->callMethod(
$this->_oModel,
'getPrevious'
)
);
}
}

Datei anzeigen

@ -0,0 +1,607 @@
<?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\DataWizard\tests\unit\Application\Model;
use D3\DataWizard\Application\Model\Exceptions\ExportFileException;
use D3\DataWizard\Application\Model\Exceptions\TaskException;
use D3\DataWizard\Application\Model\ExportRenderer\Csv;
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Application\Model\d3filesystem;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use FormManager\Inputs\Hidden;
use FormManager\Inputs\Number;
use FormManager\Inputs\Radio;
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
use OxidEsales\Eshop\Core\Exception\StandardException;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class ExportBaseTest extends d3ModCfgUnitTestCase
{
/** @var d3TestExport */
protected $_oModel;
public function setUp() : void
{
parent::setUp();
$this->_oModel = oxNew(d3TestExport::class);
}
public function tearDown() : void
{
parent::tearDown();
unset($this->_oModel);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getDescription
* @test
* @throws ReflectionException
*/
public function canGetDescription()
{
$this->assertIsString(
$this->callMethod(
$this->_oModel,
'getDescription'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getButtonText
* @test
* @throws ReflectionException
*/
public function canGetButtonText()
{
$this->assertIsString(
$this->callMethod(
$this->_oModel,
'getButtonText'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::hasFormElements
* @test
* @throws ReflectionException
* @dataProvider canGetHasFormElementsDataProvider
*/
public function canGetHasFormElements($formElements, $expected)
{
$this->setValue($this->_oModel, 'formElements', $formElements);
$this->assertSame(
$expected,
$this->callMethod(
$this->_oModel,
'hasFormElements'
)
);
}
public function canGetHasFormElementsDataProvider(): array
{
return [
'hasFormElements' => [['abc', 'def'], true],
'hasNoFormElements' => [[], false],
];
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getFormElements
* @test
* @throws ReflectionException
* @dataProvider canGetHasFormElementsDataProvider
*/
public function canGetFormElements($formElements)
{
$this->setValue($this->_oModel, 'formElements', $formElements);
$this->assertSame(
$formElements,
$this->callMethod(
$this->_oModel,
'getFormElements'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::registerFormElement
* @test
* @throws ReflectionException
* @dataProvider canRegisterFormElementDataProvider
*/
public function canRegisterFormElement($inputClass)
{
$oldCount = count($this->getValue($this->_oModel, 'formElements'));
/** @var Radio|MockObject $inputMock */
$inputMock = $this->getMockBuilder($inputClass)
->onlyMethods([
'setTemplate',
'setAttribute'
])
->getMock();
$inputMock->expects($this->atLeastOnce())->method('setTemplate');
$inputMock->expects($this->atLeastOnce())->method('setAttribute');
$this->callMethod(
$this->_oModel,
'registerFormElement',
[$inputMock]
);
$newCount = count($this->getValue($this->_oModel, 'formElements'));
$this->assertGreaterThan($oldCount, $newCount);
}
/**
* @return \string[][]
*/
public function canRegisterFormElementDataProvider(): array
{
return [
'Radio' => [Radio::class],
'Checkbox' => [Radio::class],
'Hidden' => [Hidden::class]
];
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::run
* @test
* @throws ReflectionException
*/
public function canRunWithoutFormElements()
{
$format = 'myFormat';
$path = 'myPath';
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'hasFormElements',
'executeExport'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('hasFormElements')->willReturn(false);
$modelMock->expects($this->atLeastOnce())->method('executeExport')->with($format, $path)->willReturn('some content');
$this->_oModel = $modelMock;
$this->callMethod(
$this->_oModel,
'run',
[$format, $path]
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::run
* @test
* @throws ReflectionException
* @dataProvider canRunWithFormElementsDataProvider
*/
public function canRunWithFormElements($elements, $blThrowException)
{
$format = 'myFormat';
$path = 'myPath';
$expectedException = oxNew(StandardException::class);
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'hasFormElements',
'executeExport',
'getFormElements'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('hasFormElements')->willReturn(true);
$modelMock->expects($this->exactly((int) !$blThrowException))->method('executeExport')->with($format, $path)->willReturn('some content');
$modelMock->expects($this->atLeastOnce())->method('getFormElements')->willReturn($elements);
$this->_oModel = $modelMock;
if ($blThrowException) {
$this->expectException(get_class($expectedException));
}
$this->callMethod(
$this->_oModel,
'run',
[$format, $path]
);
}
/**
* @return array[]
*/
public function canRunWithFormElementsDataProvider(): array
{
/** @var Radio|MockObject $validMock */
$validMock = $this->getMockBuilder(Radio::class)
->onlyMethods(['isValid'])
->getMock();
$validMock->expects($this->atLeastOnce())->method('isValid')->willReturn(true);
$invalidField = new Number(null, [
'required' => true,
'min' => 1,
'max' => 10,
'step' => 5,
]);
$invalidField
->setValue(20)
->setErrorMessages(['errorMsgs']);
return [
'validElements' => [[$validMock, $validMock], false],
'invalidElements' => [[$validMock, $invalidField], true]
];
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::executeExport
* @test
* @throws ReflectionException
* @dataProvider canExecuteExportDataProvider
*/
public function canExecuteExport($path, $throwsException)
{
/** @var d3filesystem|MockObject $fsMock */
$fsMock = $this->getMockBuilder(d3filesystem::class)
->onlyMethods([
'startDirectDownload',
'filterFilename',
'trailingslashit',
'createFile'
])
->getMock();
$fsMock->expects($this->exactly((int) !isset($path)))->method('startDirectDownload')->willReturn(true);
$fsMock->method('filterFilename')->willReturnArgument(0);
$fsMock->expects($this->exactly((int) isset($path)))->method('trailingslashit')->willReturnArgument(0);
$fsMock->expects($this->exactly((int) isset($path)))->method('createFile')->willReturn((bool) !$throwsException);
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'getQuery',
'getExportData',
'renderContent',
'getFileSystem',
'getExportFileName'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('getQuery')->willReturn(['SELECT 1', ['arg1', 'arg2']]);
$modelMock->expects($this->atLeastOnce())->method('getExportData')->willReturn([[1, 2], ['field1', 'field2']]);
$modelMock->expects($this->atLeastOnce())->method('renderContent')->willReturn('some content');
$modelMock->expects($this->atLeastOnce())->method('getFileSystem')->willReturn($fsMock);
$modelMock->expects($this->atLeastOnce())->method('getExportFileName')->willReturn('exportFileName');
$this->_oModel = $modelMock;
if ($path && $throwsException) {
$this->expectException(ExportFileException::class);
}
$this->callMethod(
$this->_oModel,
'executeExport',
['CSV', $path]
);
}
/**
* @return array[]
*/
public function canExecuteExportDataProvider(): array
{
return [
'unable to create path for saving file' => ['myPath', true],
'can create path for saving file' => ['myPath', false],
'no path for download' => [null, false],
];
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::d3GetDb
* @test
* @throws ReflectionException
*/
public function canGetDb()
{
$this->assertInstanceOf(
Database::class,
$this->callMethod(
$this->_oModel,
'd3GetDb'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getFileSystem
* @test
* @throws ReflectionException
*/
public function canGetFileSystem()
{
$this->assertInstanceOf(
d3filesystem::class,
$this->callMethod(
$this->_oModel,
'getFileSystem'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getRenderer
* @test
* @throws ReflectionException
*/
public function canGetRenderer()
{
/** @var RendererInterface|MockObject $rendererMock */
$rendererMock = $this->getMockBuilder(Csv::class)
->getMock();
/** @var RendererBridge|MockObject $rendererBridgeMock */
$rendererBridgeMock = $this->getMockBuilder(RendererBridge::class)
->onlyMethods(['getRenderer'])
->getMock();
$rendererBridgeMock->expects($this->atLeastOnce())->method('getRenderer')->willReturn($rendererMock);
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'getRendererBridge'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('getRendererBridge')->willReturn($rendererBridgeMock);
$this->_oModel = $modelMock;
$this->assertSame(
$rendererMock,
$this->callMethod(
$this->_oModel,
'getRenderer',
[RendererBridge::FORMAT_CSV]
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getRendererBridge
* @test
* @throws ReflectionException
*/
public function canGetRendererBridge()
{
$this->assertInstanceOf(
RendererBridge::class,
$this->callMethod(
$this->_oModel,
'getRendererBridge'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getFileExtension
* @test
* @throws ReflectionException
*/
public function canGetFileExtension()
{
$format = RendererBridge::FORMAT_CSV;
$expected = 'myFileExtension';
/** @var RendererInterface|MockObject $rendererMock */
$rendererMock = $this->getMockBuilder(Csv::class)
->onlyMethods(['getFileExtension'])
->getMock();
$rendererMock->expects($this->atLeastOnce())->method('getFileExtension')->willReturn($expected);
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'getRenderer'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('getRenderer')->with($format)->willReturn($rendererMock);
$this->_oModel = $modelMock;
$this->assertSame(
$expected,
$this->callMethod(
$this->_oModel,
'getFileExtension',
[$format]
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::renderContent
* @test
* @throws ReflectionException
*/
public function canRenderContent()
{
$rows = ['row1', 'row2'];
$fieldnames = ['fieldname1', 'fieldname2'];
$format = RendererBridge::FORMAT_CSV;
$expected = 'myContent';
/** @var RendererInterface|MockObject $rendererMock */
$rendererMock = $this->getMockBuilder(Csv::class)
->onlyMethods(['getContent'])
->getMock();
$rendererMock->expects($this->atLeastOnce())->method('getContent')->with($rows, $fieldnames)->willReturn($expected);
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'getRenderer'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('getRenderer')->with($format)->willReturn($rendererMock);
$this->_oModel = $modelMock;
$this->assertSame(
$expected,
$this->callMethod(
$this->_oModel,
'renderContent',
[$rows, $fieldnames, $format]
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getExportFilenameBase
* @test
* @throws ReflectionException
*/
public function canGetExportFilenameBase()
{
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'getTitle'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('getTitle')->willReturn('someTitle');
$this->_oModel = $modelMock;
$this->callMethod(
$this->_oModel,
'getExportFilenameBase'
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getExportFileName
* @test
* @throws ReflectionException
*/
public function canGetExportFileName()
{
$format = RendererBridge::FORMAT_CSV;
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'getExportFilenameBase',
'getFileExtension'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('getExportFilenameBase')->willReturn('base');
$modelMock->expects($this->atLeastOnce())->method('getFileExtension')->with($format)->willReturn('extension');
$this->_oModel = $modelMock;
$this->assertRegExp(
'/^base_(\d{4})-(\d{2})-(\d{2})_(\d{2})-(\d{2})-(\d{2})\.extension$/m',
$this->callMethod(
$this->_oModel,
'getExportFileName',
[$format]
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getExportData
* @test
* @throws ReflectionException
* @dataProvider canGetExportDataDataProvider
*/
public function canGetExportData($query, $throwsException, $dbResult)
{
/** @var Database|MockObject $dbMock */
$dbMock = $this->getMockBuilder(Database::class)
->onlyMethods(['getAll'])
->getMock();
$dbMock->expects($this->exactly((int) !$throwsException))->method('getAll')->willReturn($dbResult);
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'd3GetDb'
])
->getMock();
$modelMock->expects($this->exactly((int) !$throwsException))->method('d3GetDb')->willReturn($dbMock);
$this->_oModel = $modelMock;
try {
$result = $this->callMethod(
$this->_oModel,
'getExportData',
[[$query], ['param1', 'param2']]
);
$this->assertSame(
[
[
[
'field1' => 'content1',
'field2' => 'content2'
]
],
[
'field1',
'field2'
]
],
$result
);
} catch (TaskException $e) {
if ($throwsException) {
$this->assertStringContainsString('NOEXPORTSELECT', $e->getMessage());
} elseif (!count($dbResult)) {
$this->assertStringContainsString('kein Inhalt', $e->getMessage());
}
}
}
/**
* @return array[]
*/
public function canGetExportDataDataProvider(): array
{
return [
'not SELECT throws exception' => [' UPDATE 1', true, []],
'empty SELECT' => [' SELECT 1', false, []],
'fulfilled SELECT' => [' SELECT 1', false, [['field1' => 'content1', 'field2' => 'content2']]],
];
}
}

Datei anzeigen

@ -0,0 +1,177 @@
<?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\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\Exceptions\RenderException;
use D3\DataWizard\Application\Model\ExportRenderer\Csv;
use League\Csv\Exception;
use League\Csv\Writer;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class CsvTest extends ExportRendererTest
{
/** @var Csv */
protected $_oModel;
public function setUp() : void
{
parent::setUp();
$this->_oModel = oxNew(Csv::class);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getContent
* @test
* @throws ReflectionException
* @dataProvider canGetContentDataProvider
*/
public function canGetContent($blThrowException)
{
$expected = 'expectedReturn';
$fieldList = ['field1', 'field2'];
$valueList = ['value1', 'value2'];
/** @var Writer|MockObject $csvMock */
$csvMockBuilder = $this->getMockBuilder( Writer::class);
$csvMockBuilder->disableOriginalConstructor();
$onlyMethods = ['__toString', 'insertOne', 'insertAll'];
$csvMockBuilder->onlyMethods($onlyMethods);
$csvMock = $csvMockBuilder->getMock();
$csvMock->method('insertOne')->willReturn(1);
$csvMock->method('insertAll')->willReturn(1);
if ($blThrowException) {
$csvMock->expects($this->atLeastOnce())->method('__toString')->willThrowException(oxNew(Exception::class));
$this->expectException(RenderException::class);
} else {
$csvMock->expects($this->atLeastOnce())->method('__toString')->willReturn($expected);
}
/** @var Csv|MockObject $modelMock */
$modelMock = $this->getMockBuilder(Csv::class)
->onlyMethods(['getCsv'])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('getCsv')->willReturn($csvMock);
$this->_oModel = $modelMock;
$this->assertSame(
$expected,
$this->callMethod(
$this->_oModel,
'getContent',
[$valueList, $fieldList]
)
);
}
/**
* @return array
*/
public function canGetContentDataProvider(): array
{
return [
'exception' => [true],
'no exception' => [false]
];
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getCsv
* @test
* @throws ReflectionException
*/
public function canGetCsv()
{
$this->assertInstanceOf(
Writer::class,
$this->callMethod(
$this->_oModel,
'getCsv'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getCsv
* @test
* @throws ReflectionException
*/
public function canGetCsvNoSettings()
{
/** @var Config|MockObject $configMock */
$configMock = $this->getMockBuilder(Config::class)
->onlyMethods(['getConfigParam'])
->getMock();
$configMock->expects($this->atLeastOnce())->method('getConfigParam')->willReturnCallback(
function ($argName) {
switch ($argName) {
case 'sGiCsvFieldEncloser':
case 'sCSVSign':
return false;
default:
return Registry::getConfig()->getConfigParam($argName);
}
}
);
$modelMock = $this->getMockBuilder(Csv::class)
->onlyMethods(['d3GetConfig'])
->getMock();
$modelMock->method('d3GetConfig')->willReturn($configMock);
$this->_oModel = $modelMock;
$csv = $this->callMethod(
$this->_oModel,
'getCsv'
);
$this->assertInstanceOf(
Writer::class,
$csv
);
$this->assertSame(
'"',
$csv->getEnclosure()
);
$this->assertSame(
';',
$csv->getDelimiter()
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::d3GetConfig
* @test
* @throws ReflectionException
*/
public function canGetConfig()
{
$this->assertInstanceOf(
Config::class,
$this->callMethod(
$this->_oModel,
'd3GetConfig'
)
);
}
}

Datei anzeigen

@ -0,0 +1,66 @@
<?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
*/
namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use ReflectionException;
abstract class ExportRendererTest extends d3ModCfgUnitTestCase
{
/** @var RendererInterface */
protected $_oModel;
public function tearDown() : void
{
parent::tearDown();
unset($this->_oModel);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getFileExtension
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getFileExtension
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getFileExtension
* @test
* @throws ReflectionException
*/
public function canGetFileExtension()
{
$this->assertRegExp(
"/^[a-z0-9._-]*$/i",
$this->callMethod(
$this->_oModel,
'getFileExtension'
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getTitleTranslationId
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getTitleTranslationId
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getTitleTranslationId
* @test
* @throws ReflectionException
*/
public function canGetTitleTranslationId()
{
$this->assertIsString(
$this->callMethod(
$this->_oModel,
'getTitleTranslationId'
)
);
}
}

Datei anzeigen

@ -0,0 +1,67 @@
<?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\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\Exceptions\RenderException;
use D3\DataWizard\Application\Model\ExportRenderer\Json;
use ReflectionException;
class JsonTest extends ExportRendererTest
{
/** @var Json */
protected $_oModel;
public function setUp() : void
{
parent::setUp();
$this->_oModel = oxNew(Json::class);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getContent
* @test
* @throws ReflectionException
* @dataProvider canGetContentDataProvider
*/
public function canGetContent($valueList, $expectException)
{
$fieldList = ['field1', 'field2'];
if ($expectException) {
$this->expectException(RenderException::class);
}
$this->assertJson(
$this->callMethod(
$this->_oModel,
'getContent',
[$valueList, $fieldList]
)
);
}
/**
* @return \string[][]
*/
public function canGetContentDataProvider(): array
{
return [
'valid' => [['value1', 'value2'], false],
'invalid' => [["text" => "\xB1\x31"], true] // malformed UTF8 chars
];
}
}

Datei anzeigen

@ -0,0 +1,86 @@
<?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\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\ExportRenderer\Pretty;
use MathieuViossat\Util\ArrayToTextTable;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class PrettyTest extends ExportRendererTest
{
/** @var Pretty */
protected $_oModel;
public function setUp() : void
{
parent::setUp();
$this->_oModel = oxNew(Pretty::class);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getContent
* @test
* @throws ReflectionException
*/
public function canGetContent()
{
$expected = 'expectedReturn';
$fieldList = ['field1', 'field2'];
$valueList = ['value1', 'value2'];
/** @var ArrayToTextTable|MockObject $csvMock */
$arrayToTextTableMock = $this->getMockBuilder(ArrayToTextTable::class)
->disableOriginalConstructor()
->onlyMethods(['getTable'])
->getMock();
$arrayToTextTableMock->expects($this->atLeastOnce())->method('getTable')->willReturn($expected);
/** @var Pretty|MockObject $modelMock */
$modelMock = $this->getMockBuilder(Pretty::class)
->onlyMethods(['getArrayToTextTableInstance'])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('getArrayToTextTableInstance')->willReturn($arrayToTextTableMock);
$this->_oModel = $modelMock;
$this->assertSame(
$expected,
$this->callMethod(
$this->_oModel,
'getContent',
[$valueList, $fieldList]
)
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getArrayToTextTableInstance
* @test
* @throws ReflectionException
*/
public function canGetArrayToTextTableInstance()
{
$this->assertInstanceOf(
ArrayToTextTable::class,
$this->callMethod(
$this->_oModel,
'getArrayToTextTableInstance',
[['field1', 'field2']]
)
);
}
}

Datei anzeigen

@ -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\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException;
use D3\DataWizard\Application\Model\ExportRenderer\Csv;
use D3\DataWizard\Application\Model\ExportRenderer\Json;
use D3\DataWizard\Application\Model\ExportRenderer\Pretty;
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class RendererBridgeTest extends d3ModCfgUnitTestCase
{
/** @var RendererBridge */
protected $_oModel;
public function setUp() : void
{
parent::setUp();
$this->_oModel = oxNew(RendererBridge::class);
}
public function tearDown(): void
{
parent::tearDown();
unset($this->_oModel);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getRendererList
* @test
* @throws ReflectionException
*/
public function canGetRendererList()
{
$list = $this->callMethod(
$this->_oModel,
'getRendererList'
);
$this->assertIsArray($list);
$this->assertTrue((bool) count($list));
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getTranslatedRendererIdList
* @test
* @throws ReflectionException
*/
public function canGetTranslatedRendererIdList()
{
$utlist = $this->callMethod(
$this->_oModel,
'getRendererList'
);
$list = $this->callMethod(
$this->_oModel,
'getTranslatedRendererIdList'
);
$this->assertIsArray($list);
$this->assertTrue((bool) count($list));
$this->assertSame(count($utlist), count($list));
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::translateRendererId
* @test
* @throws ReflectionException
*/
public function canTranslateRendererId()
{
$expected = "expectedTranslation";
/** @var RendererInterface|MockObject $renderMock */
$renderMock = $this->getMockBuilder(Pretty::class)
->onlyMethods(['getTitleTranslationId'])
->getMock();
$renderMock->expects($this->atLeastOnce())->method('getTitleTranslationId')->willReturn($expected);
$this->callMethod(
$this->_oModel,
'translateRendererId',
[$renderMock]
);
}
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getRenderer
* @test
* @param $format
* @param $blThrowException
* @throws ReflectionException
* @dataProvider canGetRendererDataProvider
*/
public function canGetRenderer($format, $blThrowException)
{
/** @var RendererBridge|MockObject $modelMock */
$modelMock = $this->getMockBuilder(RendererBridge::class)
->onlyMethods(['getRendererList'])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('getRendererList')->willReturn(
[
'CSV' => $this->getMockBuilder(Csv::class)->getMock(),
'Pretty' => $this->getMockBuilder(Pretty::class)->getMock(),
'JSON' => $this->getMockBuilder(Json::class)->getMock()
]
);
$this->_oModel = $modelMock;
if ($blThrowException) {
$this->expectException(NoSuitableRendererException::class);
}
$this->callMethod(
$this->_oModel,
'getRenderer',
[$format]
);
}
/**
* @return array
*/
public function canGetRendererDataProvider(): array
{
return [
'existing renderer'=> [RendererBridge::FORMAT_JSON, false],
'unknown renderer'=> ['unknownRenderer', true]
];
}
}