mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Database: Split the logic of wpdb::init_charset() into a separate method.
The logic for determining the appropriate character set and collation to use is becoming more complex, particularly with the recent additions of [37522] and [37523]. As `init_charset()` has side effects, and makes use of constants instead of parameters, it's not possible to unit test this logic. This commit splits the logic part of `init_charset()` out into a new method, `wpdb::determine_charset()`, along with appropriate unit tests. See #32105, #37522. Fixes #36917. git-svn-id: https://develop.svn.wordpress.org/trunk@37601 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -955,4 +955,78 @@ class Tests_DB extends WP_UnitTestCase {
|
||||
|
||||
$wpdb->check_connection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36917
|
||||
*/
|
||||
function test_charset_not_determined_when_disconnected() {
|
||||
global $wpdb;
|
||||
|
||||
$charset = 'utf8';
|
||||
$collate = 'this_isnt_a_collation';
|
||||
|
||||
$wpdb->close();
|
||||
|
||||
$result = $wpdb->determine_charset( $charset, $collate );
|
||||
|
||||
$this->assertSame( compact( 'charset', 'collate' ), $result );
|
||||
|
||||
$wpdb->check_connection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36917
|
||||
*/
|
||||
function test_charset_switched_to_utf8mb4() {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! $wpdb->has_cap( 'utf8mb4' ) ) {
|
||||
$this->markTestSkipped( 'This test requires utf8mb4 support.' );
|
||||
}
|
||||
|
||||
$charset = 'utf8';
|
||||
$collate = 'utf8_general_ci';
|
||||
|
||||
$result = $wpdb->determine_charset( $charset, $collate );
|
||||
|
||||
$this->assertSame( 'utf8mb4', $result['charset'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 32105
|
||||
* @ticket 36917
|
||||
*/
|
||||
function test_collate_switched_to_utf8mb4_520() {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! $wpdb->has_cap( 'utf8mb4_520' ) ) {
|
||||
$this->markTestSkipped( 'This test requires utf8mb4_520 support.' );
|
||||
}
|
||||
|
||||
$charset = 'utf8';
|
||||
$collate = 'utf8_general_ci';
|
||||
|
||||
$result = $wpdb->determine_charset( $charset, $collate );
|
||||
|
||||
$this->assertSame( 'utf8mb4_unicode_520_ci', $result['collate'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36917
|
||||
* @ticket 37522
|
||||
*/
|
||||
function test_non_unicode_collations() {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! $wpdb->has_cap( 'utf8mb4' ) ) {
|
||||
$this->markTestSkipped( 'This test requires utf8mb4 support.' );
|
||||
}
|
||||
|
||||
$charset = 'utf8';
|
||||
$collate = 'utf8_swedish_ci';
|
||||
|
||||
$result = $wpdb->determine_charset( $charset, $collate );
|
||||
|
||||
$this->assertSame( 'utf8mb4_swedish_ci', $result['collate'] );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user