2021-11-24 23:38:28 +01:00
|
|
|
<?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;
|
2024-05-13 15:23:47 +02:00
|
|
|
use D3\DataWizard\Application\Model\Constants;
|
|
|
|
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
|
2021-11-24 23:38:28 +01:00
|
|
|
use D3\DataWizard\Application\Model\Exceptions\DebugException;
|
2021-11-26 23:16:32 +01:00
|
|
|
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
|
2021-11-24 23:38:28 +01:00
|
|
|
use D3\DataWizard\tests\tools\d3TestAction;
|
2024-05-13 15:23:47 +02:00
|
|
|
use Doctrine\DBAL\Exception as DBALException;
|
2021-11-24 23:38:28 +01:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use OxidEsales\Eshop\Core\Request;
|
2024-05-13 15:23:47 +02:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
|
2021-11-24 23:38:28 +01:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use ReflectionException;
|
|
|
|
|
2024-05-13 15:23:47 +02:00
|
|
|
class d3ActionWizardTest extends d3AdminController
|
2021-11-24 23:38:28 +01:00
|
|
|
{
|
|
|
|
/** @var d3ActionWizard */
|
|
|
|
protected $_oController;
|
|
|
|
|
2021-11-26 23:16:32 +01:00
|
|
|
protected $testClassName = d3ActionWizard::class;
|
|
|
|
|
2022-01-17 10:59:18 +01:00
|
|
|
public function setUp(): void
|
2021-11-24 23:38:28 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2021-11-26 23:16:32 +01:00
|
|
|
$this->_oController = oxNew($this->testClassName);
|
2021-11-24 23:38:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-26 23:16:32 +01:00
|
|
|
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getGroups()
|
2021-11-24 23:38:28 +01:00
|
|
|
* @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'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-26 23:16:32 +01:00
|
|
|
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getGroupTasks()
|
2021-11-24 23:38:28 +01:00
|
|
|
* @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'],
|
2022-01-17 10:59:18 +01:00
|
|
|
['test2'],
|
2021-11-24 23:38:28 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-26 23:16:32 +01:00
|
|
|
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::execute()
|
2021-11-24 23:38:28 +01:00
|
|
|
* @test
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @dataProvider executePassDataProvider
|
|
|
|
*/
|
|
|
|
public function executePass($blDebug)
|
|
|
|
{
|
|
|
|
/** @var Request|MockObject $requestMock */
|
|
|
|
$requestMock = $this->getMockBuilder(get_class(Registry::getRequest()))
|
|
|
|
->onlyMethods(['getRequestEscapedParameter'])
|
|
|
|
->getMock();
|
2021-11-26 23:16:32 +01:00
|
|
|
$requestMock->expects($this->any())->method('getRequestEscapedParameter')->willReturnCallback([$this, 'executePassRequestCallback']);
|
2021-11-24 23:38:28 +01:00
|
|
|
Registry::set(Request::class, $requestMock);
|
|
|
|
|
2024-05-13 15:23:47 +02:00
|
|
|
/** @var ModuleSettingService $settingsServiceMock */
|
|
|
|
$settingsServiceMock = $this->getMockBuilder(ModuleSettingService::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->onlyMethods(['getBoolean'])
|
2021-11-26 23:16:32 +01:00
|
|
|
->getMock();
|
2024-05-13 15:23:47 +02:00
|
|
|
$settingsServiceMock->expects($this->once())->method('getBoolean')->with(
|
|
|
|
$this->identicalTo('d3datawizard_debug'),
|
|
|
|
$this->identicalTo(Constants::OXID_MODULE_ID)
|
|
|
|
)->willReturn($blDebug);
|
2021-11-26 23:16:32 +01:00
|
|
|
|
|
|
|
/** @var d3ActionWizard|MockObject $controllerMock */
|
|
|
|
$controllerMock = $this->getMockBuilder(d3ActionWizard::class)
|
2024-05-13 15:23:47 +02:00
|
|
|
->onlyMethods(['getSettingsService'])
|
2021-11-26 23:16:32 +01:00
|
|
|
->getMock();
|
2024-05-13 15:23:47 +02:00
|
|
|
$controllerMock->method('getSettingsService')->willReturn($settingsServiceMock);
|
2021-11-26 23:16:32 +01:00
|
|
|
$this->_oController = $controllerMock;
|
|
|
|
|
2021-11-24 23:38:28 +01:00
|
|
|
/** @var d3TestAction|MockObject $actionMock */
|
|
|
|
$actionMock = $this->getMockBuilder(d3TestAction::class)
|
|
|
|
->onlyMethods([
|
|
|
|
'getQuery',
|
2022-01-17 10:59:18 +01:00
|
|
|
'run',
|
2021-11-24 23:38:28 +01:00
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
$actionMock->expects($this->atLeastOnce())->method('getQuery')->willReturn(['SELECT 1', ['1']]);
|
2024-05-13 15:23:47 +02:00
|
|
|
$actionMock->expects($this->exactly((int) !$blDebug))->method('run');
|
2021-11-24 23:38:28 +01:00
|
|
|
|
|
|
|
/** @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'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-26 23:16:32 +01:00
|
|
|
public function executePassRequestCallback($varName)
|
|
|
|
{
|
2024-05-13 15:23:47 +02:00
|
|
|
return match ( $varName ) {
|
|
|
|
'taskid' => 'testTaskId',
|
|
|
|
'format' => RendererBridge::FORMAT_CSV,
|
|
|
|
default => oxNew( Request::class )->getRequestEscapedParameter( $varName ),
|
|
|
|
};
|
2021-11-26 23:16:32 +01:00
|
|
|
}
|
|
|
|
|
2021-11-24 23:38:28 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function executePassDataProvider(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'no debug' => [false],
|
|
|
|
'debug' => [true],
|
|
|
|
];
|
|
|
|
}
|
2024-05-13 15:23:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string[][]
|
|
|
|
*/
|
|
|
|
public function runTaskFailedDataProvider(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[DataWizardException::class],
|
|
|
|
[DBALException::class],
|
|
|
|
];
|
|
|
|
}
|
2022-01-17 10:59:18 +01:00
|
|
|
}
|