Skip to content

Commit 9fb84f4

Browse files
Tests: Cover user_can_richedit().
Verify that the function returns `true` when the browser supports the visual editor and the user option is enabled, `false` otherwise. Developed in #15359. Props devmuhib, huzaifaalmesbah, lancewillett. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65738 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2fcad86 commit 9fb84f4

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/**
4+
* Tests for the `user_can_richedit()` function.
5+
*
6+
* @group general
7+
* @group editor
8+
*
9+
* @covers ::user_can_richedit
10+
*/
11+
class Tests_General_UserCanRichedit extends WP_UnitTestCase {
12+
13+
/**
14+
* Original $is_chrome global.
15+
*
16+
* @var bool|null
17+
*/
18+
private $orig_is_chrome;
19+
20+
public function set_up() {
21+
global $is_chrome;
22+
23+
parent::set_up();
24+
25+
$this->orig_is_chrome = isset( $is_chrome ) ? $is_chrome : null;
26+
}
27+
28+
/**
29+
* Cleans up global rich edit cache and restores the browser flag.
30+
*/
31+
public function tear_down() {
32+
global $wp_rich_edit, $is_chrome;
33+
34+
$wp_rich_edit = null;
35+
36+
if ( null !== $this->orig_is_chrome ) {
37+
$is_chrome = $this->orig_is_chrome;
38+
} else {
39+
unset( $GLOBALS['is_chrome'] );
40+
}
41+
42+
parent::tear_down();
43+
}
44+
45+
/**
46+
* Tests that user_can_richedit() returns true when the browser supports it and user option is enabled.
47+
*
48+
* @ticket 65819
49+
*/
50+
public function test_user_can_richedit_enabled() {
51+
global $wp_rich_edit, $is_chrome;
52+
53+
$wp_rich_edit = null;
54+
$is_chrome = true;
55+
56+
$user_id = self::factory()->user->create();
57+
wp_set_current_user( $user_id );
58+
update_user_option( $user_id, 'rich_editing', 'true' );
59+
60+
$this->assertTrue( user_can_richedit() );
61+
}
62+
63+
/**
64+
* Tests that user_can_richedit() returns false when user option is disabled.
65+
*
66+
* @ticket 65819
67+
*/
68+
public function test_user_can_richedit_disabled_by_user_option() {
69+
global $wp_rich_edit, $is_chrome;
70+
71+
$wp_rich_edit = null;
72+
$is_chrome = true;
73+
74+
$user_id = self::factory()->user->create();
75+
wp_set_current_user( $user_id );
76+
update_user_option( $user_id, 'rich_editing', 'false' );
77+
78+
$this->assertFalse( user_can_richedit() );
79+
}
80+
}

0 commit comments

Comments
 (0)