Skip to content

Commit 6b6be36

Browse files
committed
Tests: Use a data provider for malformed post type query coverage
1 parent c4a6004 commit 6b6be36

1 file changed

Lines changed: 28 additions & 46 deletions

File tree

tests/phpunit/tests/wp/parseRequest.php

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -59,67 +59,49 @@ static function ( $url ) {
5959

6060
/**
6161
* @ticket 65123
62+
* @dataProvider data_parse_request_ignores_non_scalar_post_type_values
6263
*/
63-
public function test_parse_request_ignores_non_scalar_post_type_values_from_get() {
64+
public function test_parse_request_ignores_non_scalar_post_type_values( $request_method, $request_uri ) {
6465
$original_get = $_GET;
6566
$original_post = $_POST;
6667
$original_request = $_SERVER['REQUEST_URI'] ?? null;
6768
$original_self = $_SERVER['PHP_SELF'] ?? null;
6869

69-
$_GET['post_type'] = array( array( 'page' ), 'post' );
70-
$_SERVER['REQUEST_URI'] = '/?post_type[][]=page&post_type[]=post';
71-
$_SERVER['PHP_SELF'] = '/index.php';
72-
73-
$this->wp->parse_request();
74-
75-
$this->assertSame( array( 'post' ), array_values( $this->wp->query_vars['post_type'] ) );
76-
77-
$_GET = $original_get;
78-
$_POST = $original_post;
79-
80-
if ( null === $original_request ) {
81-
unset( $_SERVER['REQUEST_URI'] );
70+
if ( 'GET' === $request_method ) {
71+
$_GET['post_type'] = array( array( 'page' ), 'post' );
8272
} else {
83-
$_SERVER['REQUEST_URI'] = $original_request;
73+
$_POST['post_type'] = array( array( 'page' ), 'post' );
8474
}
8575

86-
if ( null === $original_self ) {
87-
unset( $_SERVER['PHP_SELF'] );
88-
} else {
89-
$_SERVER['PHP_SELF'] = $original_self;
90-
}
91-
}
92-
93-
/**
94-
* @ticket 65123
95-
*/
96-
public function test_parse_request_ignores_non_scalar_post_type_values_from_post() {
97-
$original_get = $_GET;
98-
$original_post = $_POST;
99-
$original_request = $_SERVER['REQUEST_URI'] ?? null;
100-
$original_self = $_SERVER['PHP_SELF'] ?? null;
101-
102-
$_POST['post_type'] = array( array( 'page' ), 'post' );
103-
$_SERVER['REQUEST_URI'] = '/';
76+
$_SERVER['REQUEST_URI'] = $request_uri;
10477
$_SERVER['PHP_SELF'] = '/index.php';
10578

106-
$this->wp->parse_request();
79+
try {
80+
$this->wp->parse_request();
10781

108-
$this->assertSame( array( 'post' ), array_values( $this->wp->query_vars['post_type'] ) );
82+
$this->assertSame( array( 'post' ), array_values( $this->wp->query_vars['post_type'] ) );
83+
} finally {
84+
$_GET = $original_get;
85+
$_POST = $original_post;
10986

110-
$_GET = $original_get;
111-
$_POST = $original_post;
87+
if ( null === $original_request ) {
88+
unset( $_SERVER['REQUEST_URI'] );
89+
} else {
90+
$_SERVER['REQUEST_URI'] = $original_request;
91+
}
11292

113-
if ( null === $original_request ) {
114-
unset( $_SERVER['REQUEST_URI'] );
115-
} else {
116-
$_SERVER['REQUEST_URI'] = $original_request;
93+
if ( null === $original_self ) {
94+
unset( $_SERVER['PHP_SELF'] );
95+
} else {
96+
$_SERVER['PHP_SELF'] = $original_self;
97+
}
11798
}
99+
}
118100

119-
if ( null === $original_self ) {
120-
unset( $_SERVER['PHP_SELF'] );
121-
} else {
122-
$_SERVER['PHP_SELF'] = $original_self;
123-
}
101+
public function data_parse_request_ignores_non_scalar_post_type_values() {
102+
return array(
103+
'get' => array( 'GET', '/?post_type[][]=page&post_type[]=post' ),
104+
'post' => array( 'POST', '/' ),
105+
);
124106
}
125107
}

0 commit comments

Comments
 (0)