| 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 |  * @package    core_backup
 | 
        
           |  |  | 19 |  * @category   phpunit
 | 
        
           |  |  | 20 |  * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
 | 
        
           |  |  | 21 |  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 22 |  */
 | 
        
           |  |  | 23 |   | 
        
           |  |  | 24 | defined('MOODLE_INTERNAL') || die();
 | 
        
           |  |  | 25 |   | 
        
           |  |  | 26 | // Include all the needed stuff
 | 
        
           |  |  | 27 | global $CFG;
 | 
        
           |  |  | 28 | require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
 | 
        
           |  |  | 29 | require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
 | 
        
           |  |  | 30 | require_once($CFG->dirroot . '/backup/moodle2/backup_custom_fields.php');
 | 
        
           |  |  | 31 | require_once($CFG->dirroot . '/backup/moodle2/backup_subplugin.class.php');
 | 
        
           |  |  | 32 |   | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 | /**
 | 
        
           |  |  | 35 |  * Instantiable class extending base_plan in order to be able to perform tests
 | 
        
           |  |  | 36 |  */
 | 
        
           |  |  | 37 | class mock_base_plan extends base_plan {
 | 
        
           |  |  | 38 |     public function build() {
 | 
        
           |  |  | 39 |     }
 | 
        
           |  |  | 40 |   | 
        
           |  |  | 41 |     public function get_progress() {
 | 
        
           |  |  | 42 |         return null;
 | 
        
           |  |  | 43 |     }
 | 
        
           |  |  | 44 | }
 | 
        
           |  |  | 45 |   | 
        
           |  |  | 46 | /**
 | 
        
           |  |  | 47 |  * Instantiable class extending base_step in order to be able to perform tests
 | 
        
           |  |  | 48 |  */
 | 
        
           |  |  | 49 | class mock_base_step extends base_step {
 | 
        
           |  |  | 50 |     public function execute() {
 | 
        
           |  |  | 51 |     }
 | 
        
           |  |  | 52 | }
 | 
        
           |  |  | 53 |   | 
        
           |  |  | 54 | /**
 | 
        
           |  |  | 55 |  * Instantiable class extending backup_step in order to be able to perform tests
 | 
        
           |  |  | 56 |  */
 | 
        
           |  |  | 57 | class mock_backup_step extends backup_step {
 | 
        
           |  |  | 58 |     public function execute() {
 | 
        
           |  |  | 59 |     }
 | 
        
           |  |  | 60 | }
 | 
        
           |  |  | 61 |   | 
        
           |  |  | 62 | /**
 | 
        
           |  |  | 63 |  * Instantiable class extending backup_task in order to mockup get_taskbasepath()
 | 
        
           |  |  | 64 |  */
 | 
        
           |  |  | 65 | class mock_backup_task_basepath extends backup_task {
 | 
        
           |  |  | 66 |   | 
        
           |  |  | 67 |     /** @var string name of the mod plugin (activity) being used in the tests */
 | 
        
           |  |  | 68 |     private $modulename;
 | 
        
           |  |  | 69 |   | 
        
           |  |  | 70 |     public function build() {
 | 
        
           |  |  | 71 |         // Nothing to do
 | 
        
           |  |  | 72 |     }
 | 
        
           |  |  | 73 |   | 
        
           |  |  | 74 |     public function define_settings() {
 | 
        
           |  |  | 75 |         // Nothing to do
 | 
        
           |  |  | 76 |     }
 | 
        
           |  |  | 77 |   | 
        
           |  |  | 78 |     public function get_taskbasepath() {
 | 
        
           |  |  | 79 |         global $CFG;
 | 
        
           |  |  | 80 |         return $CFG->tempdir . '/test';
 | 
        
           |  |  | 81 |     }
 | 
        
           |  |  | 82 |   | 
        
           |  |  | 83 |     public function set_modulename($modulename) {
 | 
        
           |  |  | 84 |         $this->modulename = $modulename;
 | 
        
           |  |  | 85 |     }
 | 
        
           |  |  | 86 |   | 
        
           |  |  | 87 |     public function get_modulename() {
 | 
        
           |  |  | 88 |         return $this->modulename;
 | 
        
           |  |  | 89 |     }
 | 
        
           |  |  | 90 | }
 | 
        
           |  |  | 91 |   | 
        
           |  |  | 92 | /**
 | 
        
           |  |  | 93 |  * Instantiable class extending restore_task in order to mockup get_taskbasepath()
 | 
        
           |  |  | 94 |  */
 | 
        
           |  |  | 95 | class mock_restore_task_basepath extends restore_task {
 | 
        
           |  |  | 96 |   | 
        
           |  |  | 97 |     /** @var string name of the mod plugin (activity) being used in the tests */
 | 
        
           |  |  | 98 |     private $modulename;
 | 
        
           |  |  | 99 |   | 
        
           |  |  | 100 |     public function build() {
 | 
        
           |  |  | 101 |         // Nothing to do.
 | 
        
           |  |  | 102 |     }
 | 
        
           |  |  | 103 |   | 
        
           |  |  | 104 |     public function define_settings() {
 | 
        
           |  |  | 105 |         // Nothing to do.
 | 
        
           |  |  | 106 |     }
 | 
        
           |  |  | 107 |   | 
        
           |  |  | 108 |     public function set_modulename($modulename) {
 | 
        
           |  |  | 109 |         $this->modulename = $modulename;
 | 
        
           |  |  | 110 |     }
 | 
        
           |  |  | 111 |   | 
        
           |  |  | 112 |     public function get_modulename() {
 | 
        
           |  |  | 113 |         return $this->modulename;
 | 
        
           |  |  | 114 |     }
 | 
        
           |  |  | 115 | }
 | 
        
           |  |  | 116 |   | 
        
           |  |  | 117 | /**
 | 
        
           |  |  | 118 |  * Instantiable class extending backup_structure_step in order to be able to perform tests
 | 
        
           |  |  | 119 |  */
 | 
        
           |  |  | 120 | class mock_backup_structure_step extends backup_structure_step {
 | 
        
           |  |  | 121 |   | 
        
           |  |  | 122 |     public function define_structure() {
 | 
        
           |  |  | 123 |   | 
        
           |  |  | 124 |         // Create really simple structure (1 nested with 1 attr and 2 fields)
 | 
        
           |  |  | 125 |         $test = new backup_nested_element('test',
 | 
        
           |  |  | 126 |             array('id'),
 | 
        
           |  |  | 127 |             array('field1', 'field2')
 | 
        
           |  |  | 128 |         );
 | 
        
           |  |  | 129 |         $test->set_source_array(array(array('id' => 1, 'field1' => 'value1', 'field2' => 'value2')));
 | 
        
           |  |  | 130 |   | 
        
           |  |  | 131 |         return $test;
 | 
        
           |  |  | 132 |     }
 | 
        
           |  |  | 133 |   | 
        
           |  |  | 134 |     public function add_plugin_structure($plugintype, $element, $multiple) {
 | 
        
           |  |  | 135 |         parent::add_plugin_structure($plugintype, $element, $multiple);
 | 
        
           |  |  | 136 |     }
 | 
        
           |  |  | 137 |   | 
        
           |  |  | 138 |     public function add_subplugin_structure($subplugintype, $element, $multiple, $plugintype = null, $pluginname = null) {
 | 
        
           |  |  | 139 |         parent::add_subplugin_structure($subplugintype, $element, $multiple, $plugintype, $pluginname);
 | 
        
           |  |  | 140 |     }
 | 
        
           |  |  | 141 | }
 | 
        
           |  |  | 142 |   | 
        
           |  |  | 143 | class mock_restore_structure_step extends restore_structure_step {
 | 
        
           |  |  | 144 |     public function define_structure() {
 | 
        
           |  |  | 145 |   | 
        
           |  |  | 146 |         // Create a really simple structure (1 element).
 | 
        
           |  |  | 147 |         $test = new restore_path_element('test', '/tests/test');
 | 
        
           |  |  | 148 |         return array($test);
 | 
        
           |  |  | 149 |     }
 | 
        
           |  |  | 150 |   | 
        
           |  |  | 151 |     public function add_plugin_structure($plugintype, $element) {
 | 
        
           |  |  | 152 |         parent::add_plugin_structure($plugintype, $element);
 | 
        
           |  |  | 153 |     }
 | 
        
           |  |  | 154 |   | 
        
           |  |  | 155 |     public function add_subplugin_structure($subplugintype, $element, $plugintype = null, $pluginname = null) {
 | 
        
           |  |  | 156 |         parent::add_subplugin_structure($subplugintype, $element, $plugintype, $pluginname);
 | 
        
           |  |  | 157 |     }
 | 
        
           |  |  | 158 |   | 
        
           |  |  | 159 |     public function get_pathelements() {
 | 
        
           |  |  | 160 |         return $this->pathelements;
 | 
        
           |  |  | 161 |     }
 | 
        
           |  |  | 162 | }
 | 
        
           |  |  | 163 |   | 
        
           |  |  | 164 | /**
 | 
        
           |  |  | 165 |  * Instantiable class extending activity_backup_setting to be added to task and perform tests
 | 
        
           |  |  | 166 |  */
 | 
        
           |  |  | 167 | class mock_fullpath_activity_setting extends activity_backup_setting {
 | 
        
           |  |  | 168 |     public function process_change($setting, $ctype, $oldv) {
 | 
        
           |  |  | 169 |         // Nothing to do
 | 
        
           |  |  | 170 |     }
 | 
        
           |  |  | 171 | }
 | 
        
           |  |  | 172 |   | 
        
           |  |  | 173 | /**
 | 
        
           |  |  | 174 |  * Instantiable class extending activity_backup_setting to be added to task and perform tests
 | 
        
           |  |  | 175 |  */
 | 
        
           |  |  | 176 | class mock_backupid_activity_setting extends activity_backup_setting {
 | 
        
           |  |  | 177 |     public function process_change($setting, $ctype, $oldv) {
 | 
        
           |  |  | 178 |         // Nothing to do
 | 
        
           |  |  | 179 |     }
 | 
        
           |  |  | 180 | }
 | 
        
           |  |  | 181 |   | 
        
           |  |  | 182 | /**
 | 
        
           |  |  | 183 |  * Instantiable class extending base_task in order to be able to perform tests
 | 
        
           |  |  | 184 |  */
 | 
        
           |  |  | 185 | class mock_base_task extends base_task {
 | 
        
           |  |  | 186 |     public function build() {
 | 
        
           |  |  | 187 |     }
 | 
        
           |  |  | 188 |   | 
        
           |  |  | 189 |     public function define_settings() {
 | 
        
           |  |  | 190 |     }
 | 
        
           |  |  | 191 | }
 | 
        
           |  |  | 192 |   | 
        
           |  |  | 193 | /**
 | 
        
           |  |  | 194 |  * Instantiable class extending backup_task in order to be able to perform tests
 | 
        
           |  |  | 195 |  */
 | 
        
           |  |  | 196 | class mock_backup_task extends backup_task {
 | 
        
           |  |  | 197 |     public function build() {
 | 
        
           |  |  | 198 |     }
 | 
        
           |  |  | 199 |   | 
        
           |  |  | 200 |     public function define_settings() {
 | 
        
           |  |  | 201 |     }
 | 
        
           |  |  | 202 | }
 |