Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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 mod_subsection\courseformat;
18
 
19
/**
20
 * Subsection delegated section tests.
21
 *
22
 * @package    mod_subsection
23
 * @copyright  2024 Sara Arjona <sara@moodle.com>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @covers     \mod_subsection\courseformat\sectiondelegate
26
 * @coversDefaultClass \mod_subsection\courseformat\sectiondelegate
27
 */
28
final class sectiondelegate_test extends \advanced_testcase {
29
 
30
    /**
31
     * Test has_delegate_class().
32
     *
33
     * @covers ::has_delegate_class
34
     */
35
    public function test_has_delegate_class(): void {
36
        $this->assertTrue(sectiondelegate::has_delegate_class('mod_subsection'));
37
    }
38
 
39
    /**
40
     * Test get_section_action_menu().
41
     *
42
     * @covers ::get_section_action_menu
43
     */
44
    public function test_get_section_action_menu(): void {
45
        global $PAGE;
46
 
47
        $this->resetAfterTest();
48
        $this->setAdminUser();
49
 
50
        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]);
51
        $this->getDataGenerator()->create_module('subsection', ['course' => $course->id, 'section' => 1]);
52
 
53
        $modinfo = get_fast_modinfo($course->id);
54
        $sectioninfos = $modinfo->get_section_info_all();
55
        // Get the section info for the delegated section.
56
        $sectioninfo = $sectioninfos[2];
57
        $delegated = sectiondelegate::instance($sectioninfo);
58
        $format = course_get_format($course);
59
 
60
        $outputclass = $format->get_output_classname('content\\section\\controlmenu');
61
        $controlmenu = new $outputclass($format, $sectioninfo);
62
        $renderer = $PAGE->get_renderer('format_' . $course->format);
63
 
64
        // Highlight is only present in section menu (not module), so they shouldn't be found in the result.
65
        // Duplicate is not implemented yet, so they shouldn't be found in the result.
66
        // The possible options are: View, Edit, Show, Hide, Delete and Permalink.
67
        if (get_string_manager()->string_exists('editsection', 'format_'.$format->get_format())) {
68
            $streditsection = get_string('editsection', 'format_'.$format->get_format());
69
        } else {
70
            $streditsection = get_string('editsection');
71
        }
72
        $allowedoptions = [
73
            get_string('view'),
74
            $streditsection,
75
            get_string('hidefromothers', 'format_' . $course->format),
76
            get_string('showfromothers', 'format_' . $course->format),
77
            get_string('move'),
78
            get_string('delete'),
79
            get_string('sectionlink', 'course'),
80
        ];
81
 
82
        // The default section menu should be different for the delegated section menu.
83
        $result = $delegated->get_section_action_menu($format, $controlmenu, $renderer);
84
        foreach ($result->get_secondary_actions() as $secondaryaction) {
85
            $this->assertContains($secondaryaction->text, $allowedoptions);
86
        }
87
    }
88
}