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 core_backup;
18
 
19
use core\di;
20
use core\hook\manager;
21
use advanced_testcase;
22
use core_backup\output\copy_form;
23
 
24
/**
25
 * Tests the after_copy_form_definition hook.
26
 *
27
 * @package core_backup
28
 * @copyright 2024 Monash University (https://www.monash.edu)
29
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
final class copy_form_hook_test extends advanced_testcase {
32
    /**
33
     * Test the after_copy_form_definition hook.
34
     *
35
     * @covers \core_backup\output\copy_form::definition
36
     */
37
    public function test_copy_form_hook(): void {
38
        // Load the callback classes.
39
        require_once(__DIR__ . '/fixtures/copy_form_hooks.php');
40
 
41
        // Replace the version of the manager in the DI container with a phpunit one.
42
        di::set(
43
            manager::class,
44
            manager::phpunit_get_instance([
45
                // Load a list of hooks for `test_plugin1` from the fixture file.
46
                'test_plugin1' => __DIR__ .
47
                    '/fixtures/copy_form_hooks.php',
48
            ]),
49
        );
50
 
51
        $this->resetAfterTest(true);
52
        $this->setAdminUser();
53
 
54
        $generator = $this->getDataGenerator();
55
        $course = $generator->create_course();
56
        $form  = new copy_form(
57
            null,
58
            ['course' => $course, 'returnto' => null, 'returnurl' => null]
59
        );
60
        ob_start();
61
        $form->display();
62
        $html = ob_get_clean();
63
 
64
        // Check that the wierdtestname element is part of the form.
65
        $pos = strpos($html, 'wierdtestname');
66
        $this->assertNotFalse($pos);
67
    }
68
}