Skip to content

Commit b6295df

Browse files
committed
Use option filter rather than setting option.
1 parent aee8aaa commit b6295df

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

tests/phpunit/tests/collaboration/restAutosavesController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
2121
public static function wpTearDownAfterClass() {
2222
self::delete_user( self::$author_id );
2323
self::delete_user( self::$editor_id );
24-
delete_option( 'wp_collaboration_enabled' );
2524
}
2625

2726
public function set_up() {
@@ -86,7 +85,7 @@ private function dispatch_autosave( int $post_id, string $title, string $content
8685
* @ticket 65138
8786
*/
8887
public function test_auto_draft_autosave_promotes_parent_post_when_collaboration_is_disabled() {
89-
update_option( 'wp_collaboration_enabled', 0 );
88+
add_filter( 'pre_option_wp_collaboration_enabled', '__return_zero' );
9089

9190
$post_id = $this->create_auto_draft();
9291
$title = 'No RTC autosaved title';
@@ -105,7 +104,7 @@ public function test_auto_draft_autosave_promotes_parent_post_when_collaboration
105104
* @ticket 65138
106105
*/
107106
public function test_auto_draft_autosave_promotes_parent_post_when_collaboration_is_enabled() {
108-
update_option( 'wp_collaboration_enabled', 1 );
107+
add_filter( 'pre_option_wp_collaboration_enabled', '__return_true' );
109108

110109
$post_id = $this->create_auto_draft();
111110
$title = 'RTC autosaved title';
@@ -124,7 +123,7 @@ public function test_auto_draft_autosave_promotes_parent_post_when_collaboration
124123
* @ticket 65138
125124
*/
126125
public function test_collaborator_auto_draft_autosave_promotes_parent_post_when_collaboration_is_enabled() {
127-
update_option( 'wp_collaboration_enabled', 1 );
126+
add_filter( 'pre_option_wp_collaboration_enabled', '__return_true' );
128127

129128
$post_id = $this->create_auto_draft();
130129
$title = 'RTC collaborator autosaved title';
@@ -144,7 +143,7 @@ public function test_collaborator_auto_draft_autosave_promotes_parent_post_when_
144143
* @ticket 65138
145144
*/
146145
public function test_draft_autosave_creates_revision_when_collaboration_is_enabled() {
147-
update_option( 'wp_collaboration_enabled', 1 );
146+
add_filter( 'pre_option_wp_collaboration_enabled', '__return_true' );
148147

149148
$original_title = 'Original RTC draft title';
150149
$original_content = '<!-- wp:paragraph --><p>Original RTC draft content</p><!-- /wp:paragraph -->';

tests/phpunit/tests/collaboration/wpDeleteOldCollaborationData.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
1616
self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
1717
self::$post_id = $factory->post->create( array( 'post_author' => self::$editor_id ) );
1818

19-
update_option( 'wp_collaboration_enabled', 1 );
19+
add_filter( 'pre_option_wp_collaboration_enabled', '__return_true' );
2020
}
2121

2222
public static function wpTearDownAfterClass() {
23-
self::delete_user( self::$editor_id );
24-
delete_option( 'wp_collaboration_enabled' );
25-
wp_delete_post( self::$post_id, true );
23+
remove_filter( 'pre_option_wp_collaboration_enabled', '__return_true' );
2624
}
2725

2826
public function set_up() {
2927
parent::set_up();
3028

31-
update_option( 'wp_collaboration_enabled', 1 );
29+
add_filter( 'pre_option_wp_collaboration_enabled', '__return_true' );
3230
}
3331

3432
/**
@@ -195,7 +193,7 @@ public function test_cron_cleanup_when_collaboration_disabled(): void {
195193
$this->assertIsInt( wp_next_scheduled( 'wp_delete_old_collaboration_data' ), 'Cron event should be scheduled before cleanup.' );
196194

197195
// Disable collaboration.
198-
update_option( 'wp_collaboration_enabled', false );
196+
add_filter( 'pre_option_wp_collaboration_enabled', '__return_zero' );
199197

200198
wp_delete_old_collaboration_data();
201199

0 commit comments

Comments
 (0)