| Línea 27... |
Línea 27... |
| 27 |
* @package core_user
|
27 |
* @package core_user
|
| 28 |
* @category test
|
28 |
* @category test
|
| 29 |
* @copyright 2013 Adrian Greeve <adrian@moodle.com>
|
29 |
* @copyright 2013 Adrian Greeve <adrian@moodle.com>
|
| 30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 31 |
*/
|
31 |
*/
|
| 32 |
class editlib_test extends \advanced_testcase {
|
32 |
final class editlib_test extends \advanced_testcase {
|
| Línea 33... |
Línea 33... |
| 33 |
|
33 |
|
| 34 |
/**
|
34 |
/**
|
| 35 |
* Test that the required fields are returned in the correct order.
|
35 |
* Test that the required fields are returned in the correct order.
|
| 36 |
*/
|
36 |
*/
|
| Línea 107... |
Línea 107... |
| 107 |
$this->assertEquals(useredit_get_disabled_name_fields(), $expectedresult);
|
107 |
$this->assertEquals(useredit_get_disabled_name_fields(), $expectedresult);
|
| Línea 108... |
Línea 108... |
| 108 |
|
108 |
|
| 109 |
// Tidy up after we finish testing.
|
109 |
// Tidy up after we finish testing.
|
| 110 |
$CFG->fullnamedisplay = $originalcfg->fullnamedisplay;
|
110 |
$CFG->fullnamedisplay = $originalcfg->fullnamedisplay;
|
| - |
|
111 |
}
|
| - |
|
112 |
|
| - |
|
113 |
/**
|
| - |
|
114 |
* Provider for test_useredit_update_user_preference
|
| - |
|
115 |
*
|
| - |
|
116 |
* @return array
|
| - |
|
117 |
*/
|
| - |
|
118 |
public static function useredit_update_user_preference_provider(): array {
|
| - |
|
119 |
return [
|
| - |
|
120 |
'Homepage fixed' => [HOMEPAGE_SITE, [], HOMEPAGE_MYCOURSES, null],
|
| - |
|
121 |
'Simple user pref' => [HOMEPAGE_USER, [], HOMEPAGE_MYCOURSES, (string)HOMEPAGE_MYCOURSES],
|
| - |
|
122 |
'Extra option' => [HOMEPAGE_USER, ['/helloworld'], '/helloworld', '/helloworld'],
|
| - |
|
123 |
'Invalid option' => [HOMEPAGE_USER, [], '/helloworld', (string)HOMEPAGE_MY],
|
| - |
|
124 |
];
|
| - |
|
125 |
}
|
| - |
|
126 |
|
| - |
|
127 |
/**
|
| - |
|
128 |
* Tests for function useredit_update_user_preference
|
| - |
|
129 |
*
|
| - |
|
130 |
* @dataProvider useredit_update_user_preference_provider
|
| - |
|
131 |
* @covers ::useredit_update_user_preference
|
| - |
|
132 |
* @param int $defaulthomepage to be set as the default homepage
|
| - |
|
133 |
* @param array $extraoptions additional options for the pref value that are added in the hook callbacks
|
| - |
|
134 |
* @param int|string $setting what we are trying to set as a user preference
|
| - |
|
135 |
* @param string|null $expected what will be actually set in the user preference
|
| - |
|
136 |
*/
|
| - |
|
137 |
public function test_useredit_update_user_preference(int $defaulthomepage, array $extraoptions,
|
| - |
|
138 |
$setting, ?string $expected): void {
|
| - |
|
139 |
global $DB, $CFG, $USER;
|
| - |
|
140 |
$this->resetAfterTest();
|
| - |
|
141 |
$user = $this->getDataGenerator()->create_user();
|
| - |
|
142 |
$this->setUser($user);
|
| - |
|
143 |
|
| - |
|
144 |
if ($extraoptions) {
|
| - |
|
145 |
// Pretend we have hook callbacks adding extra allowed options.
|
| - |
|
146 |
$testcallback = function(\core_user\hook\extend_default_homepage $hook) use ($extraoptions) {
|
| - |
|
147 |
foreach ($extraoptions as $localurl) {
|
| - |
|
148 |
$hook->add_option(new \moodle_url($localurl), new \lang_string('yes'));
|
| - |
|
149 |
}
|
| - |
|
150 |
};
|
| - |
|
151 |
$this->redirectHook(\core_user\hook\extend_default_homepage::class, $testcallback);
|
| - |
|
152 |
}
|
| - |
|
153 |
|
| - |
|
154 |
set_config('defaulthomepage', $defaulthomepage);
|
| - |
|
155 |
useredit_update_user_preference([
|
| - |
|
156 |
'id' => $user->id,
|
| - |
|
157 |
'preference_user_home_page_preference' => $setting,
|
| - |
|
158 |
]);
|
| - |
|
159 |
|
| - |
|
160 |
// Ensure user preference returns expected value.
|
| - |
|
161 |
$preference = get_user_preferences('user_home_page_preference', null, $user);
|
| - |
|
162 |
$this->assertSame($expected, $preference);
|
| 111 |
}
|
163 |
}
|