Merge branch 'MDL-41399_master-remove_test' of git://github.com/dmonllao/moodle
This commit is contained in:
@@ -89,6 +89,11 @@ class tool_generator_backend {
|
||||
*/
|
||||
private $size;
|
||||
|
||||
/**
|
||||
* @var bool True if we want a fixed dataset or false to generate random data
|
||||
*/
|
||||
private $fixeddataset;
|
||||
|
||||
/**
|
||||
* @var bool True if displaying progress
|
||||
*/
|
||||
@@ -129,11 +134,12 @@ class tool_generator_backend {
|
||||
*
|
||||
* @param string $shortname Course shortname
|
||||
* @param int $size Size as numeric index
|
||||
* @param bool $fixeddataset To use fixed or random data
|
||||
* @param bool $progress True if progress information should be displayed
|
||||
* @return int Course id
|
||||
* @throws coding_exception If parameters are invalid
|
||||
*/
|
||||
public function __construct($shortname, $size, $progress = true) {
|
||||
public function __construct($shortname, $size, $fixeddataset = false, $progress = true) {
|
||||
// Check parameter.
|
||||
if ($size < self::MIN_SIZE || $size > self::MAX_SIZE) {
|
||||
throw new coding_exception('Invalid size');
|
||||
@@ -142,6 +148,7 @@ class tool_generator_backend {
|
||||
// Set parameters.
|
||||
$this->shortname = $shortname;
|
||||
$this->size = $size;
|
||||
$this->fixeddataset = $fixeddataset;
|
||||
$this->progress = $progress;
|
||||
}
|
||||
|
||||
@@ -317,6 +324,9 @@ class tool_generator_backend {
|
||||
$this->dot($number, $count);
|
||||
}
|
||||
|
||||
// Sets the pointer at the beginning to be aware of the users we use.
|
||||
reset($this->userids);
|
||||
|
||||
$this->end_log();
|
||||
}
|
||||
|
||||
@@ -360,7 +370,7 @@ class tool_generator_backend {
|
||||
$this->log('createpages', $number, true);
|
||||
for ($i=0; $i<$number; $i++) {
|
||||
$record = array('course' => $this->course->id);
|
||||
$options = array('section' => $this->get_random_section());
|
||||
$options = array('section' => $this->get_target_section());
|
||||
$pagegenerator->create_instance($record, $options);
|
||||
$this->dot($i, $number);
|
||||
}
|
||||
@@ -445,7 +455,7 @@ class tool_generator_backend {
|
||||
// Create resource.
|
||||
$record = array('course' => $this->course->id,
|
||||
'name' => get_string('bigfile', 'tool_generator', $i));
|
||||
$options = array('section' => $this->get_random_section());
|
||||
$options = array('section' => $this->get_target_section());
|
||||
$resource = $resourcegenerator->create_instance($record, $options);
|
||||
|
||||
// Write file.
|
||||
@@ -495,13 +505,13 @@ class tool_generator_backend {
|
||||
$sofar = 0;
|
||||
for ($i=0; $i < $discussions; $i++) {
|
||||
$record = array('forum' => $forum->id, 'course' => $this->course->id,
|
||||
'userid' => $this->get_random_user());
|
||||
'userid' => $this->get_target_user());
|
||||
$discussion = $forumgenerator->create_discussion($record);
|
||||
$parentid = $DB->get_field('forum_posts', 'id', array('discussion' => $discussion->id), MUST_EXIST);
|
||||
$sofar++;
|
||||
for ($j=0; $j < $posts - 1; $j++, $sofar++) {
|
||||
$record = array('discussion' => $discussion->id,
|
||||
'userid' => $this->get_random_user(), 'parent' => $parentid);
|
||||
'userid' => $this->get_target_user(), 'parent' => $parentid);
|
||||
$forumgenerator->create_post($record);
|
||||
$this->dot($sofar, $totalposts);
|
||||
}
|
||||
@@ -511,21 +521,44 @@ class tool_generator_backend {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a random section number.
|
||||
* Gets a section number.
|
||||
*
|
||||
* Depends on $this->fixeddataset.
|
||||
*
|
||||
* @return int A section number from 1 to the number of sections
|
||||
*/
|
||||
private function get_random_section() {
|
||||
return rand(1, self::$paramsections[$this->size]);
|
||||
private function get_target_section() {
|
||||
|
||||
if (!$this->fixeddataset) {
|
||||
$key = rand(1, self::$paramsections[$this->size]);
|
||||
} else {
|
||||
// Using section 1.
|
||||
$key = 1;
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a random user id.
|
||||
* Gets a user id.
|
||||
*
|
||||
* Depends on $this->fixeddataset.
|
||||
*
|
||||
* @return int A user id for a random created user
|
||||
*/
|
||||
private function get_random_user() {
|
||||
return $this->userids[rand(1, self::$paramusers[$this->size])];
|
||||
private function get_target_user() {
|
||||
|
||||
if (!$this->fixeddataset) {
|
||||
$userid = $this->userids[rand(1, self::$paramusers[$this->size])];
|
||||
} else if ($userid = current($this->userids)) {
|
||||
// Moving pointer to the next user.
|
||||
next($this->userids);
|
||||
} else {
|
||||
// Returning to the beginning if we reached the end.
|
||||
$userid = reset($this->userids);
|
||||
}
|
||||
|
||||
return $userid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,6 +34,7 @@ list($options, $unrecognized) = cli_get_params(
|
||||
'help' => false,
|
||||
'shortname' => false,
|
||||
'size' => false,
|
||||
'fixeddataset' => false,
|
||||
'bypasscheck' => false,
|
||||
'quiet' => false
|
||||
),
|
||||
@@ -53,6 +54,7 @@ level.
|
||||
Options:
|
||||
--shortname Shortname of course to create (required)
|
||||
--size Size of course to create XS, S, M, L, XL, or XXL (required)
|
||||
--fixeddataset Use a fixed data set instead of randomly generated data
|
||||
--bypasscheck Bypasses the developer-mode check (be careful!)
|
||||
--quiet Do not show any output
|
||||
|
||||
@@ -73,6 +75,7 @@ if (empty($options['bypasscheck']) && !debugging('', DEBUG_DEVELOPER)) {
|
||||
// Get options.
|
||||
$shortname = $options['shortname'];
|
||||
$sizename = $options['size'];
|
||||
$fixeddataset = $options['fixeddataset'];
|
||||
|
||||
// Check size.
|
||||
try {
|
||||
@@ -90,5 +93,5 @@ if ($error = tool_generator_backend::check_shortname_available($shortname)) {
|
||||
session_set_user(get_admin());
|
||||
|
||||
// Do backend code to generate course.
|
||||
$backend = new tool_generator_backend($shortname, $size, empty($options['quiet']));
|
||||
$backend = new tool_generator_backend($shortname, $size, $fixeddataset, empty($options['quiet']));
|
||||
$id = $backend->make();
|
||||
|
||||
@@ -35,7 +35,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the XS course.
|
||||
$backend = new tool_generator_backend('TOOL_MAKELARGECOURSE_XS', 0, false);
|
||||
$backend = new tool_generator_backend('TOOL_MAKELARGECOURSE_XS', 0, false, false);
|
||||
$courseid = $backend->make();
|
||||
|
||||
// Get course details.
|
||||
@@ -107,4 +107,48 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
|
||||
fd.forum = ?", array($forum->instance));
|
||||
$this->assertEquals(2, $posts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an small test course with fixed data set and checks the used sections and users.
|
||||
*/
|
||||
public function test_fixed_data_set() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the S course (more sections and activities than XS).
|
||||
$backend = new tool_generator_backend('TOOL_S_COURSE_1', 1, true, false);
|
||||
$courseid = $backend->make();
|
||||
|
||||
// Get course details.
|
||||
$course = get_course($courseid);
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
|
||||
// Check module instances belongs to section 1.
|
||||
$instances = $modinfo->get_instances_of('page');
|
||||
$npageinstances = count($instances);
|
||||
foreach ($instances as $instance) {
|
||||
$this->assertEquals(1, $instance->sectionnum);
|
||||
}
|
||||
|
||||
// Users that started discussions are the same.
|
||||
$forums = $modinfo->get_instances_of('forum');
|
||||
$nforuminstances = count($forums);
|
||||
$discussions = forum_get_discussions(reset($forums), 'd.timemodified ASC');
|
||||
$lastusernumber = 0;
|
||||
$discussionstarters = array();
|
||||
foreach ($discussions as $discussion) {
|
||||
$usernumber = intval($discussion->lastname);
|
||||
|
||||
// Checks that the users are odd numbers.
|
||||
$this->assertEquals(1, $usernumber % 2);
|
||||
|
||||
// Checks that the users follows an increasing order.
|
||||
$this->assertGreaterThan($lastusernumber, $usernumber);
|
||||
$lastusernumber = $usernumber;
|
||||
$discussionstarters[$discussion->userid] = $discussion->subject;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user