allow dynamic export types (#703)

This commit is contained in:
Simone Gasparini
2019-04-25 19:33:06 +02:00
committed by Kevin Papst
parent ccf4e32523
commit f0f757cf75
4 changed files with 6 additions and 18 deletions

View File

@@ -128,7 +128,7 @@ class ExportController extends AbstractController
// this code should not be reached, as the query already filters invalid values
// when trying to call setType() with an unknown value
if (null === $renderer) {
throw $this->createNotFoundException('Invalid export renderer');
throw $this->createNotFoundException('Unknown export renderer');
}
$entries = $this->getEntries($query);

View File

@@ -9,17 +9,8 @@
namespace App\Repository\Query;
/**
* Can be used for export queries.
*/
class ExportQuery extends TimesheetQuery
{
public const TYPE_HTML = 'html';
public const TYPE_CSV = 'csv';
public const TYPE_PDF = 'pdf';
public const TYPE_XLSX = 'xlsx';
public const TYPE_ODS = 'ods';
/**
* @var string
*/
@@ -39,9 +30,7 @@ class ExportQuery extends TimesheetQuery
*/
public function setType(string $type)
{
if (in_array($type, [self::TYPE_PDF, self::TYPE_CSV, self::TYPE_HTML, self::TYPE_XLSX, self::TYPE_ODS])) {
$this->type = $type;
}
return $this;
}

View File

@@ -73,6 +73,7 @@ class ExportControllerTest extends ControllerBaseTest
$response = $client->getResponse();
$this->assertFalse($response->isSuccessful());
$this->assertEquals(404, $response->getStatusCode());
$this->assertContains('Missing export renderer', $response->getContent());
}
public function testExportActionWithInvalidRenderer()
@@ -91,6 +92,7 @@ class ExportControllerTest extends ControllerBaseTest
$response = $client->getResponse();
$this->assertFalse($response->isSuccessful());
$this->assertEquals(404, $response->getStatusCode());
$this->assertContains('Unknown export renderer', $response->getContent());
}
public function testExportAction()

View File

@@ -118,14 +118,11 @@ class ExportQueryTest extends BaseQueryTest
{
$this->assertNull($sut->getType());
$allowed = ['html', 'csv', 'pdf', 'xlsx', 'ods'];
$exportTypes = ['html', 'csv', 'pdf', 'xlsx', 'ods'];
foreach ($allowed as $type) {
foreach ($exportTypes as $type) {
$sut->setType($type);
$this->assertEquals($type, $sut->getType());
}
$sut->setType('foo');
$this->assertEquals('ods', $sut->getType());
}
}