Skip to content

Commit 1ccce21

Browse files
Tests: Cover wp_default_editor().
Verify that the function returns `tinymce` by default or user editor setting when set. Developed in #15358. Props devmuhib, huzaifaalmesbah, lancewillett. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65747 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f668959 commit 1ccce21

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/**
4+
* Tests for the `wp_default_editor()` function.
5+
*
6+
* @group general
7+
* @group editor
8+
*
9+
* @covers ::wp_default_editor
10+
*/
11+
class Tests_General_WpDefaultEditor extends WP_UnitTestCase {
12+
13+
/**
14+
* Tests that wp_default_editor() returns 'tinymce' by default.
15+
*
16+
* @ticket 65819
17+
*/
18+
public function test_wp_default_editor_default() {
19+
$this->assertSame( 'tinymce', wp_default_editor() );
20+
}
21+
22+
/**
23+
* Tests that wp_default_editor() returns user editor setting when set.
24+
*
25+
* @ticket 65819
26+
*/
27+
public function test_wp_default_editor_respects_user_setting() {
28+
$user_id = self::factory()->user->create();
29+
wp_set_current_user( $user_id );
30+
31+
$orig_updated_user_settings = $GLOBALS['_updated_user_settings'] ?? null;
32+
unset( $GLOBALS['_updated_user_settings'] );
33+
34+
$_COOKIE[ 'wp-settings-' . $user_id ] = 'editor=html';
35+
36+
try {
37+
$this->assertSame( 'html', wp_default_editor() );
38+
} finally {
39+
unset( $_COOKIE[ 'wp-settings-' . $user_id ] );
40+
41+
if ( null !== $orig_updated_user_settings ) {
42+
$GLOBALS['_updated_user_settings'] = $orig_updated_user_settings;
43+
} else {
44+
unset( $GLOBALS['_updated_user_settings'] );
45+
}
46+
}
47+
}
48+
49+
/**
50+
* Tests that the `wp_default_editor` filter modifies the default editor.
51+
*
52+
* @ticket 65819
53+
*/
54+
public function test_wp_default_editor_filter() {
55+
add_filter(
56+
'wp_default_editor',
57+
static function () {
58+
return 'html';
59+
}
60+
);
61+
62+
$this->assertSame( 'html', wp_default_editor() );
63+
}
64+
}

0 commit comments

Comments
 (0)