-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathWriteFileUnitTest.inc
More file actions
33 lines (22 loc) · 1.16 KB
/
WriteFileUnitTest.inc
File metadata and controls
33 lines (22 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
// Test file for WriteFileSniff.
// Error: Writing to plugin directory using __FILE__.
file_put_contents( dirname( __FILE__ ) . '/cache/data.txt', 'Some data' );
// Error: Writing to plugin directory using __DIR__.
fwrite( fopen( __DIR__ . '/logs/debug.log', 'w' ), 'Debug info' );
// Error: Writing using plugin_dir_path().
fputs( fopen( plugin_dir_path( __FILE__ ) . 'error.log', 'a' ), 'Error message' );
// Error: Copying to plugin directory using WP_PLUGIN_DIR.
copy( '/tmp/file.txt', WP_PLUGIN_DIR . '/test-plugin/backup.txt' );
// Error: Moving files to plugin directory.
rename( '/tmp/temp.txt', plugin_dir_path( __FILE__ ) . 'moved.txt' );
// Error: Using WP_CONTENT_DIR.
touch( WP_CONTENT_DIR . '/custom-data.txt' );
// Error: Using plugins_url (should error).
file_put_contents( plugins_url() . '/test-plugin/data.json', '{}' );
// OK: Writing to uploads directory (no error).
file_put_contents( wp_upload_dir()['basedir'] . '/my-plugin/data.txt', 'Some data' );
// OK: Using temporary directory (no error).
fwrite( fopen( wp_tempnam( 'my-plugin-' ), 'w' ), 'Temporary data' );
// OK: Using get_temp_dir (no error).
touch( get_temp_dir() . 'my-temp-file.txt' );