I'am in trouble with unity test and archetype and Adobe Connect , userlib_test.php return error because it do not accep archetype empty in role table.
See informations below :
1 - Creating role in Moodle
in lib/accesslib.php
/**
* Function that creates a role
*
* @param string $name role name
* @param string $shortname role short name
* @param string $description role description
* @param string $archetype
* @return int id or dml_exception
*/
function create_role($name, $shortname, $description, $archetype = '')
[.....]
// verify role archetype actually exists
$archetypes = get_role_archetypes();
if (empty($archetypes[$archetype])) {
$archetype = '';
}
- archetypes are harcoded and returned by get_role_archetypes(), i propose to modify comment to help developpers:
@param string $archetype - one of an archetype existing in system see // get_role_archetypes()
2 - Adobe Connect - creating role
in /mod/adobeconnect/db/install.php
if ($rid = create_role(get_string('adobeconnectpresenter', 'adobeconnect'), 'adobeconnectpresenter', get_string('adobeconnectpresenterdescription', 'adobeconnect'), 'adobeconnectpresenter')) {
$mrole = new stdClass();
$mrole->id = $rid;
$result = $result && assign_capability('mod/adobeconnect:meetingpresenter', CAP_ALLOW, $mrole->id, $sysctx->id);
set_role_contextlevels($mrole->id, $levels);
} else {
$result = false;
}
- plugin use create_role function but give an param (archetype) not kowns by system, in result an record with empty archetype column in role table
3 - PHPUnit
in user/tests/userlib_test.php
$allroles = $DB->get_records_menu('role', array(), 'id', 'archetype, id');
- i think it's wrong way, system can't return list role base on archetype because it do not accept new archetype :
- if it's madatory to use archetype, add function to clean result to delete empty entries cause by empty archetypes
- or modify $allrole to use shortname instead of archetypes to cover all role in system including new and 8 hardcoded
$allroles = $DB->get_records_menu('role', array(), 'id', 'shortname, id');
This is two ways to get better unity test, i think because i my first months with Moodle. I'am not sure if my proposition is good, any ideas ?