示例#1
0
    public function setUp() {
        parent::setUp();

        $this->switch_to_test_db(); // Switch to test DB for all the execution

        foreach ($this->testtables as $dir => $tables) {
            $this->create_test_tables($tables, $dir); // Create tables
        }
    }
示例#2
0
 public function setUp()
 {
     parent::setUp();
     $this->create_test_tables(array('course', 'groups', 'context', 'user', 'modules', 'course_modules', 'post', 'tag'), 'lib');
     $this->switch_to_test_db();
     // Create default course
     $course = new stdClass();
     $course->category = 1;
     $course->fullname = 'Anonymous test course';
     $course->shortname = 'ANON';
     $course->summary = '';
     $course->id = $this->testdb->insert_record('course', $course);
     // Create default group
     $group = new stdClass();
     $group->courseid = $course->id;
     $group->name = 'ANON';
     $group->id = $this->testdb->insert_record('groups', $group);
     // Create required contexts
     $contexts = array(CONTEXT_SYSTEM => 1, CONTEXT_COURSE => $course->id, CONTEXT_MODULE => 1);
     foreach ($contexts as $level => $instance) {
         $context = new stdClass();
         $context->contextlevel = $level;
         $context->instanceid = $instance;
         $context->path = 'not initialised';
         $context->depth = '13';
         $this->testdb->insert_record('context', $context);
     }
     // Create default user
     $user = new stdClass();
     $user->username = '******';
     $user->confirmed = 1;
     $user->firstname = 'Jimmy';
     $user->lastname = 'Kinnon';
     $user->id = $this->testdb->insert_record('user', $user);
     // Create default tag
     $tag = new stdClass();
     $tag->userid = $user->id;
     $tag->name = 'testtagname';
     $tag->rawname = 'Testtagname';
     $tag->tagtype = 'official';
     $tag->id = $this->testdb->insert_record('tag', $tag);
     // Create default post
     $post = new stdClass();
     $post->userid = $user->id;
     $post->groupid = $group->id;
     $post->content = 'test post content text';
     $post->id = $this->testdb->insert_record('post', $post);
     // Grab important ids
     $this->courseid = $course->id;
     $this->groupid = $group->id;
     $this->userid = $user->id;
     $this->tagid = $tag->id;
 }
 public function setUp()
 {
     parent::setUp();
     $this->switch_to_test_db();
     // Switch to test DB for all the execution
     foreach ($this->testtables as $dir => $tables) {
         $this->create_test_tables($tables, $dir);
         // Create tables
     }
     $this->contextid = 666;
     // Let's assume this is the context for the forum
     $this->fill_records();
     // Add common stuff needed by various test methods
 }
示例#4
0
 public function setUp()
 {
     global $CFG;
     parent::setUp();
     $this->oldcfg = clone $CFG;
     $CFG->enableavailability = true;
     $CFG->enablecompletion = true;
     $this->switch_to_test_db();
     // All operations until end of test method will happen in test DB
     foreach ($this->conditionlib_tables as $dir => $tables) {
         $this->create_test_tables($tables, $dir);
         // Create tables
     }
     $this->fill_records();
     // Add common stuff needed by various test methods
 }
示例#5
0
    public function setUp() {
        global $CFG;
        parent::setUp();

        // Make sure accesslib has cached a sensible system context object
        // before we switch to the test DB.
        $this->syscontext = get_context_instance(CONTEXT_SYSTEM);

        foreach ($this->testtables as $dir => $tables) {
            $this->create_test_tables($tables, $dir); // Create tables
        }

        $this->switch_to_test_db(); // Switch to test DB for all the execution

        $this->fill_records();

        // Ignore any frontpageroleid, that would require to crete more contexts
        $this->originaldefaultfrontpageroleid = $CFG->defaultfrontpageroleid;
        $CFG->defaultfrontpageroleid = null;
    }
示例#6
0
    public function setUp() {
        global $CFG;
        parent::setUp();

        foreach ($this->testtables as $dir => $tables) {
            $this->create_test_tables($tables, $dir); // Create tables
        }

        $this->switch_to_test_db(); // Switch to test DB for all the execution

        // Nasty hack, recreate the system context record (the accesslib API does not allow to create it easily)
        $this->create_system_context_record();
        // Reset all caches
        accesslib_clear_all_caches_for_unit_testing();

        $this->syscontext = get_context_instance(CONTEXT_SYSTEM);

        $this->fill_records();

        // Ignore any frontpageroleid, that would require to crete more contexts
        $this->originaldefaultfrontpageroleid = $CFG->defaultfrontpageroleid;
        $CFG->defaultfrontpageroleid = null;
    }
