1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113 |
- <?php
- /**
- * @group formatting
- */
- class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
- function test_dashes() {
- $this->assertSame( 'Hey — boo?', wptexturize( 'Hey -- boo?' ) );
- $this->assertSame( '<a href="http://xx--xx">Hey — boo?</a>', wptexturize( '<a href="http://xx--xx">Hey -- boo?</a>' ) );
- }
- function test_disable() {
- $this->assertSame( '<pre>---&</pre>', wptexturize( '<pre>---&</pre>' ) );
- $this->assertSame( '<pre><code></code>--&</pre>', wptexturize( '<pre><code></code>--&</pre>' ) );
- $this->assertSame( '<code>---&</code>', wptexturize( '<code>---&</code>' ) );
- $this->assertSame( '<kbd>---&</kbd>', wptexturize( '<kbd>---&</kbd>' ) );
- $this->assertSame( '<style>---&</style>', wptexturize( '<style>---&</style>' ) );
- $this->assertSame( '<script>---&</script>', wptexturize( '<script>---&</script>' ) );
- $this->assertSame( '<tt>---&</tt>', wptexturize( '<tt>---&</tt>' ) );
- $this->assertSame( '<code>href="baba"</code> “baba”', wptexturize( '<code>href="baba"</code> "baba"' ) );
- $enabled_tags_inside_code = '<code>curl -s <a href="http://x/">baba</a> | grep sfive | cut -d "\"" -f 10 > topmp3.txt</code>';
- $this->assertSame( $enabled_tags_inside_code, wptexturize( $enabled_tags_inside_code ) );
- $double_nest = '<pre>"baba"<code>"baba"<pre></pre></code>"baba"</pre>';
- $this->assertSame( $double_nest, wptexturize( $double_nest ) );
- $invalid_nest = '<pre></code>"baba"</pre>';
- $this->assertSame( $invalid_nest, wptexturize( $invalid_nest ) );
- }
- /**
- * @ticket 1418
- */
- function test_bracketed_quotes_1418() {
- $this->assertSame( '(“test”)', wptexturize( '("test")' ) );
- $this->assertSame( '(‘test’)', wptexturize( "('test')" ) );
- $this->assertSame( '(’twas)', wptexturize( "('twas)" ) );
- }
- /**
- * @ticket 3810
- */
- function test_bracketed_quotes_3810() {
- $this->assertSame( 'A dog (“Hubertus”) was sent out.', wptexturize( 'A dog ("Hubertus") was sent out.' ) );
- }
- /**
- * @ticket 4539
- */
- function test_basic_quotes() {
- $this->assertSame( 'test’s', wptexturize( 'test\'s' ) );
- $this->assertSame( '‘quoted’', wptexturize( '\'quoted\'' ) );
- $this->assertSame( '“quoted”', wptexturize( '"quoted"' ) );
- $this->assertSame( 'space before ‘quoted’ space after', wptexturize( 'space before \'quoted\' space after' ) );
- $this->assertSame( 'space before “quoted” space after', wptexturize( 'space before "quoted" space after' ) );
- $this->assertSame( '(‘quoted’)', wptexturize( '(\'quoted\')' ) );
- $this->assertSame( '{“quoted”}', wptexturize( '{"quoted"}' ) );
- $this->assertSame( '‘qu(ot)ed’', wptexturize( '\'qu(ot)ed\'' ) );
- $this->assertSame( '“qu{ot}ed”', wptexturize( '"qu{ot}ed"' ) );
- $this->assertSame( ' ‘test’s quoted’ ', wptexturize( ' \'test\'s quoted\' ' ) );
- $this->assertSame( ' “test’s quoted” ', wptexturize( ' "test\'s quoted" ' ) );
- }
- /**
- * @ticket 4539
- * @ticket 15241
- */
- function test_full_sentences_with_unmatched_single_quotes() {
- $this->assertSame(
- 'That means every moment you’re working on something without it being in the public it’s actually dying.',
- wptexturize( "That means every moment you're working on something without it being in the public it's actually dying." )
- );
- }
- /**
- * @ticket 4539
- */
- function test_quotes() {
- $this->assertSame( '“Quoted String”', wptexturize( '"Quoted String"' ) );
- // $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>"' ) );
- // $this->assertSame( 'Here is “<a href="http://example.com">a test with a link and a period</a>”.', wptexturize( 'Here is "<a href="http://example.com">a test with a link and a period</a>".' ) );
- $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>” and a space.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>" and a space.' ) );
- $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a> and some text quoted”', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a> and some text quoted"' ) );
- // $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”, and a comma.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>", and a comma.' ) );
- // $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”; and a semi-colon.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>"; and a semi-colon.' ) );
- // $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”- and a dash.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>"- and a dash.' ) );
- // $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”… and ellipses.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.' ) );
- // $this->assertSame( 'Here is “a test <a href="http://example.com">with a link</a>”.', wptexturize( 'Here is "a test <a href="http://example.com">with a link</a>".' ) );
- // $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”and a work stuck to the end.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>"and a work stuck to the end.' ) );
- $this->assertSame( 'A test with a finishing number, “like 23”.', wptexturize( 'A test with a finishing number, "like 23".' ) );
- $this->assertSame( 'A test with a number, “like 62”, is nice to have.', wptexturize( 'A test with a number, "like 62", is nice to have.' ) );
- }
- /**
- * @ticket 4539
- */
- function test_quotes_before_s() {
- $this->assertSame( 'test’s', wptexturize( "test's" ) );
- $this->assertSame( '‘test’s', wptexturize( "'test's" ) );
- $this->assertSame( '‘test’s’', wptexturize( "'test's'" ) );
- $this->assertSame( '‘string’', wptexturize( "'string'" ) );
- $this->assertSame( '‘string’s’', wptexturize( "'string's'" ) );
- }
- /**
- * @ticket 4539
- */
- function test_quotes_before_numbers() {
- $this->assertSame( 'Class of ’99', wptexturize( "Class of '99" ) );
- $this->assertSame( 'Class of ’99’s', wptexturize( "Class of '99's" ) );
- $this->assertSame( '‘Class of ’99’', wptexturize( "'Class of '99'" ) );
- $this->assertSame( '‘Class of ’99’ ', wptexturize( "'Class of '99' " ) );
- $this->assertSame( '‘Class of ’99’.', wptexturize( "'Class of '99'." ) );
- $this->assertSame( '‘Class of ’99’, she said', wptexturize( "'Class of '99', she said" ) );
- $this->assertSame( '‘Class of ’99’:', wptexturize( "'Class of '99':" ) );
- $this->assertSame( '‘Class of ’99’;', wptexturize( "'Class of '99';" ) );
- $this->assertSame( '‘Class of ’99’!', wptexturize( "'Class of '99'!" ) );
- $this->assertSame( '‘Class of ’99’?', wptexturize( "'Class of '99'?" ) );
- $this->assertSame( '‘Class of ’99’s’', wptexturize( "'Class of '99's'" ) );
- $this->assertSame( '‘Class of ’99’s’', wptexturize( "'Class of '99’s'" ) );
- $this->assertSame( '“Class of 99”', wptexturize( '"Class of 99"' ) );
- $this->assertSame( '“Class of ’99”', wptexturize( "\"Class of '99\"" ) );
- $this->assertSame( '{“Class of ’99”}', wptexturize( "{\"Class of '99\"}" ) );
- $this->assertSame( ' “Class of ’99” ', wptexturize( " \"Class of '99\" " ) );
- $this->assertSame( ' “Class of ’99”.', wptexturize( " \"Class of '99\"." ) );
- $this->assertSame( ' “Class of ’99”, she said', wptexturize( " \"Class of '99\", she said" ) );
- $this->assertSame( ' “Class of ’99”:', wptexturize( " \"Class of '99\":" ) );
- $this->assertSame( ' “Class of ’99”;', wptexturize( " \"Class of '99\";" ) );
- $this->assertSame( ' “Class of ’99”!', wptexturize( " \"Class of '99\"!" ) );
- $this->assertSame( ' “Class of ’99”?', wptexturize( " \"Class of '99\"?" ) );
- // Not a quotation, may be between two other quotations.
- $this->assertSame( '}”Class of ’99″{', wptexturize( "}\"Class of '99\"{" ) );
- }
- function test_quotes_after_numbers() {
- $this->assertSame( 'Class of ’99', wptexturize( "Class of '99" ) );
- }
- /**
- * @ticket 4539
- * @ticket 15241
- */
- function test_other_html() {
- $this->assertSame( '‘<strong>', wptexturize( "'<strong>" ) );
- // $this->assertSame( '‘<strong>Quoted Text</strong>’,', wptexturize( "'<strong>Quoted Text</strong>'," ) );
- // $this->assertSame( '“<strong>Quoted Text</strong>”,', wptexturize( '"<strong>Quoted Text</strong>",' ) );
- }
- function test_x() {
- $this->assertSame( '14×24', wptexturize( '14x24' ) );
- }
- function test_minutes_seconds() {
- $this->assertSame( '9′', wptexturize( '9\'' ) );
- $this->assertSame( '9″', wptexturize( '9"' ) );
- $this->assertSame( 'a 9′ b', wptexturize( 'a 9\' b' ) );
- $this->assertSame( 'a 9″ b', wptexturize( 'a 9" b' ) );
- $this->assertSame( '“a 9′ b”', wptexturize( '"a 9\' b"' ) );
- $this->assertSame( '‘a 9″ b’', wptexturize( "'a 9\" b'" ) );
- }
- /**
- * @ticket 8775
- */
- function test_wptexturize_quotes_around_numbers() {
- $this->assertSame( '“12345”', wptexturize( '"12345"' ) );
- $this->assertSame( '‘12345’', wptexturize( '\'12345\'' ) );
- $this->assertSame( '“a 9′ plus a ‘9’, maybe a 9′ ‘9’”', wptexturize( '"a 9\' plus a \'9\', maybe a 9\' \'9\'"' ) );
- $this->assertSame( '<p>’99<br />‘123’<br />’tis<br />‘s’</p>', wptexturize( '<p>\'99<br />\'123\'<br />\'tis<br />\'s\'</p>' ) );
- }
- /**
- * @ticket 8912
- */
- function test_wptexturize_html_comments() {
- $this->assertSame( '<!--[if !IE]>--><!--<![endif]-->', wptexturize( '<!--[if !IE]>--><!--<![endif]-->' ) );
- $this->assertSame( '<!--[if !IE]>"a 9\' plus a \'9\', maybe a 9\' \'9\' "<![endif]-->', wptexturize( '<!--[if !IE]>"a 9\' plus a \'9\', maybe a 9\' \'9\' "<![endif]-->' ) );
- $this->assertSame( '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', wptexturize( '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>' ) );
- }
- /**
- * @ticket 4539
- * @ticket 15241
- */
- function test_entity_quote_cuddling() {
- $this->assertSame( ' “Testing”', wptexturize( ' "Testing"' ) );
- // $this->assertSame( '&“Testing”', wptexturize( '&"Testing"' ) );
- }
- /**
- * @ticket 22823
- */
- function test_apostrophes_before_primes() {
- $this->assertSame( 'WordPress 3.5’s release date', wptexturize( "WordPress 3.5's release date" ) );
- }
- /**
- * @ticket 23185
- */
- function test_spaces_around_hyphens() {
- $nbsp = "\xC2\xA0";
- $this->assertSame( ' – ', wptexturize( ' - ' ) );
- $this->assertSame( ' – ', wptexturize( ' - ' ) );
- $this->assertSame( ' – ', wptexturize( ' - ' ) );
- $this->assertSame( ' – ', wptexturize( ' - ' ) );
- $this->assertSame( "$nbsp–$nbsp", wptexturize( "$nbsp-$nbsp" ) );
- $this->assertSame( " –$nbsp", wptexturize( " -$nbsp" ) );
- $this->assertSame( "$nbsp– ", wptexturize( "$nbsp- " ) );
- $this->assertSame( ' — ', wptexturize( ' -- ' ) );
- $this->assertSame( ' — ', wptexturize( ' -- ' ) );
- $this->assertSame( ' — ', wptexturize( ' -- ' ) );
- $this->assertSame( ' — ', wptexturize( ' -- ' ) );
- $this->assertSame( "$nbsp—$nbsp", wptexturize( "$nbsp--$nbsp" ) );
- $this->assertSame( " —$nbsp", wptexturize( " --$nbsp" ) );
- $this->assertSame( "$nbsp— ", wptexturize( "$nbsp-- " ) );
- }
- /**
- * @ticket 31030
- */
- function test_hyphens_at_start_and_end() {
- $this->assertSame( '– ', wptexturize( '- ' ) );
- $this->assertSame( '– –', wptexturize( '- -' ) );
- $this->assertSame( ' –', wptexturize( ' -' ) );
- $this->assertSame( '— ', wptexturize( '-- ' ) );
- $this->assertSame( '— —', wptexturize( '-- --' ) );
- $this->assertSame( ' —', wptexturize( ' --' ) );
- }
- /**
- * Test spaces around quotes.
- *
- * These should never happen, even if the desired output changes some day.
- *
- * @ticket 22692
- */
- function test_spaces_around_quotes_never() {
- $nbsp = "\xC2\xA0";
- $problem_input = "$nbsp\"A";
- $problem_output = "$nbsp”A";
- $this->assertNotEquals( $problem_output, wptexturize( $problem_input ) );
- }
- /**
- * Test spaces around quotes.
- *
- * These are desirable outputs for the current design.
- *
- * @ticket 22692
- * @dataProvider data_spaces_around_quotes
- */
- function test_spaces_around_quotes( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_spaces_around_quotes() {
- $nbsp = "\xC2\xA0";
- $pi = "\xCE\xA0";
- return array(
- array(
- "stop. $nbsp\"A quote after 2 spaces.\"",
- "stop. $nbsp“A quote after 2 spaces.”",
- ),
- array(
- "stop.$nbsp$nbsp\"A quote after 2 spaces.\"",
- "stop.$nbsp$nbsp“A quote after 2 spaces.”",
- ),
- array(
- "stop. $nbsp'A quote after 2 spaces.'",
- "stop. $nbsp‘A quote after 2 spaces.’",
- ),
- array(
- "stop.$nbsp$nbsp'A quote after 2 spaces.'",
- "stop.$nbsp$nbsp‘A quote after 2 spaces.’",
- ),
- array(
- 'stop. "A quote after 2 spaces."',
- 'stop. “A quote after 2 spaces.”',
- ),
- array(
- 'stop. "A quote after 2 spaces."',
- 'stop. “A quote after 2 spaces.”',
- ),
- array(
- "stop. 'A quote after 2 spaces.'",
- 'stop. ‘A quote after 2 spaces.’',
- ),
- array(
- "stop. 'A quote after 2 spaces.'",
- 'stop. ‘A quote after 2 spaces.’',
- ),
- array(
- "Contraction: $pi's",
- "Contraction: $pi’s",
- ),
- );
- }
- /**
- * Apostrophe before a number always becomes ’ (apos);
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_apos_before_digits
- */
- function test_apos_before_digits( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_apos_before_digits() {
- return array(
- array(
- "word '99 word",
- 'word ’99 word',
- ),
- array(
- "word'99 word",
- 'word’99 word',
- ),
- array(
- "word '99word",
- 'word ’99word',
- ),
- array(
- "word'99word",
- 'word’99word',
- ),
- array(
- "word '99’s word", // Appears as a separate but logically superfluous pattern in 3.8.
- 'word ’99’s word',
- ),
- array(
- "according to our source, '33 students scored less than 50' on the test.", // Apostrophes and primes have priority over quotes.
- 'according to our source, ’33 students scored less than 50′ on the test.',
- ),
- );
- }
- /**
- * Apostrophe after a space or ([{<" becomes ‘ (opening_single_quote)
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_opening_single_quote
- */
- function test_opening_single_quote( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_opening_single_quote() {
- return array(
- array(
- "word 'word word",
- 'word ‘word word',
- ),
- array(
- "word ('word word",
- 'word (‘word word',
- ),
- array(
- "word ['word word",
- 'word [‘word word',
- ),
- array(
- "word <'word word", // Invalid HTML.
- "word <'word word",
- ),
- array(
- "word <'word word", // Valid HTML input makes curly quotes.
- 'word <‘word word',
- ),
- array(
- "word {'word word",
- 'word {‘word word',
- ),
- array(
- "word \"'word word",
- 'word “‘word word', // Two opening quotes.
- ),
- array(
- "'word word",
- '‘word word',
- ),
- array(
- "word('word word",
- 'word(‘word word',
- ),
- array(
- "word['word word",
- 'word[‘word word',
- ),
- array(
- "word<'word word",
- "word<'word word",
- ),
- array(
- "word<'word word",
- 'word<‘word word',
- ),
- array(
- "word{'word word",
- 'word{‘word word',
- ),
- array(
- "word\"'word word",
- 'word”‘word word', // Closing quote, then opening quote.
- ),
- array(
- "word ' word word",
- 'word ‘ word word',
- ),
- array(
- "word (' word word",
- 'word (‘ word word',
- ),
- array(
- "word [' word word",
- 'word [‘ word word',
- ),
- array(
- "word <' word word",
- "word <' word word",
- ),
- array(
- "word <' word word",
- 'word <‘ word word',
- ),
- array(
- "word {' word word",
- 'word {‘ word word',
- ),
- array(
- "word \"' word word",
- 'word “‘ word word', // Two opening quotes.
- ),
- array(
- "' word word",
- '‘ word word',
- ),
- array(
- "word(' word word",
- 'word(‘ word word',
- ),
- array(
- "word[' word word",
- 'word[‘ word word',
- ),
- array(
- "word<' word word",
- "word<' word word",
- ),
- array(
- "word<' word word",
- 'word<‘ word word',
- ),
- array(
- "word{' word word",
- 'word{‘ word word',
- ),
- array(
- "word\"' word word",
- 'word”‘ word word', // Closing quote, then opening quote.
- ),
- );
- }
- /**
- * Double quote after a number becomes ″ (double_prime)
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_double_prime
- */
- function test_double_prime( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_double_prime() {
- return array(
- array(
- 'word 99" word',
- 'word 99″ word',
- ),
- array(
- 'word 99"word',
- 'word 99″word',
- ),
- array(
- 'word99" word',
- 'word99″ word',
- ),
- array(
- 'word99"word',
- 'word99″word',
- ),
- );
- }
- /**
- * Apostrophe after a number becomes ′ (prime)
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_single_prime
- */
- function test_single_prime( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_single_prime() {
- return array(
- array(
- "word 99' word",
- 'word 99′ word',
- ),
- array(
- "word 99'word", // Not a prime anymore. Apostrophes get priority.
- 'word 99’word',
- ),
- array(
- "word99' word",
- 'word99′ word',
- ),
- array(
- "word99'word", // Not a prime anymore.
- 'word99’word',
- ),
- );
- }
- /**
- * Apostrophe "in a word" becomes ’ (apos)
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_contractions
- */
- function test_contractions( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_contractions() {
- return array(
- array(
- "word word's word",
- 'word word’s word',
- ),
- array(
- "word'[ word", // Apostrophes are never followed by opening punctuation.
- "word'[ word",
- ),
- array(
- "word'( word",
- "word'( word",
- ),
- array(
- "word'{ word",
- "word'{ word",
- ),
- array(
- "word'< word",
- "word'< word",
- ),
- array(
- "word'< word", // Invalid HTML input does trigger the apos pattern.
- 'word’< word',
- ),
- );
- }
- /**
- * Double quote after a space or ([-{< becomes “ (opening_quote) if not followed by spaces
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_opening_quote
- */
- function test_opening_quote( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_opening_quote() {
- return array(
- array(
- 'word "word word',
- 'word “word word',
- ),
- array(
- 'word ("word word',
- 'word (“word word',
- ),
- array(
- 'word ["word word',
- 'word [“word word',
- ),
- array(
- 'word <"word word', // Invalid HTML.
- 'word <"word word',
- ),
- array(
- 'word <"word word',
- 'word <“word word',
- ),
- array(
- 'word {"word word',
- 'word {“word word',
- ),
- array(
- 'word -"word word',
- 'word -“word word',
- ),
- array(
- 'word-"word word',
- 'word-“word word',
- ),
- array(
- '"word word',
- '“word word',
- ),
- array(
- 'word("word word',
- 'word(“word word',
- ),
- array(
- 'word["word word',
- 'word[“word word',
- ),
- array(
- 'word<"word word',
- 'word<"word word',
- ),
- array(
- 'word<"word word',
- 'word<“word word',
- ),
- array(
- 'word{"word word',
- 'word{“word word',
- ),
- array(
- 'word "99 word',
- 'word “99 word',
- ),
- );
- }
- /**
- * Double quote becomes ” (closing_quote) unless it is already converted to double_prime or opening_quote.
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_closing_quote
- */
- function test_closing_quote( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_closing_quote() {
- return array(
- array(
- 'word word" word',
- 'word word” word',
- ),
- array(
- 'word word") word',
- 'word word”) word',
- ),
- array(
- 'word word"] word',
- 'word word”] word',
- ),
- array(
- 'word word"} word',
- 'word word”} word',
- ),
- array(
- 'word word"> word', // Invalid HTML input?
- 'word word”> word',
- ),
- array(
- 'word word"> word', // Valid HTML should work.
- 'word word”> word',
- ),
- array(
- 'word word"',
- 'word word”',
- ),
- array(
- 'word word"word',
- 'word word”word',
- ),
- array(
- 'word"word"word',
- 'word”word”word',
- ),
- array(
- 'test sentence".',
- 'test sentence”.',
- ),
- array(
- 'test sentence",',
- 'test sentence”,',
- ),
- array(
- 'test sentence":',
- 'test sentence”:',
- ),
- array(
- 'test sentence";',
- 'test sentence”;',
- ),
- array(
- 'test sentence"!',
- 'test sentence”!',
- ),
- array(
- 'test sentence"?',
- 'test sentence”?',
- ),
- array(
- 'test sentence."',
- 'test sentence.”',
- ),
- array(
- 'test sentence". word',
- 'test sentence”. word',
- ),
- array(
- 'test sentence." word',
- 'test sentence.” word',
- ),
- );
- }
- /**
- * Test that single quotes followed by a space or .,-)}]> become ’ (closing_single_quote)
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_closing_single_quote
- */
- function test_closing_single_quote( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_closing_single_quote() {
- return array(
- array(
- "word word' word",
- 'word word’ word',
- ),
- array(
- "word word'. word",
- 'word word’. word',
- ),
- array(
- "word word'.word",
- 'word word’.word',
- ),
- array(
- "word word', she said",
- 'word word’, she said',
- ),
- array(
- "word word': word",
- 'word word’: word',
- ),
- array(
- "word word'; word",
- 'word word’; word',
- ),
- array(
- "word word'! word",
- 'word word’! word',
- ),
- array(
- "word word'? word",
- 'word word’? word',
- ),
- array(
- "word word'- word",
- 'word word’- word',
- ),
- array(
- "word word') word",
- 'word word’) word',
- ),
- array(
- "word word'} word",
- 'word word’} word',
- ),
- array(
- "word word'] word",
- 'word word’] word',
- ),
- array(
- "word word'> word",
- 'word word’> word',
- ),
- array(
- "word word'",
- 'word word’',
- ),
- array(
- "test sentence'.",
- 'test sentence’.',
- ),
- array(
- "test sentence.'",
- 'test sentence.’',
- ),
- array(
- "test sentence'. word",
- 'test sentence’. word',
- ),
- array(
- "test sentence.' word",
- 'test sentence.’ word',
- ),
- );
- }
- /**
- * Tests multiplication.
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @ticket 30445
- * @dataProvider data_multiplication
- */
- function test_multiplication( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_multiplication() {
- return array(
- array(
- '9x9',
- '9×9',
- ),
- array(
- '12x34',
- '12×34',
- ),
- array(
- '-123x1=-123',
- '-123×1=-123',
- ),
- // @ticket 30445
- array(
- '-123x-1',
- '-123x-1',
- ),
- array(
- '0.675x1=0.675',
- '0.675×1=0.675',
- ),
- array(
- '9 x 9',
- '9 x 9',
- ),
- array(
- '0x70',
- '0x70',
- ),
- array(
- '3x2x1x0',
- '3x2x1x0',
- ),
- );
- }
- /**
- * Test ampersands. & always becomes & unless it is followed by # or ;
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_ampersand
- */
- function test_ampersand( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_ampersand() {
- return array(
- array(
- 'word & word',
- 'word & word',
- ),
- array(
- 'word&word',
- 'word&word',
- ),
- array(
- 'word word',
- 'word word',
- ),
- array(
- 'word & word',
- 'word & word',
- ),
- array(
- 'word ઼ word',
- 'word ઼ word',
- ),
- array(
- 'word Δ word',
- 'word Δ word',
- ),
- array(
- 'word &# word',
- 'word &# word',
- ),
- array(
- 'word &44; word',
- 'word &44; word',
- ),
- array(
- 'word && word',
- 'word && word',
- ),
- array(
- 'word &!amp; word',
- 'word &!amp; word',
- ),
- array(
- 'word &#',
- 'word &#',
- ),
- array(
- 'word &',
- 'word &',
- ),
- );
- }
- /**
- * Test "cockney" phrases, which begin with an apostrophe instead of an opening single quote.
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_cockney
- */
- function test_cockney( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_cockney() {
- return array(
- array(
- "word 'tain't word",
- 'word ’tain’t word',
- ),
- array(
- "word 'twere word",
- 'word ’twere word',
- ),
- array(
- "word 'twas word",
- 'word ’twas word',
- ),
- array(
- "word 'tis word",
- 'word ’tis word',
- ),
- array(
- "word 'twill word",
- 'word ’twill word',
- ),
- array(
- "word 'til word",
- 'word ’til word',
- ),
- array(
- "word 'bout word",
- 'word ’bout word',
- ),
- array(
- "word 'nuff word",
- 'word ’nuff word',
- ),
- array(
- "word 'round word",
- 'word ’round word',
- ),
- array(
- "word 'cause word",
- 'word ’cause word',
- ),
- array(
- "word 'em word",
- 'word ’em word',
- ),
- );
- }
- /**
- * Test smart dashes.
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_smart_dashes
- */
- function test_smart_dashes( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_smart_dashes() {
- return array(
- array(
- 'word --- word',
- 'word — word',
- ),
- array(
- 'word---word',
- 'word—word',
- ),
- array(
- 'word -- word',
- 'word — word',
- ),
- array(
- 'word--word',
- 'word–word',
- ),
- array(
- 'word - word',
- 'word – word',
- ),
- array(
- 'word-word',
- 'word-word',
- ),
- array(
- 'word xn– word',
- 'word xn– word',
- ),
- array(
- 'wordxn–word',
- 'wordxn–word',
- ),
- array(
- 'wordxn--word',
- 'wordxn--word',
- ),
- );
- }
- /**
- * Test miscellaneous static replacements.
- *
- * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
- *
- * @ticket 22692
- * @dataProvider data_misc_static_replacements
- */
- function test_misc_static_replacements( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_misc_static_replacements() {
- return array(
- array(
- 'word ... word',
- 'word … word',
- ),
- array(
- 'word...word',
- 'word…word',
- ),
- array(
- 'word `` word',
- 'word “ word',
- ),
- array(
- 'word``word',
- 'word“word',
- ),
- array(
- "word '' word",
- 'word ” word',
- ),
- array(
- "word''word",
- 'word”word',
- ),
- array(
- 'word (tm) word',
- 'word ™ word',
- ),
- array(
- 'word (tm)word',
- 'word ™word',
- ),
- array(
- 'word(tm) word',
- 'word(tm) word',
- ),
- array(
- 'word(tm)word',
- 'word(tm)word',
- ),
- );
- }
- /**
- * Numbers inside of matching quotes get curly quotes instead of apostrophes and primes.
- *
- * @ticket 8775
- * @dataProvider data_quoted_numbers
- */
- function test_quoted_numbers( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_quoted_numbers() {
- return array(
- array(
- 'word "42.00" word',
- 'word “42.00” word',
- ),
- array(
- 'word "42.00"word',
- 'word “42.00”word',
- ),
- array(
- "word '42.00' word",
- 'word ‘42.00’ word',
- ),
- array(
- "word '42.00'word",
- 'word ‘42.00’word',
- ),
- array(
- 'word "42" word',
- 'word “42” word',
- ),
- array(
- 'word "42,00" word',
- 'word “42,00” word',
- ),
- array(
- 'word "4,242.00" word',
- 'word “4,242.00” word',
- ),
- array(
- "word '99's word",
- 'word ’99’s word',
- ),
- array(
- "word '99'samsonite",
- 'word ’99’samsonite',
- ),
- );
- }
- /**
- * Quotations should be allowed to have dashes around them.
- *
- * @ticket 20342
- * @dataProvider data_quotes_and_dashes
- */
- function test_quotes_and_dashes( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_quotes_and_dashes() {
- return array(
- array(
- 'word---"quote"',
- 'word—“quote”',
- ),
- array(
- 'word--"quote"',
- 'word–“quote”',
- ),
- array(
- 'word-"quote"',
- 'word-“quote”',
- ),
- array(
- "word---'quote'",
- 'word—‘quote’',
- ),
- array(
- "word--'quote'",
- 'word–‘quote’',
- ),
- array(
- "word-'quote'",
- 'word-‘quote’',
- ),
- array(
- '"quote"---word',
- '“quote”—word',
- ),
- array(
- '"quote"--word',
- '“quote”–word',
- ),
- array(
- '"quote"-word',
- '“quote”-word',
- ),
- array(
- "'quote'---word",
- '‘quote’—word',
- ),
- array(
- "'quote'--word",
- '‘quote’–word',
- ),
- array(
- "'quote'-word",
- '‘quote’-word',
- ),
- );
- }
- /**
- * Test HTML and shortcode avoidance.
- *
- * @ticket 12690
- * @dataProvider data_tag_avoidance
- */
- function test_tag_avoidance( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_tag_avoidance() {
- return array(
- array(
- '[ ... ]',
- '[ … ]',
- ),
- array(
- '[ is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
- '[ is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
- ),
- array(
- '[is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
- '[is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
- ),
- array(
- '[caption - is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
- '[caption – is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
- ),
- array(
- '[ photos by <a href="http://example.com/?a[]=1&a[]=2"> this guy & that guy </a> ]',
- '[ photos by <a href="http://example.com/?a[]=1&a[]=2"> this guy & that guy </a> ]',
- ),
- array(
- '[photos by <a href="http://example.com/?a[]=1&a[]=2"> this guy & that guy </a>]',
- '[photos by <a href="http://example.com/?a[]=1&a[]=2"> this guy & that guy </a>]',
- ),
- array(
- '& <script>&&</script>',
- '& <script>&&</script>',
- ),
- array(
- '[gallery ...]',
- '[gallery ...]',
- ),
- array(
- '[[gallery ...]', // This tag is still valid.
- '[[gallery ...]',
- ),
- array(
- '[gallery ...]]', // This tag is also valid.
- '[gallery ...]]',
- ),
- array(
- '[/gallery ...]', // This would actually be ignored by the shortcode system.
- '[/gallery ...]', // The decision to not texturize it is intentional, if not correct.
- ),
- array(
- '[[gallery]]...[[/gallery]]', // Shortcode parsing will ignore the inner ']...[' part and treat this as a single escaped shortcode.
- '[[gallery]]…[[/gallery]]',
- ),
- array(
- '[[[gallery]]]...[[[/gallery]]]', // Again, shortcode parsing matches, but only the '[[gallery]' and '[/gallery]]' parts.
- '[[[gallery]]]…[[[/gallery]]]',
- ),
- array(
- '[gallery ...',
- '[gallery …',
- ),
- array(
- '[gallery <br ... /> ...]', // This tag is still valid. Shortcode 'attributes' are not considered
- '[gallery <br ... /> ...]', // in the initial parsing of shortcodes, and HTML is allowed.
- ),
- array(
- '<br [gallery ...] ... />',
- '<br [gallery ...] ... />',
- ),
- array(
- '<br [gallery ...] ... /',
- '<br [gallery ...] ... /',
- ),
- array(
- '<br ... />',
- '<br ... />',
- ),
- array(
- '<br ... />...<br ... />',
- '<br ... />…<br ... />',
- ),
- array(
- '[gallery ...]...[gallery ...]',
- '[gallery ...]…[gallery ...]',
- ),
- array(
- '[[gallery ...]]',
- '[[gallery ...]]',
- ),
- array(
- '[[gallery ...]',
- '[[gallery ...]',
- ),
- array(
- '[gallery ...]]',
- '[gallery ...]]',
- ),
- array(
- '[/gallery ...]]',
- '[/gallery ...]]',
- ),
- array(
- '[[gallery <br ... /> ...]]', // This gets parsed as an escaped shortcode with embedded HTML. Brains may explode.
- '[[gallery <br ... /> ...]]',
- ),
- array(
- '<br [[gallery ...]] ... />',
- '<br [[gallery ...]] ... />',
- ),
- array(
- '<br [[gallery ...]] ... /',
- '<br [[gallery ...]] ... /',
- ),
- array(
- '[[gallery ...]]...[[gallery ...]]',
- '[[gallery ...]]…[[gallery ...]]',
- ),
- array(
- '[[gallery ...]...[/gallery]]',
- '[[gallery ...]…[/gallery]]',
- ),
- array(
- '<!-- ... -->',
- '<!-- ... -->',
- ),
- array(
- '<!--...-->',
- '<!--...-->',
- ),
- array(
- '<!-- ... -- > ...',
- '<!-- ... -- > ...',
- ),
- array(
- '<!-- ...', // An unclosed comment is still a comment.
- '<!-- ...',
- ),
- array(
- 'a<!-->b', // Browsers seem to allow this.
- 'a<!-->b',
- ),
- array(
- 'a<!--->b',
- 'a<!--->b',
- ),
- array(
- 'a<!---->b',
- 'a<!---->b',
- ),
- array(
- 'a<!----->b',
- 'a<!----->b',
- ),
- array(
- 'a<!-- c --->b',
- 'a<!-- c --->b',
- ),
- array(
- 'a<!-- c -- d -->b',
- 'a<!-- c -- d -->b',
- ),
- array(
- 'a<!-- <!-- c --> -->b<!-- close -->',
- 'a<!-- <!-- c --> –>b<!-- close -->',
- ),
- array(
- '<!-- <br /> [gallery] ... -->',
- '<!-- <br /> [gallery] ... -->',
- ),
- array(
- '...<!-- ... -->...',
- '…<!-- ... -->…',
- ),
- array(
- '[gallery ...]...<!-- ... -->...<br ... />',
- '[gallery ...]…<!-- ... -->…<br ... />',
- ),
- array(
- '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>',
- '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>',
- ),
- array(
- 'word <img src="http://example.com/wp-content/uploads/2014/06/image-300x216.gif" /> word', // Ensure we are not corrupting image URLs.
- 'word <img src="http://example.com/wp-content/uploads/2014/06/image-300x216.gif" /> word',
- ),
- array(
- '[ do texturize "[quote]" here ]',
- '[ do texturize “[quote]” here ]',
- ),
- array(
- '[ regex catches this <a href="[quote]">here</a> ]',
- '[ regex catches this <a href="[quote]">here</a> ]',
- ),
- array(
- '[ but also catches the <b>styled "[quote]" here</b> ]',
- '[ but also catches the <b>styled “[quote]” here</b> ]',
- ),
- array(
- '[Let\'s get crazy<input>[caption code="<a href=\'?a[]=100\'>hello</a>"]</input>world]', // [caption] shortcode is invalid here because it contains '[]' chars.
- '[Let’s get crazy<input>[caption code=”<a href=\'?a[]=100\'>hello</a>“]</input>world]',
- ),
- array(
- '<> ... <>',
- '<> … <>',
- ),
- array(
- '<> ... <> ... >',
- '<> … <> … >',
- ),
- array(
- '<> ... < ... > ... <>',
- '<> … < ... > … <>',
- ),
- );
- }
- /**
- * Year abbreviations consist of exactly two digits.
- *
- * @ticket 26850
- * @dataProvider data_year_abbr
- */
- function test_year_abbr( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_year_abbr() {
- return array(
- array(
- "word '99 word",
- 'word ’99 word',
- ),
- array(
- "word '99. word",
- 'word ’99. word',
- ),
- array(
- "word '99, word",
- 'word ’99, word',
- ),
- array(
- "word '99; word",
- 'word ’99; word',
- ),
- array(
- "word '99' word", // For this pattern, prime doesn't make sense. Should get apos and a closing quote.
- 'word ’99’ word',
- ),
- array(
- "word '99'. word",
- 'word ’99’. word',
- ),
- array(
- "word '99', word",
- 'word ’99’, word',
- ),
- array(
- "word '99.' word",
- 'word ’99.’ word',
- ),
- array(
- "word '99",
- 'word ’99',
- ),
- array(
- "'99 word",
- '’99 word',
- ),
- array(
- "word '999 word", // Does not match the apos pattern, should be opening quote.
- 'word ‘999 word',
- ),
- array(
- "word '99% word",
- 'word ‘99% word',
- ),
- array(
- "word '9 word",
- 'word ‘9 word',
- ),
- array(
- "word '99.9 word",
- 'word ‘99.9 word',
- ),
- array(
- "word '999",
- 'word ‘999',
- ),
- array(
- "word '9",
- 'word ‘9',
- ),
- array(
- "in '4 years, 3 months,' Obama cut the deficit",
- 'in ‘4 years, 3 months,’ Obama cut the deficit',
- ),
- array(
- "testing's '4' through 'quotes'",
- 'testing’s ‘4’ through ‘quotes’',
- ),
- );
- }
- /**
- * Make sure translation actually works.
- *
- * Also make sure apostrophes and closing quotes aren't being confused by default.
- *
- * @ticket 27426
- * @dataProvider data_translate
- */
- function test_translate( $input, $output ) {
- add_filter( 'gettext_with_context', array( $this, 'filter_translate' ), 10, 4 );
- $result = wptexturize( $input, true );
- remove_filter( 'gettext_with_context', array( $this, 'filter_translate' ), 10, 4 );
- wptexturize( 'reset', true );
- return $this->assertSame( $output, $result );
- }
- function filter_translate( $translations, $text, $context, $domain ) {
- switch ( $text ) {
- case '–':
- return '!endash!';
- case '—':
- return '!emdash!';
- case '‘':
- return '!openq1!';
- case '’':
- if ( 'apostrophe' === $context ) {
- return '!apos!';
- } else {
- return '!closeq1!';
- }
- case '“':
- return '!openq2!';
- case '”':
- return '!closeq2!';
- case '′':
- return '!prime1!';
- case '″':
- return '!prime2!';
- case '’tain’t,’twere,’twas,’tis,’twill,’til,’bout,’nuff,’round,’cause,’em':
- return '!apos!tain!apos!t,!apos!twere,!apos!twas,!apos!tis,!apos!twill,!apos!til,!apos!bout,!apos!nuff,!apos!round,!apos!cause,!apos!em';
- default:
- return $translations;
- }
- }
- function data_translate() {
- return array(
- array(
- "word '99 word",
- 'word !apos!99 word',
- ),
- array(
- "word'99 word",
- 'word!apos!99 word',
- ),
- array(
- "word 'test sentence' word",
- 'word !openq1!test sentence!closeq1! word',
- ),
- array(
- "'test sentence'",
- '!openq1!test sentence!closeq1!',
- ),
- array(
- 'word "test sentence" word',
- 'word !openq2!test sentence!closeq2! word',
- ),
- array(
- '"test sentence"',
- '!openq2!test sentence!closeq2!',
- ),
- array(
- "word 'word word",
- 'word !openq1!word word',
- ),
- array(
- "word ('word word",
- 'word (!openq1!word word',
- ),
- array(
- "word ['word word",
- 'word [!openq1!word word',
- ),
- array(
- 'word 99" word',
- 'word 99!prime2! word',
- ),
- array(
- 'word 99"word',
- 'word 99!prime2!word',
- ),
- array(
- 'word99" word',
- 'word99!prime2! word',
- ),
- array(
- 'word99"word',
- 'word99!prime2!word',
- ),
- array(
- "word 99' word",
- 'word 99!prime1! word',
- ),
- array(
- "word99' word",
- 'word99!prime1! word',
- ),
- array(
- "word word's word",
- 'word word!apos!s word',
- ),
- array(
- "word word'. word",
- 'word word!closeq1!. word',
- ),
- array(
- "word ]'. word",
- 'word ]!closeq1!. word',
- ),
- array(
- 'word "word word',
- 'word !openq2!word word',
- ),
- array(
- 'word ("word word',
- 'word (!openq2!word word',
- ),
- array(
- 'word ["word word',
- 'word [!openq2!word word',
- ),
- array(
- 'word word" word',
- 'word word!closeq2! word',
- ),
- array(
- 'word word") word',
- 'word word!closeq2!) word',
- ),
- array(
- 'word word"] word',
- 'word word!closeq2!] word',
- ),
- array(
- 'word word"',
- 'word word!closeq2!',
- ),
- array(
- 'word word"word',
- 'word word!closeq2!word',
- ),
- array(
- 'test sentence".',
- 'test sentence!closeq2!.',
- ),
- array(
- 'test sentence."',
- 'test sentence.!closeq2!',
- ),
- array(
- 'test sentence." word',
- 'test sentence.!closeq2! word',
- ),
- array(
- "word word' word",
- 'word word!closeq1! word',
- ),
- array(
- "word word'. word",
- 'word word!closeq1!. word',
- ),
- array(
- "word word'.word",
- 'word word!closeq1!.word',
- ),
- array(
- "word word'",
- 'word word!closeq1!',
- ),
- array(
- "test sentence'.",
- 'test sentence!closeq1!.',
- ),
- array(
- "test sentence.'",
- 'test sentence.!closeq1!',
- ),
- array(
- "test sentence'. word",
- 'test sentence!closeq1!. word',
- ),
- array(
- "test sentence.' word",
- 'test sentence.!closeq1! word',
- ),
- array(
- "word 'tain't word",
- 'word !apos!tain!apos!t word',
- ),
- array(
- "word 'twere word",
- 'word !apos!twere word',
- ),
- array(
- 'word "42.00" word',
- 'word !openq2!42.00!closeq2! word',
- ),
- array(
- "word '42.00' word",
- 'word !openq1!42.00!closeq1! word',
- ),
- array(
- "word word'. word",
- 'word word!closeq1!. word',
- ),
- array(
- "word word'.word",
- 'word word!closeq1!.word',
- ),
- array(
- "word word', she said",
- 'word word!closeq1!, she said',
- ),
- );
- }
- /**
- * Extra sanity checks for _wptexturize_pushpop_element()
- *
- * @ticket 28483
- * @dataProvider data_element_stack
- */
- function test_element_stack( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_element_stack() {
- return array(
- array(
- '<span>hello</code>---</span>',
- '<span>hello</code>—</span>',
- ),
- array(
- '</code>hello<span>---</span>',
- '</code>hello<span>—</span>',
- ),
- array(
- '<code>hello</code>---</span>',
- '<code>hello</code>—</span>',
- ),
- array(
- '<span>hello</span>---<code>',
- '<span>hello</span>—<code>',
- ),
- array(
- '<span>hello<code>---</span>',
- '<span>hello<code>---</span>',
- ),
- array(
- '<code>hello<span>---</span>',
- '<code>hello<span>---</span>',
- ),
- array(
- '<code>hello</span>---</span>',
- '<code>hello</span>---</span>',
- ),
- array(
- '<span><code>hello</code>---</span>',
- '<span><code>hello</code>—</span>',
- ),
- array(
- '<code>hello</code>world<span>---</span>',
- '<code>hello</code>world<span>—</span>',
- ),
- );
- }
- /**
- * Test disabling shortcode texturization.
- *
- * @ticket 29557
- * @dataProvider data_unregistered_shortcodes
- */
- function test_unregistered_shortcodes( $input, $output ) {
- add_filter( 'no_texturize_shortcodes', array( $this, 'filter_shortcodes' ), 10, 1 );
- $output = $this->assertSame( $output, wptexturize( $input ) );
- remove_filter( 'no_texturize_shortcodes', array( $this, 'filter_shortcodes' ), 10, 1 );
- return $output;
- }
- function filter_shortcodes( $disabled ) {
- $disabled[] = 'audio';
- return $disabled;
- }
- function data_unregistered_shortcodes() {
- return array(
- array(
- '[a]a--b[audio]---[/audio]a--b[/a]',
- '[a]a–b[audio]---[/audio]a–b[/a]',
- ),
- array(
- '[code ...]...[/code]', // '[code]' is not a registered shortcode.
- '[code …]…[/code]',
- ),
- array(
- '[hello ...]...[/hello]', // '[hello]' is not a registered shortcode.
- '[hello …]…[/hello]',
- ),
- array(
- '[...]...[/...]', // These are potentially usable shortcodes.
- '[…]…[/…]',
- ),
- array(
- '[gal>ery ...]',
- '[gal>ery …]',
- ),
- array(
- '[randomthing param="test"]',
- '[randomthing param=”test”]',
- ),
- array(
- '[[audio]...[/audio]...', // These are potentially usable shortcodes.
- '[[audio]…[/audio]…', // Unfortunately, the meaning of [[audio] is ambiguous unless we run the entire shortcode regexp.
- ),
- array(
- '[audio]...[/audio]]...', // These are potentially usable shortcodes.
- '[audio]...[/audio]]...', // Unfortunately, the meaning of [/audio]] is ambiguous unless we run the entire shortcode regexp.
- ), // This test would not pass in 3.9 because the extra brace was always ignored by texturize.
- array(
- '<span>hello[/audio]---</span>',
- '<span>hello[/audio]—</span>',
- ),
- array(
- '[/audio]hello<span>---</span>',
- '[/audio]hello<span>—</span>',
- ),
- array(
- '[audio]hello[/audio]---</span>',
- '[audio]hello[/audio]—</span>',
- ),
- array(
- '<span>hello</span>---[audio]',
- '<span>hello</span>—[audio]',
- ),
- array(
- '<span>hello[audio]---</span>',
- '<span>hello[audio]---</span>',
- ),
- array(
- '[audio]hello<span>---</span>',
- '[audio]hello<span>---</span>',
- ),
- array(
- '[audio]hello</span>---</span>',
- '[audio]hello</span>---</span>',
- ),
- );
- }
- /**
- * Ensure primes logic is not too greedy at the end of a quotation.
- *
- * @ticket 29256
- * @dataProvider data_primes_vs_quotes
- */
- function test_primes_vs_quotes( $input, $output ) {
- return $this->assertSame( $output, wptexturize( $input ) );
- }
- function data_primes_vs_quotes() {
- return array(
- array(
- "George's porch is 99' long.",
- 'George’s porch is 99′ long.',
- ),
- array(
- 'The best year "was that time in 2012" when everyone partied, he said.',
- 'The best year “was that time in 2012” when everyone partied, he said.',
- ),
- array(
- "I need 4 x 20' = 80' of trim.", // Works only with a space before the '=' char.
- 'I need 4 x 20′ = 80′ of trim.',
- ),
- array(
- '"Lorem ipsum dolor sit amet 1234"',
- '“Lorem ipsum dolor sit amet 1234”',
- ),
- array(
- "'Etiam eu egestas dui 1234'",
- '‘Etiam eu egestas dui 1234’',
- ),
- array(
- 'according to our source, "33% of all students scored less than 50" on the test.',
- 'according to our source, “33% of all students scored less than 50” on the test.',
- ),
- array(
- "The doctor said, 'An average height is between 5' and 6' in study group 7'. He then produced a 6' chart of averages. A man of 7', incredibly, is very possible.",
- 'The doctor said, ‘An average height is between 5′ and 6′ in study group 7’. He then produced a 6′ chart of averages. A man of 7′, incredibly, is very possible.',
- ),
- array(
- 'Pirates have voted on "The Expendables 3" with their clicks -- and it turns out the Sylvester Stallone-starrer hasn\'t been astoundingly popular among digital thieves, relatively speaking.
- As of Sunday, 5.12 million people worldwide had pirated "Expendables 3" since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
- That likely contributed to the action movie\'s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after "Captain America: The Winter Soldier" (7.31 million), "Divergent" (6.29 million) and "The Amazing Spider-Man 2" (5.88 million). Moreover, that\'s despite "Expendables 3" becoming available more than three weeks prior to the film\'s U.S. theatrical debut.
- String with a number followed by a single quote \'Expendables 3\' vestibulum in arcu mi.',
- 'Pirates have voted on “The Expendables 3” with their clicks — and it turns out the Sylvester Stallone-starrer hasn’t been astoundingly popular among digital thieves, relatively speaking.
- As of Sunday, 5.12 million people worldwide had pirated “Expendables 3” since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
- That likely contributed to the action movie’s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after “Captain America: The Winter Soldier” (7.31 million), “Divergent” (6.29 million) and “The Amazing Spider-Man 2” (5.88 million). Moreover, that’s despite “Expendables 3” becoming available more than three weeks prior to the film’s U.S. theatrical debut.
- String with a number followed by a single quote ‘Expendables 3’ vestibulum in arcu mi.',
- ),
- );
- }
- /**
- * Make sure translation actually works.
- *
- * Also make sure opening and closing quotes are allowed to be identical.
- *
- * @ticket 29256
- * @dataProvider data_primes_quotes_translation
- */
- function test_primes_quotes_translation( $input, $output ) {
- add_filter( 'gettext_with_context', array( $this, 'filter_translate2' ), 10, 4 );
- $result = wptexturize( $input, true );
- remove_filter( 'gettext_with_context', array( $this, 'filter_translate2' ), 10, 4 );
- wptexturize( 'reset', true );
- return $this->assertSame( $output, $result );
- }
- function filter_translate2( $translations, $text, $context, $domain ) {
- switch ( $text ) {
- case '–':
- return '!endash!';
- case '—':
- return '!emdash!';
- case '‘':
- return '!q1!';
- case '’':
- if ( 'apostrophe' === $context ) {
- return '!apos!';
- } else {
- return '!q1!';
- }
- case '“':
- return '!q2!';
- case '”':
- return '!q2!';
- case '′':
- return '!prime1!';
- case '″':
- return '!prime2!';
- default:
- return $translations;
- }
- }
- function data_primes_quotes_translation() {
- return array(
- array(
- "George's porch is 99' long.",
- 'George!apos!s porch is 99!prime1! long.',
- ),
- array(
- 'The best year "was that time in 2012" when everyone partied, he said.',
- 'The best year !q2!was that time in 2012!q2! when everyone partied, he said.',
- ),
- array(
- "I need 4 x 20' = 80' of trim.", // Works only with a space before the '=' char.
- 'I need 4 x 20!prime1! = 80!prime1! of trim.',
- ),
- array(
- '"Lorem ipsum dolor sit amet 1234"',
- '!q2!Lorem ipsum dolor sit amet 1234!q2!',
- ),
- array(
- "'Etiam eu egestas dui 1234'",
- '!q1!Etiam eu egestas dui 1234!q1!',
- ),
- array(
- 'according to our source, "33% of all students scored less than 50" on the test.',
- 'according to our source, !q2!33% of all students scored less than 50!q2! on the test.',
- ),
- array(
- "The doctor said, 'An average height is between 5' and 6' in study group 7'. He then produced a 6' chart of averages. A man of 7', incredibly, is very possible.",
- 'The doctor said, !q1!An average height is between 5!prime1! and 6!prime1! in study group 7!q1!. He then produced a 6!prime1! chart of averages. A man of 7!prime1!, incredibly, is very possible.',
- ),
- array(
- 'Pirates have voted on "The Expendables 3" with their clicks -- and it turns out the Sylvester Stallone-starrer hasn\'t been astoundingly popular among digital thieves, relatively speaking.
- As of Sunday, 5.12 million people worldwide had pirated "Expendables 3" since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
- That likely contributed to the action movie\'s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after "Captain America: The Winter Soldier" (7.31 million), "Divergent" (6.29 million) and "The Amazing Spider-Man 2" (5.88 million). Moreover, that\'s despite "Expendables 3" becoming available more than three weeks prior to the film\'s U.S. theatrical debut.
- String with a number followed by a single quote \'Expendables 3\' vestibulum in arcu mi.',
- 'Pirates have voted on !q2!The Expendables 3!q2! with their clicks !emdash! and it turns out the Sylvester Stallone-starrer hasn!apos!t been astoundingly popular among digital thieves, relatively speaking.
- As of Sunday, 5.12 million people worldwide had pirated !q2!Expendables 3!q2! since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
- That likely contributed to the action movie!apos!s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after !q2!Captain America: The Winter Soldier!q2! (7.31 million), !q2!Divergent!q2! (6.29 million) and !q2!The Amazing Spider-Man 2!q2! (5.88 million). Moreover, that!apos!s despite !q2!Expendables 3!q2! becoming available more than three weeks prior to the film!apos!s U.S. theatrical debut.
- String with a number followed by a single quote !q1!Expendables 3!q1! vestibulum in arcu mi.',
- ),
- );
- }
- /**
- * Automated performance testing of the main regex.
- *
- * @dataProvider data_whole_posts
- */
- function test_pcre_performance( $input ) {
- global $shortcode_tags;
- // With shortcodes disabled.
- $regex = _get_wptexturize_split_regex();
- $result = benchmark_pcre_backtracking( $regex, $input, 'split' );
- $this->assertLessThan( 200, $result );
- // With shortcodes enabled.
- $shortcode_regex = _get_wptexturize_shortcode_regex( array_keys( $shortcode_tags ) );
- $regex = _get_wptexturize_split_regex( $shortcode_regex );
- $result = benchmark_pcre_backtracking( $regex, $input, 'split' );
- return $this->assertLessThan( 200, $result );
- }
- /**
- * Ensure that a trailing less-than symbol doesn't cause a PHP warning.
- *
- * @ticket 35864
- */
- function test_trailing_less_than() {
- $this->assertSame( 'F–oo<', wptexturize( 'F--oo<', true ) );
- }
- function data_whole_posts() {
- require_once DIR_TESTDATA . '/formatting/whole-posts.php';
- return data_whole_posts();
- }
- }
|