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