Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 15... Línea 15...
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
namespace core_backup;
17
namespace core_backup;
-
 
18
 
-
 
19
use backup;
-
 
20
use core\di;
Línea 18... Línea 21...
18
 
21
use copy_helper;
Línea 19... Línea 22...
19
use backup;
22
use core\hook\manager;
20
 
23
 
Línea 32... Línea 35...
32
 * @copyright  2020 onward The Moodle Users Association <https://moodleassociation.org/>
35
 * @copyright  2020 onward The Moodle Users Association <https://moodleassociation.org/>
33
 * @author     Matt Porritt <mattp@catalyst-au.net>
36
 * @author     Matt Porritt <mattp@catalyst-au.net>
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 * @coversDefaultClass \copy_helper
38
 * @coversDefaultClass \copy_helper
36
 */
39
 */
37
class copy_helper_test extends \advanced_testcase {
40
final class copy_helper_test extends \advanced_testcase {
Línea 38... Línea 41...
38
 
41
 
39
    /**
42
    /**
40
     *
43
     *
41
     * @var \stdClass Course used for testing.
44
     * @var \stdClass Course used for testing.
Línea 63... Línea 66...
63
    /**
66
    /**
64
     * Set up tasks for all tests.
67
     * Set up tasks for all tests.
65
     */
68
     */
66
    protected function setUp(): void {
69
    protected function setUp(): void {
67
        global $DB, $CFG, $USER;
70
        global $DB, $CFG, $USER;
-
 
71
        parent::setUp();
Línea 68... Línea 72...
68
 
72
 
Línea 69... Línea 73...
69
        $this->resetAfterTest(true);
73
        $this->resetAfterTest(true);
70
 
74
 
Línea 833... Línea 837...
833
        // Expect and exception as form data is incomplete.
837
        // Expect and exception as form data is incomplete.
834
        $this->expectException(\moodle_exception::class);
838
        $this->expectException(\moodle_exception::class);
835
        $copydata = \copy_helper::process_formdata($formdata);
839
        $copydata = \copy_helper::process_formdata($formdata);
836
        \copy_helper::create_copy($copydata);
840
        \copy_helper::create_copy($copydata);
837
    }
841
    }
-
 
842
 
-
 
843
    /**
-
 
844
     * Test copy_helper_process_formdata hook.
-
 
845
     *
-
 
846
     * @covers \core_backup\hook\copy_helper_process_formdata
-
 
847
     */
-
 
848
    public function test_copy_helper_process_formdata_hook(): void {
-
 
849
        // Load the callback classes.
-
 
850
        require_once(__DIR__ . '/fixtures/helper_hooks.php');
-
 
851
 
-
 
852
        // Replace the version of the manager in the DI container with a phpunit one.
-
 
853
        di::set(
-
 
854
            manager::class,
-
 
855
            manager::phpunit_get_instance([
-
 
856
                // Load a list of hooks for `test_plugin1` from the fixture file.
-
 
857
                'test_plugin1' => __DIR__ .
-
 
858
                    '/fixtures/helper_hooks.php',
-
 
859
            ]),
-
 
860
        );
-
 
861
 
-
 
862
        $formdata = (object) [
-
 
863
            'courseid' => 4,
-
 
864
            'fullname' => 'Name',
-
 
865
            'shortname' => 'name',
-
 
866
            'category' => 12,
-
 
867
            'visible' => 1,
-
 
868
            'startdate' => '123456789',
-
 
869
            'enddate' => '123456789',
-
 
870
            'idnumber' => 'dnum',
-
 
871
            'userdata' => false,
-
 
872
            'extra' => 13,
-
 
873
        ];
-
 
874
 
-
 
875
        $processed = copy_helper::process_formdata($formdata);
-
 
876
 
-
 
877
        // Check that the extra fields are present.
-
 
878
        $this->assertTrue(isset($processed->extra));
-
 
879
        $this->assertEquals(13, $processed->extra);
-
 
880
    }
838
}
881
}