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
 * Helpers for unit tests.
19
 *
20
 * @package    tool_usertours
21
 * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
trait tool_usertours_helper_trait {
25
    /**
26
     * A helper to create an empty tour.
27
     *
28
     * @param   stdClass    $tourconfig     The configuration for the new tour
29
     * @param   bool        $persist        Whether to persist the data
30
     * @return  \tool_usertours\tour
31
     */
32
    public function helper_create_tour(\stdClass $tourconfig = null, $persist = true) {
33
        $minvalues = [
34
            'id' => null,
35
            'pathmatch' => '/my/%',
36
            'enabled' => true,
37
            'name' => '',
38
            'description' => '',
39
            'configdata' => '',
40
            'displaystepnumbers' => true,
41
        ];
42
 
43
        if ($tourconfig === null) {
44
            $tourconfig = new \stdClass();
45
        }
46
 
47
        foreach ($minvalues as $key => $value) {
48
            if (!isset($tourconfig->$key)) {
49
                $tourconfig->$key = $value;
50
            }
51
        }
52
 
53
        $tour = \tool_usertours\tour::load_from_record($tourconfig, true);
54
        if ($persist) {
55
            $tour->persist(true);
56
        }
57
 
58
        return $tour;
59
    }
60
 
61
    /**
62
     * A helper to create an empty step for the specified tour.
63
     *
64
     * @param   stdClass    $stepconfig     The configuration for the new step
65
     * @param   bool        $persist        Whether to persist the data
66
     * @return  \tool_usertours\step
67
     */
68
    public function helper_create_step(\stdClass $stepconfig = null, $persist = true) {
69
        $minvalues = [
70
            'id' => null,
71
            'title' => '',
72
            'content' => '',
73
            'targettype' => \tool_usertours\target::TARGET_UNATTACHED,
74
            'targetvalue' => '',
75
            'sortorder' => 0,
76
            'configdata' => '',
77
        ];
78
 
79
        if ($stepconfig === null) {
80
            $stepconfig = new \stdClass();
81
        }
82
 
83
        foreach ($minvalues as $key => $value) {
84
            if (!isset($stepconfig->$key)) {
85
                $stepconfig->$key = $value;
86
            }
87
        }
88
 
89
        $step = \tool_usertours\step::load_from_record($stepconfig, true);
90
        if ($persist) {
91
            $step->persist(true);
92
        }
93
 
94
        return $step;
95
    }
96
}