Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
744efd5d59
|
|||
675b18aaa8
|
|||
a0788ba666
|
|||
3aa64f8f63
|
|||
b1946c4aae
|
|||
61827e7825
|
|||
5fda1baecb
|
|||
f5d35021f5
|
|||
e134a4c14a
|
|||
b5d6936074
|
|||
ac7ae90310
|
|||
067326e704
|
|||
ae09cf88a5
|
|||
3b47f4da05
|
|||
903d178124
|
|||
bd90f18a87
|
|||
74edceafc8
|
|||
ea77239510
|
|||
e1502b274e
|
|||
500f226399
|
|||
1023bd2fa6
|
|||
dd7b8ed1e6
|
|||
a1cd84b415
|
|||
af10e80086
|
|||
148f4f8213
|
|||
f2935209ed
|
|||
a7e6c91042
|
|||
9e9a0fdd4c
|
|||
eef594d970
|
|||
759e8a377d
|
|||
f42c42cbe4
|
|||
baf30ef196
|
|||
8b354993ca
|
|||
4c91b0d699
|
|||
34b2b0b061
|
|||
9e9bab88f0
|
|||
466e751a5c
|
|||
5367dfdb5a
|
@ -23,6 +23,7 @@ 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;
|
||||
@ -47,7 +48,7 @@ class d3ActionWizard extends AdminDetailsController
|
||||
return $this->configuration->getActionGroups();
|
||||
}
|
||||
|
||||
public function getGroupActions($group)
|
||||
public function getGroupTasks($group)
|
||||
{
|
||||
return $this->configuration->getActionsByGroup($group);
|
||||
}
|
||||
@ -58,27 +59,45 @@ class d3ActionWizard extends AdminDetailsController
|
||||
* @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()
|
||||
{
|
||||
return Registry::getConfig();
|
||||
}
|
||||
|
||||
public function getUserMessages()
|
||||
{
|
||||
return null;
|
@ -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;
|
||||
@ -47,7 +50,7 @@ class d3ExportWizard extends AdminDetailsController
|
||||
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()
|
||||
{
|
||||
return Registry::getConfig();
|
||||
}
|
||||
|
||||
public function getUserMessages()
|
||||
{
|
||||
return null;
|
@ -15,6 +15,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\Application\Model;
|
||||
|
||||
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;
|
||||
@ -22,7 +27,10 @@ use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
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
|
||||
@ -36,6 +44,15 @@ abstract class ActionBase implements QueryBase
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if ($this->hasFormElements()) {
|
||||
/** @var Input $element */
|
||||
foreach ($this->getFormElements() as $element) {
|
||||
if (false === $element->isValid()) {
|
||||
throw oxNew(InputUnvalidException::class, $this, $element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->executeAction( $this->getQuery() );
|
||||
}
|
||||
|
||||
@ -60,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,
|
||||
@ -74,6 +91,15 @@ abstract class ActionBase implements QueryBase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DatabaseInterface|null
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
public function d3GetDb()
|
||||
{
|
||||
return DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@ -81,4 +107,35 @@ abstract class ActionBase implements QueryBase
|
||||
{
|
||||
return "D3_DATAWIZARD_ACTION_SUBMIT";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Input $input
|
||||
*/
|
||||
public function registerFormElement(Input $input)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasFormElements(): bool
|
||||
{
|
||||
return (bool) count($this->formElements);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFormElements(): array
|
||||
{
|
||||
return $this->formElements;
|
||||
}
|
||||
}
|
@ -16,6 +16,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;
|
||||
@ -28,6 +29,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 = [];
|
||||
@ -39,12 +41,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
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +50,7 @@ class Configuration
|
||||
*/
|
||||
public function registerAction($group, ActionBase $action)
|
||||
{
|
||||
$this->actions[$group][md5(serialize($action))] = $action;
|
||||
$this->actions[$group][md5(get_class($action))] = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,7 +59,7 @@ class Configuration
|
||||
*/
|
||||
public function registerExport($group, ExportBase $export)
|
||||
{
|
||||
$this->exports[$group][md5(serialize($export))] = $export;
|
||||
$this->exports[$group][md5(get_class($export))] = $export;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,7 +149,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];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,6 +165,12 @@ class Configuration
|
||||
*/
|
||||
public function getExportById($id) : ExportBase
|
||||
{
|
||||
return $this->getAllExports()[$id];
|
||||
$allExports = $this->getAllExports();
|
||||
|
||||
if (false == $allExports[$id]) {
|
||||
throw oxNew(DataWizardException::class, 'no export with id '.$id);
|
||||
}
|
||||
|
||||
return $allExports[$id];
|
||||
}
|
||||
}
|
@ -17,6 +17,6 @@ namespace D3\DataWizard\Application\Model\Exceptions;
|
||||
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
|
||||
class RenderException extends StandardException implements DataWizardException
|
||||
class DataWizardException extends StandardException
|
||||
{
|
||||
}
|
@ -16,10 +16,9 @@ declare(strict_types=1);
|
||||
namespace D3\DataWizard\Application\Model\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class DebugException extends StandardException implements DataWizardException
|
||||
class DebugException extends DataWizardException
|
||||
{
|
||||
public function __construct($sMessage = "not set", $iCode = 0, Exception $previous = null )
|
||||
{
|
32
Application/Model/Exceptions/ExportFileException.php
Normal file
32
Application/Model/Exceptions/ExportFileException.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?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\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class ExportFileException extends DataWizardException
|
||||
{
|
||||
public function __construct($sMessage = "not set", $iCode = 0, Exception $previous = null )
|
||||
{
|
||||
$sMessage = sprintf(
|
||||
Registry::getLang()->translateString('D3_DATAWIZARD_ERR_EXPORTFILEERROR'),
|
||||
$sMessage
|
||||
);
|
||||
|
||||
parent::__construct($sMessage, $iCode, $previous );
|
||||
}
|
||||
}
|
53
Application/Model/Exceptions/InputUnvalidException.php
Normal file
53
Application/Model/Exceptions/InputUnvalidException.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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\Exceptions;
|
||||
|
||||
use D3\DataWizard\Application\Model\QueryBase;
|
||||
use Exception;
|
||||
use FormManager\Inputs\Input;
|
||||
|
||||
class InputUnvalidException extends DataWizardException
|
||||
{
|
||||
/** @var QueryBase */
|
||||
public $task;
|
||||
|
||||
/**
|
||||
* InputUnvalidException constructor.
|
||||
* @param QueryBase $task
|
||||
* @param Input $inputElement
|
||||
* @param int $iCode
|
||||
* @param Exception|null $previous
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct( QueryBase $task, Input $inputElement, $iCode = 0, Exception $previous = null )
|
||||
{
|
||||
$messages = [];
|
||||
foreach ($inputElement->getError()->getIterator() as $item) {
|
||||
$messages[] = $inputElement->label->innerHTML.' -> '.$item->getMessage();
|
||||
}
|
||||
|
||||
$sMessage = implode(
|
||||
' - ',
|
||||
[
|
||||
$task->getTitle(),
|
||||
implode(', ', $messages)
|
||||
]
|
||||
);
|
||||
parent::__construct( $sMessage, $iCode, $previous );
|
||||
|
||||
$this->task = $task;
|
||||
}
|
||||
}
|
@ -16,10 +16,9 @@ declare(strict_types=1);
|
||||
namespace D3\DataWizard\Application\Model\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class NoSuitableRendererException extends StandardException implements DataWizardException
|
||||
class NoSuitableRendererException extends DataWizardException
|
||||
{
|
||||
public function __construct($sMessage = "not set", $iCode = 0, Exception $previous = null )
|
||||
{
|
@ -15,6 +15,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\Application\Model\Exceptions;
|
||||
|
||||
interface DataWizardException
|
||||
class RenderException extends DataWizardException
|
||||
{
|
||||
}
|
@ -17,9 +17,8 @@ namespace D3\DataWizard\Application\Model\Exceptions;
|
||||
|
||||
use D3\DataWizard\Application\Model\QueryBase;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
|
||||
class TaskException extends StandardException implements DataWizardException
|
||||
class TaskException extends DataWizardException
|
||||
{
|
||||
/** @var QueryBase */
|
||||
public $task;
|
@ -15,11 +15,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\Application\Model;
|
||||
|
||||
use D3\DataWizard\Application\Model\Exceptions\ExportFileException;
|
||||
use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
|
||||
use D3\ModCfg\Application\Model\d3filesystem;
|
||||
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
|
||||
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use FormManager\Inputs\Checkbox;
|
||||
use FormManager\Inputs\Input;
|
||||
use FormManager\Inputs\Radio;
|
||||
use OxidEsales\Eshop\Core\DatabaseProvider;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
||||
@ -28,7 +33,10 @@ use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
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
|
||||
@ -38,6 +46,7 @@ abstract class ExportBase implements QueryBase
|
||||
|
||||
/**
|
||||
* @param string $format
|
||||
* @param $path
|
||||
*
|
||||
* @throws DBALException
|
||||
* @throws DatabaseConnectionException
|
||||
@ -47,19 +56,20 @@ abstract class ExportBase implements QueryBase
|
||||
* @throws StandardException
|
||||
* @throws d3ShopCompatibilityAdapterException
|
||||
* @throws d3_cfg_mod_exception
|
||||
* @return string
|
||||
*/
|
||||
public function run($format = RendererBridge::FORMAT_CSV)
|
||||
public function run( string $format = RendererBridge::FORMAT_CSV, $path = null): string
|
||||
{
|
||||
[ $rows, $fieldNames ] = $this->getExportData( $this->getQuery() );
|
||||
if ($this->hasFormElements()) {
|
||||
/** @var Input $element */
|
||||
foreach ($this->getFormElements() as $element) {
|
||||
if (false === $element->isValid()) {
|
||||
throw oxNew(InputUnvalidException::class, $this, $element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$content = $this->renderContent($rows, $fieldNames, $format);
|
||||
|
||||
/** @var $oFS d3filesystem */
|
||||
$oFS = oxNew(d3filesystem::class);
|
||||
$oFS->startDirectDownload(
|
||||
$oFS->filterFilename($this->getExportFileName($format)),
|
||||
$content
|
||||
);
|
||||
return $this->executeExport($format, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,7 +88,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()
|
||||
{
|
||||
return oxNew(RendererBridge::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,13 +164,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 )
|
||||
);
|
||||
}
|
||||
|
||||
@ -160,4 +178,85 @@ abstract class ExportBase implements QueryBase
|
||||
|
||||
return [ $rows, $fieldNames ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Input $input
|
||||
*/
|
||||
public function registerFormElement(Input $input)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasFormElements(): bool
|
||||
{
|
||||
return (bool) count($this->formElements);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFormElements(): array
|
||||
{
|
||||
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 \OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface|null
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
protected function d3GetDb(): ?\OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface
|
||||
{
|
||||
return DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3filesystem|mixed
|
||||
*/
|
||||
protected function getFileSystem()
|
||||
{
|
||||
return oxNew(d3filesystem::class);
|
||||
}
|
||||
}
|
@ -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 method_exists($csv, 'getContent') ? $csv->getContent() : (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()
|
||||
{
|
||||
return Registry::getConfig();
|
||||
}
|
||||
}
|
51
Application/Model/ExportRenderer/Json.php
Normal file
51
Application/Model/ExportRenderer/Json.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?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;
|
||||
|
||||
class Json implements RendererInterface
|
||||
{
|
||||
/**
|
||||
* @param $rows
|
||||
* @param $fieldNames
|
||||
*
|
||||
* @return string
|
||||
* @throws RenderException
|
||||
*/
|
||||
public function getContent($rows, $fieldNames): string
|
||||
{
|
||||
$flags = JSON_PRETTY_PRINT;
|
||||
$json = json_encode( $rows, $flags );
|
||||
if ( $json === false ) {
|
||||
throw oxNew( RenderException::class, json_last_error_msg(), json_last_error());
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
public function getFileExtension(): string
|
||||
{
|
||||
return 'json';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitleTranslationId(): string
|
||||
{
|
||||
return "D3_DATAWIZARD_EXPORT_FORMAT_JSON";
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
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";
|
||||
}
|
||||
}
|
74
Application/Model/ExportRenderer/RendererBridge.php
Normal file
74
Application/Model/ExportRenderer/RendererBridge.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?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\NoSuitableRendererException;
|
||||
|
||||
class RendererBridge
|
||||
{
|
||||
const FORMAT_CSV = 'CSV';
|
||||
const FORMAT_PRETTY = 'Pretty';
|
||||
const FORMAT_JSON = 'JSON';
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRendererList(): array
|
||||
{
|
||||
return [
|
||||
self::FORMAT_CSV => oxNew(Csv::class),
|
||||
self::FORMAT_PRETTY => oxNew(Pretty::class),
|
||||
self::FORMAT_JSON => oxNew(Json::class)
|
||||
];
|
||||
}
|
||||
|
||||
public function getTranslatedRendererIdList()
|
||||
{
|
||||
$rendererList = $this->getRendererList();
|
||||
array_walk($rendererList, [$this, 'translateRendererId']);
|
||||
return $rendererList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RendererInterface $instance
|
||||
*/
|
||||
protected function translateRendererId(RendererInterface &$instance)
|
||||
{
|
||||
$instance = $instance->getTitleTranslationId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $format
|
||||
*
|
||||
* @return RendererInterface
|
||||
* @throws NoSuitableRendererException
|
||||
*/
|
||||
public function getRenderer(string $format = self::FORMAT_CSV): RendererInterface
|
||||
{
|
||||
$format = strtolower($format);
|
||||
|
||||
$rendererList = array_change_key_case($this->getRendererList(), CASE_LOWER);
|
||||
$rendererListTypes = array_keys(array_change_key_case($rendererList, CASE_LOWER));
|
||||
|
||||
if (in_array($format, $rendererListTypes, true)) {
|
||||
return $rendererList[$format];
|
||||
}
|
||||
|
||||
/** @var NoSuitableRendererException $e */
|
||||
$e = oxNew(NoSuitableRendererException::class, $format);
|
||||
throw $e;
|
||||
}
|
||||
}
|
@ -29,4 +29,9 @@ interface RendererInterface
|
||||
* @return string
|
||||
*/
|
||||
public function getFileExtension() : string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitleTranslationId() : string;
|
||||
}
|
@ -15,16 +15,20 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\Application\Model;
|
||||
|
||||
use FormManager\Inputs\Input;
|
||||
|
||||
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;
|
||||
@ -38,4 +42,19 @@ interface QueryBase
|
||||
* @return array [string $query, array $parameters]
|
||||
*/
|
||||
public function getQuery() : array;
|
||||
|
||||
/**
|
||||
* @param Input $input
|
||||
*/
|
||||
public function registerFormElement(Input $input);
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasFormElements(): bool;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFormElements(): array;
|
||||
}
|
@ -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',
|
||||
|
||||
@ -48,20 +49,10 @@ $aLang = array(
|
||||
'D3_DATAWIZARD_ERR_NOEXPORT_INSTALLED' => 'Es sind keine Exporte installiert oder aktiviert.',
|
||||
'D3_DATAWIZARD_ERR_NOEXPORTCONTENT' => 'Export ist leer, kein Inhalt zum Download verfĂĽgbar',
|
||||
'D3_DATAWIZARD_ERR_NOSUITABLERENDERER' => 'kein Renderer fĂĽr Format "%1$s" registriert',
|
||||
|
||||
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES' => 'deaktivierte Kategorien, mit aktiven Artikel',
|
||||
'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_ORDERSPERMONTH' => 'Bestellungen pro Monat',
|
||||
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_BASKETSIZE' => 'Warenkorbhöhe',
|
||||
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_MONTH' => 'Monat',
|
||||
'D3_DATAWIZARD_ERR_EXPORTFILEERROR' => 'Exportdatei "%1$s" kann nicht angelegt werden',
|
||||
|
||||
'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',
|
||||
);
|
58
Application/views/admin/en/d3DataWizard_lang.php
Normal file
58
Application/views/admin/en/d3DataWizard_lang.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?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);
|
||||
|
||||
$sLangName = "English";
|
||||
// -------------------------------
|
||||
// RESOURCE IDENTITFIER = STRING
|
||||
// -------------------------------
|
||||
$aLang = array(
|
||||
|
||||
//Navigation
|
||||
'charset' => 'UTF-8',
|
||||
'd3mxDataWizard' => '<i class="fas fa-fw fa-hat-wizard"></i> Data Wizard',
|
||||
'd3mxDataWizard_Export' => 'exports',
|
||||
'd3mxDataWizard_Action' => 'actions',
|
||||
|
||||
'SHOP_MODULE_GROUP_d3datawizard_general' => 'basic settings',
|
||||
'SHOP_MODULE_d3datawizard_debug' => 'shows queries instead of executing them',
|
||||
|
||||
'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',
|
||||
|
||||
'D3_DATAWIZARD_DEBUG' => 'Debug: %1$s',
|
||||
|
||||
'D3_DATAWIZARD_ERR_NOEXPORTSELECT' => 'Export cannot be executed. Exports require SELECT Query.',
|
||||
'D3_DATAWIZARD_ERR_NOEXPORT_INSTALLED' => 'No exports are installed or activated.',
|
||||
'D3_DATAWIZARD_ERR_NOEXPORTCONTENT' => 'Export is empty, no content available for download',
|
||||
'D3_DATAWIZARD_ERR_NOSUITABLERENDERER' => 'No renderer registered for format "%1$s"',
|
||||
'D3_DATAWIZARD_ERR_EXPORTFILEERROR' => 'Export file "%1$s" cannot be created',
|
||||
|
||||
'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',
|
||||
);
|
4
Application/views/admin/tpl/d3ActionWizard.tpl
Normal file
4
Application/views/admin/tpl/d3ActionWizard.tpl
Normal file
@ -0,0 +1,4 @@
|
||||
[{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}]
|
||||
|
||||
[{include file="d3Wizards.tpl" submit="d3ActionSubmit.tpl"}]
|
4
Application/views/admin/tpl/d3ExportWizard.tpl
Normal file
4
Application/views/admin/tpl/d3ExportWizard.tpl
Normal file
@ -0,0 +1,4 @@
|
||||
[{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}]
|
||||
|
||||
[{include file="d3Wizards.tpl" submit="d3ExportSubmit.tpl"}]
|
@ -15,7 +15,7 @@
|
||||
}
|
||||
/* 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);
|
||||
background-image: [{$d3dw_backgroundimage}];
|
||||
}
|
||||
h4 .btn {
|
||||
font-size: 1.3rem;
|
||||
@ -23,10 +23,14 @@
|
||||
h5.card-header {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
.formElements label {
|
||||
display: inline-block;
|
||||
margin: .5rem 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
[{capture name="d3script"}][{strip}]
|
||||
function startAction(id) {
|
||||
function startTask(id, format = '') {
|
||||
let elements = document.getElementsByClassName('errorbox');
|
||||
for (var i = 0; i < elements.length; i++){
|
||||
elements[i].style.display = 'none';
|
||||
@ -37,7 +41,8 @@
|
||||
}, 3000);
|
||||
document.getElementById('mask').className='on';
|
||||
document.getElementById('popup2').className='d3loader-2 on';
|
||||
document.getElementById('actionid').value = id;
|
||||
document.getElementById('taskid').value = id;
|
||||
document.getElementById('format').value = format;
|
||||
document.getElementById('myedit').submit();
|
||||
}
|
||||
[{/strip}][{/capture}]
|
||||
@ -46,8 +51,9 @@
|
||||
<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="">
|
||||
<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}]
|
||||
@ -65,24 +71,39 @@
|
||||
<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"}]
|
||||
[{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">
|
||||
[{$action->getTitle()}]
|
||||
[{$item->getTitle()}]
|
||||
</h5>
|
||||
<div class="card-body">
|
||||
<p class="card-text">
|
||||
[{$action->getDescription()}]
|
||||
</p>
|
||||
[{if $item->getDescription()}]
|
||||
[{assign var="description" value=$item->getDescription()}]
|
||||
[{assign var="sectionlength" value="100"}]
|
||||
|
||||
<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>
|
||||
[{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>
|
||||
@ -98,7 +119,7 @@
|
||||
</div>
|
||||
[{else}]
|
||||
<div class="alert alert-primary" role="alert">
|
||||
[{oxmultilang ident="D3_DATAWIZARD_ERR_NOACTION_INSTALLED"}]
|
||||
[{oxmultilang ident=$d3dw_noitemmessageid}]
|
||||
</div>
|
||||
[{/if}]
|
||||
</form>
|
8
Application/views/admin/tpl/inc/actionSubmit.tpl
Normal file
8
Application/views/admin/tpl/inc/actionSubmit.tpl
Normal file
@ -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}]
|
24
Application/views/admin/tpl/inc/exportSubmit.tpl
Normal file
24
Application/views/admin/tpl/inc/exportSubmit.tpl
Normal file
@ -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}]
|
51
CHANGELOG.md
51
CHANGELOG.md
@ -1,5 +1,56 @@
|
||||
# Changelog
|
||||
|
||||
## 1.5.0.0 (2021-12-20)
|
||||
|
||||
#### Added
|
||||
- add tests
|
||||
|
||||
#### Changed
|
||||
- restrict dependencies to OXID 6.2, use 2.x for newer installations
|
||||
|
||||
---
|
||||
|
||||
## 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
|
52
README.en.md
52
README.en.md
@ -1,4 +1,5 @@
|
||||
> [deutsche Version](README.md)
|
||||
[](README.md)
|
||||
[](README.en.md)
|
||||
|
||||
# DÂł Data Wizard for OXID eShop
|
||||
|
||||
@ -6,65 +7,44 @@ 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.
|
||||
|
||||
Translated with www.DeepL.com/Translator (free version)
|
||||

|
||||
|
||||
## 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:^1.0
|
||||
```
|
||||
|
||||
Activate in the admin area of the shop under "Extensions -> Modules".
|
||||
Activate the module in the admin area of the shop in "Extensions -> Modules".
|
||||
|
||||
# Extensibility
|
||||
## Extensibility
|
||||
|
||||
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
|
||||
|
||||
See [CHANGELOG](CHANGELOG.md) for further informations.
|
||||
|
||||
## Licence of this software (d3/datawizard)
|
||||
(status: 06.05.2021)
|
||||
(status: 2021-05-06)
|
||||
|
||||
```
|
||||
Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
@ -92,7 +72,7 @@ Gradients available on the site are free to use on personal and commercial proje
|
||||
The following software packages are not part of this module. However, they are required for use. The linked packages are under the following licences:
|
||||
|
||||
### league/csv [MIT]
|
||||
(https://github.com/thephpleague/csv - status: 06.05.2021)
|
||||
(https://github.com/thephpleague/csv - status: 2021-05-06)
|
||||
|
||||
```
|
||||
Copyright (c) 2013-2017 ignace nyamagana butera
|
||||
@ -116,7 +96,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
```
|
||||
|
||||
### mathieuviossat/arraytotexttable [MIT]
|
||||
(https://github.com/viossat/arraytotexttable - status: 06.05.2021)
|
||||
(https://github.com/viossat/arraytotexttable - status: 2021-05-06)
|
||||
|
||||
```
|
||||
Copyright (c) 2015 Mathieu Viossat
|
||||
|
46
README.md
46
README.md
@ -1,59 +1,43 @@
|
||||
> [english version](README.en.md)
|
||||
[](README.md)
|
||||
[](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.
|
||||
|
||||

|
||||
|
||||
## 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:^1.0
|
||||
```
|
||||
|
||||
Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module".
|
||||
|
||||
## Erweiterbarkeit
|
||||
|
||||
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
assets/administration_exports.jpg
Normal file
BIN
assets/administration_exports.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
@ -26,16 +26,28 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"oxid-esales/oxideshop-ce": "6.3 - 6.8",
|
||||
"oxid-esales/oxideshop-ce": "6.3 - 6.7",
|
||||
"league/csv": "^9.0",
|
||||
"mathieuviossat/arraytotexttable": "^1.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": {
|
||||
"source-directory": "/src",
|
||||
"blacklist-filter": [
|
||||
"*.md",
|
||||
"composer.json"
|
||||
],
|
||||
"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"
|
||||
|
@ -32,7 +32,7 @@ $aModule = [
|
||||
'en' => '',
|
||||
],
|
||||
'thumbnail' => '',
|
||||
'version' => '0.1',
|
||||
'version' => '1.5.0.0',
|
||||
'author' => 'D³ 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' => []
|
||||
];
|
@ -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<74>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;
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?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\NoSuitableRendererException;
|
||||
|
||||
class RendererBridge
|
||||
{
|
||||
const FORMAT_CSV = 'CSV';
|
||||
const FORMAT_PRETTY = 'Pretty';
|
||||
|
||||
/**
|
||||
* @param string $format
|
||||
*
|
||||
* @throws NoSuitableRendererException
|
||||
* @return RendererInterface
|
||||
*/
|
||||
public function getRenderer($format = self::FORMAT_CSV): RendererInterface
|
||||
{
|
||||
switch ($format) {
|
||||
case self::FORMAT_CSV:
|
||||
return oxNew(Csv::class);
|
||||
case self::FORMAT_PRETTY:
|
||||
return oxNew(Pretty::class);
|
||||
}
|
||||
|
||||
/** @var NoSuitableRendererException $e */
|
||||
$e = oxNew(NoSuitableRendererException::class, $format);
|
||||
throw $e;
|
||||
}
|
||||
}
|
@ -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 Artikel
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
@ -1,62 +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\Order;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class KeyFigures extends ExportBase
|
||||
{
|
||||
/**
|
||||
* Shopkennzahlen
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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');
|
||||
|
||||
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
|
||||
GROUP BY :monthTitle
|
||||
ORDER BY :monthTitle DESC
|
||||
LIMIT 30',
|
||||
[
|
||||
'monthTitle' => $monthTitle,
|
||||
'ordersTitle' => $ordersTitle,
|
||||
'basketsTitle' => $basketsTitle
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
[{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: 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;
|
||||
}
|
||||
</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">
|
||||
<p class="card-text">
|
||||
[{$export->getDescription()}]
|
||||
</p>
|
||||
|
||||
<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"}]
|
2
tests/.gitignore
vendored
Normal file
2
tests/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
reports
|
||||
.phpunit.result.cache
|
52
tests/README.md
Normal file
52
tests/README.md
Normal file
@ -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
Executable file
39
tests/additional.inc.php
Executable file
@ -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
Executable file
15
tests/d3datawizard_config.php
Executable file
@ -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
|
||||
*/
|
||||
|
||||
define('D3DATAWIZARD_REQUIRE_MODCFG', true);
|
||||
|
27
tests/phpunit.xml
Normal file
27
tests/phpunit.xml
Normal file
@ -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
Normal file
18
tests/tools/d3TestAction.php
Normal file
@ -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
Normal file
18
tests/tools/d3TestExport.php
Normal file
@ -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";
|
||||
}
|
||||
}
|
193
tests/unit/Application/Controller/Admin/d3ActionWizardTest.php
Normal file
193
tests/unit/Application/Controller/Admin/d3ActionWizardTest.php
Normal file
@ -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],
|
||||
];
|
||||
}
|
||||
}
|
@ -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'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
195
tests/unit/Application/Controller/Admin/d3ExportWizardTest.php
Normal file
195
tests/unit/Application/Controller/Admin/d3ExportWizardTest.php
Normal file
@ -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],
|
||||
];
|
||||
}
|
||||
}
|
316
tests/unit/Application/Model/ActionBaseTest.php
Normal file
316
tests/unit/Application/Model/ActionBaseTest.php
Normal file
@ -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()
|
||||
{
|
||||
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'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
454
tests/unit/Application/Model/ConfigurationTest.php
Normal file
454
tests/unit/Application/Model/ConfigurationTest.php
Normal file
@ -0,0 +1,454 @@
|
||||
<?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;
|
||||
|
||||
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],
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
<?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 PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
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'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
<?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 PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
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'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
<?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 FormManager\Inputs\Number;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
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);
|
||||
|
||||
/** @var Number $invalidField */
|
||||
$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'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
<?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 PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
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'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
<?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 PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
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'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
607
tests/unit/Application/Model/ExportBaseTest.php
Normal file
607
tests/unit/Application/Model/ExportBaseTest.php
Normal file
@ -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()
|
||||
{
|
||||
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']]],
|
||||
];
|
||||
}
|
||||
}
|
180
tests/unit/Application/Model/ExportRenderer/CsvTest.php
Normal file
180
tests/unit/Application/Model/ExportRenderer/CsvTest.php
Normal file
@ -0,0 +1,180 @@
|
||||
<?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;
|
||||
|
||||
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 = ['insertOne', 'insertAll'];
|
||||
if (method_exists($csvMockBuilder->getMock(), 'getContent')) {
|
||||
$onlyMethods[] = 'getContent';
|
||||
} else {
|
||||
$csvMockBuilder->addMethods(['getContent']);
|
||||
}
|
||||
$csvMockBuilder->onlyMethods($onlyMethods);
|
||||
$csvMock = $csvMockBuilder->getMock();
|
||||
|
||||
if ($blThrowException) {
|
||||
$csvMock->expects($this->atLeastOnce())->method('getContent')->willThrowException(oxNew(Exception::class));
|
||||
$this->expectException(RenderException::class);
|
||||
} else {
|
||||
$csvMock->expects($this->atLeastOnce())->method('getContent')->willReturn($expected);
|
||||
}
|
||||
$csvMock->expects($this->atLeastOnce())->method('insertOne')->with($fieldList)->willReturn(1);
|
||||
$csvMock->expects($this->atLeastOnce())->method('insertAll')->with($valueList)->willReturn(1);
|
||||
|
||||
/** @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'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?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;
|
||||
|
||||
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'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
66
tests/unit/Application/Model/ExportRenderer/JsonTest.php
Normal file
66
tests/unit/Application/Model/ExportRenderer/JsonTest.php
Normal file
@ -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
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
];
|
||||
}
|
||||
}
|
85
tests/unit/Application/Model/ExportRenderer/PrettyTest.php
Normal file
85
tests/unit/Application/Model/ExportRenderer/PrettyTest.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?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;
|
||||
|
||||
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']]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
<?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;
|
||||
|
||||
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]
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user