Differences Between: [Versions 39 and 310]
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 * Unit tests for the privacy legacy polyfill for gradingform. 19 * 20 * @package core_grading 21 * @category test 22 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * Unit tests for the Grading API's privacy legacy_polyfill. 30 * 31 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com> 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class gradeform_privacy_legacy_polyfill_test extends advanced_testcase { 35 /** 36 * Test that the core_grading\privacy\legacy_polyfill works and that the static _export_gradingform_instance_data can be called. 37 */ 38 public function test_export_gradingform_instance_data() { 39 $context = context_system::instance(); 40 41 $mock = $this->createMock(test_gradingform_legacy_polyfill_mock_wrapper::class); 42 $mock->expects($this->once()) 43 ->method('get_return_value') 44 ->with('_export_gradingform_instance_data', [$context, 3, ['subcontext']]); 45 46 test_legacy_polyfill_gradingform_provider::$mock = $mock; 47 test_legacy_polyfill_gradingform_provider::export_gradingform_instance_data($context, 3, ['subcontext']); 48 } 49 50 /** 51 * Test for _get_metadata shim. 52 */ 53 public function test_get_metadata() { 54 $collection = new \core_privacy\local\metadata\collection('core_gradingform'); 55 $this->assertSame($collection, test_legacy_polyfill_gradingform_provider::get_metadata($collection)); 56 } 57 58 /** 59 * Test the _delete_gradingform_for_instances shim. 60 */ 61 public function test_delete_gradingform_for_instances() { 62 $context = context_system::instance(); 63 64 $mock = $this->createMock(test_gradingform_legacy_polyfill_mock_wrapper::class); 65 $mock->expects($this->once()) 66 ->method('get_return_value') 67 ->with('_delete_gradingform_for_instances', [[3, 17]]); 68 69 test_legacy_polyfill_gradingform_provider::$mock = $mock; 70 test_legacy_polyfill_gradingform_provider::delete_gradingform_for_instances([3, 17]); 71 } 72 } 73 74 /** 75 * Legacy polyfill test class for the gradingform_provider. 76 * 77 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com> 78 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 79 */ 80 class test_legacy_polyfill_gradingform_provider implements 81 \core_privacy\local\metadata\provider, 82 \core_grading\privacy\gradingform_provider_v2 { 83 84 use \core_grading\privacy\gradingform_legacy_polyfill; 85 use \core_privacy\local\legacy_polyfill; 86 87 /** 88 * @var test_legacy_polyfill_gradingform_provider $mock. 89 */ 90 public static $mock = null; 91 92 /** 93 * Export user data relating to an instance ID. 94 * 95 * @param \context $context Context to use with the export writer. 96 * @param int $instanceid The instance ID to export data for. 97 * @param array $subcontext The directory to export this data to. 98 */ 99 protected static function _export_gradingform_instance_data(\context $context, $instanceid, $subcontext) { 100 static::$mock->get_return_value(__FUNCTION__, func_get_args()); 101 } 102 103 /** 104 * Deletes all user data related to the provided instance IDs. 105 * 106 * @param array $instanceids The instance IDs to delete information from. 107 */ 108 protected static function _delete_gradingform_for_instances($instanceids) { 109 static::$mock->get_return_value(__FUNCTION__, func_get_args()); 110 } 111 112 /** 113 * Returns metadata about this plugin. 114 * 115 * @param \core_privacy\local\metadata\collection $collection The initialised collection to add items to. 116 * @return \core_privacy\local\metadata\collection A listing of user data stored through this system. 117 */ 118 protected static function _get_metadata(\core_privacy\local\metadata\collection $collection) { 119 return $collection; 120 } 121 } 122 123 /** 124 * Called inside the polyfill methods in the test polyfill provider, allowing us to ensure these are called with correct params. 125 * 126 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com> 127 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 128 */ 129 class test_gradingform_legacy_polyfill_mock_wrapper { 130 /** 131 * Get the return value for the specified item. 132 */ 133 public function get_return_value() { 134 } 135 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body