MDL-61976 mod_wiki: Trim returned value to avoid EOF-related failures
[moodle.git] / portfolio / tests / privacy_legacy_polyfill_test.php
blobc58d2ee00bf5c3df79bcc75723bfbd2ac1c974fa
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.
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/>.
17 /**
18 * Unit tests for the privacy legacy polyfill for portfolio.
20 * @package core_privacy
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
26 defined('MOODLE_INTERNAL') || die();
28 /**
29 * Unit tests for the Portfolio API's privacy legacy_polyfill.
31 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class core_portfolio_privacy_legacy_polyfill_test extends advanced_testcase {
35 /**
36 * Test that the core_portfolio\privacy\legacy_polyfill works and that the static _export_portfolio_user_data can be called.
38 public function test_export_portfolio_user_data() {
39 $userid = 476;
40 $context = context_system::instance();
42 $mock = $this->createMock(test_portfolio_legacy_polyfill_mock_wrapper::class);
43 $mock->expects($this->once())
44 ->method('get_return_value')
45 ->with('_export_portfolio_user_data', [$userid, $context, [], []]);
47 test_legacy_polyfill_portfolio_provider::$mock = $mock;
48 test_legacy_polyfill_portfolio_provider::export_portfolio_user_data($userid, $context, [], []);
51 /**
52 * Test for _get_metadata shim.
54 public function test_get_metadata() {
55 $collection = new \core_privacy\local\metadata\collection('core_portfolio');
56 $this->assertSame($collection, test_legacy_polyfill_portfolio_provider::get_metadata($collection));
59 /**
60 * Test the _delete_portfolio_for_context shim.
62 public function test_delete_portfolio_for_context() {
63 $context = context_system::instance();
65 $mock = $this->createMock(test_portfolio_legacy_polyfill_mock_wrapper::class);
66 $mock->expects($this->once())
67 ->method('get_return_value')
68 ->with('_delete_portfolio_for_context', [$context]);
70 test_legacy_polyfill_portfolio_provider::$mock = $mock;
71 test_legacy_polyfill_portfolio_provider::delete_portfolio_for_context($context);
74 /**
75 * Test the _delete_portfolio_for_context shim.
77 public function test_delete_portfolio_for_user() {
78 $userid = 696;
79 $context = \context_system::instance();
81 $mock = $this->createMock(test_portfolio_legacy_polyfill_mock_wrapper::class);
82 $mock->expects($this->once())
83 ->method('get_return_value')
84 ->with('_delete_portfolio_for_user', [$userid, $context]);
86 test_legacy_polyfill_portfolio_provider::$mock = $mock;
87 test_legacy_polyfill_portfolio_provider::delete_portfolio_for_user($userid, $context);
91 /**
92 * Legacy polyfill test class for the portfolio_provider.
94 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
95 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
97 class test_legacy_polyfill_portfolio_provider implements
98 \core_privacy\local\metadata\provider,
99 \core_portfolio\privacy\portfolio_provider {
101 use \core_portfolio\privacy\legacy_polyfill;
102 use \core_privacy\local\legacy_polyfill;
105 * @var test_legacy_polyfill_portfolio_provider $mock.
107 public static $mock = null;
110 * Export all user data for the portfolio plugin.
112 * @param int $userid
113 * @param context $context
114 * @param array $subcontext
115 * @param array $linkarray
117 protected static function _export_portfolio_user_data($userid, \context $context, array $subcontext, array $linkarray) {
118 static::$mock->get_return_value(__FUNCTION__, func_get_args());
122 * Deletes all user data for the given context.
124 * @param context $context
126 protected static function _delete_portfolio_for_context(\context $context) {
127 static::$mock->get_return_value(__FUNCTION__, func_get_args());
131 * Delete personal data for the given user and context.
133 * @param int $userid
134 * @param context $context
136 protected static function _delete_portfolio_for_user($userid, \context $context) {
137 static::$mock->get_return_value(__FUNCTION__, func_get_args());
141 * Returns metadata about this plugin.
143 * @param \core_privacy\local\metadata\collection $collection The initialised collection to add items to.
144 * @return \core_privacy\local\metadata\collection A listing of user data stored through this system.
146 protected static function _get_metadata(\core_privacy\local\metadata\collection $collection) {
147 return $collection;
152 * Called inside the polyfill methods in the test polyfill provider, allowing us to ensure these are called with correct params.
154 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
155 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
157 class test_portfolio_legacy_polyfill_mock_wrapper {
159 * Get the return value for the specified item.
161 public function get_return_value() {