| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group option |
| | 5 | */ |
| | 6 | class Tests_Sanitize_Option extends WP_UnitTestCase { |
| | 7 | |
| | 8 | /** |
| | 9 | * Data provider to test all of the sanitize_option() case |
| | 10 | * |
| | 11 | * Inner array params: $option_name, $sanitized, $original |
| | 12 | * @return array |
| | 13 | * |
| | 14 | */ |
| | 15 | public function sanitize_option_provider() { |
| | 16 | return array( |
| | 17 | array( 'admin_email', 'mail@email.com', 'mail@email.com' ), |
| | 18 | array( 'page_on_front', 0, 0 ), |
| | 19 | array( 'posts_per_page', 10, 10 ), |
| | 20 | array( 'default_ping_status', 'open', 'open' ), |
| | 21 | array( 'blogname', 'My Site', 'My Site' ), |
| | 22 | array( 'blog_charset', 'UTF-8', 'UTF-8' ), |
| | 23 | array( 'blog_public', 1, 1 ), |
| | 24 | array( 'date_format', 'F j, Y', 'F j, Y' ), |
| | 25 | array( 'ping_sites', 'http://rpc.pingomatic.com/', 'http://rpc.pingomatic.com/' ), |
| | 26 | array( 'gmt_offset', 0, 0 ), |
| | 27 | array( 'siteurl', 'http://example.org', 'http://example.org' ), |
| | 28 | array( 'home', 'http://example.org', 'http://example.org' ), |
| | 29 | array( 'WPLANG', 0, 0 ), |
| | 30 | array( |
| | 31 | 'illegal_names', |
| | 32 | array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ), |
| | 33 | array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ), |
| | 34 | ), |
| | 35 | array( |
| | 36 | 'banned_email_domains', |
| | 37 | array( 'mail.com', 'gmail.com' ), |
| | 38 | array( 'mail.com', 'gmail.com' ), |
| | 39 | ), |
| | 40 | array( 'timezone_string', 0, 0 ), |
| | 41 | |
| | 42 | array( 'permalink_structure', 0, 0 ), |
| | 43 | array( 'default_role', 'subscriber', 'subscriber' ), |
| | 44 | array( 'moderation_keys', 'string of words', 'string of words' ), |
| | 45 | |
| | 46 | |
| | 47 | ); |
| | 48 | } |
| | 49 | |
| | 50 | /** |
| | 51 | * @dataProvider sanitize_option_provider |
| | 52 | */ |
| | 53 | function test_sanitize_option( $option_name, $sanitized, $original ) { |
| | 54 | $this->assertEquals( $sanitized , sanitize_option( $option_name, $original ) ); |
| | 55 | } |
| | 56 | |
| | 57 | public function upload_path_provider() { |
| | 58 | return array( |
| | 59 | array( '<a href="http://www.website.com">Link</a>', 'Link' ), |
| | 60 | array( '<script>url</script>', 'url' ), |
| | 61 | array( '/path/to/things', '/path/to/things' ), |
| | 62 | array( '\path\to\things', '\path\to\things' ), |
| | 63 | ); |
| | 64 | } |
| | 65 | |
| | 66 | /** |
| | 67 | * @dataProvider upload_path_provider |
| | 68 | */ |
| | 69 | function test_sanitize_option_upload_path( $provided, $expected ) { |
| | 70 | $this->assertEquals( $expected , sanitize_option( 'upload_path', $provided ) ); |
| | 71 | } |
| | 72 | } |
| | 73 | No newline at end of file |