Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 27... Línea 27...
27
class property_list_test extends \advanced_testcase {
27
class property_list_test extends \advanced_testcase {
Línea 28... Línea 28...
28
 
28
 
29
    /**
29
    /**
30
     * Test that an empty PList with a root dictionary is created.
30
     * Test that an empty PList with a root dictionary is created.
31
     */
31
     */
32
    public function test_create_empty_plist() {
32
    public function test_create_empty_plist(): void {
33
        $emptyplist = new property_list();
33
        $emptyplist = new property_list();
34
        $xml = trim($emptyplist->to_xml());
34
        $xml = trim($emptyplist->to_xml());
35
        $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>
35
        $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>
36
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
36
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
37
<plist version="1.0"><dict/></plist>', $xml);
37
<plist version="1.0"><dict/></plist>', $xml);
Línea 38... Línea 38...
38
    }
38
    }
39
 
39
 
40
    /**
40
    /**
41
     * Test that a Plist is constructed from an XML string.
41
     * Test that a Plist is constructed from an XML string.
42
     */
42
     */
43
    public function test_construct_plist_from_xml() {
43
    public function test_construct_plist_from_xml(): void {
44
        $xml = $this->get_plist_xml_header()
44
        $xml = $this->get_plist_xml_header()
45
            . "<key>testKey</key>"
45
            . "<key>testKey</key>"
46
            . "<string>testValue</string>"
46
            . "<string>testValue</string>"
Línea 53... Línea 53...
53
    }
53
    }
Línea 54... Línea 54...
54
 
54
 
55
    /**
55
    /**
56
     * Test that an element can be added to the root dictionary.
56
     * Test that an element can be added to the root dictionary.
57
     */
57
     */
58
    public function test_add_element_to_root() {
58
    public function test_add_element_to_root(): void {
59
        $plist = new property_list();
59
        $plist = new property_list();
60
        $newelement = new \CFPropertyList\CFString('testValue');
60
        $newelement = new \CFPropertyList\CFString('testValue');
61
        $plist->add_element_to_root('testKey', $newelement);
61
        $plist->add_element_to_root('testKey', $newelement);
62
        $generatedxml = trim($plist->to_xml());
62
        $generatedxml = trim($plist->to_xml());
Línea 66... Línea 66...
66
    }
66
    }
Línea 67... Línea 67...
67
 
67
 
68
    /**
68
    /**
69
     * Test that an element's value can be retrieved.
69
     * Test that an element's value can be retrieved.
70
     */
70
     */
71
    public function test_get_element_value() {
71
    public function test_get_element_value(): void {
72
        $xml = $this->get_plist_xml_header()
72
        $xml = $this->get_plist_xml_header()
73
                . "<key>testKey</key>"
73
                . "<key>testKey</key>"
74
                . "<string>testValue</string>"
74
                . "<string>testValue</string>"
75
                . $this->get_plist_xml_footer();
75
                . $this->get_plist_xml_footer();
Línea 78... Línea 78...
78
    }
78
    }
Línea 79... Línea 79...
79
 
79
 
80
    /**
80
    /**
81
     * Test that an element's value can be retrieved.
81
     * Test that an element's value can be retrieved.
82
     */
82
     */
83
    public function test_get_element_value_if_not_exists() {
83
    public function test_get_element_value_if_not_exists(): void {
84
        $plist = new property_list();
84
        $plist = new property_list();
85
        $this->assertEmpty($plist->get_element_value('testKey'));
85
        $this->assertEmpty($plist->get_element_value('testKey'));
Línea 86... Línea 86...
86
    }
86
    }
87
 
87
 
88
    /**
88
    /**
89
     * Test an element's value can be retrieved if it is an array.
89
     * Test an element's value can be retrieved if it is an array.
90
     */
90
     */
91
    public function test_get_element_value_if_array() {
91
    public function test_get_element_value_if_array(): void {
92
        $xml = $this->get_plist_xml_header()
92
        $xml = $this->get_plist_xml_header()
93
            . "<key>testDict</key>"
93
            . "<key>testDict</key>"
94
            . "<dict>"
94
            . "<dict>"
Línea 107... Línea 107...
107
     * @param string $key Key of element to try and update.
107
     * @param string $key Key of element to try and update.
108
     * @param mixed $value Value to try to update with.
108
     * @param mixed $value Value to try to update with.
109
     *
109
     *
110
     * @dataProvider good_update_data_provider
110
     * @dataProvider good_update_data_provider
111
     */
111
     */
112
    public function test_updating_element_value($xml, $key, $value) {
112
    public function test_updating_element_value($xml, $key, $value): void {
113
        $xml = $this->get_plist_xml_header()
113
        $xml = $this->get_plist_xml_header()
114
            . $xml
114
            . $xml
115
            . $this->get_plist_xml_footer();
115
            . $this->get_plist_xml_footer();
116
        $plist = new property_list($xml);
116
        $plist = new property_list($xml);
117
        $plist->update_element_value($key, $value);
117
        $plist->update_element_value($key, $value);
Línea 127... Línea 127...
127
     * @param mixed $expected Expected value of element after update is called.
127
     * @param mixed $expected Expected value of element after update is called.
128
     * @param string $exceptionmessage Message of exception expected to be thrown.
128
     * @param string $exceptionmessage Message of exception expected to be thrown.
Línea 129... Línea 129...
129
 
129
 
130
     * @dataProvider bad_update_data_provider
130
     * @dataProvider bad_update_data_provider
131
     */
131
     */
132
    public function test_updating_element_value_with_bad_data(string $xml, string $key, $value, $expected, $exceptionmessage) {
132
    public function test_updating_element_value_with_bad_data(string $xml, string $key, $value, $expected, $exceptionmessage): void {
133
        $xml = $this->get_plist_xml_header()
133
        $xml = $this->get_plist_xml_header()
134
            . $xml
134
            . $xml
135
            . $this->get_plist_xml_footer();
135
            . $this->get_plist_xml_footer();
Línea 144... Línea 144...
144
    }
144
    }
Línea 145... Línea 145...
145
 
145
 
146
    /**
146
    /**
147
     * Test that a dictionary can have it's value (array) updated.
147
     * Test that a dictionary can have it's value (array) updated.
148
     */
148
     */
149
    public function test_updating_element_array_if_dictionary() {
149
    public function test_updating_element_array_if_dictionary(): void {
150
        $xml = $this->get_plist_xml_header()
150
        $xml = $this->get_plist_xml_header()
151
            . "<key>testDict</key>"
151
            . "<key>testDict</key>"
152
            . "<dict>"
152
            . "<dict>"
153
            . "<key>testKey</key>"
153
            . "<key>testKey</key>"
Línea 160... Línea 160...
160
    }
160
    }
Línea 161... Línea 161...
161
 
161
 
162
    /**
162
    /**
163
     * Test that a dictionary can have it's value (array) updated.
163
     * Test that a dictionary can have it's value (array) updated.
164
     */
164
     */
165
    public function test_updating_element_array_if_dictionary_with_bad_data() {
165
    public function test_updating_element_array_if_dictionary_with_bad_data(): void {
166
        $xml = $this->get_plist_xml_header()
166
        $xml = $this->get_plist_xml_header()
167
            . "<key>testDict</key>"
167
            . "<key>testDict</key>"
168
            . "<dict>"
168
            . "<dict>"
169
            . "<key>testKey</key>"
169
            . "<key>testKey</key>"
Línea 182... Línea 182...
182
    }
182
    }
Línea 183... Línea 183...
183
 
183
 
184
    /**
184
    /**
185
     * Test that an element can be deleted.
185
     * Test that an element can be deleted.
186
     */
186
     */
187
    public function test_delete_element() {
187
    public function test_delete_element(): void {
188
        $xml = $this->get_plist_xml_header()
188
        $xml = $this->get_plist_xml_header()
189
            . "<key>testKey</key>"
189
            . "<key>testKey</key>"
190
            . "<string>testValue</string>"
190
            . "<string>testValue</string>"
191
            . $this->get_plist_xml_footer();
191
            . $this->get_plist_xml_footer();
Línea 198... Línea 198...
198
    }
198
    }
Línea 199... Línea 199...
199
 
199
 
200
    /**
200
    /**
201
     * Test that an element can be deleted.
201
     * Test that an element can be deleted.
202
     */
202
     */
203
    public function test_delete_element_if_not_exists() {
203
    public function test_delete_element_if_not_exists(): void {
204
        $xml = $this->get_plist_xml_header()
204
        $xml = $this->get_plist_xml_header()
205
            . "<key>testKey</key>"
205
            . "<key>testKey</key>"
206
            . "<string>testValue</string>"
206
            . "<string>testValue</string>"
207
            . $this->get_plist_xml_footer();
207
            . $this->get_plist_xml_footer();
Línea 220... Línea 220...
220
     * @param string $xml PList XML used to generate CFPropertyList.
220
     * @param string $xml PList XML used to generate CFPropertyList.
221
     * @param string $expectedjson Expected JSON output.
221
     * @param string $expectedjson Expected JSON output.
222
     *
222
     *
223
     * @dataProvider json_data_provider
223
     * @dataProvider json_data_provider
224
     */
224
     */
225
    public function test_export_to_json($xml, $expectedjson) {
225
    public function test_export_to_json($xml, $expectedjson): void {
226
        $xml = $this->get_plist_xml_header()
226
        $xml = $this->get_plist_xml_header()
227
            . $xml
227
            . $xml
228
            . $this->get_plist_xml_footer();
228
            . $this->get_plist_xml_footer();
229
        $plist = new property_list($xml);
229
        $plist = new property_list($xml);
230
        $generatedjson = $plist->to_json();
230
        $generatedjson = $plist->to_json();
Línea 232... Línea 232...
232
    }
232
    }
Línea 233... Línea 233...
233
 
233
 
234
    /**
234
    /**
235
     * Test that the xml is exported to JSON from a real SEB config file. Expected JSON extracted from SEB logs.
235
     * Test that the xml is exported to JSON from a real SEB config file. Expected JSON extracted from SEB logs.
236
     */
236
     */
237
    public function test_export_to_json_full_file() {
237
    public function test_export_to_json_full_file(): void {
238
        $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted_mac_001.seb');
238
        $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted_mac_001.seb');
239
        $plist = new property_list($xml);
239
        $plist = new property_list($xml);
240
        $plist->delete_element('originatorVersion'); // JSON should not contain originatorVersion key.
240
        $plist->delete_element('originatorVersion'); // JSON should not contain originatorVersion key.
241
        $generatedjson = $plist->to_json();
241
        $generatedjson = $plist->to_json();
Línea 244... Línea 244...
244
    }
244
    }
Línea 245... Línea 245...
245
 
245
 
246
    /**
246
    /**
247
     * Test the set_or_update_value function.
247
     * Test the set_or_update_value function.
248
     */
248
     */
249
    public function test_set_or_update_value() {
249
    public function test_set_or_update_value(): void {
Línea 250... Línea 250...
250
        $plist = new property_list();
250
        $plist = new property_list();
251
 
251
 
252
        $this->assertEmpty($plist->get_element_value('string'));
252
        $this->assertEmpty($plist->get_element_value('string'));