mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-54623 mod_assign: Fix for unit test
Fix mod_assign_external_testcase::test_list_participants_returns_user_property_types() to avoid using hardcoded user properties.
This commit is contained in:
parent
5684c89b93
commit
920d3a95a1
@ -2313,27 +2313,34 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for the type of the user-related properties in mod_assign_external::list_participants_returns().
|
* Test for the type of the user-related properties in mod_assign_external::list_participants_returns().
|
||||||
*
|
|
||||||
* @throws coding_exception
|
|
||||||
*/
|
*/
|
||||||
public function test_list_participants_returns_user_property_types() {
|
public function test_list_participants_returns_user_property_types() {
|
||||||
// User properties defined in list_participants_returns().
|
// Get user properties.
|
||||||
$userproperties = [
|
$userdesc = core_user_external::user_description();
|
||||||
'id', 'username', 'firstname', 'lastname', 'idnumber', 'email', 'address', 'phone1', 'phone2', 'icq', 'skype', 'yahoo',
|
$this->assertTrue(isset($userdesc->keys));
|
||||||
'aim', 'msn', 'department', 'institution', 'firstaccess', 'lastaccess', 'description', 'descriptionformat', 'city',
|
$userproperties = array_keys($userdesc->keys);
|
||||||
'url', 'country'
|
|
||||||
];
|
// Get returns description for mod_assign_external::list_participants_returns().
|
||||||
$returns = mod_assign_external::list_participants_returns();
|
$listreturns = mod_assign_external::list_participants_returns();
|
||||||
$this->assertTrue(isset($returns->content));
|
$this->assertTrue(isset($listreturns->content));
|
||||||
$keydescs = $returns->content->keys;
|
$listreturnsdesc = $listreturns->content->keys;
|
||||||
// Get properties from returns description.
|
|
||||||
$keys = array_keys($keydescs);
|
// Iterate over list returns description's keys.
|
||||||
foreach ($userproperties as $property) {
|
foreach ($listreturnsdesc as $key => $desc) {
|
||||||
// Assert that the property exists in the returns description.
|
// Check if key exists in user properties and the description has a type attribute.
|
||||||
$this->assertContains($property, $keys);
|
if (in_array($key, $userproperties) && isset($desc->type)) {
|
||||||
|
try {
|
||||||
|
// The core_user::get_property_type() method might throw a coding_exception since
|
||||||
|
// core_user_external::user_description() might contain properties that are not yet included in
|
||||||
|
// core_user's $propertiescache.
|
||||||
|
$propertytype = core_user::get_property_type($key);
|
||||||
|
|
||||||
// Assert that user-related property types match those of the defined in core_user.
|
// Assert that user-related property types match those of the defined in core_user.
|
||||||
$desc = $keydescs[$property];
|
$this->assertEquals($propertytype, $desc->type);
|
||||||
$this->assertEquals(core_user::get_property_type($property), $desc->type);
|
} catch (coding_exception $e) {
|
||||||
|
// All good.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user