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
 * Contains tests for template's page operations.
19
 *
20
 * @package   mod_customcert
21
 * @copyright 2023 Leon Stringer <leon.stringer@ntlworld.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_customcert;
26
 
27
/**
28
 * Contains tests for template's page operations.
29
 *
30
 * @package   mod_customcert
31
 * @copyright 2023 Leon Stringer <leon.stringer@ntlworld.com>
32
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class page_test extends \advanced_testcase {
35
 
36
    /**
37
     * Set the test up.
38
     *
39
     * @return void
40
     */
41
    public function setUp(): void {
42
        $this->resetAfterTest();
43
    }
44
 
45
    /**
46
     * Check deleting a non-empty page has no errors.
47
     *   1. Create a template.
48
     *   2. Add a second page.
49
     *   3. Add an element to the second page.
50
     *   4. Delete the second page.
51
     * Previously the above scenario resulted in an error (#571).
52
     *
53
     * @covers \template::delete_page
54
     */
55
    public function test_delete_non_empty_page(): void {
56
        global $DB;
57
 
58
        $template = \mod_customcert\template::create('Test name', \context_system::instance()->id);
59
 
60
        // Add a second page and add an element to it.
61
        $page2id = $template->add_page();
62
        $element = new \stdClass();
63
        $element->pageid = $page2id;
64
        $element->name = 'Image';
65
        $element->element = 'image';
66
        $DB->insert_record('customcert_elements', $element);
67
 
68
        $template->delete_page($page2id);
69
 
70
        $records = $DB->count_records('customcert_elements', ['pageid' => $page2id]);
71
        $this->assertEquals(0, $records);
72
 
73
        $records = $DB->count_records('customcert_pages', ['id' => $page2id]);
74
        $this->assertEquals(0, $records);
75
    }
76
}