extract content rendering into separate method
Cette révision appartient à :
Parent
744efd5d59
révision
532e5f6960
@ -224,9 +224,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();
|
||||
@ -259,4 +257,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;
|
||||
}
|
||||
}
|
@ -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']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Chargement…
Référencer dans un nouveau ticket
Block a user