Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * PHPUnit questionnaire generator tests
19
 *
20
 * @package    mod_questionnaire
21
 * @copyright  2015 Mike Churchward (mike@churchward.ca)
22
 * @author     Mike Churchward
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
/**
27
 * Unit tests for questionnaire_generator_testcase.
28
 * @group mod_questionnaire
29
 */
30
class mod_questionnaire_generator_testcase extends advanced_testcase {
31
    public function test_create_instance() {
32
        global $DB;
33
 
34
        $this->resetAfterTest(true);
35
 
36
        $course = $this->getDataGenerator()->create_course();
37
        $this->assertFalse($DB->record_exists('questionnaire', array('course' => $course->id)));
38
 
39
        /** @var mod_questionnaire_generator $generator */
40
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_questionnaire');
41
        $this->assertInstanceOf('mod_questionnaire_generator', $generator);
42
        $this->assertEquals('questionnaire', $generator->get_modulename());
43
 
44
        $questionnaire = $generator->create_instance(array('course' => $course->id));
45
        $this->assertEquals(1, $DB->count_records('questionnaire'));
46
 
47
        $cm = get_coursemodule_from_instance('questionnaire', $questionnaire->id);
48
        $this->assertEquals($questionnaire->id, $cm->instance);
49
        $this->assertEquals('questionnaire', $cm->modname);
50
        $this->assertEquals($course->id, $cm->course);
51
 
52
        $context = context_module::instance($cm->id);
53
        $this->assertEquals($questionnaire->cmid, $context->instanceid);
54
 
55
        $survey = $DB->get_record('questionnaire_survey', array('id' => $questionnaire->sid));
56
        $this->assertEquals($survey->id, $questionnaire->sid);
57
        $this->assertEquals($questionnaire->name, $survey->name);
58
        $this->assertEquals($questionnaire->name, $survey->title);
59
 
60
        // Should test creating a public questionnaire, template questionnaire and creating one from a template.
61
 
62
        // Should test event creation if open dates and close dates are specified?
63
    }
64
 
65
    public function test_create_content() {
66
        global $DB;
67
 
68
        $this->resetAfterTest(true);
69
 
70
        $course = $this->getDataGenerator()->create_course();
71
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_questionnaire');
72
        $questionnaire = $generator->create_instance(array('course' => $course->id));
73
        $cm = get_coursemodule_from_instance('questionnaire', $questionnaire->id);
74
        $questionnaire = new questionnaire($course, $cm, $questionnaire->id, null, false);
75
 
76
        $newcontent = array(
77
            'title' => 'New title',
78
            'email' => 'test@email.com',
79
            'subtitle' => 'New subtitle',
80
            'info' => 'New info',
81
            'thanks_page' => 'http://thankurl.com',
82
            'thank_head' => 'New thank header',
83
            'thank_body' => 'New thank body',
84
        );
85
        $sid = $generator->create_content($questionnaire, $newcontent);
86
        $this->assertEquals($sid, $questionnaire->sid);
87
        $survey = $DB->get_record('questionnaire_survey', array('id' => $sid));
88
        foreach ($newcontent as $name => $value) {
89
            $this->assertEquals($survey->{$name}, $value);
90
        }
91
    }
92
}