Skip to content

Commit 253dfb4

Browse files
committed
Tests: Cover wp_is_serving_rest_request().
Verify REST request detection when `REST_REQUEST` is undefined, true, or false. Isolate constant-defining cases in separate processes. Developed in: #14414 Props shailu25. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@64509 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6737fec commit 253dfb4

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/**
4+
* Tests for the wp_is_serving_rest_request() function.
5+
*
6+
* @group functions
7+
* @group restapi
8+
*
9+
* @covers ::wp_is_serving_rest_request
10+
*/
11+
class Tests_Functions_WpIsServingRestRequest extends WP_UnitTestCase {
12+
13+
/**
14+
* Tests that the function returns false when REST_REQUEST is not defined.
15+
*
16+
* @ticket 65819
17+
*/
18+
public function test_returns_false_when_rest_request_constant_is_not_defined() {
19+
$this->assertFalse(
20+
defined( 'REST_REQUEST' ),
21+
'Precondition: REST_REQUEST must not be defined for this assertion.'
22+
);
23+
$this->assertFalse( wp_is_serving_rest_request() );
24+
}
25+
26+
/**
27+
* Tests that the function returns true when REST_REQUEST is true.
28+
*
29+
* Runs in a separate process because constants cannot be redefined.
30+
*
31+
* @ticket 65819
32+
*
33+
* @runInSeparateProcess
34+
* @preserveGlobalState disabled
35+
*/
36+
public function test_returns_true_when_rest_request_constant_is_true() {
37+
define( 'REST_REQUEST', true );
38+
39+
$this->assertTrue( wp_is_serving_rest_request() );
40+
}
41+
42+
/**
43+
* Tests that the function returns false when REST_REQUEST is false.
44+
*
45+
* Runs in a separate process because constants cannot be redefined.
46+
*
47+
* @ticket 65819
48+
*
49+
* @runInSeparateProcess
50+
* @preserveGlobalState disabled
51+
*/
52+
public function test_returns_false_when_rest_request_constant_is_false() {
53+
define( 'REST_REQUEST', false );
54+
55+
$this->assertFalse( wp_is_serving_rest_request() );
56+
}
57+
}

0 commit comments

Comments
 (0)