Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 /** 18 * mod_imscp generator tests 19 * 20 * @package mod_imscp 21 * @category test 22 * @copyright 2013 Marina Glancy 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 /** 27 * Genarator tests class for mod_imscp. 28 * 29 * @package mod_imscp 30 * @category test 31 * @copyright 2013 Marina Glancy 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class mod_imscp_generator_testcase extends advanced_testcase { 35 36 public function test_create_instance() { 37 global $DB, $CFG, $USER; 38 $this->resetAfterTest(); 39 $this->setAdminUser(); 40 41 $course = $this->getDataGenerator()->create_course(); 42 43 $this->assertFalse($DB->record_exists('imscp', array('course' => $course->id))); 44 $imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course)); 45 $records = $DB->get_records('imscp', array('course' => $course->id), 'id'); 46 $this->assertEquals(1, count($records)); 47 $this->assertTrue(array_key_exists($imscp->id, $records)); 48 49 $params = array('course' => $course->id, 'name' => 'Another imscp'); 50 $imscp = $this->getDataGenerator()->create_module('imscp', $params); 51 $records = $DB->get_records('imscp', array('course' => $course->id), 'id'); 52 $this->assertEquals(2, count($records)); 53 $this->assertEquals('Another imscp', $records[$imscp->id]->name); 54 55 // Examples of specifying the package file (do not validate anything, just check for exceptions). 56 // 1. As path to the file in filesystem... 57 $params = array( 58 'course' => $course->id, 59 'packagepath' => $CFG->dirroot.'/mod/imscp/tests/packages/singlescobasic.zip' 60 ); 61 $imscp = $this->getDataGenerator()->create_module('imscp', $params); 62 63 // 2. As file draft area id... 64 $fs = get_file_storage(); 65 $params = array( 66 'course' => $course->id, 67 'package' => file_get_unused_draft_itemid() 68 ); 69 $usercontext = context_user::instance($USER->id); 70 $filerecord = array('component' => 'user', 'filearea' => 'draft', 71 'contextid' => $usercontext->id, 'itemid' => $params['package'], 72 'filename' => 'singlescobasic.zip', 'filepath' => '/'); 73 $fs->create_file_from_pathname($filerecord, $CFG->dirroot.'/mod/imscp/tests/packages/singlescobasic.zip'); 74 $imscp = $this->getDataGenerator()->create_module('imscp', $params); 75 } 76 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body