Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 24... Línea 24...
24
 
24
 
25
/**
25
/**
26
 * Expired data requests tests.
26
 * Expired data requests tests.
27
 *
27
 *
-
 
28
 * @package    tool_dataprivacy
28
 * @package    tool_dataprivacy
29
 * @covers     \tool_dataprivacy\data_request
29
 * @copyright  2018 Michael Hawkins
30
 * @copyright  2018 Michael Hawkins
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
 */
Línea 32... Línea 33...
32
class expired_data_requests_test extends data_privacy_testcase {
33
final class expired_data_requests_test extends data_privacy_testcase {
33
 
34
 
34
    /**
35
    /**
35
     * Test tearDown.
36
     * Test tearDown.
Línea 39... Línea 40...
39
    }
40
    }
Línea 40... Línea 41...
40
 
41
 
41
    /**
42
    /**
42
     * Test finding and deleting expired data requests
43
     * Test finding and deleting expired data requests
43
     */
44
     */
44
    public function test_data_request_expiry() {
45
    public function test_data_request_expiry(): void {
45
        global $DB;
46
        global $DB;
46
        $this->resetAfterTest();
47
        $this->resetAfterTest();
Línea 47... Línea 48...
47
        \core_privacy\local\request\writer::setup_real_writer_instance();
48
        \core_privacy\local\request\writer::setup_real_writer_instance();
Línea 106... Línea 107...
106
        $this->assertEquals(api::DATAREQUEST_STATUS_EXPIRED, $request->get('status'));
107
        $this->assertEquals(api::DATAREQUEST_STATUS_EXPIRED, $request->get('status'));
107
        $this->assertEquals(0, $DB->count_records('files', $fileconditions));
108
        $this->assertEquals(0, $DB->count_records('files', $fileconditions));
108
    }
109
    }
Línea 109... Línea 110...
109
 
110
 
-
 
111
    /**
-
 
112
     * Test that data requests are not expired when expiration is disabled (set to zero)
-
 
113
     */
-
 
114
    public function test_data_request_expiry_never(): void {
-
 
115
        global $DB;
-
 
116
 
-
 
117
        $this->resetAfterTest();
-
 
118
 
-
 
119
        \core_privacy\local\request\writer::setup_real_writer_instance();
-
 
120
 
-
 
121
        // Disable request expiry.
-
 
122
        set_config('privacyrequestexpiry', 0, 'tool_dataprivacy');
-
 
123
 
-
 
124
        // Create and approve data request.
-
 
125
        $user = $this->getDataGenerator()->create_user();
-
 
126
        $usercontext = \context_user::instance($user->id);
-
 
127
 
-
 
128
        $this->setUser($user->id);
-
 
129
        $datarequest = api::create_data_request($user->id, api::DATAREQUEST_TYPE_EXPORT);
-
 
130
        $requestid = $datarequest->get('id');
-
 
131
 
-
 
132
        $this->setAdminUser();
-
 
133
        api::approve_data_request($requestid);
-
 
134
 
-
 
135
        ob_start();
-
 
136
        $this->runAdhocTasks('\tool_dataprivacy\task\process_data_request_task');
-
 
137
        ob_end_clean();
-
 
138
 
-
 
139
        // Run expiry deletion - should not affect test export.
-
 
140
        $expiredrequests = data_request::get_expired_requests();
-
 
141
        $this->assertEmpty($expiredrequests);
-
 
142
        data_request::expire($expiredrequests);
-
 
143
 
-
 
144
        // Confirm approved and exported.
-
 
145
        $request = new data_request($requestid);
-
 
146
        $this->assertEquals(api::DATAREQUEST_STATUS_DOWNLOAD_READY, $request->get('status'));
-
 
147
        $fileconditions = [
-
 
148
            'userid' => $user->id,
-
 
149
            'component' => 'tool_dataprivacy',
-
 
150
            'filearea' => 'export',
-
 
151
            'itemid' => $requestid,
-
 
152
            'contextid' => $usercontext->id,
-
 
153
        ];
-
 
154
        $this->assertEquals(2, $DB->count_records('files', $fileconditions));
-
 
155
    }
-
 
156
 
110
    /**
157
    /**
111
     * Test for \tool_dataprivacy\data_request::is_expired()
158
     * Test for \tool_dataprivacy\data_request::is_expired()
112
     * Tests for the expected request status to protect from false positive/negative,
159
     * Tests for the expected request status to protect from false positive/negative,
113
     * then tests is_expired() is returning the expected response.
160
     * then tests is_expired() is returning the expected response.
114
     */
161
     */
115
    public function test_is_expired() {
162
    public function test_is_expired(): void {
116
        $this->resetAfterTest();
163
        $this->resetAfterTest();
Línea 117... Línea 164...
117
        \core_privacy\local\request\writer::setup_real_writer_instance();
164
        \core_privacy\local\request\writer::setup_real_writer_instance();
118
 
165