From 880aff7bf9c1c8422171d40d64bdf88d87c27d84 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Wed, 24 Mar 2021 11:39:01 +0100 Subject: [PATCH] MDL-71051 core_user: move edit profile category form to classes --- .../form/profile_category_form.php} | 7 +++++-- user/profile/definelib.php | 5 ++--- user/profile/field/social/tests/privacy_test.php | 6 +++--- user/tests/profilelib_test.php | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) rename user/{profile/index_category_form.php => classes/form/profile_category_form.php} (97%) diff --git a/user/profile/index_category_form.php b/user/classes/form/profile_category_form.php similarity index 97% rename from user/profile/index_category_form.php rename to user/classes/form/profile_category_form.php index 551e7fb2879..ffc07073aa0 100644 --- a/user/profile/index_category_form.php +++ b/user/classes/form/profile_category_form.php @@ -22,6 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace core_user\form; + +use moodleform; + if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. } @@ -34,7 +38,7 @@ require_once($CFG->dirroot.'/lib/formslib.php'); * @copyright 2007 onwards Shane Elliot {@link http://pukunui.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class category_form extends moodleform { +class profile_category_form extends moodleform { /** * Define the form. @@ -92,4 +96,3 @@ class category_form extends moodleform { } } - diff --git a/user/profile/definelib.php b/user/profile/definelib.php index c50bffeb1a6..ef024d6bb55 100644 --- a/user/profile/definelib.php +++ b/user/profile/definelib.php @@ -492,10 +492,9 @@ function profile_list_categories() { * @param string $redirect */ function profile_edit_category($id, $redirect) { - global $DB, $OUTPUT, $CFG; + global $DB, $OUTPUT; - require_once($CFG->dirroot.'/user/profile/index_category_form.php'); - $categoryform = new category_form(); + $categoryform = new \core_user\form\profile_category_form(); if ($category = $DB->get_record('user_info_category', array('id' => $id))) { $categoryform->set_data($category); diff --git a/user/profile/field/social/tests/privacy_test.php b/user/profile/field/social/tests/privacy_test.php index bc6707cd2c6..38bd287fa42 100644 --- a/user/profile/field/social/tests/privacy_test.php +++ b/user/profile/field/social/tests/privacy_test.php @@ -290,9 +290,9 @@ class profilefield_social_testcase extends provider_testcase { private function add_profile_field($categoryid, $datatype) { $data = $this->getDataGenerator()->create_custom_profile_field([ 'datatype' => $datatype, - 'shortname' => 'tstField', - 'name' => 'Test field', - 'description' => 'This is a test.', + 'shortname' => 'icq', + 'name' => 'icq', + 'description' => '', 'categoryid' => $categoryid, ]); return $data->id; diff --git a/user/tests/profilelib_test.php b/user/tests/profilelib_test.php index cbfea7cb0ae..77da39879f1 100644 --- a/user/tests/profilelib_test.php +++ b/user/tests/profilelib_test.php @@ -222,7 +222,7 @@ class core_user_profilelib_testcase extends advanced_testcase { // Add a required, visible, unlocked custom field. $this->getDataGenerator()->create_custom_profile_field(['shortname' => 'house', 'name' => 'House', 'required' => 1, - 'visible' => 1, 'locked' => 0, 'datatype' => 'text', 'default' => null]); + 'visible' => 1, 'locked' => 0, 'datatype' => 'text', 'defaultdata' => null]); // Create some student accounts. $hermione = $this->getDataGenerator()->create_user(['profile_field_house' => 'Gryffindor']);