Skip to content

Commit 4db780e

Browse files
Tests: Improve unit tests for is_post_status_viewable().
Includes: * Adding the missing `@covers` annotation. * Converting data provider methods to `static` for a slight performance improvement. * Using named data providers. Follow-up to [50130]. Props mukesh27, swissspidy, SergeyBiryukov. See #63167. git-svn-id: https://develop.svn.wordpress.org/trunk@61170 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c8de9a3 commit 4db780e

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

tests/phpunit/tests/post/isPostStatusViewable.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
/**
44
* @group post
5+
*
6+
* @covers is_post_status_viewable
57
*/
68
class Tests_Post_IsPostStatusViewable extends WP_UnitTestCase {
79

@@ -21,6 +23,7 @@ public static function wpTearDownAfterClass() {
2123
* This may include emulations of built in (_builtin) statuses.
2224
*
2325
* @ticket 49380
26+
*
2427
* @dataProvider data_custom_post_statuses
2528
*
2629
* @param array $cps_args Registration arguments.
@@ -46,46 +49,41 @@ public function test_custom_post_statuses( $cps_args, $expected ) {
4649
* bool Expected result.
4750
* }
4851
*/
49-
public function data_custom_post_statuses() {
52+
public static function data_custom_post_statuses() {
5053
return array(
51-
// 0. False for non-publicly queryable types.
52-
array(
54+
'false for non-publicly queryable types' => array(
5355
array(
5456
'publicly_queryable' => false,
5557
'_builtin' => false,
5658
'public' => true,
5759
),
5860
false,
5961
),
60-
// 1. True for publicly queryable types.
61-
array(
62+
'true for publicly queryable types' => array(
6263
array(
6364
'publicly_queryable' => true,
6465
'_builtin' => false,
6566
'public' => false,
6667
),
6768
true,
6869
),
69-
// 2. False for built-in non-public types.
70-
array(
70+
'false for built-in non-public types' => array(
7171
array(
7272
'publicly_queryable' => false,
7373
'_builtin' => true,
7474
'public' => false,
7575
),
7676
false,
7777
),
78-
// 3. False for non-built-in public types.
79-
array(
78+
'false for non-built-in public types' => array(
8079
array(
8180
'publicly_queryable' => false,
8281
'_builtin' => false,
8382
'public' => true,
8483
),
8584
false,
8685
),
87-
// 4. True for built-in public types.
88-
array(
86+
'true for built-in public types' => array(
8987
array(
9088
'publicly_queryable' => false,
9189
'_builtin' => true,
@@ -99,13 +97,14 @@ public function data_custom_post_statuses() {
9997
/**
10098
* Test built-in and unregistered post status.
10199
*
102-
* @dataProvider data_built_unregistered_in_status_types
103100
* @ticket 49380
104101
*
102+
* @dataProvider data_built_in_and_unregistered_status_types
103+
*
105104
* @param mixed $status Post status to check.
106105
* @param bool $expected Expected viewable status.
107106
*/
108-
public function test_built_unregistered_in_status_types( $status, $expected ) {
107+
public function test_built_in_and_unregistered_status_types( $status, $expected ) {
109108
// Test status passed as string.
110109
$this->assertSame( $expected, is_post_status_viewable( $status ) );
111110
// Test status passed as object.
@@ -120,27 +119,28 @@ public function test_built_unregistered_in_status_types( $status, $expected ) {
120119
* @type bool $expected Expected viewable status.
121120
* }
122121
*/
123-
public function data_built_unregistered_in_status_types() {
122+
public static function data_built_in_and_unregistered_status_types() {
124123
return array(
125-
array( 'publish', true ),
126-
array( 'future', false ),
127-
array( 'draft', false ),
128-
array( 'pending', false ),
129-
array( 'private', false ),
130-
array( 'trash', false ),
131-
array( 'auto-draft', false ),
132-
array( 'inherit', false ),
133-
array( 'request-pending', false ),
134-
array( 'request-confirmed', false ),
135-
array( 'request-failed', false ),
136-
array( 'request-completed', false ),
124+
'publish' => array( 'publish', true ),
125+
'future' => array( 'future', false ),
126+
'draft' => array( 'draft', false ),
127+
'pending' => array( 'pending', false ),
128+
'private' => array( 'private', false ),
129+
'trash' => array( 'trash', false ),
130+
'auto-draft' => array( 'auto-draft', false ),
131+
'inherit' => array( 'inherit', false ),
132+
'request-pending' => array( 'request-pending', false ),
133+
'request-confirmed' => array( 'request-confirmed', false ),
134+
'request-failed' => array( 'request-failed', false ),
135+
'request-completed' => array( 'request-completed', false ),
137136

138137
// Various unregistered statuses.
139-
array( 'unregistered-status', false ),
140-
array( false, false ),
141-
array( true, false ),
142-
array( 20, false ),
143-
array( '', false ),
138+
'unregistered' => array( 'unregistered-status', false ),
139+
'false' => array( false, false ),
140+
'true' => array( true, false ),
141+
'number 20' => array( 20, false ),
142+
'null' => array( null, false ),
143+
'empty string' => array( '', false ),
144144
);
145145
}
146146

0 commit comments

Comments
 (0)