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 - https://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
 * Provides {@see mod_subcourse_output_mobile_testcase} class.
19
 *
20
 * @copyright   2020 David Mudrák <david@moodle.com>
21
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
namespace mod_subcourse;
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
/**
29
 * Unit tests for the methods provided by the {@see \mod_subcourse\output\mobile} class.
30
 *
31
 * @package   mod_subcourse
32
 * @category  test
33
 * @copyright 2020 David Mudrák <david@moodle.com>
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class output_mobile_test extends \advanced_testcase {
37
 
38
    /**
39
     * Test the return value of the main_view() method.
40
     *
41
     * @covers ::main_view
42
     */
43
    public function test_main_view() {
44
 
45
        $this->resetAfterTest();
46
        $this->setAdminUser();
47
 
48
        $generator = $this->getDataGenerator();
49
 
50
        $metacourse = $generator->create_course();
51
        $refcourse = $generator->create_course();
52
        $student = $generator->create_user();
53
 
54
        $generator->enrol_user($student->id, $metacourse->id, 'student');
55
        $generator->enrol_user($student->id, $refcourse->id, 'student');
56
 
57
        // Give some grades in the referenced course.
58
        $gi = new \grade_item($generator->create_grade_item(['courseid' => $refcourse->id]), false);
59
        $gi->update_final_grade($student->id, 90, 'test');
60
        $gi->force_regrading();
61
        grade_regrade_final_grades($refcourse->id);
62
 
63
        // Create the Subcourse module instance in the metacourse, representing the final grade in the referenced course.
64
        $subcourse = $generator->create_module('subcourse', [
65
            'course' => $metacourse->id,
66
            'refcourse' => $refcourse->id,
67
        ]);
68
 
69
        // Fetch all students' grades from the refcourse to the metacourse.
70
        subcourse_grades_update($metacourse->id, $subcourse->id, $refcourse->id, null, false, false, [], false);
71
 
72
        // Get the data for the student using the Mobile App.
73
        $this->setUser($student);
74
 
75
        // Ionic5 compatible view for the app version 3.9.5.
76
        $mainview3950 = \mod_subcourse\output\mobile::main_view([
77
            'cmid' => $subcourse->cmid,
78
            'courseid' => $metacourse->id,
79
            'appversioncode' => 3950,
80
        ]);
81
 
82
        $this->assertEquals('main', $mainview3950['templates'][0]['id']);
83
        $this->assertStringContainsString('plugin.mod_subcourse.currentgrade', $mainview3950['templates'][0]['html']);
84
 
85
        // Ionic3 compatible view for the app version 3.9.4.
86
        $mainview3940 = \mod_subcourse\output\mobile::main_view([
87
            'cmid' => $subcourse->cmid,
88
            'courseid' => $metacourse->id,
89
            'appversioncode' => 3940,
90
        ]);
91
 
92
        $this->assertEquals('main', $mainview3940['templates'][0]['id']);
93
        $this->assertStringContainsString('plugin.mod_subcourse.currentgrade', $mainview3940['templates'][0]['html']);
94
    }
95
}