8
0

extract content rendering into separate method

Dieser Commit ist enthalten in:
Daniel Seifert 2021-12-21 13:27:19 +01:00
Ursprung 69bf942608
Commit e05278da19
Signiert von: DanielS
GPG-Schlüssel-ID: 8A7C4C6ED1915C6F
2 geänderte Dateien mit 51 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -225,9 +225,7 @@ abstract class ExportBase implements QueryBase
*/
protected function executeExport(string $format, $path): string
{
[$rows, $fieldNames] = $this->getExportData($this->getQuery());
$content = $this->renderContent($rows, $fieldNames, $format);
$content = $this->getContent( $format );
/** @var $oFS d3filesystem */
$oFS = $this->getFileSystem();
@ -260,4 +258,21 @@ abstract class ExportBase implements QueryBase
{
return oxNew(d3filesystem::class);
}
/**
* @param string $format
*
* @return string
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws Exceptions\NoSuitableRendererException
*/
public function getContent( string $format ): string
{
[ $rows, $fieldNames ] = $this->getExportData( $this->getQuery() );
$content = $this->renderContent( $rows, $fieldNames, $format );
return $content;
}
}

Datei anzeigen

@ -285,16 +285,12 @@ class ExportBaseTest extends d3ModCfgUnitTestCase
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'getQuery',
'getExportData',
'renderContent',
'getContent',
'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('getContent')->willReturn('some content');
$modelMock->expects($this->atLeastOnce())->method('getFileSystem')->willReturn($fsMock);
$modelMock->expects($this->atLeastOnce())->method('getExportFileName')->willReturn('exportFileName');
@ -604,4 +600,35 @@ class ExportBaseTest extends d3ModCfgUnitTestCase
'fulfilled SELECT' => [' SELECT 1', false, [['field1' => 'content1', 'field2' => 'content2']]],
];
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getContent
* @test
* @throws ReflectionException
*/
public function canGetContent()
{
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'getQuery',
'getExportData',
'renderContent'
])
->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');
$this->_oModel = $modelMock;
$this->assertSame(
'some content',
$this->callMethod(
$this->_oModel,
'getContent',
['CSV']
)
);
}
}