MDL-78251 tiny: Reduce use of UI for setting test expectations
[moodle.git] / mod / imscp / tests / generator_test.php
blob2d45d376469244612d137025f79890e0c36ea4c2
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.
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/>.
17 namespace mod_imscp;
19 /**
20 * Genarator tests class for mod_imscp.
22 * @package mod_imscp
23 * @category test
24 * @copyright 2013 Marina Glancy
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 class generator_test extends \advanced_testcase {
29 public function test_create_instance() {
30 global $DB, $CFG, $USER;
31 $this->resetAfterTest();
32 $this->setAdminUser();
34 $course = $this->getDataGenerator()->create_course();
36 $this->assertFalse($DB->record_exists('imscp', array('course' => $course->id)));
37 $imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course));
38 $records = $DB->get_records('imscp', array('course' => $course->id), 'id');
39 $this->assertEquals(1, count($records));
40 $this->assertTrue(array_key_exists($imscp->id, $records));
42 $params = array('course' => $course->id, 'name' => 'Another imscp');
43 $imscp = $this->getDataGenerator()->create_module('imscp', $params);
44 $records = $DB->get_records('imscp', array('course' => $course->id), 'id');
45 $this->assertEquals(2, count($records));
46 $this->assertEquals('Another imscp', $records[$imscp->id]->name);
48 // Examples of specifying the package file (do not validate anything, just check for exceptions).
49 // 1. As path to the file in filesystem...
50 $params = array(
51 'course' => $course->id,
52 'packagepath' => $CFG->dirroot.'/mod/imscp/tests/packages/singlescobasic.zip'
54 $imscp = $this->getDataGenerator()->create_module('imscp', $params);
56 // 2. As file draft area id...
57 $fs = get_file_storage();
58 $params = array(
59 'course' => $course->id,
60 'package' => file_get_unused_draft_itemid()
62 $usercontext = \context_user::instance($USER->id);
63 $filerecord = array('component' => 'user', 'filearea' => 'draft',
64 'contextid' => $usercontext->id, 'itemid' => $params['package'],
65 'filename' => 'singlescobasic.zip', 'filepath' => '/');
66 $fs->create_file_from_pathname($filerecord, $CFG->dirroot.'/mod/imscp/tests/packages/singlescobasic.zip');
67 $imscp = $this->getDataGenerator()->create_module('imscp', $params);