improved tag auto-completion and added tag management (#1083)

This commit is contained in:
Kevin Papst
2019-09-04 23:47:33 +02:00
committed by GitHub
parent 3ea05cb705
commit d041a3f4f9
25 changed files with 368 additions and 17 deletions

View File

@@ -55,6 +55,35 @@ class TagControllerTest extends APIControllerBaseTest
$this->assertEquals(0, count($result));
}
public function testPostAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'name' => 'foo',
];
$this->request($client, '/api/tags', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertStructure($result);
$this->assertNotEmpty($result['id']);
}
public function testPostActionWithInvalidUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$data = [
'name' => 'foo',
];
$this->request($client, '/api/tags', 'POST', [], json_encode($data));
$response = $client->getResponse();
$this->assertFalse($response->isSuccessful());
$this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode());
$json = json_decode($response->getContent(), true);
$this->assertEquals('User cannot create tags', $json['message']);
}
public function testPartOfEntries()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
@@ -90,4 +119,21 @@ class TagControllerTest extends APIControllerBaseTest
{
$this->assertEntityNotFoundForDelete(User::ROLE_ADMIN, '/api/tags/255', []);
}
protected function assertStructure(array $result, $full = true)
{
$expectedKeys = [
'id', 'name', 'timesheets'
];
if ($full) {
$expectedKeys = array_merge($expectedKeys, []);
}
$actual = array_keys($result);
sort($actual);
sort($expectedKeys);
$this->assertEquals($expectedKeys, $actual, 'Tag structure does not match');
}
}

View File

@@ -60,4 +60,39 @@ class TagControllerTest extends ControllerBaseTest
$this->assertHasDataTable($client);
$this->assertDataTableRowCount($client, 'datatable_admin_tags', 2);
}
public function testCreateAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/tags/create');
$form = $client->getCrawler()->filter('form[name=tag_edit_form]')->form();
$client->submit($form, [
'tag_edit_form' => [
'name' => 'A tAG Name!',
]
]);
$this->assertIsRedirect($client, $this->createUrl('/admin/tags/'));
$client->followRedirect();
$this->assertHasDataTable($client);
$this->request($client, '/admin/tags/11/edit');
$editForm = $client->getCrawler()->filter('form[name=tag_edit_form]')->form();
$this->assertEquals('A tAG Name!', $editForm->get('tag_edit_form[name]')->getValue());
}
public function testEditAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/tags/1/edit');
$form = $client->getCrawler()->filter('form[name=tag_edit_form]')->form();
$client->submit($form, [
'tag_edit_form' => ['name' => 'Test 2 updated']
]);
$this->assertIsRedirect($client, $this->createUrl('/admin/tags/'));
$client->followRedirect();
$this->assertHasDataTable($client);
$this->request($client, '/admin/tags/1/edit');
$editForm = $client->getCrawler()->filter('form[name=tag_edit_form]')->form();
$this->assertEquals('Test 2 updated', $editForm->get('tag_edit_form[name]')->getValue());
}
}

View File

@@ -231,6 +231,6 @@ class UserControllerTest extends ControllerBaseTest
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
$this->assertAccessIsGranted($client, '/admin/user/permissions');
$this->assertHasDataTable($client);
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 80);
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 81);
}
}

View File

@@ -117,6 +117,7 @@ class AppExtensionTest extends TestCase
'title' => null,
],
'auto_reload_datatable' => false,
'autocomplete_chars' => 3,
],
'kimai.theme.select_type' => null,
'kimai.theme.show_about' => true,