示例#7
0
 /**
  * Setup the DB fixture data
  */
 public function setup()
 {
     parent::setUp();
     $tables = array('block_instance', 'cache_flags', 'capabilities', 'context', 'context_temp', 'course', 'course_modules', 'course_categories', 'course_sections', 'files', 'files_cleanup', 'grade_items', 'grade_categories', 'groups', 'groups_members', 'modules', 'role', 'role_names', 'role_context_levels', 'role_assignments', 'role_capabilities', 'user');
     $this->create_test_tables($tables, 'lib');
     $this->create_test_table('forum', 'mod/forum');
     $this->switch_to_test_db();
     global $DB, $CFG;
     // Insert needed capabilities
     $DB->insert_record('capabilities', array('id' => 45, 'name' => 'moodle/course:update', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 4));
     $DB->insert_record('capabilities', array('id' => 14, 'name' => 'moodle/site:backup', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 28));
     $DB->insert_record('capabilities', array('id' => 17, 'name' => 'moodle/site:restore', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 28));
     $DB->insert_record('capabilities', array('id' => 52, 'name' => 'moodle/course:managefiles', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 4));
     $DB->insert_record('capabilities', array('id' => 73, 'name' => 'moodle/user:editownprofile', 'cattype' => 'write', 'contextlevel' => 10, 'component' => 'moodle', 'riskbitmask' => 16));
     // Insert system context
     $DB->insert_record('context', array('id' => 1, 'contextlevel' => 10, 'instanceid' => 0, 'path' => '/1', 'depth' => 1));
     $DB->insert_record('context', array('id' => 2, 'contextlevel' => 50, 'instanceid' => 1, 'path' => '/1/2', 'depth' => 2));
     // Insert site course
     $DB->insert_record('course', array('category' => 0, 'sortorder' => 1, 'fullname' => 'Test site', 'shortname' => 'test', 'format' => 'site', 'modinfo' => 'a:0:{}'));
     // User and capability stuff (stolen from testaccesslib.php)
     $syscontext = get_system_context(false);
     $adminrole = create_role(get_string('administrator'), 'admin', get_string('administratordescription'), 'moodle/legacy:admin');
     /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
     assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $syscontext->id);
     update_capabilities('moodle');
     update_capabilities('mod/forum');
     $contexts = $this->load_test_data('context', array('contextlevel', 'instanceid', 'path', 'depth'), array(1 => array(40, 666, '', 2)));
     $contexts[0] = $syscontext;
     $contexts[1]->path = $contexts[0]->path . '/' . $contexts[1]->id;
     $this->testdb->set_field('context', 'path', $contexts[1]->path, array('id' => $contexts[1]->id));
     $users = $this->load_test_data('user', array('username', 'confirmed', 'deleted'), array('a' => array('a', 1, 0)));
     $admin = $this->testdb->get_record('role', array('shortname' => 'admin'));
     $ras = $this->load_test_data('role_assignments', array('userid', 'roleid', 'contextid'), array('a' => array($users['a']->id, $admin->id, $contexts[0]->id)));
     $this->switch_global_user_id(1);
     accesslib_clear_all_caches_for_unit_testing();
     // Create a coursecat
     $newcategory = new stdClass();
     $newcategory->name = 'test category';
     $newcategory->sortorder = 999;
     if (!($newcategory->id = $DB->insert_record('course_categories', $newcategory))) {
         print_error('cannotcreatecategory', '', '', format_string($newcategory->name));
     }
     $newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
     mark_context_dirty($newcategory->context->path);
     fix_course_sortorder();
     // Required to build course_categories.depth and .path.
     $this->coursecat = $DB->get_record('course_categories', array('id' => $newcategory->id));
     // Create a course
     $coursedata = new stdClass();
     $coursedata->category = $newcategory->id;
     $coursedata->shortname = 'testcourse';
     $coursedata->fullname = 'Test Course';
     try {
         $this->course = create_course($coursedata);
     } catch (moodle_exception $e) {
         // Most likely the result of an aborted unit test: the test course was not correctly deleted
         $this->course = $DB->get_record('course', array('shortname' => $coursedata->shortname));
     }
     // Create a user
     $this->user = new stdClass();
     $this->user->username = '******';
     $this->user->password = '******';
     $this->user->firstname = 'TestUser';
     $this->user->lastname = 'TestUser';
     $this->user->email = '*****@*****.**';
     try {
         $this->user->id = create_user($this->user);
     } catch (moodle_exception $e) {
         // Most likely the result of an aborted unit test: the test user was not correctly deleted
         $this->user->id = $DB->get_field('user', 'id', array('username' => $this->user->username));
     }
     // Assign user to course
     // role_assign(5, $this->user->id, 0, get_context_instance(CONTEXT_COURSE, $this->course->id)->id);
     // Create a module
     $module = new stdClass();
     $module->intro = 'Forum used for testing filelib API';
     $module->type = 'general';
     $module->forcesubscribe = 1;
     $module->format = 1;
     $module->name = 'Test Forum';
     $module->module = $DB->get_field('modules', 'id', array('name' => 'forum'));
     $module->modulename = 'forum';
     $module->add = 'forum';
     $module->cmidnumber = '';
     $module->course = $this->course->id;
     $module->instance = forum_add_instance($module, '');
     $this->section = get_course_section(1, $this->course->id);
     $module->section = $this->section->id;
     $module->coursemodule = add_course_module($module);
     add_mod_to_section($module);
     $module->cmidnumber = set_coursemodule_idnumber($module->coursemodule, '');
     rebuild_course_cache($this->course->id);
     $this->module = $DB->get_record('forum', array('id' => $module->instance));
     $this->module->instance = $module->instance;
     // Update local copy of course
     $this->course = $DB->get_record('course', array('id' => $this->course->id));
 }
 public function setUp()
 {
     global $COURSE, $SITE;
     parent::setUp();
     $this->originalcourse = $COURSE;
     $this->testpage = new moodle_page();
     $this->create_test_tables(array('course', 'context'), 'lib');
     $this->create_test_table('forum', 'mod/forum');
     $this->switch_to_test_db();
     $context = new stdClass();
     $context->contextlevel = CONTEXT_COURSE;
     $context->instanceid = $SITE->id;
     $context->path = 'not initialised';
     $context->depth = '-1';
     $this->testdb->insert_record('context', $context);
 }
 public function setUp()
 {
     global $USER;
     if (!empty($USER->editing)) {
         // We want to avoid the capability checks associated with
         // checking the user is editing.
         $this->isediting = $USER->editing;
         unset($USER->editing);
     }
     parent::setUp();
     $this->create_test_tables(array('block', 'block_instances', 'block_positions', 'context'), 'lib');
     $this->switch_to_test_db();
 }
