Skip to content

Instantly share code, notes, and snippets.

@marinaglancy
Last active December 26, 2015 05:19
Show Gist options
  • Select an option

  • Save marinaglancy/7099644 to your computer and use it in GitHub Desktop.

Select an option

Save marinaglancy/7099644 to your computer and use it in GitHub Desktop.
Example of using generator in unittests
<?php
class my_test_generator_testcase extends advanced_testcase {
public function test_generator_methods() {
global $DB;
$this->resetAfterTest(true);
$category = $this->getDataGenerator()->create_category();
$course = $this->getDataGenerator()->create_course();
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user(array('firstname' => 'USER'));
$teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
$result = $this->getDataGenerator()->enrol_user($user1->id, $course->id, $teacherrole->id, 'manual');
$block = $this->getDataGenerator()->create_block('online_users');
$page = $this->getDataGenerator()->create_module('page', array('course' => $course->id));
$forumgenerator = $this->getDataGenerator()->get_plugin_generator('mod_forum');
$forum = $forumgenerator->create_instance(array('course' => $course->id));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment