Last active
December 26, 2015 05:19
-
-
Save marinaglancy/7099644 to your computer and use it in GitHub Desktop.
Example of using generator in unittests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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