From f40cb29765c35b580300b54d02c58a48fb3e2d4a Mon Sep 17 00:00:00 2001 From: Markus Heck Date: Mon, 27 Jan 2025 14:42:55 +0100 Subject: [PATCH] create users for automated tests in integration_test profile --- README.md | 10 ++++++---- classes/playbook.php | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1cbcfcd..6f38341 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,15 @@ This playbook configures a moodle instance with AdLer. The following roles are available: -- test_users: Creates test users +- test_users: Creates test users for manual use - moodle_dev_env: For moodle development (don't install plugins) -- integration_test: For integration and end-to-end tests (activate mobile services) +- integration_test: For integration and end-to-end tests (activate mobile services, create test users for automated tests) The following environment variables are used: -- DECLARATIVE_SETUP_MANAGER_PASSWORD: Password for the manager user -- DECLARATIVE_SETUP_STUDENT_PASSWORD: Password for the student user +- DECLARATIVE_SETUP_MANAGER_PASSWORD: Password for the manager user (role: test_users) +- DECLARATIVE_SETUP_STUDENT_PASSWORD: Password for the student user (role: test_users) +- DECLERATIVE_SETUP_INTEGRATION_TEST_MANAGER_PASSWORD: Password for the integration test manager user (role: integration_test) +- DECLERATIVE_SETUP_INTEGRATION_TEST_STUDENT_PASSWORD: Password for the integration test student user (role: integration_test) ## files/plugins.json This file is required if `moodle_dev_env` role is not used. Get the current version from diff --git a/classes/playbook.php b/classes/playbook.php index 634aa9a..6672c94 100644 --- a/classes/playbook.php +++ b/classes/playbook.php @@ -113,6 +113,30 @@ protected function playbook_implementation(): void { )); $play->play(); + if ($this->has_role('integration_test')) { + // Create test users + $play = new user(new user_model( + 'manager', + $this->get_environment_variable('INTEGRATION_TEST_MANAGER_PASSWORD'), + )); + $play->play(); + $play = new user(new user_model( + 'student', + $this->get_environment_variable('INTEGRATION_TEST_STUDENT_PASSWORD'), + )); + $play->play(); + + // create adler course category for test users + $play = new course_category(new course_category_model( + '/adler/integration_test', + users: [ + new role_user_model('integration_test_manager', ['adler_manager']), + new role_user_model('integration_test_student', []), + ], + )); + $play->play(); + } + if ($this->has_role('test_users')) { // Create test users $play = new user(new user_model(