Skip to content

Commit

Permalink
MDL-77164 privacy: typehint test content writer
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Apr 13, 2023
1 parent fcf8879 commit 4d765cd
Show file tree
Hide file tree
Showing 27 changed files with 62 additions and 4 deletions.
4 changes: 4 additions & 0 deletions admin/roles/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function test_export_user_preferences() {
$showadvanced = 1;
set_user_preference('definerole_showadvanced', $showadvanced);
provider::export_user_preferences($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context(\context_system::instance());
$prefs = $writer->get_user_preferences('core_role');
$this->assertEquals(transform::yesno($showadvanced), transform::yesno($prefs->definerole_showadvanced->value));
Expand Down Expand Up @@ -184,6 +185,7 @@ public function test_export_user_data() {
// Retrieve role capabilities and role assignments.
provider::export_user_data($approvedcontextlist);
foreach ($contextlist as $context) {
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
if ($context->contextlevel == CONTEXT_MODULE) {
Expand Down Expand Up @@ -413,6 +415,7 @@ public function test_export_user_role_to_cohort() {
];
// Test User is assigned role teacher to cohort.
provider::export_user_role_to_cohort($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($contextuserassignover);
$this->assertTrue($writer->has_any_data());
$exported = (array)$writer->get_related_data($subcontextteacher, 'cohortroles');
Expand All @@ -430,6 +433,7 @@ public function test_export_user_role_to_cohort() {
api::create_cohort_role_assignment($params);
api::sync_all_cohort_roles();
provider::export_user_role_to_cohort($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($contextuser);
$this->assertTrue($writer->has_any_data());
$exported = (array)$writer->get_related_data($subcontextteacher, 'cohortroles');
Expand Down
1 change: 1 addition & 0 deletions admin/tool/mobile/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function test_export_user_data() {
$key = $DB->get_record('user_private_key', ['value' => $keyvalue]);
// Validate exported data.
$this->setUser($user);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertFalse($writer->has_any_data());
$this->export_context_data_for_user($user->id, $context, 'tool_mobile');
Expand Down
1 change: 1 addition & 0 deletions auth/mnet/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function test_export_user_data() {

$usercontext = \context_user::instance($user->id);

/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($usercontext);
$this->assertFalse($writer->has_any_data());
$approvedlist = new approved_contextlist($user, 'auth_mnet', [$usercontext->id]);
Expand Down
2 changes: 2 additions & 0 deletions blocks/html/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function test_user_block() {

// Export the data.
$this->export_context_data_for_user($user->id, $context, 'block_html');
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = \core_privacy\local\request\writer::with_context($context);
$this->assertTrue($writer->has_any_data());

Expand Down Expand Up @@ -233,6 +234,7 @@ public function test_user_block_unconfigured() {

// Export the data.
$this->export_context_data_for_user($user->id, $context, 'block_html');
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = \core_privacy\local\request\writer::with_context($context);
$this->assertFalse($writer->has_any_data());
}
Expand Down
1 change: 1 addition & 0 deletions calendar/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public function test_export_user_data() {
provider::export_user_data($approvedcontextlist);

foreach ($contextlist as $context) {
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());

Expand Down
1 change: 1 addition & 0 deletions enrol/cohort/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function test_export_user_data() {
$approvedcontextlist = new approved_contextlist($user1, 'enrol_cohort', $contextlist->get_contextids());
provider::export_user_data($approvedcontextlist);
foreach ($contextlist as $context) {
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$data = $writer->get_data([
get_string('pluginname', 'enrol_cohort'),
Expand Down
1 change: 1 addition & 0 deletions enrol/meta/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function test_export_user_data() {
$approvedcontextlist = new approved_contextlist($user1, 'enrol_meta', $contextlist->get_contextids());
provider::export_user_data($approvedcontextlist);
foreach ($contextlist as $context) {
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$data = $writer->get_data([
get_string('pluginname', 'enrol_meta'),
Expand Down
1 change: 1 addition & 0 deletions grade/grading/form/guide/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function test_export_user_preferences() {
// Validate exported data.
provider::export_user_preferences($user->id);
$context = \context_user::instance($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$prefs = $writer->get_user_preferences('gradingform_guide');
Expand Down
1 change: 1 addition & 0 deletions grade/grading/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function test_export_user_data_no_content() {
$this->setUser($user);
$context = \context_system::instance();

/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertFalse($writer->has_any_data());
$this->export_context_data_for_user($user->id, $context, 'core_grading');
Expand Down
2 changes: 2 additions & 0 deletions grade/report/grader/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function test_export_user_preferences_single() {
// Validate exported data for our test user.
provider::export_user_preferences($user->id);
$context = \context_user::instance($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$prefs = $writer->get_user_preferences('gradereport_grader');
Expand All @@ -99,6 +100,7 @@ public function test_export_user_preferences_multiple() {
// Validate exported data.
provider::export_user_preferences($user->id);
$context = \context_user::instance($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$prefs = $writer->get_user_preferences('gradereport_grader');
Expand Down
1 change: 1 addition & 0 deletions grade/report/user/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function test_export_user_preferences_single() {
// Validate exported data.
provider::export_user_preferences($user->id);
$context = \context_user::instance($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$prefs = $writer->get_user_preferences('gradereport_user');
Expand Down
3 changes: 3 additions & 0 deletions group/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function test_export_groups() {

// Retrieve groups for user1.
$this->setUser($user1);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
provider::export_groups($context, '');

Expand Down Expand Up @@ -134,6 +135,7 @@ public function test_export_groups_for_component() {

// Retrieve groups for user1.
$this->setUser($user1);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
provider::export_groups($context, 'enrol_self');

Expand Down Expand Up @@ -792,6 +794,7 @@ public function test_export_user_data() {
// Export all of the data for the context.
$this->export_context_data_for_user($user1->id, $context, 'core_group');

/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());

Expand Down
3 changes: 3 additions & 0 deletions lib/editor/atto/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function test_fetch_and_exports_drafts() {
// Export the data for the system context.
// There should be two.
$this->export_context_data_for_user($user->id, $systemcontext, 'editor_atto');
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = \core_privacy\local\request\writer::with_context($systemcontext);
$this->assertTrue($writer->has_any_data());

Expand Down Expand Up @@ -535,6 +536,7 @@ public function test_another_user_edits_you() {

// Should have the data.
$this->export_context_data_for_user($user->id, $usercontext, 'editor_atto');
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = \core_privacy\local\request\writer::with_context($usercontext);
$this->assertTrue($writer->has_any_data());

Expand Down Expand Up @@ -587,6 +589,7 @@ public function test_another_you_edit_different_user() {

// Should have the data.
$this->export_context_data_for_user($user->id, $otherusercontext, 'editor_atto');
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = \core_privacy\local\request\writer::with_context($otherusercontext);
$this->assertTrue($writer->has_any_data());

Expand Down
14 changes: 10 additions & 4 deletions lib/editor/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public function test_no_preference() {
$this->setAdminUser();

provider::export_user_preferences($USER->id);
$this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context(\context_system::instance());
$this->assertFalse($writer->has_any_data());
}

/**
Expand All @@ -67,7 +69,9 @@ public function test_empty_preference() {

// Export test users preferences.
provider::export_user_preferences($user->id);
$this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context(\context_system::instance());
$this->assertFalse($writer->has_any_data());
}

/**
Expand All @@ -87,9 +91,11 @@ public function test_editor_atto() {

// Export test users preferences.
provider::export_user_preferences($user->id);
$this->assertTrue(writer::with_context(\context_system::instance())->has_any_data());
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context(\context_system::instance());
$this->assertTrue($writer->has_any_data());

$prefs = writer::with_context(\context_system::instance())->get_user_preferences('core_editor');
$prefs = $writer->get_user_preferences('core_editor');
$this->assertNotEmpty($prefs->htmleditor);
$this->assertNotEmpty($prefs->htmleditor->value);
$this->assertNotEmpty($prefs->htmleditor->description);
Expand Down
9 changes: 9 additions & 0 deletions lib/userkey/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function test_export_userkeys_basic_key() {

provider::export_userkeys($context, $subcontext, 'core_tests');

/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);

$this->assertTrue($writer->has_any_data());
Expand Down Expand Up @@ -107,6 +108,7 @@ public function test_export_userkeys_complex_key() {
// Export all keys in core_tests.
provider::export_userkeys($context, $subcontext, 'core_tests');

/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);

$this->assertTrue($writer->has_any_data());
Expand Down Expand Up @@ -143,6 +145,7 @@ public function test_export_userkeys_basic_key_without_filter() {

provider::export_userkeys($context, $subcontext, 'core_tests');

/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);

$this->assertTrue($writer->has_any_data());
Expand Down Expand Up @@ -179,11 +182,13 @@ public function test_export_userkeys_complex_key_with_filter() {

// Export all keys in core_tests against instance 43 - no keys.
provider::export_userkeys($context, $subcontext, 'core_tests', 43);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertFalse($writer->has_any_data());

// Export all keys in core_tests against instance 42.
provider::export_userkeys($context, $subcontext, 'core_tests', 42);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$exported = $writer->get_related_data($subcontext, 'userkeys');
Expand Down Expand Up @@ -224,11 +229,13 @@ public function test_export_userkeys_multiple_complex_key_with_filter() {

// Export all keys in core_tests against instance 43 - no keys.
provider::export_userkeys($context, $subcontext, 'core_tests', 43);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertFalse($writer->has_any_data());

// Export all keys in core_tests against instance 42.
provider::export_userkeys($context, $subcontext, 'core_tests', 42);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$exported = $writer->get_related_data($subcontext, 'userkeys');
Expand Down Expand Up @@ -278,11 +285,13 @@ public function test_export_userkeys_multiple_users() {

// Export all keys in core_tests against instance 43 - no keys.
provider::export_userkeys($context, $subcontext, 'core_tests', 43);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertFalse($writer->has_any_data());

// Export all keys in core_tests against instance 42.
provider::export_userkeys($context, $subcontext, 'core_tests', 42);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$exported = $writer->get_related_data($subcontext, 'userkeys');
Expand Down
2 changes: 2 additions & 0 deletions mod/assign/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public function test_export_user_data_student() {
// Give the submission a grade.
$assign->save_grade($user->id, $data);

/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertFalse($writer->has_any_data());

Expand Down Expand Up @@ -411,6 +412,7 @@ public function test_export_user_data_teacher() {
$flagdata->extensionduedate = $duedate;
$assign->update_user_flags($flagdata);

/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertFalse($writer->has_any_data());

Expand Down
1 change: 1 addition & 0 deletions mod/quiz/accessrule/seb/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function test_export_user_data() {
);

writer::reset();
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertFalse($writer->has_any_data());
provider::export_user_data($approvedcontextlist);
Expand Down
2 changes: 2 additions & 0 deletions mod/quiz/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public function test_user_with_data() {
provider::export_user_data($approvedcontextlist);

// Ensure that the quiz data was exported correctly.
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());

Expand Down Expand Up @@ -366,6 +367,7 @@ public function test_wrong_context() {
provider::export_user_data($approvedcontextlist);

// Ensure that nothing was exported.
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertFalse($writer->has_any_data_in_any_context());

Expand Down
1 change: 1 addition & 0 deletions mod/scorm/report/basic/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function test_export_user_preferences_single() {
// Validate exported data.
provider::export_user_preferences($user->id);
$context = \context_user::instance($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$prefs = $writer->get_user_preferences('scormreport_basic');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function test_export_user_preferences_single() {
// Validate exported data.
provider::export_user_preferences($user->id);
$context = \context_user::instance($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$prefs = $writer->get_user_preferences('scormreport_interactions');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function test_export_user_preferences_single() {
// Validate exported data.
provider::export_user_preferences($user->id);
$context = \context_user::instance($user->id);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
$prefs = $writer->get_user_preferences('scormreport_objectives');
Expand Down
1 change: 1 addition & 0 deletions notes/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public function test_export_user_data() {
foreach ($contextlist as $context) {
$this->assertEquals(CONTEXT_COURSE, $context->contextlevel);

/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
}
Expand Down
3 changes: 3 additions & 0 deletions question/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function test_export_question_usage_no_usage() {
$options = new \question_display_options();

provider::export_question_usage($testuser->id, $context, [], $quba->get_id(), $options, false);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);

$this->assertFalse($writer->has_any_data_in_any_context());
Expand Down Expand Up @@ -137,6 +138,7 @@ public function test_export_question_usage_with_usage() {
// Export all questions for this attempt.
$options = new \question_display_options();
provider::export_question_usage($testuser->id, $context, [], $quba->get_id(), $options, true);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);

$this->assertTrue($writer->has_any_data_in_any_context());
Expand All @@ -161,6 +163,7 @@ public function test_export_question_usage_with_usage() {
$options->marks = \question_display_options::HIDDEN;

provider::export_question_usage($testuser->id, $context, [], $quba->get_id(), $options, true);
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);

$this->assertTrue($writer->has_any_data_in_any_context());
Expand Down
1 change: 1 addition & 0 deletions question/tests/privacy_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function assert_question_attempt_exported(\context $context, array $subco
[get_string('questions', 'core_question')]
);

/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);

foreach ($quba->get_slots() as $slotno) {
Expand Down
Loading

0 comments on commit 4d765cd

Please sign in to comment.