From 69b33d3538c2e433e498bd2821dfc6b2b33bd6e6 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 10 May 2024 16:48:29 +0200 Subject: [PATCH] fix tests --- Application/Model/ExportBase.php | 11 +++---- .../Model/Exceptions/DebugExceptionTest.php | 3 +- .../Exceptions/ExportFileExceptionTest.php | 3 +- .../NoSuitableRendererExceptionTest.php | 3 +- .../unit/Application/Model/ExportBaseTest.php | 29 ++++++++++++------- views/twig/admin/inc/Wizards.html.twig | 4 +-- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/Application/Model/ExportBase.php b/Application/Model/ExportBase.php index 6433066..4de4b8c 100644 --- a/Application/Model/ExportBase.php +++ b/Application/Model/ExportBase.php @@ -149,8 +149,6 @@ abstract class ExportBase implements QueryBase * @return array * @throws DBALException * @throws Exception - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface */ public function getExportData(array $query): array { @@ -166,9 +164,7 @@ abstract class ExportBase implements QueryBase ); } - /** @var Connection $connection */ - $connection = ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get(); - $rows = $connection->executeQuery($queryString, $parameters)->fetchAllAssociative(); + $rows = $this->getConnection()->executeQuery($queryString, $parameters)->fetchAllAssociative(); if (count($rows) <= 0) { throw oxNew( @@ -183,6 +179,11 @@ abstract class ExportBase implements QueryBase return [ $rows, $fieldNames ]; } + protected function getConnection(): Connection + { + return ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get(); + } + public function registerFormElement(Input $input): void { if ($input instanceof Radio || $input instanceof Checkbox) { diff --git a/tests/unit/Application/Model/Exceptions/DebugExceptionTest.php b/tests/unit/Application/Model/Exceptions/DebugExceptionTest.php index 2d273ee..bc8c513 100644 --- a/tests/unit/Application/Model/Exceptions/DebugExceptionTest.php +++ b/tests/unit/Application/Model/Exceptions/DebugExceptionTest.php @@ -18,6 +18,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions; use D3\DataWizard\Application\Model\Exceptions\DebugException; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use Exception; +use OxidEsales\Eshop\Core\Registry; use PHPUnit\Framework\MockObject\MockObject; use ReflectionException; @@ -51,7 +52,7 @@ class DebugExceptionTest extends d3ModCfgUnitTestCase ); $this->assertStringContainsString( - 'Debug', + Registry::getLang()->translateString('D3_DATAWIZARD_DEBUG'), $this->callMethod( $this->_oModel, 'getMessage' diff --git a/tests/unit/Application/Model/Exceptions/ExportFileExceptionTest.php b/tests/unit/Application/Model/Exceptions/ExportFileExceptionTest.php index feb5ee2..511930e 100644 --- a/tests/unit/Application/Model/Exceptions/ExportFileExceptionTest.php +++ b/tests/unit/Application/Model/Exceptions/ExportFileExceptionTest.php @@ -18,6 +18,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions; use D3\DataWizard\Application\Model\Exceptions\ExportFileException; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use Exception; +use OxidEsales\Eshop\Core\Registry; use PHPUnit\Framework\MockObject\MockObject; use ReflectionException; @@ -51,7 +52,7 @@ class ExportFileExceptionTest extends d3ModCfgUnitTestCase ); $this->assertStringContainsString( - 'EXPORTFILEERROR', + Registry::getLang()->translateString('D3_DATAWIZARD_ERR_EXPORTFILEERROR'), $this->callMethod( $this->_oModel, 'getMessage' diff --git a/tests/unit/Application/Model/Exceptions/NoSuitableRendererExceptionTest.php b/tests/unit/Application/Model/Exceptions/NoSuitableRendererExceptionTest.php index 702087d..d5ad95d 100644 --- a/tests/unit/Application/Model/Exceptions/NoSuitableRendererExceptionTest.php +++ b/tests/unit/Application/Model/Exceptions/NoSuitableRendererExceptionTest.php @@ -18,6 +18,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions; use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use Exception; +use OxidEsales\Eshop\Core\Registry; use PHPUnit\Framework\MockObject\MockObject; use ReflectionException; @@ -51,7 +52,7 @@ class NoSuitableRendererExceptionTest extends d3ModCfgUnitTestCase ); $this->assertStringContainsString( - 'NOSUITABLERENDERER', + Registry::getLang()->translateString('D3_DATAWIZARD_ERR_NOSUITABLERENDERER'), $this->callMethod( $this->_oModel, 'getMessage' diff --git a/tests/unit/Application/Model/ExportBaseTest.php b/tests/unit/Application/Model/ExportBaseTest.php index 2cbb4a0..603dbea 100644 --- a/tests/unit/Application/Model/ExportBaseTest.php +++ b/tests/unit/Application/Model/ExportBaseTest.php @@ -23,6 +23,8 @@ 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 Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\Result; use FormManager\Inputs\Hidden; use FormManager\Inputs\Number; use FormManager\Inputs\Radio; @@ -320,17 +322,17 @@ class ExportBaseTest extends d3ModCfgUnitTestCase } /** - * @covers \D3\DataWizard\Application\Model\ExportBase::d3GetDb + * @covers \D3\DataWizard\Application\Model\ExportBase::getConnection * @test * @throws ReflectionException */ - public function canGetDb() + public function canGetConnection() { $this->assertInstanceOf( - Database::class, + Connection::class, $this->callMethod( $this->_oModel, - 'd3GetDb' + 'getConnection' ) ); } @@ -542,19 +544,26 @@ class ExportBaseTest extends d3ModCfgUnitTestCase */ public function canGetExportData($query, $throwsException, $dbResult) { - /** @var Database|MockObject $dbMock */ - $dbMock = $this->getMockBuilder(Database::class) - ->onlyMethods(['getAll']) + /** @var Result|MockObject $resultMock */ + $resultMock = $this->getMockBuilder(Result::class) + ->onlyMethods(get_class_methods(Result::class)) ->getMock(); - $dbMock->expects($this->exactly((int) !$throwsException))->method('getAll')->willReturn($dbResult); + $resultMock->method('fetchAllAssociative')->willReturn($dbResult); + + /** @var Database|MockObject $connectionMock */ + $connectionMock = $this->getMockBuilder(Connection::class) + ->disableOriginalConstructor() + ->onlyMethods(['executeQuery']) + ->getMock(); + $connectionMock->expects($this->exactly((int) !$throwsException))->method('executeQuery')->willReturn($resultMock); /** @var d3TestExport|MockObject $modelMock */ $modelMock = $this->getMockBuilder(d3TestExport::class) ->onlyMethods([ - 'd3GetDb', + 'getConnection', ]) ->getMock(); - $modelMock->expects($this->exactly((int) !$throwsException))->method('d3GetDb')->willReturn($dbMock); + $modelMock->expects($this->exactly((int) !$throwsException))->method('getConnection')->willReturn($connectionMock); $this->_oModel = $modelMock; diff --git a/views/twig/admin/inc/Wizards.html.twig b/views/twig/admin/inc/Wizards.html.twig index 64ae0ec..4a1dbe5 100644 --- a/views/twig/admin/inc/Wizards.html.twig +++ b/views/twig/admin/inc/Wizards.html.twig @@ -90,14 +90,14 @@ {{ shorttext }}...

- ...{{ description|replace(shorttext, '') }} + ...{{ description|replace({shorttext:''}) }}

{% endif %} {% endif %} {% if item.hasFormElements() %} {% for formElement in item.getFormElements() %} - {{ formElement }} + {{ formElement|raw }} {% endfor %} {% endif %}