示例#10
0
 public function setUp()
 {
     global $CFG;
     parent::setUp();
     // Create the table we need and switch to test DB.
     $this->create_test_table('config', 'lib');
     $this->switch_to_test_db();
     // Store original $CFG;
     $this->origcfgstringfilters = $CFG->stringfilters;
     $this->origcfgfilterall = $CFG->filterall;
 }
 public function setUp()
 {
     parent::setUp();
     $this->create_test_tables(array('block', 'block_instances', 'block_positions', 'context'), 'lib');
     $this->switch_to_test_db();
 }
    /**
     * Set up function. In this instance we are setting up database
     * records to be used in the unit tests.
     * @todo MDL-32271 use a class for creating safe core moodle tables. This isn't
     * possible at the moment.
     */

    public function setUp() {
        global $DB, $CFG;

        // Set up test database and appropriate tables.
        parent::setUp();
        $this->create_test_tables(array('data', 'data_fields', 'data_records', 'data_content'), 'mod/data');
        $this->create_test_tables(array('user', 'modules', 'course_modules','context'), 'lib');
        $this->switch_to_test_db();

        // Set up data for the test database.
        $tablename = array('0' => 'user',
                           '1' => 'data_fields',
                           '2' => 'data_records',
                           '3' => 'data_content',
                           '4' => 'modules',
                           '5' => 'course_modules',
                           '6' => 'context');

        for ($i = 0; $i < 7; $i++) {
            $filename = $CFG->dirroot . '/mod/data/simpletest/test_' . $tablename[$i] . '.csv';
            if (file_exists($filename)) {
                $file = file_get_contents($filename);
            }
            $this->insert_data_from_csv($file, $tablename[$i]);
        }

        // Set up a data record.
        $datarecord = new stdClass();
        $datarecord->course = '99999';
        $datarecord->name = 'test database';
        $datarecord->intro = 'Test Database for unit testing';
        $datarecord->introformat = '1';
        $DB->insert_record('data', $datarecord, false);
        $data = $DB->get_record('data', array('id'=> '1'));
        $this->recorddata = $data;

        // Create the search array which contains our advanced search criteria.

        $fieldinfo = array('0' => new stdClass(),
                           '1' => new stdClass(),
                           '2' => new stdClass(),
                           '3' => new stdClass(),
                           '4' => new stdClass());
        $fieldinfo['0']->id = 1;
        $fieldinfo['0']->data = '3.721,46.6126';
        $fieldinfo['1']->id = 2;
        $fieldinfo['1']->data = 'Hahn Premium';
        $fieldinfo['2']->id = 5;
        $fieldinfo['2']->data = 'Female';
        $fieldinfo['3']->id = 7;
        $fieldinfo['3']->data = 'kel';
        $fieldinfo['4']->id = 9;
        $fieldinfo['4']->data = 'VIC';

        foreach($fieldinfo as $field) {
            $searchfield = data_get_field_from_id($field->id, $data);
            if ($field->id == 2) {
                $searchfield->field->param1 = 'Hahn Premium';
                $val = array();
                $val['selected'] = array('0' => 'Hahn Premium');
                $val['allrequired'] = 0;
            } else {
                $val = $field->data;
            }
            $search_array[$field->id] = new stdClass();
            list($search_array[$field->id]->sql, $search_array[$field->id]->params) = $searchfield->generate_sql('c' . $field->id, $val);
        }

        $this->recordsearcharray = $search_array;

        // Setting up the comparison stdClass for the last test.
        $this->finalrecord[6] = new stdClass();
        $this->finalrecord[6]->id = 6;
        $this->finalrecord[6]->approved = 1;
        $this->finalrecord[6]->timecreated = 1234567891;
        $this->finalrecord[6]->timemodified = 1234567892;
        $this->finalrecord[6]->userid = 6;
        $this->finalrecord[6]->firstname = 'Benedict';
        $this->finalrecord[6]->lastname = 'Horn';
    }
 public function setUp()
 {
     global $ACCESSLIB_PRIVATE;
     parent::setUp();
     // All operations until end of test method will happen in test DB
     $this->switch_to_test_db();
     foreach ($this->tables as $dir => $tables) {
         $this->create_test_tables($tables, $dir);
         // Create tables
     }
     // clear context cache for testing with dummy system context etc
     $ACCESSLIB_PRIVATE->contexcache = new context_cache();
     $context = new stdClass();
     $context->contextlevel = CONTEXT_SYSTEM;
     $context->instanceid = 0;
     $context->depth = 1;
     $context->path = null;
     //not known before insert
     $context->id = $this->testdb->insert_record('context', $context);
     $context->path = '/' . $context->id;
     $this->testdb->update_record('context', $context);
     $ACCESSLIB_PRIVATE->systemcontext = $context->id;
     $this->load_course_category();
     $this->load_modules();
     $this->load_roles();
     $this->load_capabilities();
     $this->load_role_capabilities();
     // load test courses and contexts
     $this->courses['single'] = $this->get_new_course(0);
     $this->contexts['single'] = get_context_instance(CONTEXT_COURSE, $this->courses['single']->id);
     $this->courses['group'] = $this->get_new_course(1);
     $this->contexts['group'] = get_context_instance(CONTEXT_COURSE, $this->courses['group']->id);
     $this->admin = $this->get_new_user('admin');
     $this->teacher = $this->get_new_user('editingteacher');
     $this->student = $this->get_new_user('student');
     $this->nouser = $this->get_new_user(null);
     // this user will have no role in courses
 }
 public function setUp()
 {
     parent::setUp();
     $this->switch_to_test_db();
 }
 public function setUp() {
     global $USER;
     if (!empty($USER->editing)) {
         // We want to avoid the capability checks associated with
         // checking the user is editing.
         $this->isediting = $USER->editing;
         unset($USER->editing);
     }
     parent::setUp();
     $this->create_test_tables(array('block', 'block_instances', 'block_positions', 'context', 'course_categories', 'course'), 'lib');
     $this->switch_to_test_db();
     // Nasty hack, recreate the system context record (the accesslib API does not allow to create it easily)
     $this->create_system_context_record();
     // Reset all caches
     accesslib_clear_all_caches_for_unit_testing();
 }