Skip to content

Commit cb73ba7

Browse files
committed
Failing test for ticket 38921
1 parent 44f1517 commit cb73ba7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/phpunit/includes/utils.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,11 @@ public function __construct() {
571571
public function __call( $name, $arguments ) {
572572
return call_user_func_array( array( $this, $name ), $arguments );
573573
}
574+
575+
public function reset_cache_values() {
576+
$this->table_charset = array();
577+
$this->col_meta = array();
578+
}
574579
}
575580

576581
/**

tests/phpunit/tests/db.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,4 +2486,35 @@ public function test_check_connection_returns_true_when_there_is_a_connection()
24862486

24872487
$this->assertTrue( $wpdb->check_connection( false ) );
24882488
}
2489+
2490+
/**
2491+
* Tests if the column charset doesn't throw errors with the `pre_get_table_charset` filter.
2492+
*
2493+
* @ticket 38921
2494+
*/
2495+
public function test_get_table_and_column_charset_with_pre_get_table_charset_filter() {
2496+
global $wpdb;
2497+
$expected_charset = $wpdb->get_col_charset( $wpdb->posts, 'post_content' );
2498+
2499+
self::$_wpdb->reset_cache_values();
2500+
2501+
add_filter( 'pre_get_table_charset', array( $this, 'change_table_charset_callback' ), 10, 2 );
2502+
$table_charset = self::$_wpdb->get_table_charset( $wpdb->posts );
2503+
$column_charset = self::$_wpdb->get_col_charset( $wpdb->posts, 'post_content' );
2504+
remove_filter( 'pre_get_table_charset', array( $this, 'change_table_charset_callback' ), 10, 2 );
2505+
2506+
$this->assertSame( 'fake_charset', $table_charset );
2507+
$this->assertSame( $expected_charset, $column_charset );
2508+
}
2509+
2510+
/**
2511+
* Callback for the `pre_get_table_charset` filter.
2512+
*
2513+
* @param string $charset The table's character set.
2514+
* @param string $table The name of the table.
2515+
* @return string $charset The table's character set.
2516+
*/
2517+
public function change_table_charset_callback( $charset, $table ) {
2518+
return 'fake_charset';
2519+
}
24892520
}

0 commit comments

Comments
 (0)