Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/blocks/online_users/tests/generator/lib.php

    r136 r1331  
    3838
    3939    /**
    40      * Create new block instance
    41      * @param array|stdClass $record
    42      * @param array $options
    43      * @return stdClass activity record with extra cmid field
     40     * Create (simulated) logged in users and add some of them to groups in a course
    4441     */
    45     public function create_instance($record = null, array $options = null) {
    46         global $DB, $CFG;
    47         require_once("$CFG->dirroot/mod/page/locallib.php");
     42    public function create_logged_in_users() {
     43        global $DB;
    4844
    49         $this->instancecount++;
     45        $generator = advanced_testcase::getDataGenerator();
     46        $data = array();
    5047
    51         $record = (object)(array)$record;
    52         $options = (array)$options;
     48        // Create 2 courses.
     49        $course1 = $generator->create_course();
     50        $data['course1'] = $course1;
     51        $course2 = $generator->create_course();
     52        $data['course2'] = $course2;
    5353
    54         $record = $this->prepare_record($record);
     54        // Create 9 (simulated) logged in users enroled into $course1.
     55        for ($i = 1; $i <= 9; $i++) {
     56            $user = $generator->create_user();
     57            $DB->set_field('user', 'lastaccess', time(), array('id' => $user->id));
     58            $generator->enrol_user($user->id, $course1->id);
     59            $DB->insert_record('user_lastaccess', array('userid' => $user->id, 'courseid' => $course1->id, 'timeaccess' => time()));
     60            $data['user' . $i] = $user;
     61        }
     62        // Create 3 (simulated) logged in users who are not enroled into $course1.
     63        for ($i = 10; $i <= 12; $i++) {
     64            $user = $generator->create_user();
     65            $DB->set_field('user', 'lastaccess', time(), array('id' => $user->id));
     66            $data['user' . $i] = $user;
     67        }
    5568
    56         $id = $DB->insert_record('block_instances', $record);
    57         context_block::instance($id);
     69        // Create 3 groups in course 1.
     70        $group1 = $generator->create_group(array('courseid' => $course1->id));
     71        $data['group1'] = $group1;
     72        $group2 = $generator->create_group(array('courseid' => $course1->id));
     73        $data['group2'] = $group2;
     74        $group3 = $generator->create_group(array('courseid' => $course1->id));
     75        $data['group3'] = $group3;
    5876
    59         $instance = $DB->get_record('block_instances', array('id'=>$id), '*', MUST_EXIST);
     77        // Add 3 users to course group 1.
     78        $generator->create_group_member(array('groupid' => $group1->id, 'userid' => $data['user1']->id));
     79        $generator->create_group_member(array('groupid' => $group1->id, 'userid' => $data['user2']->id));
     80        $generator->create_group_member(array('groupid' => $group1->id, 'userid' => $data['user3']->id));
    6081
    61         return $instance;
     82        // Add 4 users to course group 2.
     83        $generator->create_group_member(array('groupid' => $group2->id, 'userid' => $data['user3']->id));
     84        $generator->create_group_member(array('groupid' => $group2->id, 'userid' => $data['user4']->id));
     85        $generator->create_group_member(array('groupid' => $group2->id, 'userid' => $data['user5']->id));
     86        $generator->create_group_member(array('groupid' => $group2->id, 'userid' => $data['user6']->id));
     87
     88        return $data; // Return the user, course and group objects.
    6289    }
    6390}
Note: See TracChangeset for help on using the changeset viewer.