Skip to content

Commit df6d8a6

Browse files
committed
Tests: Cover repeated string replacement.
Test `_deep_replace()` with nested matches, multiple search strings, empty input, and scalar subjects. Verify that replacement continues until no matches remain. Developed in: #14636 Props shailu25, huzaifaalmesbah. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@64752 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 86bb4fc commit df6d8a6

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* Tests for _deep_replace().
5+
*
6+
* @group formatting
7+
*
8+
* @covers ::_deep_replace
9+
*/
10+
class Tests_Formatting_DeepReplace extends WP_UnitTestCase {
11+
12+
/**
13+
* @ticket 65819
14+
*
15+
* @dataProvider data_deep_replace
16+
*
17+
* @param string|string[] $search Value to search for.
18+
* @param string $subject Subject to search.
19+
* @param string $expected Expected result.
20+
*/
21+
public function test_deep_replace( $search, $subject, $expected ) {
22+
$this->assertSame( $expected, _deep_replace( $search, $subject ) );
23+
}
24+
25+
/**
26+
* Data provider.
27+
*
28+
* @return array[]
29+
*/
30+
public static function data_deep_replace() {
31+
return array(
32+
'no match' => array( 'x', 'hello', 'hello' ),
33+
'single occurrence' => array( 'bad', 'one bad word', 'one word' ),
34+
'nested repetitions' => array( '../', '....//....//file', 'file' ),
35+
'array of search strings' => array( array( 'a', 'b' ), 'abacab', 'c' ),
36+
'empty subject' => array( 'x', '', '' ),
37+
'casts non-string subject' => array( '1', 111, '' ),
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)