| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group admin |
| | 5 | */ |
| | 6 | class Tests_Admin_Includes_Schema extends WP_UnitTestCase { |
| | 7 | |
| | 8 | private static $options; |
| | 9 | |
| | 10 | /** |
| | 11 | * Make sure the schema code is loaded before the tests are run. |
| | 12 | */ |
| | 13 | public static function wpSetUpBeforeClass() { |
| | 14 | global $wpdb; |
| | 15 | |
| | 16 | self::$options = 'testprefix_options'; |
| | 17 | |
| | 18 | $options = self::$options; |
| | 19 | |
| | 20 | require_once( ABSPATH . 'wp-admin/includes/schema.php' ); |
| | 21 | |
| | 22 | $charset_collate = $wpdb->get_charset_collate(); |
| | 23 | $max_index_length = 191; |
| | 24 | |
| | 25 | $wpdb->query( |
| | 26 | " |
| | 27 | CREATE TABLE {$options} ( |
| | 28 | option_id bigint(20) unsigned NOT NULL auto_increment, |
| | 29 | option_name varchar(191) NOT NULL default '', |
| | 30 | option_value longtext NOT NULL, |
| | 31 | autoload varchar(20) NOT NULL default 'yes', |
| | 32 | PRIMARY KEY (option_id), |
| | 33 | UNIQUE KEY option_name (option_name) |
| | 34 | ) {$charset_collate} |
| | 35 | " |
| | 36 | ); |
| | 37 | } |
| | 38 | |
| | 39 | /** |
| | 40 | * Drop tables that were created before running the tests. |
| | 41 | */ |
| | 42 | public static function wpTearDownAfterClass() { |
| | 43 | global $wpdb; |
| | 44 | |
| | 45 | $options = self::$options; |
| | 46 | |
| | 47 | $wpdb->query( "DROP TABLE IF EXISTS {$options}" ); |
| | 48 | } |
| | 49 | |
| | 50 | /** |
| | 51 | * @ticket 44893 |
| | 52 | * @dataProvider data_populate_options |
| | 53 | */ |
| | 54 | function test_populate_options( $options, $expected ) { |
| | 55 | global $wpdb; |
| | 56 | |
| | 57 | remove_all_filters( 'option_admin_email' ); |
| | 58 | remove_all_filters( 'pre_option_admin_email' ); |
| | 59 | remove_all_filters( 'default_option_admin_email' ); |
| | 60 | |
| | 61 | $orig_options = $wpdb->options; |
| | 62 | $wpdb->options = self::$options; |
| | 63 | |
| | 64 | populate_options( $options ); |
| | 65 | |
| | 66 | wp_cache_delete( 'alloptions', 'options' ); |
| | 67 | |
| | 68 | $results = array(); |
| | 69 | foreach ( $expected as $option => $value ) { |
| | 70 | $results[ $option ] = get_option( $option ); |
| | 71 | } |
| | 72 | |
| | 73 | $wpdb->query( "TRUNCATE TABLE {$wpdb->options}" ); |
| | 74 | |
| | 75 | $wpdb->options = $orig_options; |
| | 76 | |
| | 77 | $this->assertEquals( $expected, $results ); |
| | 78 | } |
| | 79 | |
| | 80 | public function data_populate_options() { |
| | 81 | return array( |
| | 82 | array( |
| | 83 | array(), |
| | 84 | array( |
| | 85 | // Random options to check. |
| | 86 | 'posts_per_rss' => 10, |
| | 87 | 'rss_use_excerpt' => 0, |
| | 88 | 'mailserver_url' => 'mail.example.com', |
| | 89 | 'mailserver_login' => 'login@example.com', |
| | 90 | 'mailserver_pass' => 'password', |
| | 91 | ), |
| | 92 | ), |
| | 93 | array( |
| | 94 | array( |
| | 95 | 'posts_per_rss' => 7, |
| | 96 | 'rss_use_excerpt' => 1, |
| | 97 | ), |
| | 98 | array( |
| | 99 | // Random options to check. |
| | 100 | 'posts_per_rss' => 7, |
| | 101 | 'rss_use_excerpt' => 1, |
| | 102 | 'mailserver_url' => 'mail.example.com', |
| | 103 | 'mailserver_login' => 'login@example.com', |
| | 104 | 'mailserver_pass' => 'password', |
| | 105 | ), |
| | 106 | ), |
| | 107 | array( |
| | 108 | array( |
| | 109 | 'custom_option' => '1', |
| | 110 | ), |
| | 111 | array( |
| | 112 | // Random options to check. |
| | 113 | 'custom_option' => '1', |
| | 114 | 'posts_per_rss' => 10, |
| | 115 | 'rss_use_excerpt' => 0, |
| | 116 | 'mailserver_url' => 'mail.example.com', |
| | 117 | 'mailserver_login' => 'login@example.com', |
| | 118 | 'mailserver_pass' => 'password', |
| | 119 | ), |
| | 120 | ), |
| | 121 | array( |
| | 122 | array( |
| | 123 | 'use_quicktags' => '1', |
| | 124 | ), |
| | 125 | array( |
| | 126 | // This option is on a blacklist and should never exist. |
| | 127 | 'use_quicktags' => false, |
| | 128 | ), |
| | 129 | ), |
| | 130 | array( |
| | 131 | array( |
| | 132 | 'rss_0123456789abcdef0123456789abcdef' => '1', |
| | 133 | 'rss_0123456789abcdef0123456789abcdef_ts' => '1', |
| | 134 | ), |
| | 135 | array( |
| | 136 | // These options would be obsolete magpie cache data and should never exist. |
| | 137 | 'rss_0123456789abcdef0123456789abcdef' => false, |
| | 138 | 'rss_0123456789abcdef0123456789abcdef_ts' => false, |
| | 139 | ), |
| | 140 | ), |
| | 141 | ); |
| | 142 | } |
| | 143 | } |