Changeset 57920
- Timestamp:
- 04/03/2024 09:29:13 PM (3 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r57919 r57920 287 287 288 288 // Misc filters. 289 289 290 add_filter( 'option_ping_sites', 'privacy_ping_filter' ); 290 291 add_filter( 'option_blog_charset', '_wp_specialchars' ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop. -
trunk/src/wp-includes/option.php
r57110 r57920 393 393 394 394 $grouped_options = array( 395 ' yes'=> array(),396 ' no'=> array(),395 ' => array(), 396 ' => array(), 397 397 ); 398 398 $results = array(); 399 399 foreach ( $options as $option => $autoload ) { 400 400 wp_protect_special_option( $option ); // Ensure only valid options can be passed. 401 if ( ' no' === $autoload || false === $autoload ) { // Sanitize autoload value and categorize accordingly.402 $grouped_options[' no'][] = $option;401 if ( 'no' === $autoload || false === $autoload ) { // Sanitize autoload value and categorize accordingly. 402 $grouped_options[''][] = $option; 403 403 } else { 404 $grouped_options[' yes'][] = $option;404 $grouped_options[''][] = $option; 405 405 } 406 406 $results[ $option ] = false; // Initialize result value. … … 466 466 467 467 /* 468 * If any options were changed to ' yes', delete their individual caches, and delete 'alloptions' cache so that it468 * If any options were changed to '', delete their individual caches, and delete 'alloptions' cache so that it 469 469 * is refreshed as needed. 470 * If no options were changed to ' yes' but any options were changed to 'no', delete them from the 'alloptions'471 * cache. This is not necessary when options were changed to ' yes', since in that situation the entire cache is470 * If no options were changed to '' but any options were changed to 'no', delete them from the 'alloptions' 471 * cache. This is not necessary when options were changed to '', since in that situation the entire cache is 472 472 * deleted anyway. 473 473 */ 474 if ( $grouped_options[' yes'] ) {475 wp_cache_delete_multiple( $grouped_options[' yes'], 'options' );474 if ( $grouped_options[''] ) { 475 wp_cache_delete_multiple( $grouped_options[''], 'options' ); 476 476 wp_cache_delete( 'alloptions', 'options' ); 477 } elseif ( $grouped_options[' no'] ) {477 } elseif ( $grouped_options[''] ) { 478 478 $alloptions = wp_load_alloptions( true ); 479 479 480 foreach ( $grouped_options[' no'] as $option ) {480 foreach ( $grouped_options[''] as $option ) { 481 481 if ( isset( $alloptions[ $option ] ) ) { 482 482 unset( $alloptions[ $option ] ); … … 607 607 if ( ! $alloptions ) { 608 608 $suppress = $wpdb->suppress_errors(); 609 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ); 609 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload IN ( '" . implode( "', '", wp_autoload_values_to_autoload() ) . "' )" ); 610 610 611 if ( ! $alloptions_db ) { 611 612 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); … … 706 707 * @global wpdb $wpdb WordPress database abstraction object. 707 708 * 708 * @param string $option Name of the option to update. Expected to not be SQL-escaped. 709 * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. 710 * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options, 711 * `$autoload` can only be updated using `update_option()` if `$value` is also changed. 712 * Accepts 'yes'|true to enable or 'no'|false to disable. 713 * Autoloading too many options can lead to performance problems, especially if the 714 * options are not frequently used. For options which are accessed across several places 715 * in the frontend, it is recommended to autoload them, by using 'yes'|true. 716 * For options which are accessed only on few specific URLs, it is recommended 717 * to not autoload them, by using 'no'|false. For non-existent options, the default value 718 * is 'yes'. Default null. 709 * @param string $option Name of the option to update. Expected to not be SQL-escaped. 710 * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. 711 * @param bool|null $autoload Optional. Whether to load the option when WordPress starts up. 712 * Accepts a boolean, or `null` to stick with the initial value or, if no initial value is set, 713 * to leave the decision up to default heuristics in WordPress. 714 * For existing options, 715 * `$autoload` can only be updated using `update_option()` if `$value` is also changed. 716 * For backward compatibility 'yes' and 'no' are also accepted. 717 * Autoloading too many options can lead to performance problems, especially if the 718 * options are not frequently used. For options which are accessed across several places 719 * in the frontend, it is recommended to autoload them, by using true. 720 * For options which are accessed only on few specific URLs, it is recommended 721 * to not autoload them, by using false. 722 * For non-existent options, the default is null, which means WordPress will determine 723 * the autoload value. 719 724 * @return bool True if the value was updated, false otherwise. 720 725 */ … … 802 807 /** This filter is documented in wp-includes/option.php */ 803 808 if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) { 804 // Default setting for new options is 'yes'.805 if ( null === $autoload ) {806 $autoload = 'yes';807 }808 809 809 return add_option( $option, $value, '', $autoload ); 810 810 } … … 828 828 829 829 if ( null !== $autoload ) { 830 $update_args['autoload'] = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; 830 $update_args['autoload'] = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ); 831 } else { 832 // Retrieve the current autoload value to reevaluate it in case it was set automatically. 833 $raw_autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); 834 $allow_values = array( 'auto-on', 'auto-off', 'auto' ); 835 if ( in_array( $raw_autoload, $allow_values, true ) ) { 836 $autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ); 837 if ( $autoload !== $raw_autoload ) { 838 $update_args['autoload'] = $autoload; 839 } 840 } 831 841 } 832 842 … … 854 864 wp_cache_set( $option, $serialized_value, 'options' ); 855 865 } 856 } elseif ( 'yes' === $update_args['autoload']) {866 } elseif ( ) { 857 867 // Delete the individual cache, then set in alloptions cache. 858 868 wp_cache_delete( $option, 'options' ); … … 916 926 * 917 927 * @since 1.0.0 928 918 929 * 919 930 * @global wpdb $wpdb WordPress database abstraction object. 920 931 * 921 * @param string $option Name of the option to add. Expected to not be SQL-escaped. 922 * @param mixed $value Optional. Option value. Must be serializable if non-scalar. 923 * Expected to not be SQL-escaped. 924 * @param string $deprecated Optional. Description. Not used anymore. 925 * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. 926 * Accepts 'yes'|true to enable or 'no'|false to disable. 927 * Autoloading too many options can lead to performance problems, especially if the 928 * options are not frequently used. For options which are accessed across several places 929 * in the frontend, it is recommended to autoload them, by using 'yes'|true. 930 * For options which are accessed only on few specific URLs, it is recommended 931 * to not autoload them, by using 'no'|false. Default 'yes'. 932 * @param string $option Name of the option to add. Expected to not be SQL-escaped. 933 * @param mixed $value Optional. Option value. Must be serializable if non-scalar. 934 * Expected to not be SQL-escaped. 935 * @param string $deprecated Optional. Description. Not used anymore. 936 * @param bool|null $autoload Optional. Whether to load the option when WordPress starts up. 937 * Accepts a boolean, or `null` to leave the decision up to default heuristics in WordPress. 938 * For backward compatibility 'yes' and 'no' are also accepted. 939 * Autoloading too many options can lead to performance problems, especially if the 940 * options are not frequently used. For options which are accessed across several places 941 * in the frontend, it is recommended to autoload them, by using 'yes'|true. 942 * For options which are accessed only on few specific URLs, it is recommended 943 * to not autoload them, by using false. 944 * Default is null, which means WordPress will determine the autoload value. 932 945 * @return bool True if the option was added, false otherwise. 933 946 */ 934 function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes') {947 function add_option( $option, $value = '', $deprecated = '', $autoload = ) { 935 948 global $wpdb; 936 949 … … 992 1005 993 1006 $serialized_value = maybe_serialize( $value ); 994 $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; 1007 1008 $autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ); 995 1009 996 1010 /** … … 1010 1024 1011 1025 if ( ! wp_installing() ) { 1012 if ( 'yes' === $autoload) {1026 if ( ) { 1013 1027 $alloptions = wp_load_alloptions( true ); 1014 1028 $alloptions[ $option ] = $serialized_value; … … 1094 1108 1095 1109 if ( ! wp_installing() ) { 1096 if ( 'yes' === $row->autoload) {1110 if ( ) { 1097 1111 $alloptions = wp_load_alloptions( true ); 1098 1112 … … 1132 1146 1133 1147 return false; 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1134 1238 } 1135 1239 … … 2925 3029 return $registered[ $option ]['default']; 2926 3030 } 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 -
trunk/tests/phpunit/tests/customize/setting.php
r56536 r57920 611 611 $setting->save(); 612 612 $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) ); 613 $this->assertSame( ' yes', $autoload );613 $this->assertSame( '', $autoload ); 614 614 $this->assertSame( $value, get_option( $name ) ); 615 615 … … 627 627 $setting->save(); 628 628 $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) ); 629 $this->assertSame( ' yes', $autoload );629 $this->assertSame( '', $autoload ); 630 630 $this->assertSame( $value, get_option( $name ) ); 631 631 … … 643 643 $setting->save(); 644 644 $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $setting->id ) ); 645 $this->assertSame( ' no', $autoload );645 $this->assertSame( '', $autoload ); 646 646 $this->assertSame( $value, get_option( $name ) ); 647 647 … … 666 666 $setting1->save(); 667 667 $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $id_base ) ); 668 $this->assertSame( ' no', $autoload, 'Even though setting1 did not indicate autoload (thus normally true), since another multidimensional option setting of the base did say autoload=false, it should be autoload=no' );668 $this->assertSame( '', $autoload, 'Even though setting1 did not indicate autoload (thus normally true), since another multidimensional option setting of the base did say autoload=false, it should be autoload=no' ); 669 669 } 670 670 -
trunk/tests/phpunit/tests/option/option.php
r56946 r57920 309 309 'string 123' => array( '123' ), 310 310 'integer 123' => array( 123 ), 311 'integer -123' => array( - 123 ),311 'integer -123' => array( -123 ), 312 312 'float 12.3' => array( 12.3 ), 313 'float -1.23' => array( - 1.23 ),313 'float -1.23' => array( -1.23 ), 314 314 'boolean true' => array( true ), 315 315 ); … … 360 360 public function data_option_autoloading() { 361 361 return array( 362 array( 'autoload_yes', 'yes', 'yes' ), 363 array( 'autoload_true', true, 'yes' ), 364 array( 'autoload_string', 'foo', 'yes' ), 365 array( 'autoload_int', 123456, 'yes' ), 366 array( 'autoload_array', array(), 'yes' ), 367 array( 'autoload_no', 'no', 'no' ), 368 array( 'autoload_false', false, 'no' ), 369 ); 362 // Supported values. 363 array( 'autoload_yes', 'yes', 'on' ), 364 array( 'autoload_true', true, 'on' ), 365 array( 'autoload_no', 'no', 'off' ), 366 array( 'autoload_false', false, 'off' ), 367 array( 'autoload_null', null, 'auto' ), 368 369 // Technically unsupported values. 370 array( 'autoload_string', 'foo', 'auto' ), 371 array( 'autoload_int', 123456, 'auto' ), 372 array( 'autoload_array', array(), 'auto' ), 373 ); 374 } 375 376 /** 377 * @ticket 42441 378 * 379 * @covers ::update_option 380 * 381 * @dataProvider data_option_autoloading_large_option 382 */ 383 public function test_update_option_autoloading_large_option( $autoload, $expected ) { 384 global $wpdb; 385 $name = 'foo'; 386 add_option( $name, 'bar' ); 387 add_filter( 'wp_max_autoloaded_option_size', array( $this, 'filter_max_option_size' ) ); 388 $value = file( DIR_TESTDATA . '/formatting/entities.txt' ); 389 $updated = update_option( $name, $value, $autoload ); 390 $this->assertTrue( $updated ); 391 392 $actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $name ) ); 393 $this->assertSame( $expected, $actual->autoload ); 394 } 395 396 public function data_option_autoloading_large_option() { 397 return array( 398 'on' => array( 399 'autoload' => 'on', 400 'expected' => 'on', 401 ), 402 'off' => array( 403 'autoload' => 'off', 404 'expected' => 'off', 405 ), 406 'yes' => array( 407 'autoload' => 'yes', 408 'expected' => 'on', 409 ), 410 'true' => array( 411 'autoload' => true, 412 'expected' => 'on', 413 ), 414 'no' => array( 415 'autoload' => 'no', 416 'expected' => 'off', 417 ), 418 'false' => array( 419 'autoload' => false, 420 'expected' => 'off', 421 ), 422 'null' => array( 423 'autoload' => null, 424 'expected' => 'auto-off', 425 ), 426 ); 427 } 428 429 public function filter_max_option_size( $current ) { 430 return 1000; 431 } 432 433 /** 434 * @ticket 42441 435 * 436 * @covers ::update_option 437 */ 438 public function test_update_option_autoloading_small_option_auto() { 439 global $wpdb; 440 441 $name = 'foo'; 442 add_option( $name, 'bar' ); 443 $updated = update_option( $name, 'small_option_data' ); 444 $this->assertTrue( $updated ); 445 446 $actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $name ) ); 447 $this->assertSame( 'auto', $actual->autoload ); 370 448 } 371 449 -
trunk/tests/phpunit/tests/option/wpLoadAlloptions.php
r55745 r57920 18 18 public function test_if_alloptions_is_cached() { 19 19 $this->assertNotEmpty( wp_cache_get( 'alloptions', 'options' ) ); 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 20 46 } 21 47 -
trunk/tests/phpunit/tests/option/wpSetOptionAutoload.php
r56508 r57920 23 23 24 24 $this->assertTrue( wp_set_option_autoload( $option, 'yes' ), 'Function did not succeed' ); 25 $this->assertSame( ' yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );25 $this->assertSame( '', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); 26 26 $this->assertFalse( wp_cache_get( $option, 'options' ), 'Option not deleted from individual cache' ); 27 27 $this->assertFalse( wp_cache_get( 'alloptions', 'options' ), 'Alloptions cache not cleared' ); … … 42 42 43 43 $this->assertTrue( wp_set_option_autoload( $option, 'no' ), 'Function did not succeed' ); 44 $this->assertSame( ' no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );44 $this->assertSame( '', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); 45 45 $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), 'Option not deleted from alloptions cache' ); 46 46 } … … 60 60 61 61 $this->assertFalse( wp_set_option_autoload( $option, 'yes' ), 'Function did unexpectedly succeed' ); 62 $this->assertSame( ' yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value unexpectedly updated in database' );62 $this->assertSame( '', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value unexpectedly updated in database' ); 63 63 } 64 64 … … 93 93 94 94 $this->assertTrue( wp_set_option_autoload( $option, true ), 'Function did not succeed' ); 95 $this->assertSame( ' yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );95 $this->assertSame( '', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); 96 96 } 97 97 … … 110 110 111 111 $this->assertTrue( wp_set_option_autoload( $option, false ), 'Function did not succeed' ); 112 $this->assertSame( ' no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' );112 $this->assertSame( '', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); 113 113 } 114 114 } -
trunk/tests/phpunit/tests/option/wpSetOptionAutoloadValues.php
r56559 r57920 31 31 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 32 32 $this->assertSame( $num_queries + 2, get_num_queries(), 'Function made unexpected amount of database queries' ); 33 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );33 $this->assertSame( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 34 34 foreach ( $options as $option => $autoload ) { 35 35 $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) ); … … 62 62 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 63 63 $this->assertSame( $num_queries + 2, get_num_queries(), 'Function made unexpected amount of database queries' ); 64 $this->assertSame( array( ' no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );64 $this->assertSame( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 65 65 foreach ( $options as $option => $autoload ) { 66 66 $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), sprintf( 'Option %s not deleted from alloptions cache', $option ) ); … … 90 90 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 91 91 $this->assertSame( $num_queries + 1, get_num_queries(), 'Function made unexpected amount of database queries' ); 92 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );92 $this->assertSame( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 93 93 foreach ( $options as $option => $autoload ) { 94 94 $this->assertArrayHasKey( $option, wp_cache_get( 'alloptions', 'options' ), sprintf( 'Option %s unexpectedly deleted from alloptions cache', $option ) ); … … 125 125 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 126 126 $this->assertSame( $num_queries + 3, get_num_queries(), 'Function made unexpected amount of database queries' ); 127 $this->assertSameSets( array( ' yes', 'no', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );127 $this->assertSameSets( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 128 128 foreach ( $options as $option => $autoload ) { 129 129 $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) ); … … 159 159 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 160 160 $this->assertSame( $num_queries + 2, get_num_queries(), 'Function made unexpected amount of database queries' ); 161 $this->assertSameSets( array( ' yes', 'no', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );161 $this->assertSameSets( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 162 162 foreach ( $options as $option => $autoload ) { 163 163 if ( 'no' === $autoload ) { … … 200 200 201 201 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 202 $this->assertSame( array( ' no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );202 $this->assertSame( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 203 203 } 204 204 … … 225 225 $this->assertSame( $expected, wp_set_option_autoload_values( $options ), 'Function produced unexpected result' ); 226 226 $this->assertSame( $num_queries + 3, get_num_queries(), 'Function made unexpected amount of database queries' ); 227 $this->assertSameSets( array( ' yes', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );227 $this->assertSameSets( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 228 228 } 229 229 -
trunk/tests/phpunit/tests/option/wpSetOptionsAutoload.php
r56508 r57920 31 31 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function did not succeed' ); 32 32 $this->assertSame( $num_queries + 2, get_num_queries(), 'Updating options autoload value ran too many queries' ); 33 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );33 $this->assertSame( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 34 34 foreach ( $options as $option => $value ) { 35 35 $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) ); … … 60 60 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'no' ), 'Function did not succeed' ); 61 61 $this->assertSame( $num_queries + 2, get_num_queries(), 'Updating options autoload value ran too many queries' ); 62 $this->assertSame( array( ' no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );62 $this->assertSame( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 63 63 foreach ( $options as $option => $value ) { 64 64 $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), sprintf( 'Option %s not deleted from alloptions cache', $option ) ); … … 88 88 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function did unexpectedly succeed' ); 89 89 $this->assertSame( $num_queries + 1, get_num_queries(), 'Function attempted to update options autoload value in database' ); 90 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Options autoload value unexpectedly updated in database' );90 $this->assertSame( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Options autoload value unexpectedly updated in database' ); 91 91 } 92 92 … … 134 134 135 135 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), 'yes' ), 'Function produced unexpected result' ); 136 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );136 $this->assertSame( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 137 137 foreach ( $options as $option => $value ) { 138 138 $this->assertFalse( wp_cache_get( $option, 'options' ), sprintf( 'Option %s not deleted from individual cache', $option ) ); … … 162 162 163 163 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), true ), 'Function produced unexpected result' ); 164 $this->assertSame( array( ' yes', 'yes' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );164 $this->assertSame( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 165 165 } 166 166 … … 186 186 187 187 $this->assertSame( $expected, wp_set_options_autoload( array_keys( $options ), false ), 'Function produced unexpected result' ); 188 $this->assertSame( array( ' no', 'no' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' );188 $this->assertSame( array( '' ), $wpdb->get_col( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name IN (" . implode( ',', array_fill( 0, count( $options ), '%s' ) ) . ')', ...array_keys( $options ) ) ), 'Option autoload values not updated in database' ); 189 189 } 190 190 } -
trunk/tests/phpunit/tests/theme/autoloadThemeMods.php
r57153 r57920 29 29 switch_theme( $new_theme_stylesheet ); 30 30 31 $this->assertSame( ' no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' );32 $this->assertSame( ' yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' );31 $this->assertSame( '', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' ); 32 $this->assertSame( '', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' ); 33 33 34 34 switch_theme( $current_theme_stylesheet ); 35 35 36 $this->assertSame( ' yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' );37 $this->assertSame( ' no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' );36 $this->assertSame( '', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$current_theme_stylesheet" ) ), 'Theme mods autoload value not set to yes in database' ); 37 $this->assertSame( '', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", "theme_mods_$new_theme_stylesheet" ) ), 'Theme mods autoload value not set to no in database' ); 38 38 39 39 // Basic assertion to make sure that we haven't lost the mods.
Note: See TracChangeset
for help on using the changeset viewer.