allow dynamic export types (#703)
This commit is contained in:
committed by
Kevin Papst
parent
ccf4e32523
commit
f0f757cf75
@@ -128,7 +128,7 @@ class ExportController extends AbstractController
|
|||||||
// this code should not be reached, as the query already filters invalid values
|
// this code should not be reached, as the query already filters invalid values
|
||||||
// when trying to call setType() with an unknown value
|
// when trying to call setType() with an unknown value
|
||||||
if (null === $renderer) {
|
if (null === $renderer) {
|
||||||
throw $this->createNotFoundException('Invalid export renderer');
|
throw $this->createNotFoundException('Unknown export renderer');
|
||||||
}
|
}
|
||||||
|
|
||||||
$entries = $this->getEntries($query);
|
$entries = $this->getEntries($query);
|
||||||
|
|||||||
@@ -9,17 +9,8 @@
|
|||||||
|
|
||||||
namespace App\Repository\Query;
|
namespace App\Repository\Query;
|
||||||
|
|
||||||
/**
|
|
||||||
* Can be used for export queries.
|
|
||||||
*/
|
|
||||||
class ExportQuery extends TimesheetQuery
|
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
|
* @var string
|
||||||
*/
|
*/
|
||||||
@@ -39,9 +30,7 @@ class ExportQuery extends TimesheetQuery
|
|||||||
*/
|
*/
|
||||||
public function setType(string $type)
|
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;
|
$this->type = $type;
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ class ExportControllerTest extends ControllerBaseTest
|
|||||||
$response = $client->getResponse();
|
$response = $client->getResponse();
|
||||||
$this->assertFalse($response->isSuccessful());
|
$this->assertFalse($response->isSuccessful());
|
||||||
$this->assertEquals(404, $response->getStatusCode());
|
$this->assertEquals(404, $response->getStatusCode());
|
||||||
|
$this->assertContains('Missing export renderer', $response->getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExportActionWithInvalidRenderer()
|
public function testExportActionWithInvalidRenderer()
|
||||||
@@ -91,6 +92,7 @@ class ExportControllerTest extends ControllerBaseTest
|
|||||||
$response = $client->getResponse();
|
$response = $client->getResponse();
|
||||||
$this->assertFalse($response->isSuccessful());
|
$this->assertFalse($response->isSuccessful());
|
||||||
$this->assertEquals(404, $response->getStatusCode());
|
$this->assertEquals(404, $response->getStatusCode());
|
||||||
|
$this->assertContains('Unknown export renderer', $response->getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExportAction()
|
public function testExportAction()
|
||||||
|
|||||||
@@ -118,14 +118,11 @@ class ExportQueryTest extends BaseQueryTest
|
|||||||
{
|
{
|
||||||
$this->assertNull($sut->getType());
|
$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);
|
$sut->setType($type);
|
||||||
$this->assertEquals($type, $sut->getType());
|
$this->assertEquals($type, $sut->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
$sut->setType('foo');
|
|
||||||
$this->assertEquals('ods', $sut->getType());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user