Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 26... Línea 26...
26
 *
26
 *
27
 * @package    tool_dataprivacy
27
 * @package    tool_dataprivacy
28
 * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
28
 * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
30
 */
31
class data_request_test extends data_privacy_testcase {
31
final class data_request_test extends data_privacy_testcase {
Línea 32... Línea 32...
32
 
32
 
33
    /**
33
    /**
34
     * Data provider for testing is_resettable, and is_active.
34
     * Data provider for testing is_resettable, and is_active.
35
     *
35
     *
36
     * @return  array
36
     * @return  array
37
     */
37
     */
38
    public function status_state_provider(): array {
38
    public static function status_state_provider(): array {
39
        return [
39
        return [
40
            [
40
            [
41
                'state' => api::DATAREQUEST_STATUS_PENDING,
41
                'state' => api::DATAREQUEST_STATUS_PENDING,
42
                'resettable' => false,
42
                'resettable' => false,
Línea 87... Línea 87...
87
 
87
 
88
    /**
88
    /**
89
     * Test the pseudo states of a data request with an export request.
89
     * Test the pseudo states of a data request with an export request.
90
     *
90
     *
91
     * @dataProvider        status_state_provider
91
     * @dataProvider        status_state_provider
92
     * @param       int     $status
92
     * @param       int     $state
93
     * @param       bool    $resettable
93
     * @param       bool    $resettable
94
     * @param       bool    $active
94
     * @param       bool    $active
95
     */
95
     */
96
    public function test_pseudo_states_export(int $status, bool $resettable, bool $active): void {
96
    public function test_pseudo_states_export(int $state, bool $resettable, bool $active): void {
97
        $uut = new \tool_dataprivacy\data_request();
97
        $uut = new \tool_dataprivacy\data_request();
98
        $uut->set('status', $status);
98
        $uut->set('status', $state);
Línea 99... Línea 99...
99
        $uut->set('type', api::DATAREQUEST_TYPE_EXPORT);
99
        $uut->set('type', api::DATAREQUEST_TYPE_EXPORT);
100
 
100
 
101
        $this->assertEquals($resettable, $uut->is_resettable());
101
        $this->assertEquals($resettable, $uut->is_resettable());
Línea 102... Línea 102...
102
        $this->assertEquals($active, $uut->is_active());
102
        $this->assertEquals($active, $uut->is_active());
103
    }
103
    }
104
 
104
 
105
    /**
105
    /**
106
     * Test the pseudo states of a data request with a delete request.
106
     * Test the pseudo states of a data request with a delete request.
107
     *
107
     *
108
     * @dataProvider        status_state_provider
108
     * @dataProvider        status_state_provider
109
     * @param       int     $status
109
     * @param       int     $state
110
     * @param       bool    $resettable
110
     * @param       bool    $resettable
111
     * @param       bool    $active
111
     * @param       bool    $active
112
     */
112
     */
113
    public function test_pseudo_states_delete(int $status, bool $resettable, bool $active): void {
113
    public function test_pseudo_states_delete(int $state, bool $resettable, bool $active): void {
Línea 114... Línea 114...
114
        $uut = new \tool_dataprivacy\data_request();
114
        $uut = new \tool_dataprivacy\data_request();
115
        $uut->set('status', $status);
115
        $uut->set('status', $state);
116
        $uut->set('type', api::DATAREQUEST_TYPE_DELETE);
116
        $uut->set('type', api::DATAREQUEST_TYPE_DELETE);
Línea 117... Línea 117...
117
 
117
 
118
        $this->assertEquals($resettable, $uut->is_resettable());
118
        $this->assertEquals($resettable, $uut->is_resettable());
119
        $this->assertEquals($active, $uut->is_active());
119
        $this->assertEquals($active, $uut->is_active());
120
    }
120
    }
121
 
121
 
122
    /**
122
    /**
123
     * Test the pseudo states of a data request.
123
     * Test the pseudo states of a data request.
124
     *
124
     *
125
     * @dataProvider        status_state_provider
125
     * @dataProvider        status_state_provider
126
     * @param       int     $status
126
     * @param       int     $state
Línea 127... Línea 127...
127
     */
127
     */
128
    public function test_can_reset_others($status): void {
128
    public function test_can_reset_others(int $state, bool $resettable, bool $active): void {
Línea 129... Línea 129...
129
        $uut = new \tool_dataprivacy\data_request();
129
        $uut = new \tool_dataprivacy\data_request();
130
        $uut->set('status', $status);
130
        $uut->set('status', $state);
131
        $uut->set('type', api::DATAREQUEST_TYPE_OTHERS);
131
        $uut->set('type', api::DATAREQUEST_TYPE_OTHERS);
132
 
132
 
133
        $this->assertFalse($uut->is_resettable());
133
        $this->assertFalse($uut->is_resettable());
134
    }
134
    }
135
 
135
 
136
    /**
136
    /**
137
     * Data provider for states which are not resettable.
137
     * Data provider for states which are not resettable.
138
     *
138
     *
139
     * @return      array
139
     * @return      array
140
     */
140
     */
Línea 141... Línea 141...
141
    public function non_resettable_provider(): array {
141
    public static function non_resettable_provider(): array {
142
        $states = [];
142
        $states = [];
Línea 143... Línea 143...
143
        foreach ($this->status_state_provider() as $thisstatus) {
143
        foreach (self::status_state_provider() as $thisstatus) {
144
            if (!$thisstatus['resettable']) {
144
            if (!$thisstatus['resettable']) {
145
                $states[] = $thisstatus;
145
                $states[] = ['state' => $thisstatus['state']];
146
            }
146
            }
147
        }
147
        }
148
 
148
 
149
        return $states;
149
        return $states;
150
    }
150
    }
151
 
151
 
Línea 152... Línea 152...
152
    /**
152
    /**
153
     * Ensure that requests which are not resettable cause an exception to be thrown.
153
     * Ensure that requests which are not resettable cause an exception to be thrown.
Línea 154... Línea 154...
154
     *
154
     *