Skip to content

Commit da4c29a

Browse files
committed
Tests: Use a dataprovider for the esc_like test.
Props jorbin, mukesh27. See #63167. git-svn-id: https://develop.svn.wordpress.org/trunk@61207 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 262afe4 commit da4c29a

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

tests/phpunit/tests/db.php

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,28 +122,41 @@ public function test_locale_floats() {
122122

123123
/**
124124
* @ticket 10041
125+
*
126+
* @dataProvider data_esc_like
127+
*
128+
* @param string $input The input string.
129+
* @param string $expected The expected escaped string.
125130
*/
126-
public function test_esc_like() {
131+
public function test_esc_like( $input, $expected ) {
127132
global $wpdb;
128133

129-
$inputs = array(
130-
'howdy%', // Single percent.
131-
'howdy_', // Single underscore.
132-
'howdy\\', // Single slash.
133-
'howdy\\howdy%howdy_', // The works.
134-
'howdy\'"[[]*#[^howdy]!+)(*&$#@!~|}{=--`/.,<>?', // Plain text.
135-
);
136-
$expected = array(
137-
'howdy\\%',
138-
'howdy\\_',
139-
'howdy\\\\',
140-
'howdy\\\\howdy\\%howdy\\_',
141-
'howdy\'"[[]*#[^howdy]!+)(*&$#@!~|}{=--`/.,<>?',
142-
);
134+
$this->assertSame( $expected, $wpdb->esc_like( $input ) );
135+
}
143136

144-
foreach ( $inputs as $key => $input ) {
145-
$this->assertSame( $expected[ $key ], $wpdb->esc_like( $input ) );
146-
}
137+
public function data_esc_like() {
138+
return array(
139+
'single percent' => array(
140+
'howdy%',
141+
'howdy\\%',
142+
),
143+
'single underscore' => array(
144+
'howdy_',
145+
'howdy\\_',
146+
),
147+
'single slash' => array(
148+
'howdy\\',
149+
'howdy\\\\',
150+
),
151+
'the works' => array(
152+
'howdy\\howdy%howdy_',
153+
'howdy\\\\howdy\\%howdy\\_',
154+
),
155+
'plain text' => array(
156+
'howdy\'"[[]*#[^howdy]!+)(*&$#@!~|}{=--`/.,<>?',
157+
'howdy\'"[[]*#[^howdy]!+)(*&$#@!~|}{=--`/.,<>?',
158+
),
159+
);
147160
}
148161

149162
/**

0 commit comments

Comments
 (0)