Drop SQLite support (#2405)

This commit is contained in:
Kevin Papst
2021-03-08 16:06:22 +01:00
committed by GitHub
parent 70f7f35009
commit 30ac5e4c24
78 changed files with 1165 additions and 1596 deletions

View File

@@ -31,7 +31,11 @@ class TimesheetControllerTest extends APIControllerBaseTest
public const DATE_FORMAT_HTML5 = 'Y-m-d\TH:i:s';
public const TEST_TIMEZONE = 'Europe/London';
protected function importFixtureForUser(string $role)
/**
* @param string $role
* @return Timesheet[]
*/
protected function importFixtureForUser(string $role): array
{
$fixture = new TimesheetFixtures();
$fixture
@@ -43,7 +47,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
->setStartDate((new \DateTime('first day of this month'))->setTime(0, 0, 1))
;
$this->importFixture($fixture);
return $this->importFixture($fixture);
}
public function testIsSecure()
@@ -300,8 +304,9 @@ class TimesheetControllerTest extends APIControllerBaseTest
->addTag($tag)
;
$em->persist($timesheet);
$em->flush();
$this->assertAccessIsGranted($client, '/api/timesheets/1');
$this->assertAccessIsGranted($client, '/api/timesheets/' . $timesheet->getId());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
@@ -314,7 +319,6 @@ class TimesheetControllerTest extends APIControllerBaseTest
'tags' => [
0 => 'test'
],
'id' => 1,
// make sure the timezone is properly applied in serializer (see #1858)
// minute and second are different from the above datetime object, because of applied default minute rounding
'begin' => '2020-03-27T14:35:00+1300',
@@ -337,16 +341,17 @@ class TimesheetControllerTest extends APIControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_ADMIN);
$timesheets = $this->importFixtureForUser(User::ROLE_ADMIN);
$this->assertCount(10, $timesheets);
$this->assertApiAccessDenied($client, '/api/timesheets/15', 'You are not allowed to view this timesheet');
$this->assertApiAccessDenied($client, '/api/timesheets/' . $timesheets[0]->getId(), 'You are not allowed to view this timesheet');
}
public function testGetEntityAccessAllowedForAdmin()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets/1');
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets/' . $timesheets[0]->getId());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
@@ -355,7 +360,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testGetEntityNotFound()
{
$this->assertEntityNotFound(User::ROLE_USER, '/api/timesheets/20');
$this->assertEntityNotFound(User::ROLE_USER, '/api/timesheets/' . PHP_INT_MAX);
}
public function testPostAction()
@@ -496,7 +501,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
{
$dateTime = new DateTimeFactory(new \DateTimeZone(self::TEST_TIMEZONE));
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$data = [
'activity' => 1,
'project' => 1,
@@ -505,7 +510,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
'description' => 'foo',
'exported' => true,
];
$this->request($client, '/api/timesheets/1', 'PATCH', [], json_encode($data));
$this->request($client, '/api/timesheets/' . $timesheets[0]->getId(), 'PATCH', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
@@ -530,7 +535,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
->setStartDate(new \DateTime('-10 days'))
->setAllowEmptyDescriptions(false)
;
$this->importFixture($fixture);
$timesheets = $this->importFixture($fixture);
$data = [
'activity' => 1,
@@ -540,7 +545,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
'description' => 'foo',
'exported' => true,
];
$this->request($client, '/api/timesheets/15', 'PATCH', [], json_encode($data));
$this->request($client, '/api/timesheets/' . $timesheets[0]->getId(), 'PATCH', [], json_encode($data));
$response = $client->getResponse();
$this->assertFalse($response->isSuccessful());
$this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode());
@@ -556,7 +561,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testInvalidPatchAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$data = [
'activity' => 10,
@@ -565,7 +570,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
'end' => (new \DateTime('- 7 hours'))->format('Y-m-d H:m'),
'description' => 'foo',
];
$this->request($client, '/api/timesheets/1', 'PATCH', [], json_encode($data));
$this->request($client, '/api/timesheets/' . $timesheets[0]->getId(), 'PATCH', [], json_encode($data));
$response = $client->getResponse();
$this->assertEquals(400, $response->getStatusCode());
@@ -577,8 +582,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testDeleteAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets/1');
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets/' . $timesheets[0]->getId());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
@@ -600,11 +605,9 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testDeleteActionForDifferentUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = 1;
$this->request($client, '/api/timesheets/' . $id, 'DELETE');
$this->request($client, '/api/timesheets/' . $timesheets[0]->getId(), 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertEquals(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode());
$this->assertEmpty($client->getResponse()->getContent());
@@ -614,9 +617,9 @@ class TimesheetControllerTest extends APIControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_ADMIN);
$timesheets = $this->importFixtureForUser(User::ROLE_ADMIN);
$this->request($client, '/api/timesheets/15', 'DELETE');
$this->request($client, '/api/timesheets/' . $timesheets[0]->getId(), 'DELETE');
$response = $client->getResponse();
$this->assertFalse($response->isSuccessful());
@@ -632,12 +635,13 @@ class TimesheetControllerTest extends APIControllerBaseTest
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet = $em->getRepository(Timesheet::class)->findAll()[0];
$id = $timesheet->getId();
$timesheet->setExported(true);
$em->persist($timesheet);
$em->flush();
$this->request($client, '/api/timesheets/1', 'DELETE');
$this->request($client, '/api/timesheets/' . $id, 'DELETE');
$this->assertApiResponseAccessDenied($client->getResponse(), 'You are not allowed to delete this timesheet');
}
@@ -648,12 +652,13 @@ class TimesheetControllerTest extends APIControllerBaseTest
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet = $em->getRepository(Timesheet::class)->findAll()[0];
$id = $timesheet->getId();
$timesheet->setExported(true);
$em->persist($timesheet);
$em->flush();
$this->request($client, '/api/timesheets/1', 'DELETE');
$this->request($client, '/api/timesheets/' . $id, 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
}
@@ -731,9 +736,10 @@ class TimesheetControllerTest extends APIControllerBaseTest
->setStartDate($start)
->setAmountRunning(1)
;
$this->importFixture($fixture);
$timesheets = $this->importFixture($fixture);
$id = $timesheets[0]->getId();
$this->request($client, '/api/timesheets/11/stop', 'PATCH');
$this->request($client, '/api/timesheets/' . $id . '/stop', 'PATCH');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
@@ -743,15 +749,16 @@ class TimesheetControllerTest extends APIControllerBaseTest
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet = $em->getRepository(Timesheet::class)->find($id);
$this->assertInstanceOf(\DateTime::class, $timesheet->getEnd());
}
public function testStopActionFailsOnStoppedEntry()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->request($client, '/api/timesheets/1/stop', 'PATCH');
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = $timesheets[0]->getId();
$this->request($client, '/api/timesheets/' . $id . '/stop', 'PATCH');
$this->assertApiException($client->getResponse(), 'Timesheet entry already stopped');
}
@@ -777,9 +784,10 @@ class TimesheetControllerTest extends APIControllerBaseTest
->setStartDate($start)
->setAmountRunning(3)
;
$this->importFixture($fixture);
$timesheets = $this->importFixture($fixture);
$id = $timesheets[3]->getId();
$this->request($client, '/api/timesheets/12/stop', 'PATCH');
$this->request($client, '/api/timesheets/' . $id . '/stop', 'PATCH');
$this->assertApiResponseAccessDenied($client->getResponse(), 'You are not allowed to stop this timesheet');
}
@@ -806,7 +814,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertEquals(5, \count($result));
$this->assertEquals(10, \count($result));
self::assertApiResponseTypeStructure('TimesheetCollection', $result[0]);
$query = ['tags' => 'Test,Admin'];
@@ -831,15 +839,16 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testRestartAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = $timesheets[0]->getId();
$data = [
'description' => 'foo',
'tags' => 'another,testing,bar'
];
$this->request($client, '/api/timesheets/1', 'PATCH', [], json_encode($data));
$this->request($client, '/api/timesheets/' . $id, 'PATCH', [], json_encode($data));
$this->request($client, '/api/timesheets/1/restart', 'PATCH');
$this->request($client, '/api/timesheets/' . $id . '/restart', 'PATCH');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
@@ -861,16 +870,17 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testRestartActionWithBegin()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = $timesheets[0]->getId();
$data = [
'description' => 'foo',
'tags' => 'another,testing,bar'
];
$this->request($client, '/api/timesheets/1', 'PATCH', [], json_encode($data));
$this->request($client, '/api/timesheets/' . $id, 'PATCH', [], json_encode($data));
$begin = new \DateTime('2019-11-27 13:55:00');
$this->request($client, '/api/timesheets/1/restart', 'PATCH', ['begin' => $begin->format(BaseApiController::DATE_FORMAT_PHP)]);
$this->request($client, '/api/timesheets/' . $id . '/restart', 'PATCH', ['begin' => $begin->format(BaseApiController::DATE_FORMAT_PHP)]);
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
@@ -893,11 +903,12 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testRestartActionWithCopyData()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = $timesheets[0]->getId();
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet = $em->getRepository(Timesheet::class)->find($id);
$timesheet->setDescription('foo');
$timesheet->addTag((new Tag())->setName('another'));
$timesheet->addTag((new Tag())->setName('testing'));
@@ -908,10 +919,10 @@ class TimesheetControllerTest extends APIControllerBaseTest
$em->persist($timesheet);
$em->flush();
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet = $em->getRepository(Timesheet::class)->find($id);
$this->assertEquals('foo', $timesheet->getDescription());
$this->request($client, '/api/timesheets/1/restart', 'PATCH', ['copy' => 'all']);
$this->request($client, '/api/timesheets/' . $id . '/restart', 'PATCH', ['copy' => 'all']);
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
@@ -946,9 +957,10 @@ class TimesheetControllerTest extends APIControllerBaseTest
->setStartDate($start)
->setAmountRunning(3)
;
$this->importFixture($fixture);
$timesheets = $this->importFixture($fixture);
$id = $timesheets[0]->getId();
$this->request($client, '/api/timesheets/2/restart', 'PATCH');
$this->request($client, '/api/timesheets/' . $id . '/restart', 'PATCH');
$this->assertApiResponseAccessDenied($client->getResponse(), 'You are not allowed to re-start this timesheet');
}
@@ -999,56 +1011,61 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testExportAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = $timesheets[0]->getId();
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet = $em->getRepository(Timesheet::class)->find($id);
$this->assertFalse($timesheet->isExported());
$this->request($client, '/api/timesheets/1/export', 'PATCH');
$this->request($client, '/api/timesheets/' . $id . '/export', 'PATCH');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
self::assertApiResponseTypeStructure('TimesheetEntity', $result);
$em->clear();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet = $em->getRepository(Timesheet::class)->find($id);
$this->assertTrue($timesheet->isExported());
$this->request($client, '/api/timesheets/1/export', 'PATCH');
$this->request($client, '/api/timesheets/' . $id . '/export', 'PATCH');
$this->assertTrue($client->getResponse()->isSuccessful());
$em->clear();
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet = $em->getRepository(Timesheet::class)->find($id);
$this->assertFalse($timesheet->isExported());
}
public function testExportNotAllowedForUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = $timesheets[0]->getId();
$this->request($client, '/api/timesheets/1/export', 'PATCH');
$this->request($client, '/api/timesheets/' . $id . '/export', 'PATCH');
$this->assertApiResponseAccessDenied($client->getResponse(), 'You are not allowed to lock this timesheet');
}
public function testExportThrowsNotFound()
{
$this->assertEntityNotFoundForPatch(User::ROLE_ADMIN, '/api/timesheets/42/export', []);
$id = PHP_INT_MAX;
$this->assertEntityNotFoundForPatch(User::ROLE_ADMIN, '/api/timesheets/' . $id . '/export', []);
}
public function testMetaActionThrowsNotFound()
{
$this->assertEntityNotFoundForPatch(User::ROLE_ADMIN, '/api/timesheets/42/meta', []);
$id = PHP_INT_MAX;
$this->assertEntityNotFoundForPatch(User::ROLE_ADMIN, '/api/timesheets/' . $id . '/meta', []);
}
public function testMetaActionThrowsExceptionOnMissingName()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = $timesheets[0]->getId();
return $this->assertExceptionForMethod($client, '/api/timesheets/1/meta', 'PATCH', ['value' => 'X'], [
return $this->assertExceptionForMethod($client, '/api/timesheets/' . $id . '/meta', 'PATCH', ['value' => 'X'], [
'code' => 400,
'message' => 'Parameter "name" of value "NULL" violated a constraint "This value should not be null."'
]);
@@ -1057,9 +1074,10 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testMetaActionThrowsExceptionOnMissingValue()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = $timesheets[0]->getId();
return $this->assertExceptionForMethod($client, '/api/timesheets/1/meta', 'PATCH', ['name' => 'X'], [
return $this->assertExceptionForMethod($client, '/api/timesheets/' . $id . '/meta', 'PATCH', ['name' => 'X'], [
'code' => 400,
'message' => 'Parameter "value" of value "NULL" violated a constraint "This value should not be null."'
]);
@@ -1068,9 +1086,10 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testMetaActionThrowsExceptionOnMissingMetafield()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = $timesheets[0]->getId();
return $this->assertExceptionForMethod($client, '/api/timesheets/1/meta', 'PATCH', ['name' => 'X', 'value' => 'Y'], [
return $this->assertExceptionForMethod($client, '/api/timesheets/' . $id . '/meta', 'PATCH', ['name' => 'X', 'value' => 'Y'], [
'code' => 500,
'message' => 'Unknown meta-field requested'
]);
@@ -1079,14 +1098,15 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testMetaAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$timesheets = $this->importFixtureForUser(User::ROLE_USER);
$id = $timesheets[0]->getId();
static::$container->get('event_dispatcher')->addSubscriber(new TimesheetTestMetaFieldSubscriberMock());
$data = [
'name' => 'metatestmock',
'value' => 'another,testing,bar'
];
$this->request($client, '/api/timesheets/1/meta', 'PATCH', [], json_encode($data));
$this->request($client, '/api/timesheets/' . $id . '/meta', 'PATCH', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -1096,7 +1116,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet = $em->getRepository(Timesheet::class)->find($id);
$this->assertEquals('another,testing,bar', $timesheet->getMetaField('metatestmock')->getValue());
}
}