diff --git a/tests/phpunit/tests/general/wpDefaultEditor.php b/tests/phpunit/tests/general/wpDefaultEditor.php index 6235a8b613f72..88a0688c223e6 100644 --- a/tests/phpunit/tests/general/wpDefaultEditor.php +++ b/tests/phpunit/tests/general/wpDefaultEditor.php @@ -20,21 +20,31 @@ public function test_wp_default_editor_default() { } /** - * Tests that wp_default_editor() returns user editor setting when set. + * Tests that wp_default_editor() respects the user editor setting. + * + * An invalid setting falls back to user_can_richedit(). * * @ticket 65819 + * + * @dataProvider data_wp_default_editor_respects_user_setting + * + * @param string $setting The user editor setting. + * @param bool $can_richedit Value returned by user_can_richedit(). + * @param string $expected Expected editor. */ - public function test_wp_default_editor_respects_user_setting() { + public function test_wp_default_editor_respects_user_setting( $setting, $can_richedit, $expected ) { $user_id = self::factory()->user->create(); wp_set_current_user( $user_id ); + add_filter( 'user_can_richedit', $can_richedit ? '__return_true' : '__return_false' ); + $orig_updated_user_settings = $GLOBALS['_updated_user_settings'] ?? null; unset( $GLOBALS['_updated_user_settings'] ); - $_COOKIE[ 'wp-settings-' . $user_id ] = 'editor=html'; + $_COOKIE[ 'wp-settings-' . $user_id ] = 'editor=' . $setting; try { - $this->assertSame( 'html', wp_default_editor() ); + $this->assertSame( $expected, wp_default_editor() ); } finally { unset( $_COOKIE[ 'wp-settings-' . $user_id ] ); @@ -46,6 +56,19 @@ public function test_wp_default_editor_respects_user_setting() { } } + /** + * Data provider. + * + * @return array + */ + public static function data_wp_default_editor_respects_user_setting() { + return array( + 'valid html setting' => array( 'html', true, 'html' ), + 'invalid setting, rich editing available' => array( 'invalid', true, 'tinymce' ), + 'invalid setting, rich editing unavailable' => array( 'invalid', false, 'html' ), + ); + } + /** * Tests that the `wp_default_editor` filter modifies the default editor. *