improve tests for EE
Dieser Commit ist enthalten in:
Ursprung
61827e7825
Commit
b1946c4aae
@ -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;
|
||||
@ -79,7 +80,7 @@ class d3ActionWizard extends AdminDetailsController
|
||||
|
||||
[ $queryString, $parameters ] = $action->getQuery();
|
||||
|
||||
if (Registry::getConfig()->getConfigParam('d3datawizard_debug')) {
|
||||
if ($this->d3GetConfig()->getConfigParam('d3datawizard_debug')) {
|
||||
throw oxNew(
|
||||
DebugException::class,
|
||||
d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters)
|
||||
@ -89,6 +90,14 @@ class d3ActionWizard extends AdminDetailsController
|
||||
$action->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function d3GetConfig()
|
||||
{
|
||||
return Registry::getConfig();
|
||||
}
|
||||
|
||||
public function getUserMessages()
|
||||
{
|
||||
return null;
|
||||
|
@ -25,6 +25,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;
|
||||
@ -87,7 +88,7 @@ class d3ExportWizard extends AdminDetailsController
|
||||
|
||||
[ $queryString, $parameters ] = $export->getQuery();
|
||||
|
||||
if (Registry::getConfig()->getConfigParam('d3datawizard_debug')) {
|
||||
if ($this->d3GetConfig()->getConfigParam('d3datawizard_debug')) {
|
||||
throw oxNew(
|
||||
DebugException::class,
|
||||
d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters)
|
||||
@ -97,6 +98,14 @@ class d3ExportWizard extends AdminDetailsController
|
||||
$export->run(Registry::getRequest()->getRequestEscapedParameter('format'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function d3GetConfig()
|
||||
{
|
||||
return Registry::getConfig();
|
||||
}
|
||||
|
||||
public function getUserMessages()
|
||||
{
|
||||
return null;
|
||||
|
@ -103,15 +103,12 @@ abstract class ActionBase implements QueryBase
|
||||
*/
|
||||
public function registerFormElement(Input $input)
|
||||
{
|
||||
switch (get_class($input)) {
|
||||
case Radio::class:
|
||||
case Checkbox::class:
|
||||
$input->setTemplate('<p class="form-check">{{ input }} {{ label }}</p>');
|
||||
$input->setAttribute('class', 'form-check-input');
|
||||
break;
|
||||
default:
|
||||
$input->setTemplate('<p class="formElements">{{ label }} {{ input }}</p>');
|
||||
$input->setAttribute('class', 'form-control');
|
||||
if ($input instanceof Radio || $input instanceof Checkbox) {
|
||||
$input->setTemplate('<p class="form-check">{{ input }} {{ label }}</p>');
|
||||
$input->setAttribute('class', 'form-check-input');
|
||||
} else {
|
||||
$input->setTemplate('<p class="formElements">{{ label }} {{ input }}</p>');
|
||||
$input->setAttribute('class', 'form-control');
|
||||
}
|
||||
$this->formElements[] = $input;
|
||||
}
|
||||
|
@ -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
|
||||
@ -59,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 = ';';
|
||||
}
|
||||
@ -81,4 +82,12 @@ class Csv implements RendererInterface
|
||||
{
|
||||
return 'D3_DATAWIZARD_EXPORT_FORMAT_CSV';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function d3GetConfig()
|
||||
{
|
||||
return Registry::getConfig();
|
||||
}
|
||||
}
|
1
tests/.gitignore
vendored
1
tests/.gitignore
vendored
@ -1 +1,2 @@
|
||||
reports
|
||||
.phpunit.result.cache
|
||||
|
@ -13,6 +13,6 @@ class d3TestAction extends ActionBase
|
||||
|
||||
public function getQuery(): array
|
||||
{
|
||||
return "SELECT 1";
|
||||
return ["UPDATE 1"];
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ 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;
|
||||
@ -30,15 +31,17 @@ class d3ActionWizardTest extends d3AdminControllerTest
|
||||
/** @var d3ActionWizard */
|
||||
protected $_oController;
|
||||
|
||||
protected $testClassName = d3ActionWizard::class;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3ActionWizard::class);
|
||||
$this->_oController = oxNew($this->testClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::getGroups()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getGroups()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
@ -63,7 +66,7 @@ class d3ActionWizardTest extends d3AdminControllerTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::getGroupTasks()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getGroupTasks()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @dataProvider canGetGroupTasksDataProvider
|
||||
@ -101,7 +104,7 @@ class d3ActionWizardTest extends d3AdminControllerTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::execute()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::execute()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @dataProvider executePassDataProvider
|
||||
@ -112,9 +115,31 @@ class d3ActionWizardTest extends d3AdminControllerTest
|
||||
$requestMock = $this->getMockBuilder(get_class(Registry::getRequest()))
|
||||
->onlyMethods(['getRequestEscapedParameter'])
|
||||
->getMock();
|
||||
$requestMock->expects($this->atLeastOnce())->method('getRequestEscapedParameter')->with('taskid')->willReturn('testTaskId');
|
||||
$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([
|
||||
@ -133,13 +158,6 @@ class d3ActionWizardTest extends d3AdminControllerTest
|
||||
$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);
|
||||
}
|
||||
@ -150,6 +168,18 @@ class d3ActionWizardTest extends d3AdminControllerTest
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
|
@ -37,6 +37,8 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
/** @var d3ActionWizard|d3ExportWizard */
|
||||
protected $_oController;
|
||||
|
||||
protected $testClassName;
|
||||
|
||||
public function tearDown() : void
|
||||
{
|
||||
parent::tearDown();
|
||||
@ -76,8 +78,8 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
*/
|
||||
public function runTaskPass()
|
||||
{
|
||||
/** @var d3ActionWizard|MockObject $controllerMock */
|
||||
$controllerMock = $this->getMockBuilder(d3ActionWizard::class)
|
||||
/** @var d3ActionWizard|d3ExportWizard|MockObject $controllerMock */
|
||||
$controllerMock = $this->getMockBuilder($this->testClassName)
|
||||
->onlyMethods(['execute'])
|
||||
->getMock();
|
||||
$controllerMock->expects($this->once())->method('execute')->willReturn(true);
|
||||
@ -106,8 +108,8 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
->getMock();
|
||||
$this->setValue($exceptionMock, 'message', 'exc_msg');
|
||||
|
||||
/** @var d3ActionWizard|MockObject $controllerMock */
|
||||
$controllerMock = $this->getMockBuilder(d3ActionWizard::class)
|
||||
/** @var d3ActionWizard|d3ExportWizard|MockObject $controllerMock */
|
||||
$controllerMock = $this->getMockBuilder($this->testClassName)
|
||||
->onlyMethods(['execute'])
|
||||
->getMock();
|
||||
$controllerMock->expects($this->once())->method('execute')->willThrowException($exceptionMock);
|
||||
@ -240,4 +242,21 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ 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\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;
|
||||
@ -32,15 +33,17 @@ class d3ExportWizardTest extends d3AdminControllerTest
|
||||
/** @var d3ExportWizard */
|
||||
protected $_oController;
|
||||
|
||||
protected $testClassName = d3ExportWizard::class;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3ExportWizard::class);
|
||||
$this->_oController = oxNew($this->testClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::getGroups()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::getGroups()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
@ -65,7 +68,7 @@ class d3ExportWizardTest extends d3AdminControllerTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::getGroupTasks()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::getGroupTasks()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @dataProvider canGetGroupTasksDataProvider
|
||||
@ -103,7 +106,7 @@ class d3ExportWizardTest extends d3AdminControllerTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::execute()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::execute()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @dataProvider executePassDataProvider
|
||||
@ -114,12 +117,32 @@ class d3ExportWizardTest extends d3AdminControllerTest
|
||||
$requestMock = $this->getMockBuilder(get_class(Registry::getRequest()))
|
||||
->onlyMethods(['getRequestEscapedParameter'])
|
||||
->getMock();
|
||||
|
||||
$requestMock->expects($this->exactly($blDebug ? 1 : 2))->method('getRequestEscapedParameter')->withConsecutive(
|
||||
['taskid'], ['format']
|
||||
)->willReturnOnConsecutiveCalls('testTaskId', 'CSV');
|
||||
$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([
|
||||
@ -138,13 +161,6 @@ class d3ExportWizardTest extends d3AdminControllerTest
|
||||
$configurationMock->expects($this->atLeastOnce())->method('getExportById')->with('testTaskId')->willReturn($exportMock);
|
||||
$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);
|
||||
}
|
||||
@ -155,6 +171,18 @@ class d3ExportWizardTest extends d3AdminControllerTest
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
|
250
tests/unit/Application/Model/ActionBaseTest.php
Normale Datei
250
tests/unit/Application/Model/ActionBaseTest.php
Normale Datei
@ -0,0 +1,250 @@
|
||||
<?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\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\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]
|
||||
];
|
||||
}
|
||||
}
|
@ -19,6 +19,8 @@ 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
|
||||
@ -93,6 +95,7 @@ class CsvTest extends ExportRendererTest
|
||||
'no exception' => [false]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getCsv
|
||||
* @test
|
||||
@ -108,4 +111,70 @@ class CsvTest extends ExportRendererTest
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ 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
|
||||
@ -33,11 +34,15 @@ class JsonTest extends ExportRendererTest
|
||||
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getContent
|
||||
* @test
|
||||
* @throws \ReflectionException
|
||||
* @dataProvider canGetContentDataProvider
|
||||
*/
|
||||
public function canGetContent()
|
||||
public function canGetContent($valueList, $expectException)
|
||||
{
|
||||
$fieldList = ['field1', 'field2'];
|
||||
$valueList = ['value1', 'value2'];
|
||||
|
||||
if ($expectException) {
|
||||
$this->expectException(RenderException::class);
|
||||
}
|
||||
|
||||
$this->assertJson(
|
||||
$this->callMethod(
|
||||
@ -47,4 +52,15 @@ class JsonTest extends ExportRendererTest
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \string[][]
|
||||
*/
|
||||
public function canGetContentDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid' => [['value1', 'value2'], false],
|
||||
'invalid' => [["text" => "\xB1\x31"], true] // malformed UTF8 chars
|
||||
];
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren