From 80d87617f24e9b9c5b1c3b0354d911ddd3c23b39 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 1 Jan 2022 16:21:40 +0100 Subject: [PATCH] Fix migration and test improvements --- ...00000_remove_admin_news_html_privilege.php | 28 +++++++++++++------ .../Controllers/Admin/NewsControllerTest.php | 1 + tests/Unit/HasDatabase.php | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/db/migrations/2021_12_30_000000_remove_admin_news_html_privilege.php b/db/migrations/2021_12_30_000000_remove_admin_news_html_privilege.php index 9250d6c8..29cd7cbc 100644 --- a/db/migrations/2021_12_30_000000_remove_admin_news_html_privilege.php +++ b/db/migrations/2021_12_30_000000_remove_admin_news_html_privilege.php @@ -17,11 +17,11 @@ class RemoveAdminNewsHtmlPrivilege extends Migration $connection = $this->schema->getConnection(); - // Delete unused privileges - $connection->delete(' - DELETE FROM `Privileges` - WHERE `name` = \'admin_news_html\' - '); + // Delete unused privilege + $connection->delete( + 'DELETE FROM `Privileges` WHERE `name` = ?', + ['admin_news_html'] + ); } /** @@ -33,9 +33,19 @@ class RemoveAdminNewsHtmlPrivilege extends Migration return; } - $connection->insert(' - INSERT INTO `Privileges` (`name`, `desc`) - VALUES (\'admin_news_html\', \'Use HTML in news\') - '); + $connection = $this->schema->getConnection(); + $connection->insert( + 'INSERT INTO `Privileges` (`name`, `desc`) VALUES (?, ?)', + ['admin_news_html', 'Use HTML in news'] + ); + + // Add permissions to news admins to edit html news + $connection->insert( + ' + INSERT IGNORE INTO GroupPrivileges (group_id, privilege_id) + VALUES ((SELECT UID FROM `Groups` WHERE `name` = ?), (SELECT id FROM `Privileges` WHERE `name` = ?)) + ', + ['News Admin', 'admin_news_html'] + ); } } diff --git a/tests/Unit/Controllers/Admin/NewsControllerTest.php b/tests/Unit/Controllers/Admin/NewsControllerTest.php index 7a66fae3..48defba4 100644 --- a/tests/Unit/Controllers/Admin/NewsControllerTest.php +++ b/tests/Unit/Controllers/Admin/NewsControllerTest.php @@ -31,6 +31,7 @@ class NewsControllerTest extends ControllerTest /** * @covers \Engelsystem\Controllers\Admin\NewsController::__construct * @covers \Engelsystem\Controllers\Admin\NewsController::edit + * @covers \Engelsystem\Controllers\Admin\NewsController::showEdit */ public function testEdit() { diff --git a/tests/Unit/HasDatabase.php b/tests/Unit/HasDatabase.php index cf9483f3..ee887337 100644 --- a/tests/Unit/HasDatabase.php +++ b/tests/Unit/HasDatabase.php @@ -55,6 +55,7 @@ trait HasDatabase ['migration' => '2020_12_28_000000_oauth_set_identifier_binary'], ['migration' => '2021_08_26_000000_add_shirt_edit_permissions'], ['migration' => '2021_10_12_000000_add_shifts_description'], + ['migration' => '2021_12_30_000000_remove_admin_news_html_privilege'], ] );