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