Skip to content

Commit 0175e0b

Browse files
Sarthak JaiswalSarthak Jaiswal
authored andcommitted
Reset wp_styles after each test
1 parent 5534c0d commit 0175e0b

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

plugins/dominant-color-images/tests/data/class-testcase.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@
55
use WP_UnitTestCase;
66

77
abstract class TestCase extends WP_UnitTestCase {
8+
9+
/**
10+
* Runs the routine before each test is executed.
11+
*/
12+
public function set_up(): void {
13+
parent::set_up();
14+
$this->reset_wp_dependencies();
15+
}
16+
17+
/**
18+
* After a test method runs, resets any state in WordPress the test method might have changed.
19+
*/
20+
public function tear_down(): void {
21+
parent::tear_down();
22+
$this->reset_wp_dependencies();
23+
}
24+
25+
/**
26+
* Reset WP_Scripts and WP_Styles.
27+
*/
28+
private function reset_wp_dependencies(): void {
29+
$GLOBALS['wp_scripts'] = null;
30+
$GLOBALS['wp_styles'] = null;
31+
}
32+
833
/**
934
* Data provider for test_get_dominant_color_GD.
1035
*

plugins/dominant-color-images/tests/test-dominant-color.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,8 @@ public function test_dominant_color_admin_inline_style(): void {
480480
* @covers ::dominant_color_admin_script
481481
*/
482482
public function test_dominant_color_admin_script(): void {
483-
ob_start();
484-
dominant_color_admin_script();
485-
$output = ob_get_clean();
483+
484+
$output = get_echo( 'dominant_color_admin_script' );
486485

487486
// Verify if script tag exists.
488487
$this->assertStringEndsWith( '</script>', trim( $output ) );

0 commit comments

Comments
 (0)