Skip to content

Commit 174722c

Browse files
Tests: Cover wptexturize_primes().
Verify: - Replacing single quotes with single prime entities (`′`) following numbers. - Replacing double quotes with double prime entities (`″`) following numbers. - Ensuring strings without target quotes remain unmodified. - Disambiguating quotes and primes within opened quotation marks. - Ensuring regular quotes not preceded by numbers become closing quotes. Developed in #15740. Props devmuhib, huzaifaalmesbah. Fixes #66609. git-svn-id: https://develop.svn.wordpress.org/trunk@65809 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c4b144d commit 174722c

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/**
4+
* Tests for the `wptexturize_primes()` function.
5+
*
6+
* @group formatting
7+
*
8+
* @covers ::wptexturize_primes
9+
*/
10+
class Tests_Formatting_WptexturizePrimes extends WP_UnitTestCase {
11+
12+
/**
13+
* Tests prime replacement for single quotes after numbers.
14+
*
15+
* @ticket 66609
16+
*/
17+
public function test_wptexturize_primes_single_quote() {
18+
$prime = '&#8242;';
19+
$open_quote = '&#8216;';
20+
$close_quote = '&#8217;';
21+
22+
$input = "He is 6' tall.";
23+
$expected = "He is 6{$prime} tall.";
24+
25+
$this->assertSame( $expected, wptexturize_primes( $input, "'", $prime, $open_quote, $close_quote ) );
26+
}
27+
28+
/**
29+
* Tests double prime replacement for double quotes after numbers.
30+
*
31+
* @ticket 66609
32+
*/
33+
public function test_wptexturize_primes_double_quote() {
34+
$prime = '&#8243;';
35+
$open_quote = '&#8220;';
36+
$close_quote = '&#8221;';
37+
38+
$input = 'A 12" record.';
39+
$expected = "A 12{$prime} record.";
40+
41+
$this->assertSame( $expected, wptexturize_primes( $input, '"', $prime, $open_quote, $close_quote ) );
42+
}
43+
44+
/**
45+
* Tests that text without the needle character is returned unchanged.
46+
*
47+
* @ticket 66609
48+
*/
49+
public function test_wptexturize_primes_without_matching_needle() {
50+
$text = 'Text without any quotes at all.';
51+
52+
$this->assertSame( $text, wptexturize_primes( $text, "'", '&#8242;', '&#8216;', '&#8217;' ) );
53+
}
54+
55+
/**
56+
* Tests closing quote disambiguation when numbers with primes are inside quotations.
57+
*
58+
* @ticket 66609
59+
*/
60+
public function test_wptexturize_primes_inside_quotations() {
61+
$prime = '&#8242;';
62+
$open_quote = '&#8216;';
63+
$close_quote = '&#8217;';
64+
65+
$input = "{$open_quote}I am 6' tall.'";
66+
$expected = "{$open_quote}I am 6{$prime} tall.{$close_quote}";
67+
68+
$this->assertSame( $expected, wptexturize_primes( $input, "'", $prime, $open_quote, $close_quote ) );
69+
}
70+
71+
/**
72+
* Tests that quotes not preceded by numbers become closing quotes.
73+
*
74+
* @ticket 66609
75+
*/
76+
public function test_wptexturize_primes_normal_quotes_become_closing_quotes() {
77+
$prime = '&#8243;';
78+
$open_quote = '&#8220;';
79+
$close_quote = '&#8221;';
80+
81+
$input = 'A "quoted word".';
82+
$expected = "A {$close_quote}quoted word{$close_quote}.";
83+
84+
$this->assertSame( $expected, wptexturize_primes( $input, '"', $prime, $open_quote, $close_quote ) );
85+
}
86+
}

0 commit comments

Comments
 (0)