See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 39 and 401]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 namespace mod_workshop; 18 19 /** 20 * Genarator tests class for mod_workshop. 21 * 22 * @package mod_workshop 23 * @category test 24 * @copyright 2013 Marina Glancy 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 */ 27 class generator_test extends \advanced_testcase { 28 29 public function test_create_instance() { 30 global $DB; 31 $this->resetAfterTest(); 32 $this->setAdminUser(); 33 34 $course = $this->getDataGenerator()->create_course(); 35 36 $this->assertFalse($DB->record_exists('workshop', array('course' => $course->id))); 37 $workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course)); 38 $records = $DB->get_records('workshop', array('course' => $course->id), 'id'); 39 $this->assertEquals(1, count($records)); 40 $this->assertTrue(array_key_exists($workshop->id, $records)); 41 42 $params = array('course' => $course->id, 'name' => 'Another workshop'); 43 $workshop = $this->getDataGenerator()->create_module('workshop', $params); 44 $records = $DB->get_records('workshop', array('course' => $course->id), 'id'); 45 $this->assertEquals(2, count($records)); 46 $this->assertEquals('Another workshop', $records[$workshop->id]->name); 47 } 48 49 public function test_create_submission() { 50 global $DB; 51 $this->resetAfterTest(); 52 $this->setAdminUser(); 53 54 $course = $this->getDataGenerator()->create_course(); 55 $workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course)); 56 $user = $this->getDataGenerator()->create_user(); 57 $this->getDataGenerator()->enrol_user($user->id, $course->id); 58 $workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop'); 59 60 $id = $workshopgenerator->create_submission($workshop->id, $user->id, array( 61 'title' => 'My custom title', 62 )); 63 64 $submissions = $DB->get_records('workshop_submissions', array('workshopid' => $workshop->id)); 65 $this->assertEquals(1, count($submissions)); 66 $this->assertTrue(isset($submissions[$id])); 67 $this->assertEquals($submissions[$id]->authorid, $user->id); 68 $this->assertSame('My custom title', $submissions[$id]->title); 69 } 70 71 public function test_create_assessment() { 72 global $DB; 73 $this->resetAfterTest(); 74 $this->setAdminUser(); 75 76 $course = $this->getDataGenerator()->create_course(); 77 $workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course)); 78 $user1 = $this->getDataGenerator()->create_user(); 79 $user2 = $this->getDataGenerator()->create_user(); 80 $this->getDataGenerator()->enrol_user($user1->id, $course->id); 81 $this->getDataGenerator()->enrol_user($user2->id, $course->id); 82 $workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop'); 83 84 $submissionid1 = $workshopgenerator->create_submission($workshop->id, $user1->id); 85 $submissionid2 = $workshopgenerator->create_submission($workshop->id, $user2->id); 86 87 $assessmentid1 = $workshopgenerator->create_assessment($submissionid1, $user2->id, array( 88 'weight' => 3, 89 'grade' => 95.00000, 90 )); 91 $assessmentid2 = $workshopgenerator->create_assessment($submissionid2, $user1->id); 92 93 $assessments = $DB->get_records('workshop_assessments'); 94 $this->assertTrue(isset($assessments[$assessmentid1])); 95 $this->assertTrue(isset($assessments[$assessmentid2])); 96 $this->assertEquals(3, $assessments[$assessmentid1]->weight); 97 $this->assertEquals(95.00000, $assessments[$assessmentid1]->grade); 98 $this->assertEquals(1, $assessments[$assessmentid2]->weight); 99 $this->assertNull($assessments[$assessmentid2]->grade); 100 } 101 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body