Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | 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
namespace core_badges\output;
18
 
19
defined('MOODLE_INTERNAL') || die();
20
global $CFG;
21
require_once($CFG->libdir . '/badgeslib.php');
22
 
23
/**
24
 * Class manage_badge_action_bar_test
25
 *
26
 * Unit test for the badges tertiary navigation
27
 *
28
 * @coversDefaultClass \core_badges\output\manage_badge_action_bar
29
 * @package     core_badges
30
 * @copyright   2021 onwards Peter Dias
31
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
1441 ariadna 33
final class manage_badge_action_bar_test extends \advanced_testcase {
1 efrain 34
    /**
35
     * Data provider for test_generate_badge_navigation
36
     *
37
     * @return array
38
     */
1441 ariadna 39
    public static function generate_badge_navigation_provider(): array {
1 efrain 40
        return [
41
            "Test tertiary nav as an editing teacher" => [
42
                "editingteacher", [
43
                    'Overview',
44
                    'Edit details',
45
                    'Criteria',
46
                    'Message',
47
                    'Recipients (0)',
48
                    'Endorsement',
49
                    'Related badges (0)',
50
                    'Alignments (0)'
51
                ],
52
            ],
53
            "Test tertiary nav as an non-editing teacher" => [
54
                "teacher", [
55
                    'Overview',
56
                    'Recipients (0)'
57
                ],
58
            ],
59
            "Test tertiary nav as an admin" => [
60
                "admin", [
61
                    'Overview',
62
                    'Edit details',
63
                    'Criteria',
64
                    'Message',
65
                    'Recipients (0)',
66
                    'Endorsement',
67
                    'Related badges (0)',
68
                    'Alignments (0)'
69
                ]
70
            ],
71
            "Test tertiary nav as a student" => [
1441 ariadna 72
                "student", [],
1 efrain 73
            ]
74
        ];
75
    }
76
 
77
    /**
78
     * Test the generate_badge_navigation function
79
     *
80
     * @dataProvider generate_badge_navigation_provider
81
     * @param string $role
82
     * @param array $expected
83
     * @covers ::generate_badge_navigation
84
     */
11 efrain 85
    public function test_generate_badge_navigation(string $role, array $expected): void {
1 efrain 86
        global $DB;
87
        $this->resetAfterTest();
88
        $course = $this->getDataGenerator()->create_course();
89
        $teacher = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
90
        if ($role != 'admin') {
91
            $user = $this->getDataGenerator()->create_and_enrol($course, $role);
92
            $this->setUser($user);
93
        } else {
94
            $this->setAdminUser();
95
        }
96
 
97
        // Mock up a course badge.
98
        $now = time();
99
        $badge = new \stdClass();
100
        $badge->id = null;
101
        $badge->name = "Test badge course";
102
        $badge->description = "Testing badges course";
103
        $badge->type = BADGE_TYPE_COURSE;
104
        $badge->courseid = $course->id;
105
        $badge->timecreated = $now - 12;
106
        $badge->timemodified = $now - 12;
107
        $badge->usercreated = $teacher->id;
108
        $badge->usermodified = $teacher->id;
109
        $badge->issuername = "Test issuer";
110
        $badge->issuerurl = "http://issuer-url.domain.co.nz";
111
        $badge->issuercontact = "issuer@example.com";
112
        $badge->expiredate = null;
113
        $badge->expireperiod = null;
114
        $badge->messagesubject = "Test message subject for badge";
115
        $badge->message = "Test message body for badge";
116
        $badge->attachment = 1;
117
        $badge->notification = 0;
118
        $badge->status = BADGE_STATUS_ACTIVE;
119
        $badge->version = '1';
120
        $badge->language = 'en';
121
        $badge->imagecaption = 'Caption';
122
        $coursebadgeid = $DB->insert_record('badge', $badge, true);
123
        $badge = new \core_badges\badge($coursebadgeid);
124
 
125
        $context = \context_course::instance($course->id);
126
        $page = new \moodle_page();
127
        $page->set_context($context);
128
        $actionbar = new manage_badge_action_bar($badge, $page);
129
 
130
        $rc = new \ReflectionClass(manage_badge_action_bar::class);
131
        $rcm = $rc->getMethod('generate_badge_navigation');
132
        $content = $rcm->invoke($actionbar);
133
        $this->assertEquals($expected, array_values($content));
134
    }
135
}