Skip to content

Instantly share code, notes, and snippets.

@marinaglancy
Created October 24, 2013 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marinaglancy/7130493 to your computer and use it in GitHub Desktop.
Save marinaglancy/7130493 to your computer and use it in GitHub Desktop.
Testing MDL-42400
<?php
include "config.php";
require_once($CFG->dirroot . '/lib/testing/classes/util.php');
$PAGE->set_context(context_system::instance());
$generator = testing_util::get_data_generator();
// Create course.
$course = $generator->create_course(array(
'numsections' => 1,
'format' => 'topics',
'shortname' => 'Course'.rand(1,100000))
);
// Find all existing module generators.
$modulegenerators = array();
$modules = core_component::get_plugin_list('mod');
foreach ($modules as $modname => $modpath) {
try {
$modulegenerators[$modname] = $generator->get_plugin_generator('mod_'.$modname);
} catch (coding_exception $e) { }
}
// Generate one instance of each module in the course.
foreach ($modulegenerators as $modname => $modgenerator) {
$module = $modgenerator->create_instance(array('course' => $course->id), array('section' => 0));
// Testing additional data generation functions defined for some module types.
if ($modname === 'glossary') {
for ($i=0; $i<10; $i++) {
$modgenerator->create_entry(array(), $module);
}
} else if ($modname === 'lesson') {
for ($i=0; $i<10; $i++) {
$modgenerator->create_page(array(), $module);
}
} else if ($modname === 'wiki') {
$modgenerator->create_first_page(array(), $module);
for ($i=0; $i<10; $i++) {
$modgenerator->create_page(array(), $module);
}
} else if ($modname === 'book') {
for ($i=0; $i<10; $i++) {
$modgenerator->create_chapter(array('bookid' => $module->id));
}
} else if ($modname === 'forum') {
for ($i=0; $i<10; $i++) {
$discussion = $modgenerator->create_discussion(array(
'forum' => $module->id,
'course' => $course->id,
'userid' => $USER->id));
}
}
}
// Link to the course.
echo "Created course ".html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)),
'Course '.$course->shortname)."<br>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment