add tests for admin controller classes
This commit is contained in:
parent
f5d35021f5
commit
5fda1baecb
1
tests/.gitignore
vendored
Normal file
1
tests/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.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>
|
45
tests/reports/logfile.xml
Normal file
45
tests/reports/logfile.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites>
|
||||
<testsuite name="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/" tests="24" assertions="56" errors="0" warnings="0" failures="0" skipped="0" time="0.929913">
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" tests="12" assertions="28" errors="0" warnings="0" failures="0" skipped="0" time="0.546801">
|
||||
<testcase name="canGetGroups" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="45" assertions="2" time="0.197758"/>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest::canGetGroupTasks" tests="2" assertions="4" errors="0" warnings="0" failures="0" skipped="0" time="0.053800">
|
||||
<testcase name="canGetGroupTasks with data set #0" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="71" assertions="2" time="0.022952"/>
|
||||
<testcase name="canGetGroupTasks with data set #1" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="71" assertions="2" time="0.030848"/>
|
||||
</testsuite>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest::executePass" tests="2" assertions="9" errors="0" warnings="0" failures="0" skipped="0" time="0.060701">
|
||||
<testcase name="executePass with data set "no debug"" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="109" assertions="4" time="0.030058"/>
|
||||
<testcase name="executePass with data set "debug"" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="109" assertions="5" time="0.030643"/>
|
||||
</testsuite>
|
||||
<testcase name="testConstructor" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="53" assertions="1" time="0.030605"/>
|
||||
<testcase name="runTaskPass" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="76" assertions="1" time="0.031500"/>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest::runTaskFailed" tests="3" assertions="9" errors="0" warnings="0" failures="0" skipped="0" time="0.117398">
|
||||
<testcase name="runTaskFailed with data set #0" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="99" assertions="3" time="0.044769"/>
|
||||
<testcase name="runTaskFailed with data set #1" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="99" assertions="3" time="0.035974"/>
|
||||
<testcase name="runTaskFailed with data set #2" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="99" assertions="3" time="0.036655"/>
|
||||
</testsuite>
|
||||
<testcase name="canGetUserMessages" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="214" assertions="1" time="0.021711"/>
|
||||
<testcase name="canGetHelpUrl" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ActionWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ActionWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ActionWizardTest.php" line="229" assertions="1" time="0.033328"/>
|
||||
</testsuite>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" tests="12" assertions="28" errors="0" warnings="0" failures="0" skipped="0" time="0.383112">
|
||||
<testcase name="canGetGroups" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="47" assertions="2" time="0.033427"/>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest::canGetGroupTasks" tests="2" assertions="4" errors="0" warnings="0" failures="0" skipped="0" time="0.061498">
|
||||
<testcase name="canGetGroupTasks with data set #0" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="73" assertions="2" time="0.030485"/>
|
||||
<testcase name="canGetGroupTasks with data set #1" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="73" assertions="2" time="0.031013"/>
|
||||
</testsuite>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest::executePass" tests="2" assertions="9" errors="0" warnings="0" failures="0" skipped="0" time="0.063269">
|
||||
<testcase name="executePass with data set "no debug"" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="111" assertions="4" time="0.032721"/>
|
||||
<testcase name="executePass with data set "debug"" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="111" assertions="5" time="0.030548"/>
|
||||
</testsuite>
|
||||
<testcase name="testConstructor" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="53" assertions="1" time="0.030584"/>
|
||||
<testcase name="runTaskPass" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="76" assertions="1" time="0.031141"/>
|
||||
<testsuite name="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest::runTaskFailed" tests="3" assertions="9" errors="0" warnings="0" failures="0" skipped="0" time="0.117993">
|
||||
<testcase name="runTaskFailed with data set #0" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="99" assertions="3" time="0.047627"/>
|
||||
<testcase name="runTaskFailed with data set #1" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="99" assertions="3" time="0.034952"/>
|
||||
<testcase name="runTaskFailed with data set #2" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="99" assertions="3" time="0.035414"/>
|
||||
</testsuite>
|
||||
<testcase name="canGetUserMessages" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="214" assertions="1" time="0.018605"/>
|
||||
<testcase name="canGetHelpUrl" class="D3\DataWizard\tests\unit\Application\Controller\Admin\d3ExportWizardTest" classname="D3.DataWizard.tests.unit.Application.Controller.Admin.d3ExportWizardTest" file="/var/www/html/oxid_ee_63/source/modules/d3/datawizard/tests/unit/Application/Controller/Admin/d3ExportWizardTest.php" line="229" assertions="1" time="0.026595"/>
|
||||
</testsuite>
|
||||
</testsuite>
|
||||
</testsuites>
|
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 "SELECT 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";
|
||||
}
|
||||
}
|
163
tests/unit/Application/Controller/Admin/d3ActionWizardTest.php
Normal file
163
tests/unit/Application/Controller/Admin/d3ActionWizardTest.php
Normal file
@ -0,0 +1,163 @@
|
||||
<?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\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;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3ActionWizard::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers 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 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 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->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],
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
<?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;
|
||||
|
||||
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 d3ActionWizard::runTask()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function runTaskPass()
|
||||
{
|
||||
/** @var d3ActionWizard|MockObject $controllerMock */
|
||||
$controllerMock = $this->getMockBuilder(d3ActionWizard::class)
|
||||
->onlyMethods(['execute'])
|
||||
->getMock();
|
||||
$controllerMock->expects($this->once())->method('execute')->willReturn(true);
|
||||
|
||||
$this->_oController = $controllerMock;
|
||||
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'runTask'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::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|MockObject $controllerMock */
|
||||
$controllerMock = $this->getMockBuilder(d3ActionWizard::class)
|
||||
->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 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->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 d3ActionWizard::getUserMessages()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function canGetUserMessages()
|
||||
{
|
||||
$this->assertNull(
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getUserMessages'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::getHelpURL()
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function canGetHelpUrl()
|
||||
{
|
||||
$this->assertNull(
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getHelpURL'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
168
tests/unit/Application/Controller/Admin/d3ExportWizardTest.php
Normal file
168
tests/unit/Application/Controller/Admin/d3ExportWizardTest.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?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\DebugException;
|
||||
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;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3ExportWizard::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers d3ActionWizard::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 d3ActionWizard::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 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->exactly($blDebug ? 1 : 2))->method('getRequestEscapedParameter')->withConsecutive(
|
||||
['taskid'], ['format']
|
||||
)->willReturnOnConsecutiveCalls('testTaskId', 'CSV');
|
||||
Registry::set(Request::class, $requestMock);
|
||||
|
||||
/** @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);
|
||||
|
||||
/** @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],
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user