Exemplo n.º 1
0
    /**
     * Adapter to enrol_user() data generator.
     * @throws Exception
     * @param array $data
     * @return void
     */
    protected function process_enrol_user($data) {
        global $SITE;

        if (empty($data['roleid'])) {
            throw new Exception('\'course enrolments\' requires the field \'role\' to be specified');
        }

        if (!isset($data['userid'])) {
            throw new Exception('\'course enrolments\' requires the field \'user\' to be specified');
        }

        if (!isset($data['courseid'])) {
            throw new Exception('\'course enrolments\' requires the field \'course\' to be specified');
        }

        if (!isset($data['enrol'])) {
            $data['enrol'] = 'manual';
        }

        // If the provided course shortname is the site shortname we consider it a system role assign.
        if ($data['courseid'] == $SITE->id) {
            // Frontpage course assign.
            $context = context_course::instance($data['courseid']);
            role_assign($data['roleid'], $data['userid'], $context->id);

        } else {
            // Course assign.
            $this->datagenerator->enrol_user($data['userid'], $data['courseid'], $data['roleid'], $data['enrol']);
        }

    }
Exemplo n.º 2
0
 /**
  * Returns a user object and its assigned new role.
  *
  * @param testing_data_generator $generator
  * @param $contextid
  * @return array The user object and the role ID
  */
 protected function get_user_objects(testing_data_generator $generator, $contextid)
 {
     global $USER;
     if (empty($USER->id)) {
         $user = $generator->create_user();
         $this->setUser($user);
     }
     $roleid = create_role('Test role', 'testrole', 'Test role description');
     if (!is_array($contextid)) {
         $contextid = array($contextid);
     }
     foreach ($contextid as $cid) {
         $assignid = role_assign($roleid, $user->id, $cid);
     }
     return array($user, $roleid);
 }
 /**
  * Creates a role.
  *
  * @param array $data
  * @return void
  */
 protected function process_role($data)
 {
     // We require the user to fill the role shortname.
     if (empty($data['shortname'])) {
         throw new Exception('\'role\' requires the field \'shortname\' to be specified');
     }
     $this->datagenerator->create_role($data);
 }
Exemplo n.º 4
0
 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . DIRECTORY_SEPARATOR . "testing" . DIRECTORY_SEPARATOR . "generator" . DIRECTORY_SEPARATOR . "data_generator.php";
     $generator = new \testing_data_generator();
     $options = $this->expandedOptions;
     $arguments = $this->arguments;
     //don't create if already exists
     $role = $DB->get_record('role', array('shortname' => $arguments[0]));
     if ($role) {
         echo "Role '" . $arguments[0] . "' already exists!\n";
         exit(0);
     }
     $options['shortname'] = $arguments[0];
     $newroleid = $generator->create_role($options);
     echo "{$newroleid}\n";
 }
 /**
  * Create a question.
  *
  * Creating questions relies on the question/type/.../tests/helper.php mechanism.
  * We start with test_question_maker::get_question_form_data($data['qtype'], $data['template'])
  * and then overlay the values from any other fields of $data that are set.
  *
  * @param array $data the row of data from the behat script.
  */
 protected function process_question($data)
 {
     if (array_key_exists('questiontext', $data)) {
         $data['questiontext'] = array('text' => $data['questiontext'], 'format' => FORMAT_HTML);
     }
     if (array_key_exists('generalfeedback', $data)) {
         $data['generalfeedback'] = array('text' => $data['generalfeedback'], 'format' => FORMAT_HTML);
     }
     $which = null;
     if (!empty($data['template'])) {
         $which = $data['template'];
     }
     $this->datagenerator->get_plugin_generator('core_question')->create_question($data['qtype'], $which, $data);
 }
 /**
  * Assigns a role to a user at the specified context
  *
  * @throws Exception
  * @param array $data
  * @return void
  */
 protected function process_role_assign($data)
 {
     if (empty($data['roleid'])) {
         throw new Exception('\'role assigns\' requires the field \'role\' to be specified');
     }
     if (!isset($data['userid'])) {
         throw new Exception('\'role assigns\' requires the field \'user\' to be specified');
     }
     if (empty($data['contextlevel'])) {
         throw new Exception('\'role assigns\' requires the field \'contextlevel\' to be specified');
     }
     if (!isset($data['reference'])) {
         throw new Exception('\'role assigns\' requires the field \'reference\' to be specified');
     }
     // Getting the context id.
     $context = $this->get_context($data['contextlevel'], $data['reference']);
     $this->datagenerator->role_assign($data['roleid'], $data['userid'], $context->id);
 }
Exemplo n.º 7
0
cron_setup_user();
// Enable the Web Services.
set_config('enablewebservices', 1);
// Enable Web Services documentation.
set_config('enablewsdocumentation', 1);
// Enable each protocol.
set_config('webserviceprotocols', 'amf,rest,soap,xmlrpc');
// Create the Web Service user.
$user = $DB->get_record('user', array('username' => 'testtete'));
if (!$user) {
    $user = new stdClass();
    $user->username = '******';
    $user->firstname = 'Web';
    $user->lastname = 'Service';
    $user->password = '******';
    $dg = new testing_data_generator();
    $user = $dg->create_user($user);
}
// Create a role for Web Services with all permissions.
if (!($roleid = $DB->get_field('role', 'id', array('shortname' => 'testtete')))) {
    $roleid = create_role('Web Service', 'testtete', 'MDK: All permissions given by default.', '');
}
$context = context_system::instance();
set_role_contextlevels($roleid, array($context->contextlevel));
role_assign($roleid, $user->id, $context->id);
if (method_exists($context, 'get_capabilities')) {
    $capabilities = $context->get_capabilities();
} else {
    $capabilities = fetch_context_capabilities($context);
}
foreach ($capabilities as $capability) {